Add functionality to die when hitting a pipe
This commit is contained in:
parent
5ad335859f
commit
ba007b5b63
|
@ -32,4 +32,10 @@ func spawn_pipes() -> void:
|
|||
|
||||
func on_game_over():
|
||||
#GameManager.load_main_scene()
|
||||
pass
|
||||
stop_pipes()
|
||||
|
||||
|
||||
func stop_pipes():
|
||||
spawn_timer.stop()
|
||||
for pipe in pipes_holder.get_children():
|
||||
pipe.set_process(false)
|
||||
|
|
|
@ -14,3 +14,8 @@ func _process(delta):
|
|||
|
||||
func _on_visible_on_screen_notifier_2d_screen_exited():
|
||||
queue_free()
|
||||
|
||||
|
||||
func _on_pipe_body_entered(body):
|
||||
if body.is_in_group(GameManager.GROUP_PLANE):
|
||||
body.die()
|
||||
|
|
|
@ -19,4 +19,6 @@ position = Vector2(0, 80)
|
|||
[node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="."]
|
||||
position = Vector2(90, 0)
|
||||
|
||||
[connection signal="body_entered" from="UpperPipe" to="." method="_on_pipe_body_entered"]
|
||||
[connection signal="body_entered" from="LowerPipe" to="." method="_on_pipe_body_entered"]
|
||||
[connection signal="screen_exited" from="VisibleOnScreenNotifier2D" to="." method="_on_visible_on_screen_notifier_2d_screen_exited"]
|
||||
|
|
|
@ -3,6 +3,8 @@ extends CharacterBody2D
|
|||
const GRAVITY: float = 1900.0
|
||||
const POWER: float = -400.0
|
||||
|
||||
var dead := false
|
||||
|
||||
@onready var animation_player = $AnimationPlayer
|
||||
|
||||
|
||||
|
@ -26,6 +28,9 @@ func fly() -> void:
|
|||
|
||||
|
||||
func die() -> void:
|
||||
if dead:
|
||||
return
|
||||
dead = true
|
||||
$AnimatedSprite2D.stop()
|
||||
GameManager.on_game_over.emit()
|
||||
# Disable physics process.
|
||||
|
|
|
@ -59,7 +59,7 @@ _data = {
|
|||
"fly": SubResource("Animation_fgssm")
|
||||
}
|
||||
|
||||
[node name="Plane" type="CharacterBody2D"]
|
||||
[node name="Plane" type="CharacterBody2D" groups=["plane"]]
|
||||
script = ExtResource("1_26bih")
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||
|
|
|
@ -2,6 +2,8 @@ extends Node
|
|||
|
||||
signal on_game_over
|
||||
|
||||
const GROUP_PLANE: String = "plane"
|
||||
|
||||
var game_scene: PackedScene = preload("res://game/game.tscn")
|
||||
var main_scene: PackedScene = preload("res://main/main.tscn")
|
||||
|
||||
|
|
Loading…
Reference in New Issue