Skip to content

Commit

Permalink
Change Mob spawning to Path2D
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Bradfield committed Sep 12, 2017
1 parent db6469f commit 30cbb26
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
20 changes: 4 additions & 16 deletions Main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions Main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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"]
Expand Down
6 changes: 3 additions & 3 deletions Player.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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" ]
Expand Down

0 comments on commit 30cbb26

Please sign in to comment.