From 30cbb268de08a0303d7327ab1cb37254f132630f Mon Sep 17 00:00:00 2001 From: Chris Bradfield Date: Mon, 11 Sep 2017 18:17:45 -0700 Subject: [PATCH] Change Mob spawning to Path2D --- Main.gd | 20 ++++---------------- Main.tscn | 15 +++++++++++++-- Player.tscn | 6 +++--- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/Main.gd b/Main.gd index aa39f48..4ca3cc4 100644 --- a/Main.gd +++ b/Main.gd @@ -24,24 +24,12 @@ func game_over(): $HUD.show_game_over() func _on_MobTimer_timeout(): + # choose a random location on the Path2D + $"MobPath/MobSpawnLocation".set_offset(randi()) var mob = Mob.instance() add_child(mob) - var direction - # choose one of the four edges - var edge = randi() % 4 - match edge: - 0: # top - mob.position = Vector2(rand_range(0, screensize.x), 0) - direction = PI/2 - 1: # right - mob.position = Vector2(screensize.x, rand_range(0, screensize.y)) - direction = PI - 2: # bottom - mob.position = Vector2(rand_range(0, screensize.x), screensize.y) - direction = PI * 3/2 - 3: # left - mob.position = Vector2(0, rand_range(0, screensize.y)) - direction = 0 + var direction = $"MobPath/MobSpawnLocation".rotation + mob.position = $"MobPath/MobSpawnLocation".position # add some randomness to the direction direction += rand_range(-PI/4, PI/4) # textures are oriented pointing up, so add 90deg diff --git a/Main.tscn b/Main.tscn index abae47a..d7941f3 100644 --- a/Main.tscn +++ b/Main.tscn @@ -11,7 +11,7 @@ bake_interval = 5.0 _data = { -"points": PoolVector2Array( 0, 0, 0, 0, 2.89188, 5.11682, 0, 0, 0, 0, 1.8782, 727.878, 0, 0, 0, 0, 481.354, 730.92, 0, 0, 0, 0, 482.368, 6.13051, 0, 0, 0, 0, 2.89188, 5.11682 ) +"points": PoolVector2Array( 0, 0, 0, 0, 1.70602, 3.56798, 0, 0, 0, 0, 482.263, 3.26522, 0, 0, 0, 0, 480.489, 729.458, 0, 0, 0, 0, 0.794434, 732.118, 0, 0, 0, 0, 1.97066, 3.83263 ) } [node name="Main" type="Node"] @@ -76,10 +76,21 @@ autoplay = false mix_target = 0 bus = "Master" -[node name="Path2D" type="Path2D" parent="."] +[node name="MobPath" type="Path2D" parent="."] curve = SubResource( 1 ) +[node name="MobSpawnLocation" type="PathFollow2D" parent="MobPath"] + +rotation = 3.14159 +offset = 0.0 +h_offset = 0.0 +v_offset = 0.0 +rotate = true +cubic_interp = true +loop = true +lookahead = 4.0 + [connection signal="hit" from="Player" to="." method="game_over"] [connection signal="timeout" from="MobTimer" to="." method="_on_MobTimer_timeout"] diff --git a/Player.tscn b/Player.tscn index 82d2f4b..ae0b304 100644 --- a/Player.tscn +++ b/Player.tscn @@ -23,8 +23,8 @@ animations = [ { [sub_resource type="CapsuleShape2D" id=2] custom_solver_bias = 0.0 -radius = 22.0177 -height = 12.3755 +radius = 19.5521 +height = 9.53202 [sub_resource type="Gradient" id=3] @@ -104,7 +104,7 @@ __meta__ = { [node name="AnimatedSprite" type="AnimatedSprite" parent="."] -scale = Vector2( 1.25, 1.25 ) +scale = Vector2( 1.1, 1.1 ) frames = SubResource( 1 ) animation = "right" _sections_unfolded = [ "Region", "Transform", "Z" ]