Skip to content

Commit

Permalink
add semi working navigation stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
atomicptr committed Jul 30, 2017
1 parent ae615f5 commit 57089b2
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 16 deletions.
19 changes: 17 additions & 2 deletions Game.tscn
@@ -1,4 +1,4 @@
[gd_scene load_steps=7 format=1]
[gd_scene load_steps=8 format=1]

[ext_resource path="res://scripts/Game.gd" type="Script" id=1]
[ext_resource path="res://map/tileset.tres" type="TileSet" id=2]
Expand All @@ -15,6 +15,12 @@ extents = Vector2( 2.13882, 156.69 )
custom_solver_bias = 0.0
extents = Vector2( 263.724, 1.84481 )

[sub_resource type="NavigationPolygon" id=3]

vertices = Vector2Array( 139, 201, 290, 200, 304, 200, 138, 224, 250, 200, 455, 210, 491, 276, 458, 276, 393, 273, 417, 231, 290, 100, 250, 100, 169, 91, 253, 87, 282, 89, 306, 97, 392, 73, 459, 77, 484, 82, 371, 99, 311, 97, 369, 75, 235, 296, 364, 294, 390, 298, -102, 406, 205, 297, 602, -106, 610, 404, 486, 176, 489, 154, 506, 30, 30, 71, 31, 50, 100, 38, 130, 46, 120, 75, 98, 75, 458, 187, 462, 176, 428, 211, 230, 180, 230, 120, 251, 120, 346, 178, 304, 179, 250, 180, 417, 209, 428, 186, 488, 299, 452, 302, 393, 232, 368, 271, 260, 33, 258, 11, 369, 3, 281, 64, 147, 89, 147, 111, 120, 95, 307, 120, 290, 119, 463, 154, 370, 197, 391, 208, 59, 259, 67, 237, 390, 21, 429, 21, 429, 51, 229, 10, 234, 32, 191, 20, -100, -106, 190, 41, 80, 170, 60, 170, 60, 130, 80, 130, 190, 180, 190, 120, 290, 180, 446, 50, 466, 58, 234, 273, 35, 267, 205, 275, 31, 287, 6, 291, 9, 266, 132, 19, 169, 19, 170, 40, 343, 120, 254, 63, 111, 200, 80, 190, 170, 200, 101, 18, 10, 49, 39, 251, 41, 231, 30, 190, 490, 25, 446, 3, 115, 221, 97, 96, 80, 100, 30, 100, 10, 70, 230, 100, 170, 100, 168, 111, 230, 200 )
polygons = [ IntArray( 0, 1, 2, 3 ), IntArray( 4, 1, 0 ), IntArray( 5, 6, 7, 8, 9 ), IntArray( 10, 11, 12, 13, 14, 15 ), IntArray( 16, 17, 18, 19, 20, 14, 21 ), IntArray( 22, 23, 24, 25, 26 ), IntArray( 14, 20, 15 ), IntArray( 27, 28, 6, 29, 30, 31 ), IntArray( 32, 33, 34, 35, 36, 37 ), IntArray( 38, 39, 29, 6, 5 ), IntArray( 18, 31, 30 ), IntArray( 40, 5, 9 ), IntArray( 41, 42, 43, 44, 45, 46 ), IntArray( 40, 9, 47, 48 ), IntArray( 49, 6, 28 ), IntArray( 49, 28, 25, 50 ), IntArray( 51, 9, 8, 52 ), IntArray( 53, 54, 55, 21, 56 ), IntArray( 57, 58, 59, 36, 35 ), IntArray( 8, 7, 50, 24 ), IntArray( 24, 50, 25 ), IntArray( 15, 60, 61, 10 ), IntArray( 19, 18, 30, 62 ), IntArray( 63, 19, 62, 39, 48 ), IntArray( 2, 63, 64, 51, 52, 65, 66, 3 ), IntArray( 16, 67, 68, 69 ), IntArray( 70, 71, 72, 73 ), IntArray( 74, 72, 71 ), IntArray( 75, 76, 77, 78 ), IntArray( 41, 79, 80, 42 ), IntArray( 45, 2, 1, 81 ), IntArray( 69, 82, 83, 17, 16 ), IntArray( 23, 22, 84, 52 ), IntArray( 52, 84, 85, 65 ), IntArray( 85, 84, 86 ), IntArray( 85, 86, 26, 87 ), IntArray( 87, 26, 25, 88 ), IntArray( 88, 25, 73, 89 ), IntArray( 35, 90, 91, 92, 12, 57 ), IntArray( 60, 93, 44 ), IntArray( 71, 94, 13, 12, 74 ), IntArray( 95, 96, 75, 97, 0 ), IntArray( 73, 98, 34, 33, 99 ), IntArray( 100, 65, 85, 89 ), IntArray( 101, 100, 89, 73, 102 ), IntArray( 103, 83, 82, 104 ), IntArray( 27, 31, 103, 104 ), IntArray( 73, 27, 104, 55 ), IntArray( 73, 55, 54, 70 ), IntArray( 73, 72, 91 ), IntArray( 73, 91, 90, 98 ), IntArray( 39, 38, 48 ), IntArray( 63, 48, 47, 64 ), IntArray( 105, 3, 66 ), IntArray( 96, 95, 105, 66, 101, 102 ), IntArray( 97, 75, 78 ), IntArray( 21, 14, 56 ), IntArray( 53, 56, 94, 71 ), IntArray( 92, 74, 12 ), IntArray( 32, 37, 106, 107, 108, 109 ), IntArray( 61, 60, 44, 43 ), IntArray( 59, 58, 97, 78, 107, 106 ), IntArray( 11, 43, 42, 110 ), IntArray( 12, 11, 110 ), IntArray( 12, 110, 111 ), IntArray( 112, 12, 111, 97 ), IntArray( 58, 112, 97 ), IntArray( 73, 99, 109 ), IntArray( 109, 108, 102 ), IntArray( 73, 109, 102 ), IntArray( 45, 81, 46 ), IntArray( 113, 41, 46, 4 ), IntArray( 113, 4, 0 ), IntArray( 0, 97, 113 ) ]
outlines = [ Vector2Array( -100, -106, 602, -106, 610, 404, -102, 406 ), Vector2Array( 30, 100, 80, 100, 80, 130, 60, 130, 60, 170, 80, 170, 80, 190, 30, 190 ), Vector2Array( 250, 180, 290, 180, 290, 200, 250, 200 ), Vector2Array( 230, 180, 230, 200, 170, 200, 170, 100, 230, 100, 230, 120, 190, 120, 190, 180 ), Vector2Array( 250, 100, 290, 100, 290, 119, 251, 120 ), Vector2Array( 311, 97, 371, 99, 370, 197, 304, 200, 304, 179, 346, 178, 343, 120, 307, 120, 306, 97 ), Vector2Array( 369, 75, 392, 73, 390, 21, 429, 21, 429, 51, 446, 50, 446, 3, 369, 3 ), Vector2Array( 10, 49, 31, 50, 30, 71, 10, 70 ), Vector2Array( 98, 75, 120, 75, 120, 95, 97, 96 ), Vector2Array( 147, 89, 169, 91, 168, 111, 147, 111 ), Vector2Array( 101, 18, 132, 19, 130, 46, 100, 38 ), Vector2Array( 169, 19, 191, 20, 190, 41, 170, 40 ), Vector2Array( 229, 10, 258, 11, 260, 33, 234, 32 ), Vector2Array( 254, 63, 281, 64, 282, 89, 253, 87 ), Vector2Array( 466, 58, 490, 25, 506, 30, 484, 82, 459, 77 ), Vector2Array( 463, 154, 489, 154, 486, 176, 462, 176 ), Vector2Array( 428, 186, 458, 187, 455, 210, 428, 211 ), Vector2Array( 391, 208, 417, 209, 417, 231, 393, 232 ), Vector2Array( 368, 271, 393, 273, 390, 298, 364, 294 ), Vector2Array( 458, 276, 491, 276, 488, 299, 452, 302 ), Vector2Array( 205, 275, 234, 273, 235, 296, 205, 297 ), Vector2Array( 111, 200, 139, 201, 138, 224, 115, 221 ), Vector2Array( 41, 231, 67, 237, 59, 259, 39, 251 ), Vector2Array( 9, 266, 35, 267, 31, 287, 6, 291 ) ]

