Add functionality to die when hitting a pipe

This commit is contained in:
James Skemp 2023-12-08 23:04:52 -06:00
parent 5ad335859f
commit ba007b5b63
6 changed files with 22 additions and 2 deletions

View File

@ -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)

View File

@ -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()

View File

@ -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"]

View File

@ -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.

View File

@ -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="."]

View File

@ -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")