Added game over/restart UI and player behaviours.

This commit is contained in:
Henry 2025-12-09 14:06:00 +00:00
parent ef773a1ec5
commit 7ea6f72e72
3 changed files with 16 additions and 1 deletions

View file

@ -1,12 +1,14 @@
extends Node2D extends Node2D
@onready var start_button = $CanvasLayer/CenterContainer/Start @onready var start_button = $CanvasLayer/CenterContainer/Start
@onready var game_over = $CanvasLayer/CenterContainer/GameOver
var enemy = preload("res://enemy.tscn") var enemy = preload("res://enemy.tscn")
var score = 0 var score = 0
func _ready(): func _ready():
start_button.show() start_button.show()
game_over.hide()
# spawn_enemies() # spawn_enemies()
func new_game(): func new_game():
@ -28,6 +30,12 @@ func _on_enemy_died(value):
score += value score += value
$CanvasLayer/UI.update_score(score) $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(): func _on_start_pressed():
start_button.hide() start_button.hide()

View file

@ -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="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="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://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="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://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"] [sub_resource type="Animation" id="Animation_1bvp3"]
length = 0.001 length = 0.001
@ -78,5 +79,10 @@ grow_vertical = 2
layout_mode = 2 layout_mode = 2
texture_normal = ExtResource("5_lquwl") 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="shield_changed" from="Player" to="CanvasLayer/UI" method="update_shield"]
[connection signal="pressed" from="CanvasLayer/CenterContainer/Start" to="." method="_on_start_pressed"] [connection signal="pressed" from="CanvasLayer/CenterContainer/Start" to="." method="_on_start_pressed"]

View file

@ -16,6 +16,7 @@ func _ready():
start() start()
func start(): func start():
show()
shield = max_shield shield = max_shield
position = Vector2(screensize.x / 2, screensize.y - 64) position = Vector2(screensize.x / 2, screensize.y - 64)
$GunCooldown.wait_time = cooldown $GunCooldown.wait_time = cooldown