[node name="Game" type="Node2D"]

script/script = ExtResource( 1 )
Expand Down Expand Up @@ -155,6 +161,13 @@ collision/mask = 1
occluder/light_mask = 1
tile_data = IntArray( 65583, 3, 65584, 3, 65585, 3, 65586, 3, 65587, 3, 65588, 3, 65589, 3, 65590, 3, 65595, 1, 196604, 1, 131076, 1, 131102, 2, 131119, 3, 131121, 1, 131126, 3, 196616, 1, 196622, 2, 196630, 2, 196647, 1, 196655, 3, 196662, 3, 262191, 3, 262198, 3, 262205, 2, 262215, 1, 327695, 1, 327713, 1, 458751, 1, 393270, 1, 458754, 2, 458758, 1, 458777, 1, 458799, 2, 458821, 1, 524347, 2, 524360, 1, 589857, 2, 589866, 1, 655373, 2, 720962, 1, 720968, 1, 786451, 2, 786479, 1, 786492, 1, 851990, 3, 851991, 3, 851992, 3, 851993, 3, 851994, 3, 851995, 3, 852000, 3, 852001, 3, 852002, 3, 852007, 3, 852008, 3, 852009, 3, 852010, 3, 852011, 3, 852012, 2, 983033, 1, 983036, 1, 917509, 3, 917510, 3, 917511, 3, 917512, 3, 917526, 3, 917548, 3, 983045, 3, 983062, 3, 983084, 3, 983093, 1, 983096, 1, 1048581, 3, 1048598, 3, 1048608, 1, 1048620, 3, 1048644, 1, 1114117, 3, 1114134, 3, 1114156, 3, 1179653, 3, 1179670, 3, 1179692, 3, 1310716, 1, 1245189, 3, 1245206, 3, 1245209, 1, 1245228, 3, 1245235, 1, 1310725, 3, 1310742, 3, 1310764, 3, 1310779, 2, 1376261, 3, 1376276, 1, 1376278, 3, 1376300, 3, 1376326, 1, 1441797, 3, 1441798, 3, 1441799, 3, 1441800, 3, 1441814, 3, 1441836, 3, 1572858, 1, 1507350, 3, 1507351, 3, 1507352, 3, 1507353, 3, 1507354, 3, 1507355, 3, 1507360, 3, 1507361, 3, 1507362, 3, 1507367, 3, 1507368, 3, 1507369, 3, 1507370, 3, 1507371, 3, 1507372, 3, 1507388, 1, 1572919, 2, 1638407, 1, 1638471, 1, 1703951, 2, 1703959, 1, 1703983, 1, 1769522, 2, 1900538, 1, 1900585, 1, 1900600, 1, 1900611, 1, 2031614, 1, 1966086, 2, 2031627, 1, 2031635, 1, 2031643, 1, 2031658, 1, 2031677, 1, 2097185, 1, 2097205, 1, 2293751, 1, 2228226, 2, 2228229, 1, 2228236, 1, 2293780, 1, 2293787, 2, 2293799, 1, 2293807, 2, 2293819, 2, 2424828, 1, 2359362, 1, 2359367, 1, 3407874, 2, 3407877, 2, 3407879, 2, 3407880, 2, 3407881, 2, 3407883, 2, 3407886, 2, 3473410, 2, 3473412, 2, 3473415, 2, 3473419, 2, 3473421, 2, 3538946, 2, 3538947, 2, 3538951, 2, 3538952, 2, 3538953, 2, 3538955, 2, 3538956, 2, 3604482, 2, 3604484, 2, 3604487, 2, 3604491, 2, 3604493, 2, 3670018, 2, 3670021, 2, 3670023, 2, 3670024, 2, 3670025, 2, 3670027, 2, 3670030, 2 )

