Refactor plane death signaling to use signal hub and use in scenes

This commit is contained in:
James Skemp 2023-12-07 21:34:06 -06:00
parent d8dca35fea
commit 5ad335859f
5 changed files with 15 additions and 9 deletions

View File

@ -9,6 +9,7 @@ extends Node2D
# Called when the node enters the scene tree for the first time.
func _ready():
GameManager.on_game_over.connect(on_game_over)
spawn_pipes()
@ -29,5 +30,6 @@ func spawn_pipes() -> void:
pipes_holder.add_child(new_pipes)
func _on_plane_died():
GameManager.load_main_scene()
func on_game_over():
#GameManager.load_main_scene()
pass

View File

@ -1,9 +1,10 @@
[gd_scene load_steps=6 format=3 uid="uid://d2had6j0ul7hn"]
[gd_scene load_steps=7 format=3 uid="uid://d2had6j0ul7hn"]
[ext_resource type="Texture2D" uid="uid://b5plspvrerf8c" path="res://assets/background/rocks_2.png" id="1_kihwf"]
[ext_resource type="Script" path="res://game/game.gd" id="1_mh8bq"]
[ext_resource type="PackedScene" uid="uid://dnu582ov5o310" path="res://plane/plane.tscn" id="2_xl0om"]
[ext_resource type="PackedScene" uid="uid://bed61tdnf2vq7" path="res://pipes/pipes.tscn" id="3_njdgd"]
[ext_resource type="PackedScene" uid="uid://bjx4v08mh6uhy" path="res://game_over/game_over.tscn" id="5_pro41"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_1my5e"]
size = Vector2(499, 20)
@ -38,5 +39,9 @@ position = Vector2(530, 540)
wait_time = 1.2
autostart = true
[connection signal="plane_died" from="Plane" to="." method="_on_plane_died"]
[node name="CanvasLayer" type="CanvasLayer" parent="."]
[node name="GameOver" parent="CanvasLayer" instance=ExtResource("5_pro41")]
visible = false
[connection signal="timeout" from="SpawnTimer" to="." method="_on_spawn_timer_timeout"]

View File

@ -8,8 +8,7 @@ var can_press_space = false
# Called when the node enters the scene tree for the first time.
func _ready():
on_game_over()
pass # Replace with function body.
GameManager.on_game_over.connect(on_game_over)
# Called every frame. 'delta' is the elapsed time since the previous frame.

View File

@ -1,7 +1,5 @@
extends CharacterBody2D
signal plane_died
const GRAVITY: float = 1900.0
const POWER: float = -400.0
@ -29,6 +27,6 @@ func fly() -> void:
func die() -> void:
$AnimatedSprite2D.stop()
plane_died.emit()
GameManager.on_game_over.emit()
# Disable physics process.
set_physics_process(false)

View File

@ -1,5 +1,7 @@
extends Node
signal on_game_over
var game_scene: PackedScene = preload("res://game/game.tscn")
var main_scene: PackedScene = preload("res://main/main.tscn")