From d008a3d32cc4854f352f81bf4bcdbdc51e5a8c82 Mon Sep 17 00:00:00 2001 From: rsxri Date: Wed, 23 Apr 2025 05:33:38 +0100 Subject: [PATCH] -feat: basic ship upgrades and corresponding ui implemented. --- MB_FYP/scenes/game.tscn | 19 +++++- MB_FYP/scenes/pause_menu.tscn | 15 ++++- MB_FYP/scenes/upgrade_menu.tscn | 112 ++++++++++++++++++++++++++++++++ MB_FYP/script/game.cs | 8 +-- MB_FYP/script/player.cs | 27 +++++++- MB_FYP/script/upgrade_menu.cs | 72 ++++++++++++++++++++ MB_FYP/script/wavecontroller.cs | 16 ++++- 7 files changed, 255 insertions(+), 14 deletions(-) create mode 100644 MB_FYP/scenes/upgrade_menu.tscn create mode 100644 MB_FYP/script/upgrade_menu.cs diff --git a/MB_FYP/scenes/game.tscn b/MB_FYP/scenes/game.tscn index 6f43cb3..257e82b 100644 --- a/MB_FYP/scenes/game.tscn +++ b/MB_FYP/scenes/game.tscn @@ -1,10 +1,11 @@ -[gd_scene load_steps=12 format=3 uid="uid://635xs5haibcn"] +[gd_scene load_steps=13 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="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"] [ext_resource type="Texture2D" uid="uid://bjxo7mbl7nert" path="res://assets/Starfield/starfield1.png" id="6_kn6se"] [ext_resource type="PackedScene" uid="uid://4fnk5c2nf6a1" path="res://scenes/border.tscn" id="7_p4rds"] [ext_resource type="Script" path="res://script/wavecontroller.cs" id="8_fhk4p"] @@ -8088,6 +8089,19 @@ offset_top = -100.0 offset_right = 200.0 offset_bottom = 100.0 +[node name="UpgradeMenu" parent="UI" node_paths=PackedStringArray("PlayerNode") instance=ExtResource("5_p2w52")] +visible = false +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 +PlayerNode = NodePath("../../WaveController/Ships/Friendly/Player") + [node name="Lasers" type="Node" parent="."] process_mode = 1 @@ -8141,9 +8155,10 @@ rotation = -1.5708 scale = Vector2(37.35, 5) collision_layer = 8 -[node name="WaveController" type="Node2D" parent="."] +[node name="WaveController" type="Node2D" parent="." node_paths=PackedStringArray("UpgradeMenu")] process_mode = 1 script = ExtResource("8_fhk4p") +UpgradeMenu = NodePath("../UI/UpgradeMenu") [node name="Ships" type="Node" parent="WaveController"] diff --git a/MB_FYP/scenes/pause_menu.tscn b/MB_FYP/scenes/pause_menu.tscn index 06ad50b..69c23a1 100644 --- a/MB_FYP/scenes/pause_menu.tscn +++ b/MB_FYP/scenes/pause_menu.tscn @@ -1,13 +1,23 @@ -[gd_scene load_steps=5 format=3 uid="uid://btjj225d18y2q"] +[gd_scene load_steps=9 format=3 uid="uid://btjj225d18y2q"] [ext_resource type="FontFile" uid="uid://be6xxaq8drt5q" path="res://assets/Fonts/Kenney Pixel Square.ttf" id="1_b7j7x"] [ext_resource type="Script" path="res://script/pause_menu.cs" id="1_mq0ks"] [ext_resource type="PackedScene" uid="uid://01tjlnox4crb" path="res://scenes/input_menu.tscn" id="2_ugxyj"] +[ext_resource type="FontFile" uid="uid://dtpvg4lmre10g" path="res://assets/Fonts/Kenney Future Narrow.ttf" id="3_p0x5a"] [sub_resource type="LabelSettings" id="LabelSettings_6mqtv"] font = ExtResource("1_b7j7x") font_size = 28 +[sub_resource type="Theme" id="Theme_siirn"] +default_font = ExtResource("3_p0x5a") + +[sub_resource type="Theme" id="Theme_1cogp"] +default_font = ExtResource("3_p0x5a") + +[sub_resource type="Theme" id="Theme_gbhoc"] +default_font = ExtResource("3_p0x5a") + [node name="PauseMenu" type="CenterContainer"] process_mode = 2 anchors_preset = 15 @@ -44,16 +54,19 @@ layout_mode = 2 [node name="InputsButton" type="Button" parent="VBox/HBox"] custom_minimum_size = Vector2(100, 0) layout_mode = 2 +theme = SubResource("Theme_siirn") text = "Inputs" [node name="ResumeButton" type="Button" parent="VBox/HBox"] custom_minimum_size = Vector2(100, 0) layout_mode = 2 +theme = SubResource("Theme_1cogp") text = "Resume" [node name="QuitButton" type="Button" parent="VBox/HBox"] custom_minimum_size = Vector2(100, 35) layout_mode = 2 +theme = SubResource("Theme_gbhoc") text = "Main Menu" [node name="InputMenu" parent="." instance=ExtResource("2_ugxyj")] diff --git a/MB_FYP/scenes/upgrade_menu.tscn b/MB_FYP/scenes/upgrade_menu.tscn new file mode 100644 index 0000000..a81d190 --- /dev/null +++ b/MB_FYP/scenes/upgrade_menu.tscn @@ -0,0 +1,112 @@ +[gd_scene load_steps=7 format=3 uid="uid://bc52c4jrk6lo"] + +[ext_resource type="Script" path="res://script/upgrade_menu.cs" id="1_aupyl"] +[ext_resource type="FontFile" uid="uid://be6xxaq8drt5q" path="res://assets/Fonts/Kenney Pixel Square.ttf" id="1_rlo6h"] +[ext_resource type="FontFile" uid="uid://dtpvg4lmre10g" path="res://assets/Fonts/Kenney Future Narrow.ttf" id="2_m2s84"] + +[sub_resource type="LabelSettings" id="LabelSettings_6mqtv"] +font = ExtResource("1_rlo6h") +font_size = 28 + +[sub_resource type="LabelSettings" id="LabelSettings_40vj8"] +font = ExtResource("2_m2s84") + +[sub_resource type="Theme" id="Theme_olqqp"] +default_font = ExtResource("2_m2s84") + +[node name="UpgradeMenu" type="CenterContainer"] +process_mode = 2 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_right = -1520.0 +offset_bottom = -880.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_aupyl") + +[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 = "Upgrade" +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="Health" type="VBoxContainer" parent="VBox/HBox"] +layout_mode = 2 + +[node name="HealthLabel" type="Label" parent="VBox/HBox/Health"] +layout_mode = 2 +text = "Health" +label_settings = SubResource("LabelSettings_40vj8") +horizontal_alignment = 1 + +[node name="HealthStat" type="Label" parent="VBox/HBox/Health"] +layout_mode = 2 +text = "+ 0%" +label_settings = SubResource("LabelSettings_40vj8") +horizontal_alignment = 1 + +[node name="HealthUpgrade" type="Button" parent="VBox/HBox/Health"] +custom_minimum_size = Vector2(100, 0) +layout_mode = 2 +theme = SubResource("Theme_olqqp") +text = "+10%" + +[node name="Damage" type="VBoxContainer" parent="VBox/HBox"] +layout_mode = 2 + +[node name="DamageLabel" type="Label" parent="VBox/HBox/Damage"] +layout_mode = 2 +text = "Damage +" +label_settings = SubResource("LabelSettings_40vj8") +horizontal_alignment = 1 + +[node name="DamageStat" type="Label" parent="VBox/HBox/Damage"] +layout_mode = 2 +text = "+ 0%" +label_settings = SubResource("LabelSettings_40vj8") +horizontal_alignment = 1 + +[node name="DamageUpgrade" type="Button" parent="VBox/HBox/Damage"] +custom_minimum_size = Vector2(100, 0) +layout_mode = 2 +theme = SubResource("Theme_olqqp") +text = "+10%" + +[node name="Speed" type="VBoxContainer" parent="VBox/HBox"] +layout_mode = 2 + +[node name="SpeedLabel" type="Label" parent="VBox/HBox/Speed"] +layout_mode = 2 +text = "Speed" +label_settings = SubResource("LabelSettings_40vj8") +horizontal_alignment = 1 + +[node name="SpeedStat" type="Label" parent="VBox/HBox/Speed"] +layout_mode = 2 +text = "+ 0%" +label_settings = SubResource("LabelSettings_40vj8") +horizontal_alignment = 1 + +[node name="SpeedUpgrade" type="Button" parent="VBox/HBox/Speed"] +custom_minimum_size = Vector2(100, 0) +layout_mode = 2 +theme = SubResource("Theme_olqqp") +text = "+10%" diff --git a/MB_FYP/script/game.cs b/MB_FYP/script/game.cs index 7b6ef43..43a182c 100644 --- a/MB_FYP/script/game.cs +++ b/MB_FYP/script/game.cs @@ -102,7 +102,6 @@ public partial class game : Node2D if (_waveController.CurrWave % 2 == 0) { _player.HealShip(100); // heal ship by 100 at the start of each 2nd round - UpdateHealthLabel(_player.Health); } } @@ -186,8 +185,8 @@ public partial class game : Node2D { _lasers.AddChild(laser); - GD.Print(laser.Position); - GD.Print(_player.Position); + //GD.Print(laser.Position); + //GD.Print(_player.Position); } private void OnPlayerHealthUpdate(int health) @@ -229,8 +228,7 @@ public partial class game : Node2D private void OnAsteroidExploded(Vector2 pos, int size, ship shooter) { - // DEBUG PRINT - GD.Print($"DEBUG: Asteroid exploded at {pos}, size: {size}"); + //GD.Print($"DEBUG: Asteroid exploded at {pos}, size: {size}"); switch (size) { diff --git a/MB_FYP/script/player.cs b/MB_FYP/script/player.cs index 6b52de1..1cbb85b 100644 --- a/MB_FYP/script/player.cs +++ b/MB_FYP/script/player.cs @@ -71,9 +71,30 @@ public partial class player : ship // Inherits from base ship class { Health += health; if (Health > MaxHealth) Health = MaxHealth; + EmitSignal(SignalName.HealthUpdate, Health); } + public void HealthUpgrade() // sets health stats (upgrades) + { + MaxHealth = (int)(MaxHealth * 1.1f); + Health = MaxHealth;; + EmitSignal(SignalName.HealthUpdate, Health); + } + + public void DamageUpgrade() // sets new damage stat (upgrades) + { + Damage = (int)(Damage * 1.1f);; + } + + public void SpeedUpgrade() // sets new speed stats (upgrades) + { + MaxSpeed = (int)(MaxSpeed * 1.1f); + MainSpeed = (int)(MainSpeed * 1.1f); + StrafeSpeed = (int)(StrafeSpeed * 1.1f); + RotationSpeed = RotationSpeed * 1.1f; + } + private void ToggleFlightAssist() { if (FlightAssistValue == 0f){FlightAssistValue = 2.5f;} @@ -83,7 +104,7 @@ public partial class player : ship // Inherits from base ship class public override void _Ready() { SetupVisual(); - GD.Print(Faction); + //GD.Print(Faction); this.SpritePath = Color switch { @@ -92,7 +113,7 @@ public partial class player : ship // Inherits from base ship class ShipColor.BLUE => this.SpritePath + "ShipBlue.png", _ => this.SpritePath }; - GD.Print(SpritePath); + //GD.Print(SpritePath); Sprite.Texture = GD.Load(SpritePath); @@ -112,7 +133,7 @@ public partial class player : ship // Inherits from base ship class if(Input.IsActionPressed("shoot")) { - GD.Print("DEBUG: FIRING PLAYER LASER"); + //GD.Print("DEBUG: FIRING PLAYER LASER"); if (FireTimer > 0f) return; ShootLaser(); FireTimer = FireCooldown; diff --git a/MB_FYP/script/upgrade_menu.cs b/MB_FYP/script/upgrade_menu.cs new file mode 100644 index 0000000..d735cb2 --- /dev/null +++ b/MB_FYP/script/upgrade_menu.cs @@ -0,0 +1,72 @@ +using Godot; +using System; + +public partial class upgrade_menu : CenterContainer +{ + private Button _healthUpgrade; + private Button _speedUpgrade; + private Button _damageUpgrade; + + private Label _healthStat; + private Label _speedStat; + private Label _damageStat; + + private int _healthInt; + private int _speedInt; + private int _damageInt; + + [Export] + public player PlayerNode; + + private int _playerBaseHealth; + private int _playerBaseDamage; + private int _playerBaseMaxSpeed; + private int _playerBaseMainSpeed; + private int _playerBaseStrafeSpeed; + private float _playerBaseRotationSpeed; + + public override void _Ready() + { + _healthUpgrade = GetNode