[node name="Navigation" type="Navigation2D" parent="Map"]

[node name="NavigationPolygonInstance" type="NavigationPolygonInstance" parent="Map/Navigation"]

navpoly = SubResource( 3 )
enabled = true

[node name="Container" type="Node2D" parent="."]

[node name="Camera2D" type="Camera2D" parent="Container"]
Expand Down Expand Up @@ -183,6 +196,8 @@ script/script = ExtResource( 3 )

[node name="Spawners" type="Node2D" parent="Container"]

editor/display_folded = true

[node name="Top" type="Node2D" parent="Container/Spawners"]

transform/pos = Vector2( 256, -50 )
Expand Down Expand Up @@ -214,7 +229,7 @@ autostart = true

[node name="Player" parent="." instance=ExtResource( 4 )]

transform/pos = Vector2( 325.722, 138.216 )
transform/pos = Vector2( 205, 131 )

[connection signal="timeout" from="Container/Spawners/SpawnTimer" to="." method="_on_SpawnTimer_timeout"]

Expand Down
22 changes: 18 additions & 4 deletions entities/enemytank/EnemyTank.gd
Expand Up @@ -6,12 +6,16 @@ onready var TankBottom = get_node("TankBottom")
onready var Game = get_tree().get_root().get_node("Game")
onready var Player = Game.get_node("Player")

