From e94dbca8288b26174b892b4c2b9e11e5be861393 Mon Sep 17 00:00:00 2001 From: rsxri Date: Wed, 23 Apr 2025 16:11:14 +0100 Subject: [PATCH] -feat: working game over menu and script. --- MB_FYP/scenes/game.tscn | 8 ++++- MB_FYP/scenes/game_over.tscn | 70 ++++++++++++++++++++++++++++++++++++ MB_FYP/script/game.cs | 3 +- MB_FYP/script/game_over.cs | 23 ++++++++++++ 4 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 MB_FYP/scenes/game_over.tscn create mode 100644 MB_FYP/script/game_over.cs diff --git a/MB_FYP/scenes/game.tscn b/MB_FYP/scenes/game.tscn index 257e82b..20ed239 100644 --- a/MB_FYP/scenes/game.tscn +++ b/MB_FYP/scenes/game.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=13 format=3 uid="uid://635xs5haibcn"] +[gd_scene load_steps=14 format=3 uid="uid://635xs5haibcn"] [ext_resource type="PackedScene" uid="uid://ckh362yqjkpi0" path="res://scenes/player.tscn" id="1_1w06w"] [ext_resource type="Script" path="res://script/game.cs" id="1_dukjm"] [ext_resource type="PackedScene" uid="uid://b6myj160l6vf8" path="res://scenes/hud.tscn" id="2_xbhg5"] +[ext_resource type="PackedScene" uid="uid://dkyw6ve8ll885" path="res://scenes/game_over.tscn" id="2_xhmka"] [ext_resource type="Script" path="res://script/pause_controller.cs" id="3_3v5pd"] [ext_resource type="PackedScene" uid="uid://dnvcics1ni4pa" path="res://scenes/asteroid.tscn" id="3_b8wlr"] [ext_resource type="PackedScene" uid="uid://bc52c4jrk6lo" path="res://scenes/upgrade_menu.tscn" id="5_p2w52"] @@ -8089,6 +8090,11 @@ offset_top = -100.0 offset_right = 200.0 offset_bottom = 100.0 +[node name="GameOver" parent="UI/PauseControl" instance=ExtResource("2_xhmka")] +process_mode = 2 +visible = false +layout_mode = 1 + [node name="UpgradeMenu" parent="UI" node_paths=PackedStringArray("PlayerNode") instance=ExtResource("5_p2w52")] visible = false anchors_preset = 8 diff --git a/MB_FYP/scenes/game_over.tscn b/MB_FYP/scenes/game_over.tscn new file mode 100644 index 0000000..1dffbcc --- /dev/null +++ b/MB_FYP/scenes/game_over.tscn @@ -0,0 +1,70 @@ +[gd_scene load_steps=7 format=3 uid="uid://dkyw6ve8ll885"] + +[ext_resource type="FontFile" uid="uid://be6xxaq8drt5q" path="res://assets/Fonts/Kenney Pixel Square.ttf" id="1_gbk3f"] +[ext_resource type="Script" path="res://script/game_over.cs" id="1_mvgnc"] +[ext_resource type="FontFile" uid="uid://dtpvg4lmre10g" path="res://assets/Fonts/Kenney Future Narrow.ttf" id="2_65i3g"] + +[sub_resource type="LabelSettings" id="LabelSettings_6mqtv"] +font = ExtResource("1_gbk3f") +font_size = 28 + +[sub_resource type="Theme" id="Theme_4c6ow"] +default_font = ExtResource("2_65i3g") + +[sub_resource type="Theme" id="Theme_te0li"] +default_font = ExtResource("2_65i3g") + +[node name="GameOver" type="CenterContainer"] +process_mode = 3 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -200.0 +offset_top = -100.0 +offset_right = 200.0 +offset_bottom = 100.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_mvgnc") + +[node name="ColorRect" type="ColorRect" parent="."] +custom_minimum_size = Vector2(400, 200) +layout_mode = 2 +color = Color(0.231373, 0.219608, 0.203922, 1) + +[node name="VBox" type="VBoxContainer" parent="."] +layout_mode = 2 + +[node name="Label" type="Label" parent="VBox"] +layout_mode = 2 +text = "Game Over" +label_settings = SubResource("LabelSettings_6mqtv") +horizontal_alignment = 1 + +[node name="VSeparator" type="VSeparator" parent="VBox"] +visibility_layer = 0 +custom_minimum_size = Vector2(0, 30) +layout_mode = 2 + +[node name="HBox" type="HBoxContainer" parent="VBox"] +layout_mode = 2 + +[node name="Retry" type="Button" parent="VBox/HBox"] +custom_minimum_size = Vector2(100, 0) +layout_mode = 2 +theme = SubResource("Theme_4c6ow") +text = "Retry" + +[node name="MainMenu" type="Button" parent="VBox/HBox"] +custom_minimum_size = Vector2(100, 0) +layout_mode = 2 +theme = SubResource("Theme_te0li") +text = "Main Menu +" + +[node name="VSeparator2" type="VSeparator" parent="VBox"] +visibility_layer = 0 +custom_minimum_size = Vector2(0, 30) +layout_mode = 2 diff --git a/MB_FYP/script/game.cs b/MB_FYP/script/game.cs index 43a182c..6c0c7e0 100644 --- a/MB_FYP/script/game.cs +++ b/MB_FYP/script/game.cs @@ -196,7 +196,8 @@ public partial class game : Node2D private void OnPlayerDeath() { - CallDeferred(nameof(SafeReloadScene)); //Reload scene to act as restart + GetTree().Paused = true; + GetNode("UI/PauseControl/GameOver").Visible = true; } private void OnAIDeath(int factionInt) diff --git a/MB_FYP/script/game_over.cs b/MB_FYP/script/game_over.cs new file mode 100644 index 0000000..28fdd22 --- /dev/null +++ b/MB_FYP/script/game_over.cs @@ -0,0 +1,23 @@ +using Godot; +using System; + +public partial class game_over : CenterContainer +{ + public override void _Ready() + { + GetNode