From 30f9bfa5ff41f9a6df54f55fdbc3e268bf47c634 Mon Sep 17 00:00:00 2001 From: rsxri Date: Tue, 22 Apr 2025 05:43:03 +0100 Subject: [PATCH] -feat: implement wave logic, automatic ai ship spawning, tweak stats --- MB_FYP/scenes/ai_fighter.tscn | 1 + MB_FYP/scenes/game.tscn | 90 +++++++++++++-------------- MB_FYP/scenes/hud.tscn | 32 +++++----- MB_FYP/script/ai_fighter.cs | 16 ++++- MB_FYP/script/game.cs | 106 +++++++++++++++++++++++++------- MB_FYP/script/hud.cs | 4 +- MB_FYP/script/player.cs | 10 +++ MB_FYP/script/ship.cs | 53 ++++++++-------- MB_FYP/script/wavecontroller.cs | 78 +++++++++++++++++++++++ 9 files changed, 276 insertions(+), 114 deletions(-) create mode 100644 MB_FYP/script/wavecontroller.cs diff --git a/MB_FYP/scenes/ai_fighter.tscn b/MB_FYP/scenes/ai_fighter.tscn index 13496fe..05f50fa 100644 --- a/MB_FYP/scenes/ai_fighter.tscn +++ b/MB_FYP/scenes/ai_fighter.tscn @@ -15,6 +15,7 @@ font_size = 40 collision_mask = 13 motion_mode = 1 script = ExtResource("1_kyds1") +Faction = 2 [node name="CollisionShape2D" type="CollisionShape2D" parent="."] shape = SubResource("CircleShape2D_6vq6f") diff --git a/MB_FYP/scenes/game.tscn b/MB_FYP/scenes/game.tscn index 7c88b9c..b7be826 100644 --- a/MB_FYP/scenes/game.tscn +++ b/MB_FYP/scenes/game.tscn @@ -4,9 +4,9 @@ [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://dnvcics1ni4pa" path="res://scenes/asteroid.tscn" id="3_b8wlr"] -[ext_resource type="PackedScene" uid="uid://3e6fmds2x8q5" path="res://scenes/ai_fighter.tscn" id="5_nkk10"] [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"] [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_4rlyh"] texture = ExtResource("6_kn6se") @@ -8081,48 +8081,7 @@ position = Vector2(769, 202) [node name="Asteroid5" parent="Asteroids" instance=ExtResource("3_b8wlr")] position = Vector2(387, 230) -[node name="Ships" type="Node" parent="."] - -[node name="Friendly" type="Node" parent="Ships"] - -[node name="Player" parent="Ships/Friendly" instance=ExtResource("1_1w06w")] -position = Vector2(959, 539) -scale = Vector2(0.6, 0.6) -Type = 1 - -[node name="AI_Fighter" parent="Ships/Friendly" instance=ExtResource("5_nkk10")] -position = Vector2(1229, 430) -scale = Vector2(0.6, 0.6) -Faction = 1 - -[node name="AI_Fighter2" parent="Ships/Friendly" instance=ExtResource("5_nkk10")] -position = Vector2(686, 333) -scale = Vector2(0.6, 0.6) -Faction = 1 - -[node name="Enemy" type="Node" parent="Ships"] - -[node name="AI_Fighter" parent="Ships/Enemy" instance=ExtResource("5_nkk10")] -position = Vector2(952, 214) -scale = Vector2(0.6, 0.6) -Faction = 2 - -[node name="AI_Fighter2" parent="Ships/Enemy" instance=ExtResource("5_nkk10")] -position = Vector2(429, 467) -scale = Vector2(0.6, 0.6) -Faction = 2 - -[node name="AI_Fighter3" parent="Ships/Enemy" instance=ExtResource("5_nkk10")] -position = Vector2(674, 887) -scale = Vector2(0.6, 0.6) -Faction = 2 - -[node name="AI_Fighter4" parent="Ships/Enemy" instance=ExtResource("5_nkk10")] -position = Vector2(1303, 840) -scale = Vector2(0.6, 0.6) -Faction = 2 - -[node name="TileMap" type="TileMap" parent="."] +[node name="BackgroundTileMap" type="TileMap" parent="."] position = Vector2(900, 500) tile_set = SubResource("TileSet_lmb5c") format = 2 @@ -8153,11 +8112,50 @@ rotation = -1.5708 scale = Vector2(37.35, 5) collision_layer = 8 +[node name="WaveController" type="Node2D" parent="."] +script = ExtResource("8_fhk4p") + +[node name="Ships" type="Node" parent="WaveController"] + +[node name="Friendly" type="Node" parent="WaveController/Ships"] + +[node name="Player" parent="WaveController/Ships/Friendly" instance=ExtResource("1_1w06w")] +position = Vector2(959, 539) +scale = Vector2(0.6, 0.6) +Color = 1 +Type = 1 + +[node name="Enemy" type="Node" parent="WaveController/Ships"] + +[node name="Spawns" type="Node" parent="WaveController"] + +[node name="Enemy" type="Node" parent="WaveController/Spawns"] + +[node name="ESpawn1" type="Marker2D" parent="WaveController/Spawns/Enemy"] +position = Vector2(-276, -585) + +[node name="ESpawn2" type="Marker2D" parent="WaveController/Spawns/Enemy"] +position = Vector2(948, 1809) + +[node name="ESpawn3" type="Marker2D" parent="WaveController/Spawns/Enemy"] +position = Vector2(2216, -428) + +[node name="Friendly" type="Node" parent="WaveController/Spawns"] + +[node name="FSpawn1" type="Marker2D" parent="WaveController/Spawns/Friendly"] +position = Vector2(-371, 842) + +[node name="FSpawn2" type="Marker2D" parent="WaveController/Spawns/Friendly"] +position = Vector2(1921, 1512) + +[node name="FSpawn3" type="Marker2D" parent="WaveController/Spawns/Friendly"] +position = Vector2(1279, -637) + [connection signal="Exploded" from="Asteroids/Asteroid" to="." method="OnAsteroidExploded"] [connection signal="Exploded" from="Asteroids/Asteroid2" to="." method="OnAsteroidExploded"] [connection signal="Exploded" from="Asteroids/Asteroid3" to="." method="OnAsteroidExploded"] [connection signal="Exploded" from="Asteroids/Asteroid4" to="." method="OnAsteroidExploded"] [connection signal="Exploded" from="Asteroids/Asteroid5" to="." method="OnAsteroidExploded"] -[connection signal="HealthUpdate" from="Ships/Friendly/Player" to="." method="OnPlayerHealthUpdate"] -[connection signal="LaserShot" from="Ships/Friendly/Player" to="." method="OnPlayerLaserShot"] -[connection signal="PlayerDeath" from="Ships/Friendly/Player" to="." method="OnPlayerDeath"] +[connection signal="HealthUpdate" from="WaveController/Ships/Friendly/Player" to="." method="OnPlayerHealthUpdate"] +[connection signal="LaserShot" from="WaveController/Ships/Friendly/Player" to="." method="OnPlayerLaserShot"] +[connection signal="PlayerDeath" from="WaveController/Ships/Friendly/Player" to="." method="OnPlayerDeath"] diff --git a/MB_FYP/scenes/hud.tscn b/MB_FYP/scenes/hud.tscn index 17db4f7..d38cce7 100644 --- a/MB_FYP/scenes/hud.tscn +++ b/MB_FYP/scenes/hud.tscn @@ -10,29 +10,27 @@ offset_right = 40.0 offset_bottom = 40.0 script = ExtResource("1_aksh1") -[node name="Score" type="Label" parent="."] +[node name="Layout" type="VBoxContainer" parent="."] layout_mode = 0 -offset_left = 15.0 -offset_top = 15.0 -offset_right = 363.0 -offset_bottom = 90.0 +offset_right = 40.0 +offset_bottom = 40.0 + +[node name="Score" type="Label" parent="Layout"] +layout_mode = 2 text = "SCORE: 9999" label_settings = ExtResource("2_ns78v") -[node name="Health" type="Label" parent="."] -layout_mode = 0 -offset_left = 17.0 -offset_top = 95.0 -offset_right = 384.0 -offset_bottom = 167.0 +[node name="Health" type="Label" parent="Layout"] +layout_mode = 2 text = "Health:" label_settings = ExtResource("2_ns78v") -[node name="FlightAssist" type="Label" parent="."] -layout_mode = 0 -offset_left = 19.0 -offset_top = 174.0 -offset_right = 226.0 -offset_bottom = 237.0 +[node name="WaveCounter" type="Label" parent="Layout"] +layout_mode = 2 +text = "Wave: " +label_settings = ExtResource("2_ns78v") + +[node name="FlightAssist" type="Label" parent="Layout"] +layout_mode = 2 text = "FA: ON" label_settings = ExtResource("2_ns78v") diff --git a/MB_FYP/script/ai_fighter.cs b/MB_FYP/script/ai_fighter.cs index 119e538..2bf5be2 100644 --- a/MB_FYP/script/ai_fighter.cs +++ b/MB_FYP/script/ai_fighter.cs @@ -4,6 +4,9 @@ using System; public partial class ai_fighter : ship { + [Signal] + public delegate void OnDeathEventHandler(int factionInt); + [Export] public float AggroRange = 500f; [Export] @@ -11,6 +14,8 @@ public partial class ai_fighter : ship [Export] public float EngageDistance = 300f; + public bool SignalsConnected { get; set; } = false; + private Label _healthLabel; private Label _hpLabel; @@ -74,6 +79,13 @@ public partial class ai_fighter : ship UpdateHealthLabel(Health); } + protected override void Explode() + { + int factionInt = (int)Faction; + EmitSignal(SignalName.OnDeath, factionInt); + QueueFree(); + } + private void HandleFiring(double delta) { //GD.Print(Name, ": checking fire"); @@ -112,11 +124,11 @@ public partial class ai_fighter : ship Node shipParent = null; if (Faction == ShipFaction.FRIENDLY) { - shipParent = GetTree().Root.GetNode("Game/Ships/Enemy"); + shipParent = GetTree().Root.GetNode("Game/WaveController/Ships/Enemy"); } else if (Faction == ShipFaction.ENEMY || Faction == ShipFaction.ACE) { - shipParent = GetTree().Root.GetNode("Game/Ships/Friendly"); + shipParent = GetTree().Root.GetNode("Game/WaveController/Ships/Friendly"); } if (shipParent == null) { diff --git a/MB_FYP/script/game.cs b/MB_FYP/script/game.cs index cbde79e..d978ef7 100644 --- a/MB_FYP/script/game.cs +++ b/MB_FYP/script/game.cs @@ -4,8 +4,9 @@ using System; public partial class game : Node2D { private Node _lasers; - private CharacterBody2D _player; + private player _player; private Node _asteroids; + private wavecontroller _waveController; private Node _friendlies; @@ -21,53 +22,79 @@ public partial class game : Node2D private Label _flightAssistLabel; + private Label _waveCounterLabel; + private hud _h; + + private int _score; private readonly PackedScene _asteroidScene = GD.Load("res://scenes/asteroid.tscn"); - private int _score; public override void _Ready() { + _waveController = GetNode("WaveController"); _hud = GetNode("UI/HUD"); - _scoreLabel = GetNode