onready var Nav = Game.get_node("Map/Navigation")

onready var BulletContainer = Game.get_node("Container/Bullets")

var velocity = Vector2(0, 0)
var desired_velocity = Vector2(0, 0)
var steering = Vector2(0, 0)

var points = []

func _ready():
TankCannon.set_owner(self)
TankBottom.set_owner(self)
Expand All @@ -20,21 +24,31 @@ func _ready():
func _process(delta):
TankCannon.look_at(Player.get_pos() + Player.velocity())

desired_velocity = (Player.get_pos() - get_pos()).normalized() * 30
steering = desired_velocity - velocity
points = Nav.get_simple_path(get_pos(), Player.get_pos(), true)

if points.size() > 1:
desired_velocity = (points[1] - get_pos()).normalized() * 25
steering = desired_velocity - velocity

velocity += steering
velocity += steering

TankBottom.set_direction(velocity.normalized())

move(velocity * delta)
velocity *= 0.9

update()

func on_hit(by):
BulletContainer.purge_owner(self)

if by != null and not by.is_in_group("enemy"):
queue_free()

func _on_ReloadTimer_timeout():
TankCannon.fire_bullet()
TankCannon.fire_bullet()

func _draw():
if points.size() > 1:
for p in points:
draw_circle(p - get_global_pos(), 2, Color(1, 0, 0)) #
4 changes: 2 additions & 2 deletions entities/enemytank/EnemyTank.tscn
Expand Up @@ -5,10 +5,10 @@
[ext_resource path="res://components/tankcannon/TankCannon.tscn" type="PackedScene" id=3]
[ext_resource path="res://entities/enemytank/enemytanktop.png" type="Texture" id=4]

[sub_resource type="RectangleShape2D" id=1]
[sub_resource type="CircleShape2D" id=1]

custom_solver_bias = 0.0
extents = Vector2( 7.03401, 8.0404 )
radius = 5.93536

[node name="EnemyTank" type="KinematicBody2D" groups=[
"hitable",
Expand Down
16 changes: 8 additions & 8 deletions entities/player/Player.tscn
Expand Up @@ -5,12 +5,12 @@
[ext_resource path="res://components/tankcannon/TankCannon.tscn" type="PackedScene" id=3]
[ext_resource path="res://entities/player/energy.png" type="Texture" id=4]

[sub_resource type="RectangleShape2D" id=1]
[sub_resource type="CircleShape2D" id=1]

custom_solver_bias = 0.0
extents = Vector2( 8.16122, 7.95641 )
radius = 6.07066

[sub_resource type="StyleBoxFlat" id=3]
[sub_resource type="StyleBoxFlat" id=2]

content_margin/left = -1.0
content_margin/right = -1.0
Expand All @@ -23,7 +23,7 @@ border_size = 1
border_blend = true
draw_bg = true

[sub_resource type="StyleBoxFlat" id=4]
[sub_resource type="StyleBoxFlat" id=3]

content_margin/left = -1.0
content_margin/right = -1.0
Expand All @@ -36,7 +36,7 @@ border_size = 0
border_blend = false
draw_bg = true

[sub_resource type="BitmapFont" id=2]
[sub_resource type="BitmapFont" id=4]

textures = [ ]
chars = IntArray( )
Expand Down Expand Up @@ -79,9 +79,9 @@ margin/left = -16.0
margin/top = 12.0
margin/right = 48.0
margin/bottom = 20.0
custom_styles/fg = SubResource( 3 )
custom_styles/bg = SubResource( 4 )
custom_fonts/font = SubResource( 2 )
custom_styles/fg = SubResource( 2 )
custom_styles/bg = SubResource( 3 )
custom_fonts/font = SubResource( 4 )
range/min = 0.0
range/max = 100.0
range/step = 1.0
Expand Down

0 comments on commit 57089b2

Please sign in to comment.