From 7ea6f72e72d7e527145ab2ca176e7e52d2c592aa Mon Sep 17 00:00:00 2001 From: Henry Date: Tue, 9 Dec 2025 14:06:00 +0000 Subject: [PATCH] Added game over/restart UI and player behaviours. --- main.gd | 8 ++++++++ main.tscn | 8 +++++++- player.gd | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/main.gd b/main.gd index 3952496..21a74fb 100644 --- a/main.gd +++ b/main.gd @@ -1,12 +1,14 @@ extends Node2D @onready var start_button = $CanvasLayer/CenterContainer/Start +@onready var game_over = $CanvasLayer/CenterContainer/GameOver var enemy = preload("res://enemy.tscn") var score = 0 func _ready(): start_button.show() + game_over.hide() # spawn_enemies() func new_game(): @@ -28,6 +30,12 @@ func _on_enemy_died(value): score += value $CanvasLayer/UI.update_score(score) +func _on_player_died(): + get_tree().call_group("enemies", "queue_free") + game_over.show() + await get_tree().create_timer(2).timeout + game_over.hide() + start_button.show() func _on_start_pressed(): start_button.hide() diff --git a/main.tscn b/main.tscn index adab708..a9cd4b4 100644 --- a/main.tscn +++ b/main.tscn @@ -1,10 +1,11 @@ -[gd_scene load_steps=9 format=3 uid="uid://cc2dnhuv4qx7m"] +[gd_scene load_steps=10 format=3 uid="uid://cc2dnhuv4qx7m"] [ext_resource type="Script" uid="uid://c51huloycn5as" path="res://main.gd" id="1_h2yge"] [ext_resource type="Texture2D" uid="uid://jj8b7vqj3ihx" path="res://Mini Pixel Pack 3/Space_BG (2 frames) (64 x 64).png" id="1_ig7tw"] [ext_resource type="PackedScene" uid="uid://pyuorpwb7lpe" path="res://player.tscn" id="2_0xm2m"] [ext_resource type="PackedScene" uid="uid://s6wf3egdqtmh" path="res://ui.tscn" id="4_1bvp3"] [ext_resource type="Texture2D" uid="uid://bonoqs5pisflo" path="res://Mini Pixel Pack 3/UI objects/START (48 x 8).png" id="5_lquwl"] +[ext_resource type="Texture2D" uid="uid://bubqwoum50gf8" path="res://Mini Pixel Pack 3/UI objects/GAME_OVER (72 x 8).png" id="6_7mycd"] [sub_resource type="Animation" id="Animation_1bvp3"] length = 0.001 @@ -78,5 +79,10 @@ grow_vertical = 2 layout_mode = 2 texture_normal = ExtResource("5_lquwl") +[node name="GameOver" type="TextureRect" parent="CanvasLayer/CenterContainer"] +layout_mode = 2 +texture = ExtResource("6_7mycd") + +[connection signal="died" from="Player" to="." method="_on_player_died"] [connection signal="shield_changed" from="Player" to="CanvasLayer/UI" method="update_shield"] [connection signal="pressed" from="CanvasLayer/CenterContainer/Start" to="." method="_on_start_pressed"] diff --git a/player.gd b/player.gd index c10e038..528b2e0 100644 --- a/player.gd +++ b/player.gd @@ -16,6 +16,7 @@ func _ready(): start() func start(): + show() shield = max_shield position = Vector2(screensize.x / 2, screensize.y - 64) $GunCooldown.wait_time = cooldown