From 56f1a2f763c565b6e293f33d66538a6bc000fc94 Mon Sep 17 00:00:00 2001 From: Sascha Date: Tue, 31 Oct 2023 16:31:27 +0100 Subject: [PATCH 01/14] refactoring GameManager and Ui --- Godot-space Shooter.csproj | 2 +- Packed-Scenes/PlayerShip.tscn | 25 +---- Scenes/SpaceShooter.tscn | 174 ++++++++++++++++++---------------- Scripts/GameManager.cs | 64 ++++--------- Scripts/PlayerShip.cs | 6 -- Scripts/Ui.cs | 50 ++++++++++ 6 files changed, 161 insertions(+), 160 deletions(-) create mode 100644 Scripts/Ui.cs diff --git a/Godot-space Shooter.csproj b/Godot-space Shooter.csproj index 1ac13b1..4faed17 100644 --- a/Godot-space Shooter.csproj +++ b/Godot-space Shooter.csproj @@ -1,4 +1,4 @@ - + net6.0 true diff --git a/Packed-Scenes/PlayerShip.tscn b/Packed-Scenes/PlayerShip.tscn index 4e3ff9e..d38b2c3 100644 --- a/Packed-Scenes/PlayerShip.tscn +++ b/Packed-Scenes/PlayerShip.tscn @@ -11,17 +11,14 @@ [sub_resource type="SphereShape3D" id="SphereShape3D_330dr"] radius = 0.9 -[node name="PlayerShip" type="Node3D" node_paths=PackedStringArray("cpulaser", "gpulaser", "jet", "PlayerRb", "shots", "healthBar")] +[node name="PlayerShip" type="Node3D" node_paths=PackedStringArray("jet", "PlayerRb", "shots")] transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74227e-08, 0, -1, 0, 0, 0) script = ExtResource("1_cpbf1") -cpulaser = NodePath("") explosion = ExtResource("2_13dyf") -gpulaser = NodePath("") jet = NodePath("RigidBody3D/Jet") laser = ExtResource("9_kbdnc") PlayerRb = NodePath("RigidBody3D") shots = NodePath("Shots") -healthBar = NodePath("ProgressBar") [node name="RigidBody3D" type="RigidBody3D" parent="."] mass = 100.0 @@ -54,23 +51,3 @@ texture = ExtResource("4_87x8f") current = true [node name="Shots" type="Node3D" parent="."] - -[node name="ProgressBar" type="ProgressBar" parent="."] -anchors_preset = 7 -anchor_left = 0.5 -anchor_top = 1.0 -anchor_right = 0.5 -anchor_bottom = 1.0 -offset_left = -238.0 -offset_top = -1241.0 -offset_right = 251.0 -offset_bottom = -1214.0 -grow_horizontal = 2 -grow_vertical = 0 -size_flags_horizontal = 4 -size_flags_vertical = 8 -max_value = 10.0 -step = 1.0 -value = 7.0 -rounded = true -show_percentage = false diff --git a/Scenes/SpaceShooter.tscn b/Scenes/SpaceShooter.tscn index a25b8de..c629e4c 100644 --- a/Scenes/SpaceShooter.tscn +++ b/Scenes/SpaceShooter.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=19 format=3 uid="uid://det8556rpxhbv"] +[gd_scene load_steps=20 format=3 uid="uid://det8556rpxhbv"] [ext_resource type="PackedScene" uid="uid://tlr55u0gn20l" path="res://Packed-Scenes/PlayerShip.tscn" id="1_njb5h"] [ext_resource type="Texture2D" uid="uid://cg6n1hh3lj7rn" path="res://Textures/tile_nebula_green_dff.png" id="2_43vix"] @@ -15,6 +15,7 @@ [ext_resource type="AudioStream" uid="uid://dlml6o3xscxqf" path="res://Sounds/weapon_player.wav" id="11_bbedd"] [ext_resource type="Script" path="res://Scripts/GameArea.cs" id="11_p0rh7"] [ext_resource type="Texture2D" uid="uid://b8gy1u2i0jkyd" path="res://Images/restart.svg" id="15_nxptg"] +[ext_resource type="Script" path="res://Scripts/Ui.cs" id="15_xl7yx"] [sub_resource type="BoxShape3D" id="BoxShape3D_bw288"] @@ -46,6 +47,8 @@ region_enabled = true region_rect = Rect2(0, 0, 810, 1380) script = ExtResource("3_imgbw") +[node name="Asteroids" type="Node3D" parent="."] + [node name="GameArea" type="Node3D" parent="."] script = ExtResource("11_p0rh7") @@ -103,118 +106,121 @@ stream = ExtResource("9_rtdps") [node name="LaserSound" type="AudioStreamPlayer3D" parent="SoundManager"] stream = ExtResource("11_bbedd") -[node name="GameManager" type="Node" parent="." node_paths=PackedStringArray("asteroidsContainer", "labelAsteroids", "labelLevel", "labelLifes", "labelNextLevel", "labelPoints", "labelDebug", "labelGameOver", "restartButton", "reachedPointsLabel")] -script = ExtResource("9_rsrr5") -debug = false -asteroids = Array[PackedScene]([ExtResource("5_do6ba"), ExtResource("6_tqoe7"), ExtResource("7_v6ul2")]) -asteroidsContainer = NodePath("../Asteroids") -labelAsteroids = NodePath("../Control/LabelAsteroids") -labelLevel = NodePath("../Control/LabelLevel") -labelLifes = NodePath("../Control/LabelLives") -labelNextLevel = NodePath("../Control/LabelNextLevel") -labelPoints = NodePath("../Control/LabelPoints") -labelDebug = NodePath("../Control/LabelDebug") -labelGameOver = NodePath("../Control/LabelGameOver") -restartButton = NodePath("../Control/RestartButton") -reachedPointsLabel = NodePath("../Control/ReachedPointsLabel") - -[node name="Asteroids" type="Node3D" parent="."] - -[node name="Control" type="Control" parent="."] -layout_mode = 3 -anchors_preset = 0 -offset_right = 40.0 -offset_bottom = 40.0 - -[node name="LabelAsteroids" type="RichTextLabel" parent="Control"] +[node name="Ui" type="Node2D" parent="." node_paths=PackedStringArray("labelAsteroids", "labelLevel", "labelLifes", "labelNextLevel", "labelPoints", "labelGameOver", "restartButton", "reachedPointsLabel", "healthBar")] +script = ExtResource("15_xl7yx") +labelAsteroids = NodePath("VBoxLabels/LabelAsteroids") +labelLevel = NodePath("VBoxLabels/LabelLevel") +labelLifes = NodePath("VBoxLabels/LabelLives") +labelNextLevel = NodePath("VBoxLabels/LabelNextLevel") +labelPoints = NodePath("VBoxLabels/LabelPoints") +labelGameOver = NodePath("VBoxGameOver/LabelGameOver") +restartButton = NodePath("VBoxGameOver/RestartButton") +reachedPointsLabel = NodePath("VBoxGameOver/ReachedPointsLabel") +healthBar = NodePath("VBoxHealth/HealthBar") + +[node name="VBoxLabels" type="VBoxContainer" parent="Ui"] +anchors_preset = 2 +anchor_top = 1.0 +anchor_bottom = 1.0 +offset_top = 1138.0 +offset_right = 152.0 +offset_bottom = 1278.0 +grow_vertical = 0 + +[node name="LabelAsteroids" type="RichTextLabel" parent="Ui/VBoxLabels"] layout_mode = 2 -offset_left = 20.0 -offset_top = 20.0 -offset_right = 260.0 -offset_bottom = 40.0 +size_flags_vertical = 3 text = "Asteroids: 0" scroll_active = false shortcut_keys_enabled = false -[node name="LabelLives" type="RichTextLabel" parent="Control"] +[node name="LabelLevel" type="RichTextLabel" parent="Ui/VBoxLabels"] layout_mode = 2 -offset_left = 20.0 -offset_top = 40.0 -offset_right = 260.0 -offset_bottom = 60.0 -text = "Lives: 3" +size_flags_vertical = 3 +text = "Level: 1" scroll_active = false shortcut_keys_enabled = false -[node name="LabelPoints" type="RichTextLabel" parent="Control"] +[node name="LabelLives" type="RichTextLabel" parent="Ui/VBoxLabels"] layout_mode = 2 -offset_left = 20.0 -offset_top = 60.0 -offset_right = 260.0 -offset_bottom = 80.0 -text = "Points: 0" +size_flags_vertical = 3 +text = "Lives: 3" scroll_active = false shortcut_keys_enabled = false -[node name="LabelLevel" type="RichTextLabel" parent="Control"] +[node name="LabelNextLevel" type="RichTextLabel" parent="Ui/VBoxLabels"] layout_mode = 2 -offset_left = 20.0 -offset_top = 80.0 -offset_right = 260.0 -offset_bottom = 100.0 -text = "Level: 1" +size_flags_vertical = 3 +text = "Next Level: 10" scroll_active = false shortcut_keys_enabled = false -[node name="LabelNextLevel" type="RichTextLabel" parent="Control"] +[node name="LabelPoints" type="RichTextLabel" parent="Ui/VBoxLabels"] layout_mode = 2 -offset_left = 20.0 -offset_top = 100.0 -offset_right = 260.0 -offset_bottom = 120.0 -text = "Next Level: 10" +size_flags_vertical = 3 +text = "Points: 0" scroll_active = false shortcut_keys_enabled = false -[node name="LabelDebug" type="RichTextLabel" parent="Control"] +[node name="VBoxGameOver" type="VBoxContainer" parent="Ui"] +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = 195.5 +offset_top = 490.0 +offset_right = 603.5 +offset_bottom = 788.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="LabelGameOver" type="RichTextLabel" parent="Ui/VBoxGameOver"] layout_mode = 2 -offset_left = 543.0 -offset_top = 1225.0 -offset_right = 783.0 -offset_bottom = 1245.0 -scale = Vector2(1, 1.88) -bbcode_enabled = true -text = "[right][color=red]Debug[/color][/right]" +size_flags_vertical = 3 +theme_override_colors/default_color = Color(1, 0, 0, 1) +theme_override_colors/font_shadow_color = Color(0, 0, 0, 1) +theme_override_colors/font_outline_color = Color(1, 1, 1, 1) +theme_override_constants/shadow_offset_x = 1 +theme_override_constants/shadow_offset_y = -1 +theme_override_constants/shadow_outline_size = 0 +theme_override_font_sizes/normal_font_size = 20 +text = "Game Over" scroll_active = false shortcut_keys_enabled = false -[node name="LabelGameOver" type="RichTextLabel" parent="Control"] +[node name="ReachedPointsLabel" type="RichTextLabel" parent="Ui/VBoxGameOver"] layout_mode = 2 -offset_left = 12.0 -offset_top = 437.0 -offset_right = 230.0 -offset_bottom = 460.0 -scale = Vector2(3.6, 7.48) +size_flags_vertical = 3 bbcode_enabled = true -text = "[center][shake rate=30 level=10 connected=1][rainbow freq=1.0 sat=0.8 val=0.8]Game Over[/rainbow][/shake][/center]" -scroll_active = false -shortcut_keys_enabled = false +text = "[center]You have reached level 1 and 0 points![/center]" -[node name="RestartButton" type="Button" parent="Control"] -layout_mode = 0 -offset_left = 354.0 -offset_top = 644.0 -offset_right = 462.0 -offset_bottom = 777.0 +[node name="RestartButton" type="Button" parent="Ui/VBoxGameOver"] +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 6 shortcut = SubResource("Shortcut_soxs4") icon = ExtResource("15_nxptg") icon_alignment = 1 -[node name="ReachedPointsLabel" type="RichTextLabel" parent="Control"] -layout_mode = 0 -offset_left = 173.0 -offset_top = 600.0 -offset_right = 652.0 -offset_bottom = 626.0 -bbcode_enabled = true -text = "[center]You have reached level 1 and 0 points![/center]" +[node name="VBoxHealth" type="VBoxContainer" parent="Ui"] +anchors_preset = 5 +anchor_left = 0.5 +anchor_right = 0.5 +offset_left = 45.0 +offset_right = 754.0 +offset_bottom = 22.0 +grow_horizontal = 2 + +[node name="HealthBar" type="ProgressBar" parent="Ui/VBoxHealth"] +layout_mode = 2 +size_flags_vertical = 3 +max_value = 10.0 +value = 7.0 +rounded = true +show_percentage = false + +[node name="GameManager" type="Node" parent="." node_paths=PackedStringArray("asteroidsContainer")] +script = ExtResource("9_rsrr5") +asteroids = Array[PackedScene]([ExtResource("5_do6ba"), ExtResource("6_tqoe7"), ExtResource("7_v6ul2")]) +asteroidsContainer = NodePath("../Asteroids") diff --git a/Scripts/GameManager.cs b/Scripts/GameManager.cs index 8a41b47..2b58d2f 100644 --- a/Scripts/GameManager.cs +++ b/Scripts/GameManager.cs @@ -1,3 +1,4 @@ +using System; using Godot; using Godot.Collections; @@ -7,45 +8,36 @@ public partial class GameManager : Node { private int asteroidMaxNumber = 3; private int asteroidNumber; public bool GameOver { get; private set; } - [Export] private bool debug = true; [Export] private Array asteroids; [Export] private Node3D asteroidsContainer; - [Export] private RichTextLabel labelAsteroids; - [Export] private RichTextLabel labelLevel; - [Export] private RichTextLabel labelLifes; - [Export] private RichTextLabel labelNextLevel; - [Export] private RichTextLabel labelPoints; - [Export] private RichTextLabel labelDebug; - [Export] private RichTextLabel labelGameOver; - [Export] private Button restartButton; - [Export] private RichTextLabel reachedPointsLabel; - private int level = 1; public int MaxLives { get; private set; } = 10; private int lives = 10; private int nextLevelPoints = 11; private int points; private float spawnRate = 1f; - private float spawnTimer; + public event EventHandler RefreshUi; + public int AsteroidNumber { get => asteroidNumber; set { asteroidNumber = value; - RefreshUi(); + RefreshUi?.Invoke(this, EventArgs.Empty); } } + public bool GamePaused { get; private set; } = true; + public int Lives { get => lives; set { lives = value; if (lives <= 0) SetGameOver(); - RefreshUi(); - PlayerShip.Instance.RefreshUi(); + RefreshUi?.Invoke(this, EventArgs.Empty); } } @@ -54,7 +46,7 @@ public partial class GameManager : Node { set { points = value; if (points >= nextLevelPoints) NextLevel(); - RefreshUi(); + RefreshUi?.Invoke(this, EventArgs.Empty); } } @@ -62,40 +54,39 @@ public partial class GameManager : Node { get => level; private set { level = value; - RefreshUi(); + RefreshUi?.Invoke(this, EventArgs.Empty); } } - private int NextLevelPoints { + public int NextLevelPoints { get => nextLevelPoints; set { nextLevelPoints = value; - RefreshUi(); + RefreshUi?.Invoke(this, EventArgs.Empty); } } - private int AsteroidMaxNumber { + public int AsteroidMaxNumber { get => asteroidMaxNumber; set { asteroidMaxNumber = value; - RefreshUi(); + RefreshUi?.Invoke(this, EventArgs.Empty); } } public static GameManager Instance { get; private set; } + [Export] public bool Debug { get; private set; } = true; public override void _Ready() { Instance = this; Lives = MaxLives; spawnTimer = spawnRate; - SoundManager.Instance.Play(SoundManager.Sound.BackgroundMusic); - restartButton.Pressed += RestartButtonOnPressed; - RefreshUi(); - PlayerShip.Instance.RefreshUi(); + SoundManager.Instance.Ready += SoundManagerReady; + RefreshUi?.Invoke(this, EventArgs.Empty); } - private void RestartButtonOnPressed() => GetTree().ReloadCurrentScene(); + private void SoundManagerReady() => SoundManager.Instance.Play(SoundManager.Sound.BackgroundMusic); public override void _Process(double delta) { spawnTimer -= (float)delta; @@ -113,34 +104,17 @@ public partial class GameManager : Node { asteroid.Name = $"Asteroid{AsteroidNumber}"; } - private void RefreshUi() { - labelLifes.Text = $"Lives: {lives}"; - labelAsteroids.Text = $"Asteroids: {asteroidNumber} / {asteroidMaxNumber}"; - labelPoints.Text = $"Points: {points}"; - labelNextLevel.Text = $"Next Level at: {NextLevelPoints}"; - labelLevel.Text = $"Actual Level: {Level}"; - labelDebug.Visible = debug; - labelGameOver.Visible = GameOver; - restartButton.Visible = GameOver; - reachedPointsLabel.Visible = GameOver; - } - private void NextLevel() { - GD.Print("Next Level!"); + Ui.Instance.ShowMessage("Next Level!"); Level++; NextLevelPoints = Level * 33; AsteroidMaxNumber = 3 + Level; spawnRate = 1f - Level * 0.1f; } - public void OnGameAreaBodyExited(Node body) { - GD.Print($"{body.Name} leaved GameArea!"); - } - private void SetGameOver() { GameOver = true; - reachedPointsLabel.Text = $"[center]You have reached level {Level} and {Points} points![/center]"; SoundManager.Instance.Stop(SoundManager.Sound.BackgroundMusic); SoundManager.Instance.Play(SoundManager.Sound.GameOver); } -} \ No newline at end of file +} diff --git a/Scripts/PlayerShip.cs b/Scripts/PlayerShip.cs index 81944aa..2dd8926 100644 --- a/Scripts/PlayerShip.cs +++ b/Scripts/PlayerShip.cs @@ -28,7 +28,6 @@ public partial class PlayerShip : Node3D { private bool shooting; [Export] private Node3D shots; - [Export] private ProgressBar healthBar; public static PlayerShip Instance { get; private set; } @@ -37,11 +36,6 @@ public partial class PlayerShip : Node3D { Instance = this; } - public void RefreshUi() { - healthBar.MaxValue = GameManager.Instance.MaxLives; - healthBar.Value = GameManager.Instance.Lives; - } - public override void _Process(double delta) { if (GameManager.Instance.GameOver) return; diff --git a/Scripts/Ui.cs b/Scripts/Ui.cs new file mode 100644 index 0000000..5b9b3ba --- /dev/null +++ b/Scripts/Ui.cs @@ -0,0 +1,50 @@ +using System; +using Godot; + +namespace Scripts; +public partial class Ui : Node2D +{ + [Export] private RichTextLabel labelAsteroids; + [Export] private RichTextLabel labelLevel; + [Export] private RichTextLabel labelLifes; + [Export] private RichTextLabel labelNextLevel; + [Export] private RichTextLabel labelPoints; + [Export] private RichTextLabel labelGameOver; + [Export] private Button restartButton; + [Export] private RichTextLabel reachedPointsLabel; + [Export] private ProgressBar healthBar; + + public static Ui Instance { get; private set; } + public override void _Ready() { + Instance = this; + GameManager.Instance.RefreshUi += RefreshUi; + restartButton.Pressed += RestartButtonOnPressed; + labelGameOver.Visible = GameManager.Instance.GameOver; + restartButton.Visible = GameManager.Instance.GameOver; + reachedPointsLabel.Visible = GameManager.Instance.GameOver; + RefreshUi(this, EventArgs.Empty); + } + + private void RefreshUi(object sender, EventArgs e) { + labelLifes.Text = $"Lives: {GameManager.Instance.Lives}"; + labelAsteroids.Text = $"Asteroids: {GameManager.Instance.AsteroidNumber} / {GameManager.Instance.AsteroidMaxNumber}"; + labelPoints.Text = $"Points: {GameManager.Instance.Points}"; + labelNextLevel.Text = $"Next Level at: {GameManager.Instance.NextLevelPoints}"; + labelLevel.Text = $"Actual Level: {GameManager.Instance.Level}"; + healthBar.MaxValue = GameManager.Instance.MaxLives; + healthBar.Value = GameManager.Instance.Lives; + + if (GameManager.Instance.GameOver) { + reachedPointsLabel.Text = $"[center]You have reached level {GameManager.Instance.Level} and {GameManager.Instance.Points} points![/center]"; + labelGameOver.Visible = GameManager.Instance.GameOver; + restartButton.Visible = GameManager.Instance.GameOver; + reachedPointsLabel.Visible = GameManager.Instance.GameOver; + } + } + + private void RestartButtonOnPressed() => GetTree().ReloadCurrentScene(); + + public void ShowMessage(string message) { + GD.Print(message); + } +} From 8a4b1452ee137f69c9d3321c1b8c399b31e86e56 Mon Sep 17 00:00:00 2001 From: Sascha Date: Sun, 12 Nov 2023 09:05:04 +0100 Subject: [PATCH 02/14] ui --- Godot-space Shooter.csproj.old.5 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Godot-space Shooter.csproj.old.5 b/Godot-space Shooter.csproj.old.5 index 1ac13b1..4faed17 100644 --- a/Godot-space Shooter.csproj.old.5 +++ b/Godot-space Shooter.csproj.old.5 @@ -1,4 +1,4 @@ - + net6.0 true From 15f746fe372cd438d7289fc58664d2abb5f98654 Mon Sep 17 00:00:00 2001 From: Sascha Date: Fri, 17 Nov 2023 10:37:28 +0100 Subject: [PATCH 03/14] new build --- Godot-space Shooter.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Godot-space Shooter.csproj b/Godot-space Shooter.csproj index 4faed17..8693357 100644 --- a/Godot-space Shooter.csproj +++ b/Godot-space Shooter.csproj @@ -1,4 +1,4 @@ - + net6.0 true From 9fa74f9e1c68808e3a63572c0093c9e2f9829caa Mon Sep 17 00:00:00 2001 From: Sascha Date: Tue, 19 Dec 2023 08:59:58 +0100 Subject: [PATCH 04/14] Upgrade to Godot 4.3.0-dev --- Godot-space Shooter.csproj | 4 ++-- Godot-space Shooter.csproj.old.5 | 2 +- Godot-space Shooter.sln.DotSettings.user | 2 ++ project.godot | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 Godot-space Shooter.sln.DotSettings.user diff --git a/Godot-space Shooter.csproj b/Godot-space Shooter.csproj index 8693357..aecde1d 100644 --- a/Godot-space Shooter.csproj +++ b/Godot-space Shooter.csproj @@ -1,6 +1,6 @@ - + - net6.0 + net8.0 true \ No newline at end of file diff --git a/Godot-space Shooter.csproj.old.5 b/Godot-space Shooter.csproj.old.5 index 4faed17..8693357 100644 --- a/Godot-space Shooter.csproj.old.5 +++ b/Godot-space Shooter.csproj.old.5 @@ -1,4 +1,4 @@ - + net6.0 true diff --git a/Godot-space Shooter.sln.DotSettings.user b/Godot-space Shooter.sln.DotSettings.user new file mode 100644 index 0000000..565c4d9 --- /dev/null +++ b/Godot-space Shooter.sln.DotSettings.user @@ -0,0 +1,2 @@ + + ExplicitlyExcluded \ No newline at end of file diff --git a/project.godot b/project.godot index 3ae0934..5bc118b 100644 --- a/project.godot +++ b/project.godot @@ -13,7 +13,7 @@ config_version=5 config/name="Space Shooter" config/version="0.1" run/main_scene="res://Scenes/SpaceShooter.tscn" -config/features=PackedStringArray("4.2", "C#", "Forward Plus") +config/features=PackedStringArray("4.3", "C#", "Forward Plus") boot_splash/image="res://Images/GodotSplashScreen.png" config/icon="res://Images/Space-Shooter.png" From e3d288251e62eda64a273fad482a18479b88f034 Mon Sep 17 00:00:00 2001 From: Sascha Date: Tue, 23 Jan 2024 11:14:45 +0100 Subject: [PATCH 05/14] Bug fixed: UI loaded before GameManger --- Godot-space Shooter.csproj | 2 +- Godot-space Shooter.csproj.old.5 | 4 +- Godot-space Shooter.sln.DotSettings.user | 3 +- Meshes/asteroid_01.mesh | Bin 28541 -> 28540 bytes Meshes/asteroid_02.mesh | Bin 19113 -> 19113 bytes Meshes/asteroid_03.mesh | Bin 30370 -> 30371 bytes Scenes/SpaceShooter.tscn | 15 +++--- Scripts/Ui.cs | 21 ++++---- export_presets.cfg | 66 +++++++++++++++++++++++ project.godot | 2 +- 10 files changed, 93 insertions(+), 20 deletions(-) diff --git a/Godot-space Shooter.csproj b/Godot-space Shooter.csproj index aecde1d..5cef799 100644 --- a/Godot-space Shooter.csproj +++ b/Godot-space Shooter.csproj @@ -1,4 +1,4 @@ - + net8.0 true diff --git a/Godot-space Shooter.csproj.old.5 b/Godot-space Shooter.csproj.old.5 index 8693357..5cef799 100644 --- a/Godot-space Shooter.csproj.old.5 +++ b/Godot-space Shooter.csproj.old.5 @@ -1,6 +1,6 @@ - + - net6.0 + net8.0 true \ No newline at end of file diff --git a/Godot-space Shooter.sln.DotSettings.user b/Godot-space Shooter.sln.DotSettings.user index 565c4d9..0e57695 100644 --- a/Godot-space Shooter.sln.DotSettings.user +++ b/Godot-space Shooter.sln.DotSettings.user @@ -1,2 +1,3 @@  - ExplicitlyExcluded \ No newline at end of file + ForceIncluded + ExplicitlyExcluded \ No newline at end of file diff --git a/Meshes/asteroid_01.mesh b/Meshes/asteroid_01.mesh index 9b36a592182b0b030b72e08eaa741772306451ee..54f557eb71f01563246aa728fa8048c94b1ed64f 100644 GIT binary patch delta 1820 zcmV+%2jlqt-U0mH0TEJDLqh@p0000G000}C007>R5iSO$MgXdKJds5F+rZHch@|pVqX2~a$kIwY3^v=Xx`^7IoNs8 ztdbjY@fqhhJsMZNPn@RrSlR~+-ZuC$ zpXcou{eJ{sG&yR=bkUwY-fK_dzTk<*%`MMluT4xmujSWned^LCao-s4|AlYV#jo#2 zV?J$9aVDbI;*)rJ*}msmVwGdQ7K_<5rrEql-Z}18r^vfad+aJUf6sF*v8hpOruZcO ze}c~|Q@pRr)4TisgFWY0wLOW`yq>qtTeTaTY1m`*rV1XXxa3xMd)`u?7MFX~9Pj@( z`~OvK72petAdVw{;ImBR^WKm(Q-|T^dMUn`R+S^VwI8 zjp^O?#L28$f1XYA7HwY7Xin;_@-ySJ%zfXno@T9Lz09qNlew6#8od^&w^7BI2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paceShooter.tscn @@ -28,8 +28,11 @@ events = [SubResource("InputEventKey_gjrl7")] [node name="SpaceShooter" type="Node3D"] -[node name="PlayerShip" parent="." instance=ExtResource("1_njb5h")] +[node name="PlayerShip" parent="." node_paths=PackedStringArray("jet", "PlayerRb", "shots") instance=ExtResource("1_njb5h")] transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74227e-08, 0, -1, 0, 0, 5) +jet = NodePath("RigidBody3D/Jet") +PlayerRb = NodePath("RigidBody3D") +shots = NodePath("Shots") [node name="Camera3D" type="Camera3D" parent="."] transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 8.8, 0) @@ -106,6 +109,11 @@ stream = ExtResource("9_rtdps") [node name="LaserSound" type="AudioStreamPlayer3D" parent="SoundManager"] stream = ExtResource("11_bbedd") +[node name="GameManager" type="Node" parent="." node_paths=PackedStringArray("asteroidsContainer")] +script = ExtResource("9_rsrr5") +asteroids = Array[PackedScene]([ExtResource("5_do6ba"), ExtResource("6_tqoe7"), ExtResource("7_v6ul2")]) +asteroidsContainer = NodePath("../Asteroids") + [node name="Ui" type="Node2D" parent="." node_paths=PackedStringArray("labelAsteroids", "labelLevel", "labelLifes", "labelNextLevel", "labelPoints", "labelGameOver", "restartButton", "reachedPointsLabel", "healthBar")] script = ExtResource("15_xl7yx") labelAsteroids = NodePath("VBoxLabels/LabelAsteroids") @@ -219,8 +227,3 @@ max_value = 10.0 value = 7.0 rounded = true show_percentage = false - -[node name="GameManager" type="Node" parent="." node_paths=PackedStringArray("asteroidsContainer")] -script = ExtResource("9_rsrr5") -asteroids = Array[PackedScene]([ExtResource("5_do6ba"), ExtResource("6_tqoe7"), ExtResource("7_v6ul2")]) -asteroidsContainer = NodePath("../Asteroids") diff --git a/Scripts/Ui.cs b/Scripts/Ui.cs index 5b9b3ba..8f35dec 100644 --- a/Scripts/Ui.cs +++ b/Scripts/Ui.cs @@ -15,14 +15,19 @@ public partial class Ui : Node2D [Export] private ProgressBar healthBar; public static Ui Instance { get; private set; } + public override void _Ready() { Instance = this; - GameManager.Instance.RefreshUi += RefreshUi; - restartButton.Pressed += RestartButtonOnPressed; - labelGameOver.Visible = GameManager.Instance.GameOver; - restartButton.Visible = GameManager.Instance.GameOver; - reachedPointsLabel.Visible = GameManager.Instance.GameOver; - RefreshUi(this, EventArgs.Empty); + if (GameManager.Instance is null) + GD.PrintErr("No GameManager found!"); + else { + GameManager.Instance.RefreshUi += RefreshUi; + restartButton.Pressed += RestartButtonOnPressed; + labelGameOver.Visible = GameManager.Instance.GameOver; + restartButton.Visible = GameManager.Instance.GameOver; + reachedPointsLabel.Visible = GameManager.Instance.GameOver; + RefreshUi(this, EventArgs.Empty); + } } private void RefreshUi(object sender, EventArgs e) { @@ -44,7 +49,5 @@ public partial class Ui : Node2D private void RestartButtonOnPressed() => GetTree().ReloadCurrentScene(); - public void ShowMessage(string message) { - GD.Print(message); - } + public void ShowMessage(string message) => GD.Print(message); } diff --git a/export_presets.cfg b/export_presets.cfg index a1fc08c..6d6f15b 100644 --- a/export_presets.cfg +++ b/export_presets.cfg @@ -40,3 +40,69 @@ rm -rf \"{temp_dir}\"" dotnet/include_scripts_content=false dotnet/include_debug_symbols=true dotnet/embed_build_outputs=false + +[preset.1] + +name="Windows Desktop" +platform="Windows Desktop" +runnable=true +dedicated_server=false +custom_features="" +export_filter="all_resources" +include_filter="" +exclude_filter="" +export_path="" +encryption_include_filters="" +encryption_exclude_filters="" +encrypt_pck=false +encrypt_directory=false + +[preset.1.options] + +custom_template/debug="" +custom_template/release="" +debug/export_console_wrapper=1 +binary_format/embed_pck=false +texture_format/bptc=true +texture_format/s3tc=true +texture_format/etc=false +texture_format/etc2=false +binary_format/architecture="x86_64" +codesign/enable=false +codesign/timestamp=true +codesign/timestamp_server_url="" +codesign/digest_algorithm=1 +codesign/description="" +codesign/custom_options=PackedStringArray() +application/modify_resources=true +application/icon="" +application/console_wrapper_icon="" +application/icon_interpolation=4 +application/file_version="" +application/product_version="" +application/company_name="" +application/product_name="" +application/file_description="" +application/copyright="" +application/trademarks="" +application/export_angle=0 +ssh_remote_deploy/enabled=false +ssh_remote_deploy/host="user@host_ip" +ssh_remote_deploy/port="22" +ssh_remote_deploy/extra_args_ssh="" +ssh_remote_deploy/extra_args_scp="" +ssh_remote_deploy/run_script="Expand-Archive -LiteralPath '{temp_dir}\\{archive_name}' -DestinationPath '{temp_dir}' +$action = New-ScheduledTaskAction -Execute '{temp_dir}\\{exe_name}' -Argument '{cmd_args}' +$trigger = New-ScheduledTaskTrigger -Once -At 00:00 +$settings = New-ScheduledTaskSettingsSet +$task = New-ScheduledTask -Action $action -Trigger $trigger -Settings $settings +Register-ScheduledTask godot_remote_debug -InputObject $task -Force:$true +Start-ScheduledTask -TaskName godot_remote_debug +while (Get-ScheduledTask -TaskName godot_remote_debug | ? State -eq running) { Start-Sleep -Milliseconds 100 } +Unregister-ScheduledTask -TaskName godot_remote_debug -Confirm:$false -ErrorAction:SilentlyContinue" +ssh_remote_deploy/cleanup_script="Stop-ScheduledTask -TaskName godot_remote_debug -ErrorAction:SilentlyContinue +Unregister-ScheduledTask -TaskName godot_remote_debug -Confirm:$false -ErrorAction:SilentlyContinue +Remove-Item -Recurse -Force '{temp_dir}'" +dotnet/include_scripts_content=false +dotnet/include_debug_symbols=true +dotnet/embed_build_outputs=false diff --git a/project.godot b/project.godot index 5bc118b..bdceb04 100644 --- a/project.godot +++ b/project.godot @@ -13,7 +13,7 @@ config_version=5 config/name="Space Shooter" config/version="0.1" run/main_scene="res://Scenes/SpaceShooter.tscn" -config/features=PackedStringArray("4.3", "C#", "Forward Plus") +config/features=PackedStringArray("4.3", "C#") boot_splash/image="res://Images/GodotSplashScreen.png" config/icon="res://Images/Space-Shooter.png" From 5bbe27e626952b46eaccd160c921ac2507990ae4 Mon Sep 17 00:00:00 2001 From: Sascha Date: Tue, 23 Jan 2024 14:49:25 +0100 Subject: [PATCH 06/14] new version --- Godot-space Shooter.csproj | 2 +- Godot-space Shooter.csproj.old.5 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Godot-space Shooter.csproj b/Godot-space Shooter.csproj index 5cef799..218871a 100644 --- a/Godot-space Shooter.csproj +++ b/Godot-space Shooter.csproj @@ -1,4 +1,4 @@ - + net8.0 true diff --git a/Godot-space Shooter.csproj.old.5 b/Godot-space Shooter.csproj.old.5 index 5cef799..218871a 100644 --- a/Godot-space Shooter.csproj.old.5 +++ b/Godot-space Shooter.csproj.old.5 @@ -1,4 +1,4 @@ - + net8.0 true From aa8b56a72c7e95e317596c399449054e847a5b5f Mon Sep 17 00:00:00 2001 From: Sascha Date: Wed, 24 Jan 2024 12:34:10 +0100 Subject: [PATCH 07/14] Pause --- Godot-space Shooter.csproj | 4 ++ Godot-space Shooter.csproj.old.5 | 1 + Godot-space Shooter.sln | 14 ++--- Scenes/SpaceShooter.tscn | 99 +++++++++++++++++++++++--------- Scripts/Asteroid.cs | 2 +- Scripts/Background.cs | 2 +- Scripts/Explosion.cs | 2 + Scripts/GameArea.cs | 2 + Scripts/GameManager.cs | 19 ++++-- Scripts/InputManager.cs | 26 +++++++++ Scripts/LaserBeam.cs | 2 + Scripts/PlayerShip.cs | 2 +- Scripts/SoundManager.cs | 2 +- Scripts/Ui.cs | 11 ++-- project.godot | 7 +++ 15 files changed, 146 insertions(+), 49 deletions(-) create mode 100644 Scripts/InputManager.cs diff --git a/Godot-space Shooter.csproj b/Godot-space Shooter.csproj index 218871a..9d3fa14 100644 --- a/Godot-space Shooter.csproj +++ b/Godot-space Shooter.csproj @@ -2,5 +2,9 @@ net8.0 true + GodotspaceShooter + + + \ No newline at end of file diff --git a/Godot-space Shooter.csproj.old.5 b/Godot-space Shooter.csproj.old.5 index 218871a..cc1116d 100644 --- a/Godot-space Shooter.csproj.old.5 +++ b/Godot-space Shooter.csproj.old.5 @@ -2,5 +2,6 @@ net8.0 true + GodotspaceShooter \ No newline at end of file diff --git a/Godot-space Shooter.sln b/Godot-space Shooter.sln index 896aa9b..5b844cf 100644 --- a/Godot-space Shooter.sln +++ b/Godot-space Shooter.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2012 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Godot-space Shooter", "Godot-space Shooter.csproj", "{240DDE4D-DBD7-403E-B52D-F5962748425A}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Godot-space Shooter", "Godot-space Shooter.csproj", "{EDAECF90-1BC3-4D10-849B-57165567D656}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -9,11 +9,11 @@ Global ExportRelease|Any CPU = ExportRelease|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {240DDE4D-DBD7-403E-B52D-F5962748425A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {240DDE4D-DBD7-403E-B52D-F5962748425A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {240DDE4D-DBD7-403E-B52D-F5962748425A}.ExportDebug|Any CPU.ActiveCfg = ExportDebug|Any CPU - {240DDE4D-DBD7-403E-B52D-F5962748425A}.ExportDebug|Any CPU.Build.0 = ExportDebug|Any CPU - {240DDE4D-DBD7-403E-B52D-F5962748425A}.ExportRelease|Any CPU.ActiveCfg = ExportRelease|Any CPU - {240DDE4D-DBD7-403E-B52D-F5962748425A}.ExportRelease|Any CPU.Build.0 = ExportRelease|Any CPU + {EDAECF90-1BC3-4D10-849B-57165567D656}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EDAECF90-1BC3-4D10-849B-57165567D656}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EDAECF90-1BC3-4D10-849B-57165567D656}.ExportDebug|Any CPU.ActiveCfg = ExportDebug|Any CPU + {EDAECF90-1BC3-4D10-849B-57165567D656}.ExportDebug|Any CPU.Build.0 = ExportDebug|Any CPU + {EDAECF90-1BC3-4D10-849B-57165567D656}.ExportRelease|Any CPU.ActiveCfg = ExportRelease|Any CPU + {EDAECF90-1BC3-4D10-849B-57165567D656}.ExportRelease|Any CPU.Build.0 = ExportRelease|Any CPU EndGlobalSection EndGlobal diff --git a/Scenes/SpaceShooter.tscn b/Scenes/SpaceShooter.tscn index f32f87f..3d0b25a 100644 --- a/Scenes/SpaceShooter.tscn +++ b/Scenes/SpaceShooter.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=20 format=3 uid="uid://det8556rpxhbv"] +[gd_scene load_steps=22 format=3 uid="uid://det8556rpxhbv"] [ext_resource type="PackedScene" uid="uid://tlr55u0gn20l" path="res://Packed-Scenes/PlayerShip.tscn" id="1_njb5h"] [ext_resource type="Texture2D" uid="uid://cg6n1hh3lj7rn" path="res://Textures/tile_nebula_green_dff.png" id="2_43vix"] @@ -14,11 +14,19 @@ [ext_resource type="AudioStream" uid="uid://bspwjmgsoxkbn" path="res://Sounds/gameover2.wav" id="9_rtdps"] [ext_resource type="AudioStream" uid="uid://dlml6o3xscxqf" path="res://Sounds/weapon_player.wav" id="11_bbedd"] [ext_resource type="Script" path="res://Scripts/GameArea.cs" id="11_p0rh7"] -[ext_resource type="Texture2D" uid="uid://b8gy1u2i0jkyd" path="res://Images/restart.svg" id="15_nxptg"] +[ext_resource type="Script" path="res://Scripts/InputManager.cs" id="15_uovst"] [ext_resource type="Script" path="res://Scripts/Ui.cs" id="15_xl7yx"] [sub_resource type="BoxShape3D" id="BoxShape3D_bw288"] +[sub_resource type="LabelSettings" id="LabelSettings_dqsad"] +font_size = 50 +font_color = Color(1, 0, 0, 1) +outline_size = 3 +outline_color = Color(1, 0.999986, 0.00293482, 1) +shadow_size = 10 +shadow_offset = Vector2(5, 5) + [sub_resource type="InputEventKey" id="InputEventKey_gjrl7"] device = -1 keycode = 4194309 @@ -26,21 +34,34 @@ keycode = 4194309 [sub_resource type="Shortcut" id="Shortcut_soxs4"] events = [SubResource("InputEventKey_gjrl7")] +[sub_resource type="LabelSettings" id="LabelSettings_vf3s8"] +font_size = 50 +font_color = Color(0.233592, 0.506913, 1, 1) +outline_size = 3 +outline_color = Color(0, 1, 0.00392157, 1) +shadow_size = 10 +shadow_offset = Vector2(5, 5) + [node name="SpaceShooter" type="Node3D"] +process_mode = 3 [node name="PlayerShip" parent="." node_paths=PackedStringArray("jet", "PlayerRb", "shots") instance=ExtResource("1_njb5h")] +process_mode = 1 transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74227e-08, 0, -1, 0, 0, 5) jet = NodePath("RigidBody3D/Jet") PlayerRb = NodePath("RigidBody3D") shots = NodePath("Shots") [node name="Camera3D" type="Camera3D" parent="."] +process_mode = 1 transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 8.8, 0) [node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] +process_mode = 1 transform = Transform3D(1, 0, 0, 0, 0.707106, 0.707106, 0, -0.707106, 0.707106, 10, 10, 10) [node name="Background" type="Sprite3D" parent="."] +process_mode = 1 transform = Transform3D(1.1, 0, 0, 0, -4.80825e-08, -1, 0, 1.1, -4.37114e-08, 0, -0.5, 0) billboard = 1 shaded = true @@ -51,8 +72,10 @@ region_rect = Rect2(0, 0, 810, 1380) script = ExtResource("3_imgbw") [node name="Asteroids" type="Node3D" parent="."] +process_mode = 1 [node name="GameArea" type="Node3D" parent="."] +process_mode = 1 script = ExtResource("11_p0rh7") [node name="Bottom" type="RigidBody3D" parent="GameArea"] @@ -86,6 +109,7 @@ transform = Transform3D(15, 0, 0, 0, 15, 0, 0, 0, 15, 0, 0, 0) shape = SubResource("BoxShape3D_bw288") [node name="SoundManager" type="Node" parent="." node_paths=PackedStringArray("backgroundMusic", "gameOverMusic", "asteroidExplosionSound", "playerExplosionSound", "laserSound")] +process_mode = 1 script = ExtResource("8_4ksf0") backgroundMusic = NodePath("BackgroundMusic") gameOverMusic = NodePath("GameOverMusic") @@ -110,13 +134,19 @@ stream = ExtResource("9_rtdps") stream = ExtResource("11_bbedd") [node name="GameManager" type="Node" parent="." node_paths=PackedStringArray("asteroidsContainer")] +process_mode = 1 script = ExtResource("9_rsrr5") asteroids = Array[PackedScene]([ExtResource("5_do6ba"), ExtResource("6_tqoe7"), ExtResource("7_v6ul2")]) asteroidsContainer = NodePath("../Asteroids") -[node name="Ui" type="Node2D" parent="." node_paths=PackedStringArray("labelAsteroids", "labelLevel", "labelLifes", "labelNextLevel", "labelPoints", "labelGameOver", "restartButton", "reachedPointsLabel", "healthBar")] +[node name="InputManager" type="Node" parent="."] +process_mode = 3 +script = ExtResource("15_uovst") + +[node name="Ui" type="Node2D" parent="." node_paths=PackedStringArray("rtlAsteroids", "labelLevel", "labelLifes", "labelNextLevel", "labelPoints", "labelGameOver", "restartButton", "reachedPointsLabel", "healthBar", "vBoxPause")] +process_mode = 3 script = ExtResource("15_xl7yx") -labelAsteroids = NodePath("VBoxLabels/LabelAsteroids") +rtlAsteroids = NodePath("VBoxLabels/rtlAsteroids") labelLevel = NodePath("VBoxLabels/LabelLevel") labelLifes = NodePath("VBoxLabels/LabelLives") labelNextLevel = NodePath("VBoxLabels/LabelNextLevel") @@ -125,6 +155,7 @@ labelGameOver = NodePath("VBoxGameOver/LabelGameOver") restartButton = NodePath("VBoxGameOver/RestartButton") reachedPointsLabel = NodePath("VBoxGameOver/ReachedPointsLabel") healthBar = NodePath("VBoxHealth/HealthBar") +vBoxPause = NodePath("VBoxPause") [node name="VBoxLabels" type="VBoxContainer" parent="Ui"] anchors_preset = 2 @@ -135,7 +166,7 @@ offset_right = 152.0 offset_bottom = 1278.0 grow_vertical = 0 -[node name="LabelAsteroids" type="RichTextLabel" parent="Ui/VBoxLabels"] +[node name="rtlAsteroids" type="RichTextLabel" parent="Ui/VBoxLabels"] layout_mode = 2 size_flags_vertical = 3 text = "Asteroids: 0" @@ -171,31 +202,25 @@ scroll_active = false shortcut_keys_enabled = false [node name="VBoxGameOver" type="VBoxContainer" parent="Ui"] +visible = false anchors_preset = 8 anchor_left = 0.5 anchor_top = 0.5 anchor_right = 0.5 anchor_bottom = 0.5 -offset_left = 195.5 -offset_top = 490.0 -offset_right = 603.5 -offset_bottom = 788.0 +offset_left = 197.0 +offset_top = 556.0 +offset_right = 605.0 +offset_bottom = 854.0 grow_horizontal = 2 grow_vertical = 2 -[node name="LabelGameOver" type="RichTextLabel" parent="Ui/VBoxGameOver"] +[node name="LabelGameOver" type="Label" parent="Ui/VBoxGameOver"] layout_mode = 2 -size_flags_vertical = 3 -theme_override_colors/default_color = Color(1, 0, 0, 1) -theme_override_colors/font_shadow_color = Color(0, 0, 0, 1) -theme_override_colors/font_outline_color = Color(1, 1, 1, 1) -theme_override_constants/shadow_offset_x = 1 -theme_override_constants/shadow_offset_y = -1 -theme_override_constants/shadow_outline_size = 0 -theme_override_font_sizes/normal_font_size = 20 text = "Game Over" -scroll_active = false -shortcut_keys_enabled = false +label_settings = SubResource("LabelSettings_dqsad") +horizontal_alignment = 1 +vertical_alignment = 1 [node name="ReachedPointsLabel" type="RichTextLabel" parent="Ui/VBoxGameOver"] layout_mode = 2 @@ -208,16 +233,34 @@ layout_mode = 2 size_flags_horizontal = 4 size_flags_vertical = 6 shortcut = SubResource("Shortcut_soxs4") -icon = ExtResource("15_nxptg") -icon_alignment = 1 +text = "Restart" + +[node name="VBoxPause" type="VBoxContainer" parent="Ui"] +offset_left = 195.5 +offset_top = 647.0 +offset_right = 603.5 +offset_bottom = 788.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="LabelPause" type="Label" parent="Ui/VBoxPause"] +layout_mode = 2 +text = "Pause" +label_settings = SubResource("LabelSettings_vf3s8") +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="ButtonResume" type="Button" parent="Ui/VBoxPause"] +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 6 +text = "Resume +" [node name="VBoxHealth" type="VBoxContainer" parent="Ui"] -anchors_preset = 5 -anchor_left = 0.5 -anchor_right = 0.5 -offset_left = 45.0 -offset_right = 754.0 -offset_bottom = 22.0 +offset_top = 1274.0 +offset_right = 152.0 +offset_bottom = 1278.0 grow_horizontal = 2 [node name="HealthBar" type="ProgressBar" parent="Ui/VBoxHealth"] diff --git a/Scripts/Asteroid.cs b/Scripts/Asteroid.cs index 8491e36..acdeec3 100644 --- a/Scripts/Asteroid.cs +++ b/Scripts/Asteroid.cs @@ -1,6 +1,6 @@ using Godot; -namespace Scripts; +namespace GodotspaceShooter.Scripts; [GlobalClass] public partial class Asteroid : Node3D { diff --git a/Scripts/Background.cs b/Scripts/Background.cs index f5d00c3..132bb13 100644 --- a/Scripts/Background.cs +++ b/Scripts/Background.cs @@ -1,6 +1,6 @@ using Godot; -namespace Scripts; +namespace GodotspaceShooter.Scripts; public partial class Background : Sprite3D { [Export] private float moveVelocity = -250f; diff --git a/Scripts/Explosion.cs b/Scripts/Explosion.cs index e6fe0b6..b707be4 100644 --- a/Scripts/Explosion.cs +++ b/Scripts/Explosion.cs @@ -1,5 +1,7 @@ using Godot; +namespace GodotspaceShooter.Scripts; + public partial class Explosion : GpuParticles3D { public override void _Process(double delta) { if (!Emitting) QueueFree(); diff --git a/Scripts/GameArea.cs b/Scripts/GameArea.cs index a89a95e..88aa1fa 100644 --- a/Scripts/GameArea.cs +++ b/Scripts/GameArea.cs @@ -1,3 +1,5 @@ using Godot; +namespace GodotspaceShooter.Scripts; + public partial class GameArea : Node3D { } \ No newline at end of file diff --git a/Scripts/GameManager.cs b/Scripts/GameManager.cs index 2b58d2f..165cc3d 100644 --- a/Scripts/GameManager.cs +++ b/Scripts/GameManager.cs @@ -2,7 +2,7 @@ using System; using Godot; using Godot.Collections; -namespace Scripts; +namespace GodotspaceShooter.Scripts; public partial class GameManager : Node { private int asteroidMaxNumber = 3; @@ -19,7 +19,7 @@ public partial class GameManager : Node { private int points; private float spawnRate = 1f; private float spawnTimer; - + public event EventHandler RefreshUi; public int AsteroidNumber { @@ -30,8 +30,6 @@ public partial class GameManager : Node { } } - public bool GamePaused { get; private set; } = true; - public int Lives { get => lives; set { @@ -60,7 +58,7 @@ public partial class GameManager : Node { public int NextLevelPoints { get => nextLevelPoints; - set { + private set { nextLevelPoints = value; RefreshUi?.Invoke(this, EventArgs.Empty); } @@ -68,12 +66,20 @@ public partial class GameManager : Node { public int AsteroidMaxNumber { get => asteroidMaxNumber; - set { + private set { asteroidMaxNumber = value; RefreshUi?.Invoke(this, EventArgs.Empty); } } + private bool gamePaused; + public bool GamePaused { + get => gamePaused; + set { + gamePaused = value; + RefreshUi?.Invoke(this, EventArgs.Empty); + } + } public static GameManager Instance { get; private set; } [Export] public bool Debug { get; private set; } = true; @@ -95,6 +101,7 @@ public partial class GameManager : Node { spawnTimer = spawnRate; } } + private void SpawnNewAsteroid() { if (GameOver) return; GD.Print("Spawn new asteroid"); diff --git a/Scripts/InputManager.cs b/Scripts/InputManager.cs new file mode 100644 index 0000000..259755a --- /dev/null +++ b/Scripts/InputManager.cs @@ -0,0 +1,26 @@ +using Godot; + +namespace GodotspaceShooter.Scripts; + +public partial class InputManager : Node +{ + private const string GAME_PAUSE = "Game_Pause"; + + public override void _Process(double delta) { + if (Input.IsActionJustReleased(GAME_PAUSE)) { + switch (GameManager.Instance.GamePaused) { + case true: + GameManager.Instance.GamePaused = false; + GD.Print(GameManager.Instance.GamePaused); + GetTree().Paused = GameManager.Instance.GamePaused; + break; + case false: + GameManager.Instance.GamePaused = true; + GD.Print(GameManager.Instance.GamePaused); + GetTree().Paused = GameManager.Instance.GamePaused; + break; + } + } + } + +} \ No newline at end of file diff --git a/Scripts/LaserBeam.cs b/Scripts/LaserBeam.cs index 5a50553..76ef446 100644 --- a/Scripts/LaserBeam.cs +++ b/Scripts/LaserBeam.cs @@ -1,5 +1,7 @@ using Godot; +namespace GodotspaceShooter.Scripts; + public partial class LaserBeam : Node3D { [Export] private RigidBody3D rigidBody; private float speed = 10f; diff --git a/Scripts/PlayerShip.cs b/Scripts/PlayerShip.cs index 2dd8926..5656aa8 100644 --- a/Scripts/PlayerShip.cs +++ b/Scripts/PlayerShip.cs @@ -1,6 +1,6 @@ using Godot; -namespace Scripts; +namespace GodotspaceShooter.Scripts; public partial class PlayerShip : Node3D { private const float jetTimerMax = 0.5f; diff --git a/Scripts/SoundManager.cs b/Scripts/SoundManager.cs index 2b49346..84c2889 100644 --- a/Scripts/SoundManager.cs +++ b/Scripts/SoundManager.cs @@ -2,7 +2,7 @@ using System; using System.Runtime.InteropServices; using Godot; -namespace Scripts; +namespace GodotspaceShooter.Scripts; public partial class SoundManager : Node { [Export] private AudioStreamPlayer backgroundMusic; diff --git a/Scripts/Ui.cs b/Scripts/Ui.cs index 8f35dec..2385950 100644 --- a/Scripts/Ui.cs +++ b/Scripts/Ui.cs @@ -1,18 +1,19 @@ using System; using Godot; -namespace Scripts; +namespace GodotspaceShooter.Scripts; public partial class Ui : Node2D { - [Export] private RichTextLabel labelAsteroids; + [Export] private RichTextLabel rtlAsteroids; [Export] private RichTextLabel labelLevel; [Export] private RichTextLabel labelLifes; [Export] private RichTextLabel labelNextLevel; [Export] private RichTextLabel labelPoints; - [Export] private RichTextLabel labelGameOver; + [Export] private Label labelGameOver; [Export] private Button restartButton; [Export] private RichTextLabel reachedPointsLabel; [Export] private ProgressBar healthBar; + [Export] private VBoxContainer vBoxPause; public static Ui Instance { get; private set; } @@ -32,7 +33,7 @@ public partial class Ui : Node2D private void RefreshUi(object sender, EventArgs e) { labelLifes.Text = $"Lives: {GameManager.Instance.Lives}"; - labelAsteroids.Text = $"Asteroids: {GameManager.Instance.AsteroidNumber} / {GameManager.Instance.AsteroidMaxNumber}"; + rtlAsteroids.Text = $"Asteroids: {GameManager.Instance.AsteroidNumber} / {GameManager.Instance.AsteroidMaxNumber}"; labelPoints.Text = $"Points: {GameManager.Instance.Points}"; labelNextLevel.Text = $"Next Level at: {GameManager.Instance.NextLevelPoints}"; labelLevel.Text = $"Actual Level: {GameManager.Instance.Level}"; @@ -45,6 +46,8 @@ public partial class Ui : Node2D restartButton.Visible = GameManager.Instance.GameOver; reachedPointsLabel.Visible = GameManager.Instance.GameOver; } + + vBoxPause.Visible = GameManager.Instance.GamePaused; } private void RestartButtonOnPressed() => GetTree().ReloadCurrentScene(); diff --git a/project.godot b/project.godot index bdceb04..49f035e 100644 --- a/project.godot +++ b/project.godot @@ -63,3 +63,10 @@ Player_Fire={ , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":1,"pressure":0.0,"pressed":false,"script":null) ] } +Game_Pause={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194305,"key_label":0,"unicode":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194313,"key_label":0,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":6,"pressure":0.0,"pressed":false,"script":null) +] +} From a3bfbab270d978509d1339b8ebbb12147e53603b Mon Sep 17 00:00:00 2001 From: Sascha Date: Wed, 24 Jan 2024 15:22:59 +0100 Subject: [PATCH 08/14] Pause Restart --- Scenes/SpaceShooter.tscn | 46 ++++++++++++++++++++++++---------------- Scripts/GameManager.cs | 1 + Scripts/InputManager.cs | 18 ++-------------- Scripts/Ui.cs | 46 ++++++++++++++++++++++++---------------- 4 files changed, 59 insertions(+), 52 deletions(-) diff --git a/Scenes/SpaceShooter.tscn b/Scenes/SpaceShooter.tscn index 3d0b25a..ae61b1a 100644 --- a/Scenes/SpaceShooter.tscn +++ b/Scenes/SpaceShooter.tscn @@ -143,19 +143,21 @@ asteroidsContainer = NodePath("../Asteroids") process_mode = 3 script = ExtResource("15_uovst") -[node name="Ui" type="Node2D" parent="." node_paths=PackedStringArray("rtlAsteroids", "labelLevel", "labelLifes", "labelNextLevel", "labelPoints", "labelGameOver", "restartButton", "reachedPointsLabel", "healthBar", "vBoxPause")] +[node name="Ui" type="Node2D" parent="." node_paths=PackedStringArray("rtlAsteroids", "rtlLevel", "rtlLifes", "rtlNextLevel", "rtlPoints", "labelGameOver", "buttonRestart", "rtlReachedPoints", "healthBar", "vBoxPause", "buttonResume", "buttonPauseRestart")] process_mode = 3 script = ExtResource("15_xl7yx") rtlAsteroids = NodePath("VBoxLabels/rtlAsteroids") -labelLevel = NodePath("VBoxLabels/LabelLevel") -labelLifes = NodePath("VBoxLabels/LabelLives") -labelNextLevel = NodePath("VBoxLabels/LabelNextLevel") -labelPoints = NodePath("VBoxLabels/LabelPoints") +rtlLevel = NodePath("VBoxLabels/trlLevel") +rtlLifes = NodePath("VBoxLabels/rtlLifes") +rtlNextLevel = NodePath("VBoxLabels/rtlNextLevel") +rtlPoints = NodePath("VBoxLabels/rtlPoints") labelGameOver = NodePath("VBoxGameOver/LabelGameOver") -restartButton = NodePath("VBoxGameOver/RestartButton") -reachedPointsLabel = NodePath("VBoxGameOver/ReachedPointsLabel") +buttonRestart = NodePath("VBoxGameOver/RestartButton") +rtlReachedPoints = NodePath("VBoxGameOver/rtlReachedPoints") healthBar = NodePath("VBoxHealth/HealthBar") vBoxPause = NodePath("VBoxPause") +buttonResume = NodePath("VBoxPause/ButtonResume") +buttonPauseRestart = NodePath("VBoxPause/PauseRestartButton") [node name="VBoxLabels" type="VBoxContainer" parent="Ui"] anchors_preset = 2 @@ -173,28 +175,28 @@ text = "Asteroids: 0" scroll_active = false shortcut_keys_enabled = false -[node name="LabelLevel" type="RichTextLabel" parent="Ui/VBoxLabels"] +[node name="trlLevel" type="RichTextLabel" parent="Ui/VBoxLabels"] layout_mode = 2 size_flags_vertical = 3 text = "Level: 1" scroll_active = false shortcut_keys_enabled = false -[node name="LabelLives" type="RichTextLabel" parent="Ui/VBoxLabels"] +[node name="rtlLifes" type="RichTextLabel" parent="Ui/VBoxLabels"] layout_mode = 2 size_flags_vertical = 3 text = "Lives: 3" scroll_active = false shortcut_keys_enabled = false -[node name="LabelNextLevel" type="RichTextLabel" parent="Ui/VBoxLabels"] +[node name="rtlNextLevel" type="RichTextLabel" parent="Ui/VBoxLabels"] layout_mode = 2 size_flags_vertical = 3 text = "Next Level: 10" scroll_active = false shortcut_keys_enabled = false -[node name="LabelPoints" type="RichTextLabel" parent="Ui/VBoxLabels"] +[node name="rtlPoints" type="RichTextLabel" parent="Ui/VBoxLabels"] layout_mode = 2 size_flags_vertical = 3 text = "Points: 0" @@ -222,7 +224,7 @@ label_settings = SubResource("LabelSettings_dqsad") horizontal_alignment = 1 vertical_alignment = 1 -[node name="ReachedPointsLabel" type="RichTextLabel" parent="Ui/VBoxGameOver"] +[node name="rtlReachedPoints" type="RichTextLabel" parent="Ui/VBoxGameOver"] layout_mode = 2 size_flags_vertical = 3 bbcode_enabled = true @@ -232,6 +234,7 @@ text = "[center]You have reached level 1 and 0 points![/center]" layout_mode = 2 size_flags_horizontal = 4 size_flags_vertical = 6 +button_mask = 5 shortcut = SubResource("Shortcut_soxs4") text = "Restart" @@ -240,8 +243,6 @@ offset_left = 195.5 offset_top = 647.0 offset_right = 603.5 offset_bottom = 788.0 -grow_horizontal = 2 -grow_vertical = 2 [node name="LabelPause" type="Label" parent="Ui/VBoxPause"] layout_mode = 2 @@ -254,14 +255,23 @@ vertical_alignment = 1 layout_mode = 2 size_flags_horizontal = 4 size_flags_vertical = 6 +button_mask = 5 text = "Resume " +[node name="PauseRestartButton" type="Button" parent="Ui/VBoxPause"] +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 6 +button_mask = 5 +shortcut = SubResource("Shortcut_soxs4") +text = "Restart" + [node name="VBoxHealth" type="VBoxContainer" parent="Ui"] -offset_top = 1274.0 -offset_right = 152.0 -offset_bottom = 1278.0 -grow_horizontal = 2 +offset_left = 330.0 +offset_top = 14.0 +offset_right = 482.0 +offset_bottom = 18.0 [node name="HealthBar" type="ProgressBar" parent="Ui/VBoxHealth"] layout_mode = 2 diff --git a/Scripts/GameManager.cs b/Scripts/GameManager.cs index 165cc3d..c5711df 100644 --- a/Scripts/GameManager.cs +++ b/Scripts/GameManager.cs @@ -77,6 +77,7 @@ public partial class GameManager : Node { get => gamePaused; set { gamePaused = value; + GetTree().Paused = gamePaused; RefreshUi?.Invoke(this, EventArgs.Empty); } } diff --git a/Scripts/InputManager.cs b/Scripts/InputManager.cs index 259755a..dc5cd24 100644 --- a/Scripts/InputManager.cs +++ b/Scripts/InputManager.cs @@ -6,21 +6,7 @@ public partial class InputManager : Node { private const string GAME_PAUSE = "Game_Pause"; - public override void _Process(double delta) { - if (Input.IsActionJustReleased(GAME_PAUSE)) { - switch (GameManager.Instance.GamePaused) { - case true: - GameManager.Instance.GamePaused = false; - GD.Print(GameManager.Instance.GamePaused); - GetTree().Paused = GameManager.Instance.GamePaused; - break; - case false: - GameManager.Instance.GamePaused = true; - GD.Print(GameManager.Instance.GamePaused); - GetTree().Paused = GameManager.Instance.GamePaused; - break; - } - } + public override void _UnhandledInput(InputEvent @event) { + if (Input.IsActionJustReleased(GAME_PAUSE)) GameManager.Instance.GamePaused = GameManager.Instance.GamePaused switch { true => false, false => true }; } - } \ No newline at end of file diff --git a/Scripts/Ui.cs b/Scripts/Ui.cs index 2385950..483bd8d 100644 --- a/Scripts/Ui.cs +++ b/Scripts/Ui.cs @@ -5,15 +5,17 @@ namespace GodotspaceShooter.Scripts; public partial class Ui : Node2D { [Export] private RichTextLabel rtlAsteroids; - [Export] private RichTextLabel labelLevel; - [Export] private RichTextLabel labelLifes; - [Export] private RichTextLabel labelNextLevel; - [Export] private RichTextLabel labelPoints; + [Export] private RichTextLabel rtlLevel; + [Export] private RichTextLabel rtlLifes; + [Export] private RichTextLabel rtlNextLevel; + [Export] private RichTextLabel rtlPoints; [Export] private Label labelGameOver; - [Export] private Button restartButton; - [Export] private RichTextLabel reachedPointsLabel; + [Export] private Button buttonRestart; + [Export] private RichTextLabel rtlReachedPoints; [Export] private ProgressBar healthBar; [Export] private VBoxContainer vBoxPause; + [Export] private Button buttonResume; + [Export] private Button buttonPauseRestart; public static Ui Instance { get; private set; } @@ -23,34 +25,42 @@ public partial class Ui : Node2D GD.PrintErr("No GameManager found!"); else { GameManager.Instance.RefreshUi += RefreshUi; - restartButton.Pressed += RestartButtonOnPressed; labelGameOver.Visible = GameManager.Instance.GameOver; - restartButton.Visible = GameManager.Instance.GameOver; - reachedPointsLabel.Visible = GameManager.Instance.GameOver; + buttonRestart.Visible = GameManager.Instance.GameOver; + rtlReachedPoints.Visible = GameManager.Instance.GameOver; + buttonRestart.Pressed += ButtonRestartOnPressed; + buttonResume.Pressed += ButtonResumeOnPressed; + buttonPauseRestart.Pressed += ButtonPauseRestartOnPressed; RefreshUi(this, EventArgs.Empty); } } - + + private void RefreshUi(object sender, EventArgs e) { - labelLifes.Text = $"Lives: {GameManager.Instance.Lives}"; + rtlLifes.Text = $"Lives: {GameManager.Instance.Lives}"; rtlAsteroids.Text = $"Asteroids: {GameManager.Instance.AsteroidNumber} / {GameManager.Instance.AsteroidMaxNumber}"; - labelPoints.Text = $"Points: {GameManager.Instance.Points}"; - labelNextLevel.Text = $"Next Level at: {GameManager.Instance.NextLevelPoints}"; - labelLevel.Text = $"Actual Level: {GameManager.Instance.Level}"; + rtlPoints.Text = $"Points: {GameManager.Instance.Points}"; + rtlNextLevel.Text = $"Next Level at: {GameManager.Instance.NextLevelPoints}"; + rtlLevel.Text = $"Actual Level: {GameManager.Instance.Level}"; healthBar.MaxValue = GameManager.Instance.MaxLives; healthBar.Value = GameManager.Instance.Lives; if (GameManager.Instance.GameOver) { - reachedPointsLabel.Text = $"[center]You have reached level {GameManager.Instance.Level} and {GameManager.Instance.Points} points![/center]"; + rtlReachedPoints.Text = $"[center]You have reached level {GameManager.Instance.Level} and {GameManager.Instance.Points} points![/center]"; labelGameOver.Visible = GameManager.Instance.GameOver; - restartButton.Visible = GameManager.Instance.GameOver; - reachedPointsLabel.Visible = GameManager.Instance.GameOver; + buttonRestart.Visible = GameManager.Instance.GameOver; + rtlReachedPoints.Visible = GameManager.Instance.GameOver; } vBoxPause.Visible = GameManager.Instance.GamePaused; } - private void RestartButtonOnPressed() => GetTree().ReloadCurrentScene(); + private void ButtonRestartOnPressed() => GetTree().ReloadCurrentScene(); + private void ButtonResumeOnPressed() => GameManager.Instance.GamePaused = false; + private void ButtonPauseRestartOnPressed() { + GameManager.Instance.GamePaused = false; + GetTree().ReloadCurrentScene(); + } public void ShowMessage(string message) => GD.Print(message); } From 6b91f6ded8e41cc479f7c1c2c55240c7f1ea6f7a Mon Sep 17 00:00:00 2001 From: Sascha Date: Wed, 24 Jan 2024 17:14:20 +0100 Subject: [PATCH 09/14] added some icons for UI --- Images/generic_arrow_3.png | Bin 0 -> 604 bytes Images/generic_arrow_3.png.import | 34 +++++ Images/generic_arrow_long.png | Bin 0 -> 278 bytes Images/generic_arrow_long.png.import | 34 +++++ Images/keyboard_a.png | Bin 0 -> 398 bytes Images/keyboard_a.png.import | 34 +++++ Images/keyboard_arrows.png | Bin 0 -> 233 bytes Images/keyboard_arrows.png.import | 34 +++++ Images/keyboard_d.png | Bin 0 -> 367 bytes Images/keyboard_d.png.import | 34 +++++ Images/keyboard_enter.png | Bin 0 -> 398 bytes Images/keyboard_enter.png.import | 34 +++++ Images/keyboard_escape.png | Bin 0 -> 385 bytes Images/keyboard_escape.png.import | 34 +++++ Images/keyboard_s.png | Bin 0 -> 405 bytes Images/keyboard_s.png.import | 34 +++++ Images/keyboard_space.png | Bin 0 -> 415 bytes Images/keyboard_space.png.import | 34 +++++ Images/keyboard_w.png | Bin 0 -> 401 bytes Images/keyboard_w.png.import | 34 +++++ Images/restart.svg | 1 - Scenes/SpaceShooter.tscn | 125 ++++++++++++++++-- Scripts/InputManager.cs | 33 +++++ Scripts/PlayerShip.cs | 42 ++---- Scripts/generic_arrow_3.svg | 6 + .../generic_arrow_3.svg.import | 8 +- 26 files changed, 505 insertions(+), 50 deletions(-) create mode 100644 Images/generic_arrow_3.png create mode 100644 Images/generic_arrow_3.png.import create mode 100644 Images/generic_arrow_long.png create mode 100644 Images/generic_arrow_long.png.import create mode 100644 Images/keyboard_a.png create mode 100644 Images/keyboard_a.png.import create mode 100644 Images/keyboard_arrows.png create mode 100644 Images/keyboard_arrows.png.import create mode 100644 Images/keyboard_d.png create mode 100644 Images/keyboard_d.png.import create mode 100644 Images/keyboard_enter.png create mode 100644 Images/keyboard_enter.png.import create mode 100644 Images/keyboard_escape.png create mode 100644 Images/keyboard_escape.png.import create mode 100644 Images/keyboard_s.png create mode 100644 Images/keyboard_s.png.import create mode 100644 Images/keyboard_space.png create mode 100644 Images/keyboard_space.png.import create mode 100644 Images/keyboard_w.png create mode 100644 Images/keyboard_w.png.import delete mode 100644 Images/restart.svg create mode 100644 Scripts/generic_arrow_3.svg rename Images/restart.svg.import => Scripts/generic_arrow_3.svg.import (71%) diff --git a/Images/generic_arrow_3.png b/Images/generic_arrow_3.png new file mode 100644 index 0000000000000000000000000000000000000000..badf0e1dd273e8ea2fb5406aa0bc00144b18c7f8 GIT binary patch literal 604 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I3?%1nZ+ru!SkfJR9T^xl_H+M9WCik#1AIbU z|C0iMnt;khw>EtPvII(k{DSlS&#%AVuRmYDKHh%+dwz!ROWAW67#MeWx;TbJ9DY09 zvxr%d$2B$0rFrN7%;a`Ci6a-Dx~>YkW_0ZQBkx}tAO09T;Qn!+;q!*uazbZg9T)_= z1uorT(2(oAaYgCCiyNGBVGQSv=T*#ME|F=Q%h+?i#QD3l#!c4?n|TWSw}r&M6z(zR zeeydbddq^$L#zfnwsUtMnt1f?Q})z@Qzj2RZ-~bWJY)*kX1K?h*WqG~d_Lm|`~R#5 zt|yy`T{LgVUD|)rNUSXHIYTsG$xDyRnRdZjc^!_L3a&^z6}lzc{6mZOX;uHlysFzn zcRo^&+`1r4ebqu;^J$Ewjf*8>lseMxEi8?>rYhqv{N83=yLs0+-6;w&!X4?0tL$E< zubfk+(Dmotl?(Ov-e%Za_;W@pG>Og?Wj*2Mt=|9j(t>xU??v*kBvX8&*FN+)W$mczM^XL7fD~Eyc%i!ti K=d#Wzp$PyA)F4*? literal 0 HcmV?d00001 diff --git a/Images/generic_arrow_3.png.import b/Images/generic_arrow_3.png.import new file mode 100644 index 0000000..bcdad32 --- /dev/null +++ b/Images/generic_arrow_3.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://ddikd6m3t7prw" +path="res://.godot/imported/generic_arrow_3.png-604ef2420be555018c588cbcb3d8f7c6.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Images/generic_arrow_3.png" +dest_files=["res://.godot/imported/generic_arrow_3.png-604ef2420be555018c588cbcb3d8f7c6.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/Images/generic_arrow_long.png b/Images/generic_arrow_long.png new file mode 100644 index 0000000000000000000000000000000000000000..ad7b55fc069efdba46ba457d95e25351fcbcef66 GIT binary patch literal 278 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0J3?w7mbKU|emUKs7M+SzC{oH>NS%G|m0G|-o z|3m|z4xrk7T$erqS^OnIe!=_u_0Q+e_qUI~FTbAuJ%fIByB z9xaJb109h)w^p^sA8h^~|3SOr|9^XaMb`Sy92!6VPn^*7KdeRM&s%4WAN`_#?A#p= z{(lMNt1o$=ugGc-RI;-D{_OwB94&`UnHaxT$}+MRu{?TYb?-$TH*eY;uDCy6q|a6@ e=4#u>#BjT~NS%G}50G|-o z|3m~aq4q`EZ&kJzu@=r_3Qih%jfgox1Z1O#KE8%DDlnH#WBR=_}i<7d`$)- zYzcf1ME5kF^Si^~?v~dud9(WijyntPF$gDfFz;~{)SPtB)#LHvZR@Yf{$J|6e}cX5 zy~EA=AD^*w)oN^MnH|BH?fAs3F=hg%fK28Gmx4u({R&GR+Z`f|;xE+hkz$N$XcjJL zIKpYvaEepH;U$x-$i_>TSahE>0!f*3+)I~o8b!oSou-!X;JTMLGmmU*K$O&i)^35- zE0;3vn6vE&ml3Cyc7o6pvkQCGt+qCV)!7`LX7yl`-0^8v688#imTkYn*qmV_mGg7H zFR#m&+U5lBX6q(dUb+42ld7(MJGD)}_Vd29&%br8J~0JWO@16c!8HaL0t}w6elF{r G5}E)E3a}Rd literal 0 HcmV?d00001 diff --git a/Images/keyboard_a.png.import b/Images/keyboard_a.png.import new file mode 100644 index 0000000..df65424 --- /dev/null +++ b/Images/keyboard_a.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cm7ru4t8ka3jn" +path="res://.godot/imported/keyboard_a.png-55bc9c150629b9f0992abde27a16be9c.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Images/keyboard_a.png" +dest_files=["res://.godot/imported/keyboard_a.png-55bc9c150629b9f0992abde27a16be9c.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/Images/keyboard_arrows.png b/Images/keyboard_arrows.png new file mode 100644 index 0000000000000000000000000000000000000000..6491f7492740c321d3244224ec17104fc94accf0 GIT binary patch literal 233 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0J3?w7mbKU|emUKs7M+SzC{oH>NS%G|s0G|-o z{}=!$0~EX2x2h7zVlN5u3y$x9e}8{H!(Gk~_kco~o-U3d9>OjtZX>C zch8<9jN6;86d7FNAR=7em23N4*6iISYZ7GI+ZB KxvXEtPvII(k{DS@U&*#U#ub02S-hTf6etw3H1#kI*a;H6A977@wzrB8& z?~noyTY_1_9IuzZ?bj|UzoZc>u0Q2}R^*}S2A3|)T-FnLU_IkOHHKdT4Jpk0GA47I znYB2B+!ZEkR5En&XfO+;I>;~xr7`|zw7H*mGh{tum4RmCwK-xBv~sx=ZXHaj_eyW9 zuE|eW!I0s;E}pZ&o&AiILQ(YuhA;1?>|i=zdR@cAsud(g}Rr3|a-_#u6 SMtuN!i^0>?&t;ucLK6TK7^xWm literal 0 HcmV?d00001 diff --git a/Images/keyboard_d.png.import b/Images/keyboard_d.png.import new file mode 100644 index 0000000..d1c62ee --- /dev/null +++ b/Images/keyboard_d.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://uy20bgblsk4x" +path="res://.godot/imported/keyboard_d.png-895bd164acd04c40e6c184d6e2572823.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Images/keyboard_d.png" +dest_files=["res://.godot/imported/keyboard_d.png-895bd164acd04c40e6c184d6e2572823.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/Images/keyboard_enter.png b/Images/keyboard_enter.png new file mode 100644 index 0000000000000000000000000000000000000000..d789807f1f13791cbdbe8ff581e8a3d466431784 GIT binary patch literal 398 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0J3?w7mbKU|emUKs7M+SzC{oH>NS%G}r0G|-o z|HJ{Ha-hP1@~AC97GFt_U$FlB`}O(j?fd8N=Z}|X@Uv&!2$cEc>EamTas2I7L%t>h z5w?VP3*#E4Pdt0IWcA|iiP8^vQ_??j+;QM@U@A07YPjyWIO#w++e*%ehn|l;KE%h( zsymrIYkC-?=ajsrij;@i*N!MRwxymE;Rxt(WQb)6XPTkp!Lgw0feXW*6Y^VxrcD09 zo6*s$;J|qy^}rOyP__-K3akZH#qHB|T{Lx8Jzz|b-f;dClfbjpg`x&7`CNOL;@3(t zGTcu%@Je?MlY`6F2WPn_%uj4TtJ}Ac#o&C79kcW=(F6JiT*Zy0Z8?m0zyDuyRl4eb zT$3nop6Z9p2`7)mRdk))=+|=mkHPBq@zY}eiDg$Z*+z5g1^I`*0s5Z7)78&qol`;+ E0E9BHXaE2J literal 0 HcmV?d00001 diff --git a/Images/keyboard_enter.png.import b/Images/keyboard_enter.png.import new file mode 100644 index 0000000..5719643 --- /dev/null +++ b/Images/keyboard_enter.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dojdjls5b310j" +path="res://.godot/imported/keyboard_enter.png-5856048a4e779616811153cc1f978fcb.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Images/keyboard_enter.png" +dest_files=["res://.godot/imported/keyboard_enter.png-5856048a4e779616811153cc1f978fcb.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/Images/keyboard_escape.png b/Images/keyboard_escape.png new file mode 100644 index 0000000000000000000000000000000000000000..968d5bfe07c74020b6cd42417c3fcf1a32a152b5 GIT binary patch literal 385 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I3?%1nZ+ru!SkfJR9T^xl_H+M9WCik#1AIbU z|C0iMnt;khw>EtPvII(k{DSNA$B>A_Z?E6v zYgQ0o4RE=cc>Zsc=3tQDNqS9kmfnjrGiL95kOcdv&tiW_PiR zUBv!_XG(tKjD=mi2?hsD91b*GV35>dllW1&K#J2yuQQ~lE5PBlsc&*+pD@P>-J{Dg z_pryE%;{Y5dzP|7NHW8Qo)w$2B*PT0+Wrc^Id-8zYouwSA6pheqI0XFZ&~)M;Sa_{an^LB{Ts5h!M7P literal 0 HcmV?d00001 diff --git a/Images/keyboard_escape.png.import b/Images/keyboard_escape.png.import new file mode 100644 index 0000000..0fa21bf --- /dev/null +++ b/Images/keyboard_escape.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dh4l4vkgkjxup" +path="res://.godot/imported/keyboard_escape.png-dba48fc566cf07dae1d84ab68c431966.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Images/keyboard_escape.png" +dest_files=["res://.godot/imported/keyboard_escape.png-dba48fc566cf07dae1d84ab68c431966.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/Images/keyboard_s.png b/Images/keyboard_s.png new file mode 100644 index 0000000000000000000000000000000000000000..2c16d711b28c5da5343afb9e36964b128d6cc089 GIT binary patch literal 405 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I3?%1nZ+ru!SkfJR9T^xl_H+M9WCik#1AIbU z|C0iMnt;khw>EtPvII(k{DS?@>&MUMuV0^ke}BKd{CkE5L9q;=+(%Cr$B>A_Z>Jv= zYF6NJ5fyN1IPt$ew|nbiv1raOS2nrJ-t&2s)_M5OiiON|yaERlj&UnWaXe>`?OuAG zLC@$(QA5AZPo4!83{x3(_!EpBQdTklV|6&E-zIu5koSP!?GwJ!_!SB}cv}lGEV~#`BwrA38D_$JD+95ub;R?fzSubAKI9N-E{8Z@s{Y5+^Idz78j8spe z(Mk4&sZz(w=l^6%coJn1%6MgO`=^UFk)cd7?Vj6zCd^xLmOXJzm&wl>_ABpO`7~G* z-rJ-x9B1CaBT&)s;cw{lt*cjkF1zDCWT;%h&U^=NUX*{an^L HB{Ts5ps&2~ literal 0 HcmV?d00001 diff --git a/Images/keyboard_s.png.import b/Images/keyboard_s.png.import new file mode 100644 index 0000000..4395221 --- /dev/null +++ b/Images/keyboard_s.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://c2n36lnm2f5he" +path="res://.godot/imported/keyboard_s.png-5dc221fc8896155dff9a7e0fe05624ee.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Images/keyboard_s.png" +dest_files=["res://.godot/imported/keyboard_s.png-5dc221fc8896155dff9a7e0fe05624ee.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/Images/keyboard_space.png b/Images/keyboard_space.png new file mode 100644 index 0000000000000000000000000000000000000000..8de87a46c2fff2535b0749002607e34d0d1bbc3c GIT binary patch literal 415 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0J3?w7mbKU|emUKs7M+SzC{oH>NS%G}r0G|-o z|HJ{Ha-hP1@~AC97GFt_U$FoE`t|$y=fBVIx0jD+c*D-5%)r3N?CIhd;&D8Ahc|;k zkCsHJ!>*>=XZ7A+Xy`r~r@~tGenW#h2dnx0MAqVmT-OrAKX9#6;NRVpUcg#(L)4~4 zyP};rAky*r-Qx88xz%-9XLrvEeSYuG-fBKy#tTOa%irItsQjLH|ITjndrXxXT=(Lb zKh3{eTYK}{y|~A_^WP^%eEg;~;lGT==WqA!ma}irs3JBog}x3~2u@A~)mDz}Sz9NpWu zde`nhre@|B%r^bmaN536dq#WgLGK++wKqifsM+02-u_s%=vwgcDf+jpquhG67Bn(3 ZOz-$nvg>_LHZY(VJYD@<);T3K0RS3_#h(BG literal 0 HcmV?d00001 diff --git a/Images/keyboard_space.png.import b/Images/keyboard_space.png.import new file mode 100644 index 0000000..e6a2013 --- /dev/null +++ b/Images/keyboard_space.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dkc2vx71bnhdh" +path="res://.godot/imported/keyboard_space.png-d31aec3c784ba7fccaaf4975d2bf5a49.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Images/keyboard_space.png" +dest_files=["res://.godot/imported/keyboard_space.png-d31aec3c784ba7fccaaf4975d2bf5a49.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/Images/keyboard_w.png b/Images/keyboard_w.png new file mode 100644 index 0000000000000000000000000000000000000000..c79a453712f67507c0aa63fe42ba396a70e16ecb GIT binary patch literal 401 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0J3?w7mbKU|emUKs7M+SzC{oH>NS%G}@0G|-o z|AYWgAyCOe`RR*+ES{1ezumFpAV`#F4`3-~h0X_xe7Cr^TfVz2&|C!?D7w09#P}tY)iUi&o>$J`-%Bf6l_a4+Ps_9Yerp@`ZuqgA~Gxsraud0 z2}oW(#o6&tlb8O}JfV#XSg!F;Zpar*u4G;+kkxi$_kt%(A11yEUN)K2;d+6CCriNI z_f9GepLm%v#ec055h;vRoDl5tfLYR&#dJb|%Ytl|(BMV9CA|xBybRQ}^n6?do~bE) zFrFM2zn5>rgZ=Tk5uYC;INr`&TFV_5Jo6hWZ9g9QjeZ)|CJQ Og2B_(&t;ucLK6U=`LGxO literal 0 HcmV?d00001 diff --git a/Images/keyboard_w.png.import b/Images/keyboard_w.png.import new file mode 100644 index 0000000..3eb5562 --- /dev/null +++ b/Images/keyboard_w.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://bnh0rcsf30nrm" +path="res://.godot/imported/keyboard_w.png-48cdec668906ea6e1ec6fa0e40447b2b.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Images/keyboard_w.png" +dest_files=["res://.godot/imported/keyboard_w.png-48cdec668906ea6e1ec6fa0e40447b2b.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/Images/restart.svg b/Images/restart.svg deleted file mode 100644 index 6626f25..0000000 --- a/Images/restart.svg +++ /dev/null @@ -1 +0,0 @@ -Created by Luis Rodriguesfrom the Noun Project \ No newline at end of file diff --git a/Scenes/SpaceShooter.tscn b/Scenes/SpaceShooter.tscn index ae61b1a..de9c797 100644 --- a/Scenes/SpaceShooter.tscn +++ b/Scenes/SpaceShooter.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=22 format=3 uid="uid://det8556rpxhbv"] +[gd_scene load_steps=32 format=3 uid="uid://det8556rpxhbv"] [ext_resource type="PackedScene" uid="uid://tlr55u0gn20l" path="res://Packed-Scenes/PlayerShip.tscn" id="1_njb5h"] [ext_resource type="Texture2D" uid="uid://cg6n1hh3lj7rn" path="res://Textures/tile_nebula_green_dff.png" id="2_43vix"] @@ -16,6 +16,16 @@ [ext_resource type="Script" path="res://Scripts/GameArea.cs" id="11_p0rh7"] [ext_resource type="Script" path="res://Scripts/InputManager.cs" id="15_uovst"] [ext_resource type="Script" path="res://Scripts/Ui.cs" id="15_xl7yx"] +[ext_resource type="Texture2D" uid="uid://ddikd6m3t7prw" path="res://Images/generic_arrow_3.png" id="17_1t6sc"] +[ext_resource type="Texture2D" uid="uid://bffseflkbu88e" path="res://Images/generic_arrow_long.png" id="18_b2vca"] +[ext_resource type="Texture2D" uid="uid://c4l1soqbo0rud" path="res://Images/keyboard_arrows.png" id="19_dpw4m"] +[ext_resource type="Texture2D" uid="uid://bnh0rcsf30nrm" path="res://Images/keyboard_w.png" id="20_3aqu5"] +[ext_resource type="Texture2D" uid="uid://cm7ru4t8ka3jn" path="res://Images/keyboard_a.png" id="21_of2rn"] +[ext_resource type="Texture2D" uid="uid://c2n36lnm2f5he" path="res://Images/keyboard_s.png" id="22_1rcux"] +[ext_resource type="Texture2D" uid="uid://uy20bgblsk4x" path="res://Images/keyboard_d.png" id="23_o81a8"] +[ext_resource type="Texture2D" uid="uid://dkc2vx71bnhdh" path="res://Images/keyboard_space.png" id="24_cuten"] +[ext_resource type="Texture2D" uid="uid://dojdjls5b310j" path="res://Images/keyboard_enter.png" id="25_u4r31"] +[ext_resource type="Texture2D" uid="uid://dh4l4vkgkjxup" path="res://Images/keyboard_escape.png" id="26_oxfmw"] [sub_resource type="BoxShape3D" id="BoxShape3D_bw288"] @@ -153,7 +163,7 @@ rtlNextLevel = NodePath("VBoxLabels/rtlNextLevel") rtlPoints = NodePath("VBoxLabels/rtlPoints") labelGameOver = NodePath("VBoxGameOver/LabelGameOver") buttonRestart = NodePath("VBoxGameOver/RestartButton") -rtlReachedPoints = NodePath("VBoxGameOver/rtlReachedPoints") +rtlReachedPoints = NodePath("") healthBar = NodePath("VBoxHealth/HealthBar") vBoxPause = NodePath("VBoxPause") buttonResume = NodePath("VBoxPause/ButtonResume") @@ -210,10 +220,10 @@ anchor_left = 0.5 anchor_top = 0.5 anchor_right = 0.5 anchor_bottom = 0.5 -offset_left = 197.0 -offset_top = 556.0 -offset_right = 605.0 -offset_bottom = 854.0 +offset_left = 201.0 +offset_top = 451.0 +offset_right = 609.0 +offset_bottom = 749.0 grow_horizontal = 2 grow_vertical = 2 @@ -224,25 +234,36 @@ label_settings = SubResource("LabelSettings_dqsad") horizontal_alignment = 1 vertical_alignment = 1 -[node name="rtlReachedPoints" type="RichTextLabel" parent="Ui/VBoxGameOver"] +[node name="lblReachedPoints" type="Label" parent="Ui/VBoxGameOver"] +custom_minimum_size = Vector2(0, 100) layout_mode = 2 -size_flags_vertical = 3 -bbcode_enabled = true -text = "[center]You have reached level 1 and 0 points![/center]" +text = "You have reached level 1 and 0 points!" +horizontal_alignment = 1 +vertical_alignment = 1 +autowrap_mode = 3 [node name="RestartButton" type="Button" parent="Ui/VBoxGameOver"] +custom_minimum_size = Vector2(200, 0) layout_mode = 2 size_flags_horizontal = 4 size_flags_vertical = 6 button_mask = 5 shortcut = SubResource("Shortcut_soxs4") text = "Restart" +icon = ExtResource("17_1t6sc") [node name="VBoxPause" type="VBoxContainer" parent="Ui"] -offset_left = 195.5 -offset_top = 647.0 -offset_right = 603.5 -offset_bottom = 788.0 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = 205.0 +offset_top = 451.0 +offset_right = 613.0 +offset_bottom = 672.0 +grow_horizontal = 2 +grow_vertical = 2 [node name="LabelPause" type="Label" parent="Ui/VBoxPause"] layout_mode = 2 @@ -252,20 +273,24 @@ horizontal_alignment = 1 vertical_alignment = 1 [node name="ButtonResume" type="Button" parent="Ui/VBoxPause"] +custom_minimum_size = Vector2(200, 0) layout_mode = 2 size_flags_horizontal = 4 size_flags_vertical = 6 button_mask = 5 text = "Resume " +icon = ExtResource("18_b2vca") [node name="PauseRestartButton" type="Button" parent="Ui/VBoxPause"] +custom_minimum_size = Vector2(200, 0) layout_mode = 2 size_flags_horizontal = 4 size_flags_vertical = 6 button_mask = 5 shortcut = SubResource("Shortcut_soxs4") text = "Restart" +icon = ExtResource("17_1t6sc") [node name="VBoxHealth" type="VBoxContainer" parent="Ui"] offset_left = 330.0 @@ -280,3 +305,75 @@ max_value = 10.0 value = 7.0 rounded = true show_percentage = false + +[node name="BoxHelp" type="BoxContainer" parent="Ui"] +anchors_preset = 1 +anchor_left = 1.0 +anchor_right = 1.0 +offset_left = 635.0 +offset_top = 12.0 +offset_right = 787.0 +offset_bottom = 212.0 +grow_horizontal = 0 + +[node name="VBoxHelp" type="VBoxContainer" parent="Ui/BoxHelp"] +layout_mode = 2 + +[node name="HBoxMovement" type="HBoxContainer" parent="Ui/BoxHelp/VBoxHelp"] +layout_mode = 2 + +[node name="TextureArrowKeys" type="TextureRect" parent="Ui/BoxHelp/VBoxHelp/HBoxMovement"] +layout_mode = 2 +texture = ExtResource("19_dpw4m") + +[node name="TextureW" type="TextureRect" parent="Ui/BoxHelp/VBoxHelp/HBoxMovement"] +visible = false +layout_mode = 2 +texture = ExtResource("20_3aqu5") + +[node name="TextureA" type="TextureRect" parent="Ui/BoxHelp/VBoxHelp/HBoxMovement"] +visible = false +layout_mode = 2 +texture = ExtResource("21_of2rn") + +[node name="TextureS" type="TextureRect" parent="Ui/BoxHelp/VBoxHelp/HBoxMovement"] +visible = false +layout_mode = 2 +texture = ExtResource("22_1rcux") + +[node name="TextureD" type="TextureRect" parent="Ui/BoxHelp/VBoxHelp/HBoxMovement"] +visible = false +layout_mode = 2 +texture = ExtResource("23_o81a8") + +[node name="lblMovement" type="Label" parent="Ui/BoxHelp/VBoxHelp/HBoxMovement"] +layout_mode = 2 +text = "Movement +" + +[node name="HBoxShooting" type="HBoxContainer" parent="Ui/BoxHelp/VBoxHelp"] +layout_mode = 2 + +[node name="TextureSpace" type="TextureRect" parent="Ui/BoxHelp/VBoxHelp/HBoxShooting"] +layout_mode = 2 +texture = ExtResource("24_cuten") + +[node name="TextureEnter" type="TextureRect" parent="Ui/BoxHelp/VBoxHelp/HBoxShooting"] +visible = false +layout_mode = 2 +texture = ExtResource("25_u4r31") + +[node name="lblShooting" type="Label" parent="Ui/BoxHelp/VBoxHelp/HBoxShooting"] +layout_mode = 2 +text = "Shooting" + +[node name="HBoxPause" type="HBoxContainer" parent="Ui/BoxHelp/VBoxHelp"] +layout_mode = 2 + +[node name="TexturePause" type="TextureRect" parent="Ui/BoxHelp/VBoxHelp/HBoxPause"] +layout_mode = 2 +texture = ExtResource("26_oxfmw") + +[node name="lblPause" type="Label" parent="Ui/BoxHelp/VBoxHelp/HBoxPause"] +layout_mode = 2 +text = "Pause" diff --git a/Scripts/InputManager.cs b/Scripts/InputManager.cs index dc5cd24..b1d1753 100644 --- a/Scripts/InputManager.cs +++ b/Scripts/InputManager.cs @@ -5,8 +5,41 @@ namespace GodotspaceShooter.Scripts; public partial class InputManager : Node { private const string GAME_PAUSE = "Game_Pause"; + private const string PLAYER_MOVE_FORWARD = "Player_Move_Forward"; + private const string PLAYER_MOVE_BACKWARDS = "Player_Move_Backwards"; + private const string PLAYER_MOVE_LEFT = "Player_Move_Left"; + private const string PLAYER_MOVE_RIGHT = "Player_Move_Right"; + private const string PLAYER_FIRE = "Player_Fire"; + private Vector3 moveDirection; + private Vector3 rotationDirection; + public override void _UnhandledInput(InputEvent @event) { + //Pause if (Input.IsActionJustReleased(GAME_PAUSE)) GameManager.Instance.GamePaused = GameManager.Instance.GamePaused switch { true => false, false => true }; + + //Movement + float moveVelocity = PlayerShip.Instance.MoveVelocity; + float rotVelocity = PlayerShip.Instance.RotationVelocity; + + moveDirection = Vector3.Zero; + rotationDirection = Vector3.Zero; + + if (Input.IsActionPressed(PLAYER_MOVE_FORWARD)) moveDirection = moveDirection with { Z = moveVelocity }; + if (Input.IsActionJustPressed(PLAYER_MOVE_FORWARD)) rotationDirection = rotationDirection with { X = -rotVelocity }; + if (Input.IsActionPressed(PLAYER_MOVE_BACKWARDS)) moveDirection = moveDirection with { Z = moveVelocity }; + if (Input.IsActionJustPressed(PLAYER_MOVE_BACKWARDS)) rotationDirection = rotationDirection with { X = +rotVelocity }; + if (Input.IsActionPressed(PLAYER_MOVE_LEFT)) moveDirection = moveDirection with { X = moveVelocity }; + if (Input.IsActionJustPressed(PLAYER_MOVE_LEFT)) rotationDirection = rotationDirection with { Z = -rotVelocity * 2 }; + if (Input.IsActionPressed(PLAYER_MOVE_RIGHT)) moveDirection = moveDirection with { X = moveVelocity }; + if (Input.IsActionJustPressed(PLAYER_MOVE_RIGHT)) rotationDirection = rotationDirection with { Z = +rotVelocity * 2 }; + if (Input.IsActionJustReleased(PLAYER_MOVE_LEFT) || Input.IsActionJustReleased(PLAYER_MOVE_RIGHT)) rotationDirection = Vector3.Zero; + + PlayerShip.Instance.MoveDirection = moveDirection; + PlayerShip.Instance.RotationDirection = rotationDirection; + + //Shooting + if (Input.IsActionJustPressed(PLAYER_FIRE)) PlayerShip.Instance.Shooting = true; + if (Input.IsActionJustReleased(PLAYER_FIRE)) PlayerShip.Instance.Shooting = false; } } \ No newline at end of file diff --git a/Scripts/PlayerShip.cs b/Scripts/PlayerShip.cs index 5656aa8..398ca4d 100644 --- a/Scripts/PlayerShip.cs +++ b/Scripts/PlayerShip.cs @@ -4,14 +4,8 @@ namespace GodotspaceShooter.Scripts; public partial class PlayerShip : Node3D { private const float jetTimerMax = 0.5f; - private const float laserTimerMax = 1f; - private const string PLAYER_MOVE_FORWARD = "Player_Move_Forward"; - private const string PLAYER_MOVE_BACKWARDS = "Player_Move_Backwards"; - private const string PLAYER_MOVE_LEFT = "Player_Move_Left"; - private const string PLAYER_MOVE_RIGHT = "Player_Move_Right"; - private const string PLAYER_FIRE = "Player_Fire"; [Export] private CpuParticles3D cpulaser; [Export] private PackedScene explosion; [Export] private GpuParticles3D gpulaser; @@ -20,14 +14,17 @@ public partial class PlayerShip : Node3D { [Export] private PackedScene laser; private float laserTimer = laserTimerMax; - private Vector3 moveDir; [Export] private float moveVelocity = 10f; + public float MoveVelocity => moveVelocity; + [Export] private float rotationVelocity = 15f; + public float RotationVelocity => rotationVelocity; + [Export] public RigidBody3D PlayerRb; - private Vector3 rotDir; - [Export] private float rotVelocity = 15f; - private bool shooting; [Export] private Node3D shots; + public Vector3 MoveDirection { get; set; } + public Vector3 RotationDirection { get; set; } + public bool Shooting { get; set; } public static PlayerShip Instance { get; private set; } @@ -37,24 +34,7 @@ public partial class PlayerShip : Node3D { } public override void _Process(double delta) { - if (GameManager.Instance.GameOver) return; - - moveDir = Vector3.Zero; - rotDir = Vector3.Zero; - - //Movement - if (Input.IsActionPressed(PLAYER_MOVE_FORWARD)) moveDir.Z -= moveVelocity; - if (Input.IsActionJustPressed(PLAYER_MOVE_FORWARD)) rotDir.X = -rotVelocity; - if (Input.IsActionPressed(PLAYER_MOVE_BACKWARDS)) moveDir.Z += moveVelocity; - if (Input.IsActionJustPressed(PLAYER_MOVE_BACKWARDS)) rotDir.X = +rotVelocity; - if (Input.IsActionPressed(PLAYER_MOVE_LEFT)) moveDir.X -= moveVelocity; - if (Input.IsActionJustPressed(PLAYER_MOVE_LEFT)) rotDir.Z = -rotVelocity * 2; - if (Input.IsActionPressed(PLAYER_MOVE_RIGHT)) moveDir.X += moveVelocity; - if (Input.IsActionJustPressed(PLAYER_MOVE_RIGHT)) rotDir.Z = +rotVelocity * 2; - if (Input.IsActionJustReleased(PLAYER_MOVE_LEFT) || Input.IsActionJustReleased(PLAYER_MOVE_RIGHT)) rotDir = Vector3.Zero; - - //Fire - if (Input.IsActionJustPressed(PLAYER_FIRE)) + if (Shooting) if (laser.Instantiate() is Node3D shot) { shot.Position = PlayerRb.Position + new Vector3(0f, 0f, 0.74f); shots.AddChild(shot); @@ -64,9 +44,9 @@ public partial class PlayerShip : Node3D { public override void _PhysicsProcess(double delta) { //Movement - if (moveDir != Vector3.Zero) { + if (MoveDirection != Vector3.Zero) { jet.Visible = true; - KinematicCollision3D collision = PlayerRb.MoveAndCollide(moveDir * (float)delta); + KinematicCollision3D collision = PlayerRb.MoveAndCollide(MoveDirection * (float)delta); if (collision?.GetCollider() is Node3D collider) { Node3D parent = collider.GetParent(); Vector3 collisionPosition = collision.GetPosition(); @@ -86,7 +66,7 @@ public partial class PlayerShip : Node3D { } //Rotation - PlayerRb.RotationDegrees = rotDir; + PlayerRb.RotationDegrees = RotationDirection; } public void Explode(Vector3 collisionPosition) { diff --git a/Scripts/generic_arrow_3.svg b/Scripts/generic_arrow_3.svg new file mode 100644 index 0000000..8a2b017 --- /dev/null +++ b/Scripts/generic_arrow_3.svg @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Images/restart.svg.import b/Scripts/generic_arrow_3.svg.import similarity index 71% rename from Images/restart.svg.import rename to Scripts/generic_arrow_3.svg.import index 33708bf..9c396fa 100644 --- a/Images/restart.svg.import +++ b/Scripts/generic_arrow_3.svg.import @@ -2,16 +2,16 @@ importer="texture" type="CompressedTexture2D" -uid="uid://b8gy1u2i0jkyd" -path="res://.godot/imported/restart.svg-98c792bd948b9b683b245e78c0930bfc.ctex" +uid="uid://d3tkfqng4erhj" +path="res://.godot/imported/generic_arrow_3.svg-b4290a859159fb8c7b12bda0e7002f2e.ctex" metadata={ "vram_texture": false } [deps] -source_file="res://Images/restart.svg" -dest_files=["res://.godot/imported/restart.svg-98c792bd948b9b683b245e78c0930bfc.ctex"] +source_file="res://Scripts/generic_arrow_3.svg" +dest_files=["res://.godot/imported/generic_arrow_3.svg-b4290a859159fb8c7b12bda0e7002f2e.ctex"] [params] From 6fa2fd932ad5fef3a0b814a3c037ca76135c2575 Mon Sep 17 00:00:00 2001 From: Sascha Date: Wed, 24 Jan 2024 17:41:32 +0100 Subject: [PATCH 10/14] pause menu fininshed --- Scenes/SpaceShooter.tscn | 40 +++++++++++++++++++++------------------- Scripts/GameManager.cs | 25 ++++++++++++++----------- Scripts/InputManager.cs | 20 ++++++++++---------- Scripts/PlayerShip.cs | 1 + Scripts/Ui.cs | 16 ++++++++-------- 5 files changed, 54 insertions(+), 48 deletions(-) diff --git a/Scenes/SpaceShooter.tscn b/Scenes/SpaceShooter.tscn index de9c797..9b721c6 100644 --- a/Scenes/SpaceShooter.tscn +++ b/Scenes/SpaceShooter.tscn @@ -153,60 +153,62 @@ asteroidsContainer = NodePath("../Asteroids") process_mode = 3 script = ExtResource("15_uovst") -[node name="Ui" type="Node2D" parent="." node_paths=PackedStringArray("rtlAsteroids", "rtlLevel", "rtlLifes", "rtlNextLevel", "rtlPoints", "labelGameOver", "buttonRestart", "rtlReachedPoints", "healthBar", "vBoxPause", "buttonResume", "buttonPauseRestart")] +[node name="Ui" type="Node2D" parent="." node_paths=PackedStringArray("rtlAsteroids", "rtlLevel", "rtlLifes", "rtlNextLevel", "rtlPoints", "vBoxGameOver", "lblGameOver", "buttonRestart", "lblReachedPoints", "healthBar", "vBoxPause", "buttonResume", "buttonPauseRestart")] process_mode = 3 script = ExtResource("15_xl7yx") -rtlAsteroids = NodePath("VBoxLabels/rtlAsteroids") -rtlLevel = NodePath("VBoxLabels/trlLevel") -rtlLifes = NodePath("VBoxLabels/rtlLifes") -rtlNextLevel = NodePath("VBoxLabels/rtlNextLevel") -rtlPoints = NodePath("VBoxLabels/rtlPoints") -labelGameOver = NodePath("VBoxGameOver/LabelGameOver") +rtlAsteroids = NodePath("VBoxStats/rtlAsteroids") +rtlLevel = NodePath("VBoxStats/trlLevel") +rtlLifes = NodePath("VBoxStats/rtlLifes") +rtlNextLevel = NodePath("VBoxStats/rtlNextLevel") +rtlPoints = NodePath("VBoxStats/rtlPoints") +vBoxGameOver = NodePath("VBoxGameOver") +lblGameOver = NodePath("VBoxGameOver/lblGameOver") buttonRestart = NodePath("VBoxGameOver/RestartButton") -rtlReachedPoints = NodePath("") +lblReachedPoints = NodePath("VBoxGameOver/lblReachedPoints") healthBar = NodePath("VBoxHealth/HealthBar") vBoxPause = NodePath("VBoxPause") buttonResume = NodePath("VBoxPause/ButtonResume") buttonPauseRestart = NodePath("VBoxPause/PauseRestartButton") -[node name="VBoxLabels" type="VBoxContainer" parent="Ui"] +[node name="VBoxStats" type="VBoxContainer" parent="Ui"] anchors_preset = 2 anchor_top = 1.0 anchor_bottom = 1.0 -offset_top = 1138.0 -offset_right = 152.0 -offset_bottom = 1278.0 +offset_left = 8.0 +offset_top = 1129.0 +offset_right = 160.0 +offset_bottom = 1269.0 grow_vertical = 0 -[node name="rtlAsteroids" type="RichTextLabel" parent="Ui/VBoxLabels"] +[node name="rtlAsteroids" type="RichTextLabel" parent="Ui/VBoxStats"] layout_mode = 2 size_flags_vertical = 3 text = "Asteroids: 0" scroll_active = false shortcut_keys_enabled = false -[node name="trlLevel" type="RichTextLabel" parent="Ui/VBoxLabels"] +[node name="trlLevel" type="RichTextLabel" parent="Ui/VBoxStats"] layout_mode = 2 size_flags_vertical = 3 text = "Level: 1" scroll_active = false shortcut_keys_enabled = false -[node name="rtlLifes" type="RichTextLabel" parent="Ui/VBoxLabels"] +[node name="rtlLifes" type="RichTextLabel" parent="Ui/VBoxStats"] layout_mode = 2 size_flags_vertical = 3 text = "Lives: 3" scroll_active = false shortcut_keys_enabled = false -[node name="rtlNextLevel" type="RichTextLabel" parent="Ui/VBoxLabels"] +[node name="rtlNextLevel" type="RichTextLabel" parent="Ui/VBoxStats"] layout_mode = 2 size_flags_vertical = 3 text = "Next Level: 10" scroll_active = false shortcut_keys_enabled = false -[node name="rtlPoints" type="RichTextLabel" parent="Ui/VBoxLabels"] +[node name="rtlPoints" type="RichTextLabel" parent="Ui/VBoxStats"] layout_mode = 2 size_flags_vertical = 3 text = "Points: 0" @@ -214,7 +216,6 @@ scroll_active = false shortcut_keys_enabled = false [node name="VBoxGameOver" type="VBoxContainer" parent="Ui"] -visible = false anchors_preset = 8 anchor_left = 0.5 anchor_top = 0.5 @@ -227,7 +228,7 @@ offset_bottom = 749.0 grow_horizontal = 2 grow_vertical = 2 -[node name="LabelGameOver" type="Label" parent="Ui/VBoxGameOver"] +[node name="lblGameOver" type="Label" parent="Ui/VBoxGameOver"] layout_mode = 2 text = "Game Over" label_settings = SubResource("LabelSettings_dqsad") @@ -253,6 +254,7 @@ text = "Restart" icon = ExtResource("17_1t6sc") [node name="VBoxPause" type="VBoxContainer" parent="Ui"] +visible = false anchors_preset = 8 anchor_left = 0.5 anchor_top = 0.5 diff --git a/Scripts/GameManager.cs b/Scripts/GameManager.cs index c5711df..984e88d 100644 --- a/Scripts/GameManager.cs +++ b/Scripts/GameManager.cs @@ -7,7 +7,18 @@ namespace GodotspaceShooter.Scripts; public partial class GameManager : Node { private int asteroidMaxNumber = 3; private int asteroidNumber; - public bool GameOver { get; private set; } + + private bool gameOver; + public bool GameOver { + get => gameOver; + private set { + gameOver = value; + GetTree().Paused = gameOver; + SoundManager.Instance.Stop(SoundManager.Sound.BackgroundMusic); + SoundManager.Instance.Play(SoundManager.Sound.GameOver); + RefreshUi?.Invoke(this, EventArgs.Empty); + } + } [Export] private Array asteroids; [Export] private Node3D asteroidsContainer; @@ -34,7 +45,7 @@ public partial class GameManager : Node { get => lives; set { lives = value; - if (lives <= 0) SetGameOver(); + if (lives <= 0) GameOver = true; RefreshUi?.Invoke(this, EventArgs.Empty); } } @@ -89,12 +100,10 @@ public partial class GameManager : Node { Instance = this; Lives = MaxLives; spawnTimer = spawnRate; - SoundManager.Instance.Ready += SoundManagerReady; + SoundManager.Instance.Play(SoundManager.Sound.BackgroundMusic); RefreshUi?.Invoke(this, EventArgs.Empty); } - private void SoundManagerReady() => SoundManager.Instance.Play(SoundManager.Sound.BackgroundMusic); - public override void _Process(double delta) { spawnTimer -= (float)delta; if (spawnTimer < 0) { @@ -119,10 +128,4 @@ public partial class GameManager : Node { AsteroidMaxNumber = 3 + Level; spawnRate = 1f - Level * 0.1f; } - - private void SetGameOver() { - GameOver = true; - SoundManager.Instance.Stop(SoundManager.Sound.BackgroundMusic); - SoundManager.Instance.Play(SoundManager.Sound.GameOver); - } } diff --git a/Scripts/InputManager.cs b/Scripts/InputManager.cs index b1d1753..3eefff9 100644 --- a/Scripts/InputManager.cs +++ b/Scripts/InputManager.cs @@ -20,19 +20,19 @@ public partial class InputManager : Node //Movement float moveVelocity = PlayerShip.Instance.MoveVelocity; - float rotVelocity = PlayerShip.Instance.RotationVelocity; + float rotationVelocity = PlayerShip.Instance.RotationVelocity; moveDirection = Vector3.Zero; rotationDirection = Vector3.Zero; - if (Input.IsActionPressed(PLAYER_MOVE_FORWARD)) moveDirection = moveDirection with { Z = moveVelocity }; - if (Input.IsActionJustPressed(PLAYER_MOVE_FORWARD)) rotationDirection = rotationDirection with { X = -rotVelocity }; - if (Input.IsActionPressed(PLAYER_MOVE_BACKWARDS)) moveDirection = moveDirection with { Z = moveVelocity }; - if (Input.IsActionJustPressed(PLAYER_MOVE_BACKWARDS)) rotationDirection = rotationDirection with { X = +rotVelocity }; - if (Input.IsActionPressed(PLAYER_MOVE_LEFT)) moveDirection = moveDirection with { X = moveVelocity }; - if (Input.IsActionJustPressed(PLAYER_MOVE_LEFT)) rotationDirection = rotationDirection with { Z = -rotVelocity * 2 }; - if (Input.IsActionPressed(PLAYER_MOVE_RIGHT)) moveDirection = moveDirection with { X = moveVelocity }; - if (Input.IsActionJustPressed(PLAYER_MOVE_RIGHT)) rotationDirection = rotationDirection with { Z = +rotVelocity * 2 }; + if (Input.IsActionPressed(PLAYER_MOVE_FORWARD)) moveDirection.Z = -moveVelocity; + if (Input.IsActionJustPressed(PLAYER_MOVE_FORWARD)) rotationDirection.X = -rotationVelocity; + if (Input.IsActionPressed(PLAYER_MOVE_BACKWARDS)) moveDirection.Z = +moveVelocity; + if (Input.IsActionJustPressed(PLAYER_MOVE_BACKWARDS)) rotationDirection.X = +rotationVelocity; + if (Input.IsActionPressed(PLAYER_MOVE_LEFT)) moveDirection.X = -moveVelocity; + if (Input.IsActionJustPressed(PLAYER_MOVE_LEFT)) rotationDirection.Z = -rotationVelocity * 2; + if (Input.IsActionPressed(PLAYER_MOVE_RIGHT)) moveDirection.X = moveVelocity; + if (Input.IsActionJustPressed(PLAYER_MOVE_RIGHT)) rotationDirection.Z = +rotationVelocity * 2; if (Input.IsActionJustReleased(PLAYER_MOVE_LEFT) || Input.IsActionJustReleased(PLAYER_MOVE_RIGHT)) rotationDirection = Vector3.Zero; PlayerShip.Instance.MoveDirection = moveDirection; @@ -40,6 +40,6 @@ public partial class InputManager : Node //Shooting if (Input.IsActionJustPressed(PLAYER_FIRE)) PlayerShip.Instance.Shooting = true; - if (Input.IsActionJustReleased(PLAYER_FIRE)) PlayerShip.Instance.Shooting = false; + // if (Input.IsActionJustReleased(PLAYER_FIRE)) PlayerShip.Instance.Shooting = false; } } \ No newline at end of file diff --git a/Scripts/PlayerShip.cs b/Scripts/PlayerShip.cs index 398ca4d..e7c8f6b 100644 --- a/Scripts/PlayerShip.cs +++ b/Scripts/PlayerShip.cs @@ -39,6 +39,7 @@ public partial class PlayerShip : Node3D { shot.Position = PlayerRb.Position + new Vector3(0f, 0f, 0.74f); shots.AddChild(shot); SoundManager.Instance.Play(SoundManager.Sound.Laser, PlayerRb.Position); + Shooting = false; } } diff --git a/Scripts/Ui.cs b/Scripts/Ui.cs index 483bd8d..b61dfc1 100644 --- a/Scripts/Ui.cs +++ b/Scripts/Ui.cs @@ -9,9 +9,10 @@ public partial class Ui : Node2D [Export] private RichTextLabel rtlLifes; [Export] private RichTextLabel rtlNextLevel; [Export] private RichTextLabel rtlPoints; - [Export] private Label labelGameOver; + [Export] private VBoxContainer vBoxGameOver; + [Export] private Label lblGameOver; [Export] private Button buttonRestart; - [Export] private RichTextLabel rtlReachedPoints; + [Export] private Label lblReachedPoints; [Export] private ProgressBar healthBar; [Export] private VBoxContainer vBoxPause; [Export] private Button buttonResume; @@ -25,9 +26,9 @@ public partial class Ui : Node2D GD.PrintErr("No GameManager found!"); else { GameManager.Instance.RefreshUi += RefreshUi; - labelGameOver.Visible = GameManager.Instance.GameOver; + lblGameOver.Visible = GameManager.Instance.GameOver; buttonRestart.Visible = GameManager.Instance.GameOver; - rtlReachedPoints.Visible = GameManager.Instance.GameOver; + lblReachedPoints.Visible = GameManager.Instance.GameOver; buttonRestart.Pressed += ButtonRestartOnPressed; buttonResume.Pressed += ButtonResumeOnPressed; buttonPauseRestart.Pressed += ButtonPauseRestartOnPressed; @@ -46,12 +47,11 @@ public partial class Ui : Node2D healthBar.Value = GameManager.Instance.Lives; if (GameManager.Instance.GameOver) { - rtlReachedPoints.Text = $"[center]You have reached level {GameManager.Instance.Level} and {GameManager.Instance.Points} points![/center]"; - labelGameOver.Visible = GameManager.Instance.GameOver; - buttonRestart.Visible = GameManager.Instance.GameOver; - rtlReachedPoints.Visible = GameManager.Instance.GameOver; + lblReachedPoints.Text = $"You have reached level {GameManager.Instance.Level} and {GameManager.Instance.Points} points!"; + vBoxGameOver.Visible = true; } + // vBoxGameOver.Visible = GameManager.Instance.GameOver; vBoxPause.Visible = GameManager.Instance.GamePaused; } From e456608f06c548027b1b61ef455223d4e5cfef26 Mon Sep 17 00:00:00 2001 From: Sascha Date: Fri, 26 Jan 2024 11:24:00 +0100 Subject: [PATCH 11/14] Add Countdown --- Godot-space Shooter.csproj.old.5 | 3 ++ Images/keyboard_any.png | Bin 0 -> 405 bytes Images/keyboard_any.png.import | 34 ++++++++++++++++++++ Material/lblSettingsCountdown.tres | 8 +++++ Scenes/SpaceShooter.tscn | 49 +++++++++++++++++++++++++++-- Scripts/GameManager.cs | 19 +++++++---- Scripts/InputManager.cs | 15 +++++++-- Scripts/Ui.cs | 41 ++++++++++++++++++++++-- 8 files changed, 156 insertions(+), 13 deletions(-) create mode 100644 Images/keyboard_any.png create mode 100644 Images/keyboard_any.png.import create mode 100644 Material/lblSettingsCountdown.tres diff --git a/Godot-space Shooter.csproj.old.5 b/Godot-space Shooter.csproj.old.5 index cc1116d..9d3fa14 100644 --- a/Godot-space Shooter.csproj.old.5 +++ b/Godot-space Shooter.csproj.old.5 @@ -4,4 +4,7 @@ true GodotspaceShooter + + + \ No newline at end of file diff --git a/Images/keyboard_any.png b/Images/keyboard_any.png new file mode 100644 index 0000000000000000000000000000000000000000..ef26da1b86f5377330a1a2c815581a4f54f362c4 GIT binary patch literal 405 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0J3?w7mbKU|emUKs7M+SzC{oH>NS%G|m0G|-o z|3m|z4xrk7T$erqS^OnIe!=ni@6Y?!^UuG(zkj{FJ%h!8TP#4SubwWBAs)xyUbW_8 zG8AA-c>hq8C4T|?2R^Q_uxi%+1l^8mX7Pi57p{5vKUn;sbxr*d_TBr8(sUQC5f0xV zcxV2EG&_%kLn@6OD*rfloYZO!%KbLqp>c+cT!L$klvGb;!PNz4nEji%_-lAiOpvJI zp7Wcl`I>>dkeTC^w333i1~(#Sq%VDCvYF49hie4TT2 z#a-C~7y=qN?#)VOQDt2hAe$d0!JK;yzh!H*nF8#%mMm&WXZpDM zA8*3vuZ!9E`2D1KDhhtqh asteroidNumber; @@ -84,7 +85,7 @@ public partial class GameManager : Node { } private bool gamePaused; - public bool GamePaused { + public bool GamePaused{ get => gamePaused; set { gamePaused = value; @@ -92,23 +93,29 @@ public partial class GameManager : Node { RefreshUi?.Invoke(this, EventArgs.Empty); } } + + public bool Countdown { get; set; } + public static GameManager Instance { get; private set; } [Export] public bool Debug { get; private set; } = true; - public override void _Ready() { Instance = this; Lives = MaxLives; spawnTimer = spawnRate; SoundManager.Instance.Play(SoundManager.Sound.BackgroundMusic); RefreshUi?.Invoke(this, EventArgs.Empty); + Countdown = true; + NewCountdown?.Invoke(this, EventArgs.Empty); } public override void _Process(double delta) { - spawnTimer -= (float)delta; - if (spawnTimer < 0) { - if (AsteroidNumber < asteroidMaxNumber) SpawnNewAsteroid(); - spawnTimer = spawnRate; + if (!GamePaused && !Countdown) { + spawnTimer -= (float)delta; + if (spawnTimer < 0) { + if (AsteroidNumber < asteroidMaxNumber) SpawnNewAsteroid(); + spawnTimer = spawnRate; + } } } diff --git a/Scripts/InputManager.cs b/Scripts/InputManager.cs index 3eefff9..be2a170 100644 --- a/Scripts/InputManager.cs +++ b/Scripts/InputManager.cs @@ -1,3 +1,4 @@ +using System; using Godot; namespace GodotspaceShooter.Scripts; @@ -13,11 +14,21 @@ public partial class InputManager : Node private Vector3 moveDirection; private Vector3 rotationDirection; - + + public event EventHandler StartCountdown; + + public static InputManager Instance { get; private set; } + + public override void _Ready() => Instance = this; + public override void _UnhandledInput(InputEvent @event) { + //Countdown + if (GameManager.Instance.Countdown && Input.IsAnythingPressed()) StartCountdown?.Invoke(this,EventArgs.Empty); + //Pause if (Input.IsActionJustReleased(GAME_PAUSE)) GameManager.Instance.GamePaused = GameManager.Instance.GamePaused switch { true => false, false => true }; - + + if (GameManager.Instance.GamePaused || GameManager.Instance.Countdown) return; //Movement float moveVelocity = PlayerShip.Instance.MoveVelocity; float rotationVelocity = PlayerShip.Instance.RotationVelocity; diff --git a/Scripts/Ui.cs b/Scripts/Ui.cs index b61dfc1..e8923b0 100644 --- a/Scripts/Ui.cs +++ b/Scripts/Ui.cs @@ -1,4 +1,5 @@ using System; +using System.Globalization; using Godot; namespace GodotspaceShooter.Scripts; @@ -17,6 +18,14 @@ public partial class Ui : Node2D [Export] private VBoxContainer vBoxPause; [Export] private Button buttonResume; [Export] private Button buttonPauseRestart; + [Export] private VBoxContainer vBoxCountdown; + [Export] private Label lblCountdown; + [Export] private TextureRect textAnyKey; + [Export] private Label lblAnyKey; + + private const double countdownMaxTimer = 3; + private double countdownTimer = countdownMaxTimer; + private bool countdownRunning; public static Ui Instance { get; private set; } @@ -25,19 +34,45 @@ public partial class Ui : Node2D if (GameManager.Instance is null) GD.PrintErr("No GameManager found!"); else { - GameManager.Instance.RefreshUi += RefreshUi; + GameManager.Instance.RefreshUi += GameManager_RefreshUi; + GameManager.Instance.NewCountdown += GameManager_NewCountdown; + InputManager.Instance.StartCountdown += InputManager_StartCountdown; lblGameOver.Visible = GameManager.Instance.GameOver; buttonRestart.Visible = GameManager.Instance.GameOver; lblReachedPoints.Visible = GameManager.Instance.GameOver; buttonRestart.Pressed += ButtonRestartOnPressed; buttonResume.Pressed += ButtonResumeOnPressed; buttonPauseRestart.Pressed += ButtonPauseRestartOnPressed; - RefreshUi(this, EventArgs.Empty); + GameManager_RefreshUi(this, EventArgs.Empty); } } + private void InputManager_StartCountdown(object sender, EventArgs e) { + lblAnyKey.Visible = false; + textAnyKey.Visible = false; + countdownRunning = true; + } + + private void GameManager_NewCountdown(object sender, EventArgs e) { + lblCountdown.Text = countdownTimer.ToString(CultureInfo.InvariantCulture); + vBoxCountdown.Visible = true; + lblAnyKey.Visible = true; + textAnyKey.Visible = true; + } + + public override void _Process(double delta) { + if (GameManager.Instance.Countdown && countdownRunning) { + countdownTimer -= delta; + lblCountdown.Text = Mathf.RoundToInt(countdownTimer).ToString(); + if (countdownTimer <= 0) { + vBoxCountdown.Visible = false; + countdownRunning = false; + GameManager.Instance.Countdown = false; + } + } + } - private void RefreshUi(object sender, EventArgs e) { + private void GameManager_RefreshUi(object sender, EventArgs e) { rtlLifes.Text = $"Lives: {GameManager.Instance.Lives}"; rtlAsteroids.Text = $"Asteroids: {GameManager.Instance.AsteroidNumber} / {GameManager.Instance.AsteroidMaxNumber}"; rtlPoints.Text = $"Points: {GameManager.Instance.Points}"; From e84d8184a5baf2e29f3a0fefa67ddd25bb35e8b1 Mon Sep 17 00:00:00 2001 From: Sascha Date: Fri, 26 Jan 2024 11:44:24 +0100 Subject: [PATCH 12/14] GameOver now visible solved #30 --- Scenes/SpaceShooter.tscn | 3 +-- Scripts/GameManager.cs | 26 +++++++++++++------------- Scripts/InputManager.cs | 2 +- Scripts/Ui.cs | 27 +++++++++++++++------------ 4 files changed, 30 insertions(+), 28 deletions(-) diff --git a/Scenes/SpaceShooter.tscn b/Scenes/SpaceShooter.tscn index a692d67..8c0b17b 100644 --- a/Scenes/SpaceShooter.tscn +++ b/Scenes/SpaceShooter.tscn @@ -222,7 +222,7 @@ scroll_active = false shortcut_keys_enabled = false [node name="VBoxGameOver" type="VBoxContainer" parent="Ui"] -visible = false +process_mode = 3 anchors_preset = 8 anchor_left = 0.5 anchor_top = 0.5 @@ -261,7 +261,6 @@ text = "Restart" icon = ExtResource("17_1t6sc") [node name="VBoxPause" type="VBoxContainer" parent="Ui"] -visible = false anchors_preset = 8 anchor_left = 0.5 anchor_top = 0.5 diff --git a/Scripts/GameManager.cs b/Scripts/GameManager.cs index e247153..26218d6 100644 --- a/Scripts/GameManager.cs +++ b/Scripts/GameManager.cs @@ -13,10 +13,9 @@ public partial class GameManager : Node { get => gameOver; private set { gameOver = value; - GetTree().Paused = gameOver; SoundManager.Instance.Stop(SoundManager.Sound.BackgroundMusic); SoundManager.Instance.Play(SoundManager.Sound.GameOver); - RefreshUi?.Invoke(this, EventArgs.Empty); + OnGameOver?.Invoke(this,EventArgs.Empty); } } @@ -31,14 +30,15 @@ public partial class GameManager : Node { private float spawnRate = 1f; private float spawnTimer; - public event EventHandler RefreshUi; - public event EventHandler NewCountdown; + public event EventHandler OnRefreshUi; + public event EventHandler OnNewCountdown; + public event EventHandler OnGameOver; public int AsteroidNumber { get => asteroidNumber; set { asteroidNumber = value; - RefreshUi?.Invoke(this, EventArgs.Empty); + OnRefreshUi?.Invoke(this, EventArgs.Empty); } } @@ -47,7 +47,7 @@ public partial class GameManager : Node { set { lives = value; if (lives <= 0) GameOver = true; - RefreshUi?.Invoke(this, EventArgs.Empty); + OnRefreshUi?.Invoke(this, EventArgs.Empty); } } @@ -56,7 +56,7 @@ public partial class GameManager : Node { set { points = value; if (points >= nextLevelPoints) NextLevel(); - RefreshUi?.Invoke(this, EventArgs.Empty); + OnRefreshUi?.Invoke(this, EventArgs.Empty); } } @@ -64,7 +64,7 @@ public partial class GameManager : Node { get => level; private set { level = value; - RefreshUi?.Invoke(this, EventArgs.Empty); + OnRefreshUi?.Invoke(this, EventArgs.Empty); } } @@ -72,7 +72,7 @@ public partial class GameManager : Node { get => nextLevelPoints; private set { nextLevelPoints = value; - RefreshUi?.Invoke(this, EventArgs.Empty); + OnRefreshUi?.Invoke(this, EventArgs.Empty); } } @@ -80,7 +80,7 @@ public partial class GameManager : Node { get => asteroidMaxNumber; private set { asteroidMaxNumber = value; - RefreshUi?.Invoke(this, EventArgs.Empty); + OnRefreshUi?.Invoke(this, EventArgs.Empty); } } @@ -90,7 +90,7 @@ public partial class GameManager : Node { set { gamePaused = value; GetTree().Paused = gamePaused; - RefreshUi?.Invoke(this, EventArgs.Empty); + OnRefreshUi?.Invoke(this, EventArgs.Empty); } } @@ -104,9 +104,9 @@ public partial class GameManager : Node { Lives = MaxLives; spawnTimer = spawnRate; SoundManager.Instance.Play(SoundManager.Sound.BackgroundMusic); - RefreshUi?.Invoke(this, EventArgs.Empty); + OnRefreshUi?.Invoke(this, EventArgs.Empty); Countdown = true; - NewCountdown?.Invoke(this, EventArgs.Empty); + OnNewCountdown?.Invoke(this, EventArgs.Empty); } public override void _Process(double delta) { diff --git a/Scripts/InputManager.cs b/Scripts/InputManager.cs index be2a170..b75d4fc 100644 --- a/Scripts/InputManager.cs +++ b/Scripts/InputManager.cs @@ -28,7 +28,7 @@ public partial class InputManager : Node //Pause if (Input.IsActionJustReleased(GAME_PAUSE)) GameManager.Instance.GamePaused = GameManager.Instance.GamePaused switch { true => false, false => true }; - if (GameManager.Instance.GamePaused || GameManager.Instance.Countdown) return; + if (GameManager.Instance.GamePaused || GameManager.Instance.Countdown || GameManager.Instance.GameOver) return; //Movement float moveVelocity = PlayerShip.Instance.MoveVelocity; float rotationVelocity = PlayerShip.Instance.RotationVelocity; diff --git a/Scripts/Ui.cs b/Scripts/Ui.cs index e8923b0..ae2be67 100644 --- a/Scripts/Ui.cs +++ b/Scripts/Ui.cs @@ -1,5 +1,6 @@ using System; using System.Globalization; +using System.Linq; using Godot; namespace GodotspaceShooter.Scripts; @@ -34,8 +35,9 @@ public partial class Ui : Node2D if (GameManager.Instance is null) GD.PrintErr("No GameManager found!"); else { - GameManager.Instance.RefreshUi += GameManager_RefreshUi; - GameManager.Instance.NewCountdown += GameManager_NewCountdown; + GameManager.Instance.OnRefreshUi += GameManager_OnRefreshUi; + GameManager.Instance.OnNewCountdown += GameManagerOnNewCountdown; + GameManager.Instance.OnGameOver += GameManager_OnGameOver; InputManager.Instance.StartCountdown += InputManager_StartCountdown; lblGameOver.Visible = GameManager.Instance.GameOver; buttonRestart.Visible = GameManager.Instance.GameOver; @@ -43,17 +45,24 @@ public partial class Ui : Node2D buttonRestart.Pressed += ButtonRestartOnPressed; buttonResume.Pressed += ButtonResumeOnPressed; buttonPauseRestart.Pressed += ButtonPauseRestartOnPressed; - GameManager_RefreshUi(this, EventArgs.Empty); + GameManager_OnRefreshUi(this, EventArgs.Empty); } } + private void GameManager_OnGameOver(object sender, EventArgs e) { + GD.Print($"Game Over! You have reached level {GameManager.Instance.Level} and {GameManager.Instance.Points} points!"); + lblReachedPoints.Text = $"You have reached level {GameManager.Instance.Level} and {GameManager.Instance.Points} points!"; + foreach (CanvasItem canvasItem in vBoxGameOver.GetChildren().Cast()) canvasItem.Visible = true; + vBoxGameOver.Visible = true; + } + private void InputManager_StartCountdown(object sender, EventArgs e) { lblAnyKey.Visible = false; textAnyKey.Visible = false; countdownRunning = true; } - private void GameManager_NewCountdown(object sender, EventArgs e) { + private void GameManagerOnNewCountdown(object sender, EventArgs e) { lblCountdown.Text = countdownTimer.ToString(CultureInfo.InvariantCulture); vBoxCountdown.Visible = true; lblAnyKey.Visible = true; @@ -72,7 +81,7 @@ public partial class Ui : Node2D } } - private void GameManager_RefreshUi(object sender, EventArgs e) { + private void GameManager_OnRefreshUi(object sender, EventArgs e) { rtlLifes.Text = $"Lives: {GameManager.Instance.Lives}"; rtlAsteroids.Text = $"Asteroids: {GameManager.Instance.AsteroidNumber} / {GameManager.Instance.AsteroidMaxNumber}"; rtlPoints.Text = $"Points: {GameManager.Instance.Points}"; @@ -80,14 +89,8 @@ public partial class Ui : Node2D rtlLevel.Text = $"Actual Level: {GameManager.Instance.Level}"; healthBar.MaxValue = GameManager.Instance.MaxLives; healthBar.Value = GameManager.Instance.Lives; - - if (GameManager.Instance.GameOver) { - lblReachedPoints.Text = $"You have reached level {GameManager.Instance.Level} and {GameManager.Instance.Points} points!"; - vBoxGameOver.Visible = true; - } - - // vBoxGameOver.Visible = GameManager.Instance.GameOver; vBoxPause.Visible = GameManager.Instance.GamePaused; + vBoxGameOver.Visible = GameManager.Instance.GameOver; } private void ButtonRestartOnPressed() => GetTree().ReloadCurrentScene(); From b7a4e4d7d419374f35eda79c27c727812720980f Mon Sep 17 00:00:00 2001 From: Sascha Date: Fri, 26 Jan 2024 14:29:21 +0100 Subject: [PATCH 13/14] introduced bars on top --- Images/flair_disabled_cross.png | Bin 0 -> 348 bytes Images/flair_disabled_cross.png.import | 34 +++ Scenes/SpaceShooter.tscn | 281 +++++++++++++------------ Scripts/GameManager.cs | 38 ++-- Scripts/Ui.cs | 52 +++-- 5 files changed, 236 insertions(+), 169 deletions(-) create mode 100644 Images/flair_disabled_cross.png create mode 100644 Images/flair_disabled_cross.png.import diff --git a/Images/flair_disabled_cross.png b/Images/flair_disabled_cross.png new file mode 100644 index 0000000000000000000000000000000000000000..064807fe8bb0ae6e394e03c80d45b3e527bea07d GIT binary patch literal 348 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0L3?#3!&-4XSEa{HEjtmSN`?>!lvI6-$0X`wF z&y8H48@K^^&yC!agR)eCEas9Rzu@`t42Duw9YF3IPZ!4!i_=FhZxn1|5OBG;_PE-M z<7yg>LOdKS-V0ey8yFn2{P^zu*$n1MKby^~x_AAx`4!!<*?vvn!*>O$HnMsx(+@`^ z8f-c?FVU!|*S+oL3Ds>p-4hM{z8-a$bb?`$3)=)0qXv~gd%cNDS}H*pv>J(%rB^oH0+2iRfxdX6$-Bc9j~x-%wh->R>)#{^7+xbxl8-bTYBC{-5vu`R1Rl9{-<{zZn!<44$rjF6*2UngHgigDwC7 literal 0 HcmV?d00001 diff --git a/Images/flair_disabled_cross.png.import b/Images/flair_disabled_cross.png.import new file mode 100644 index 0000000..735514f --- /dev/null +++ b/Images/flair_disabled_cross.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://b3ucjch8b7rve" +path="res://.godot/imported/flair_disabled_cross.png-3df80847240f401e9a98a70fda1aee83.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Images/flair_disabled_cross.png" +dest_files=["res://.godot/imported/flair_disabled_cross.png-3df80847240f401e9a98a70fda1aee83.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/Scenes/SpaceShooter.tscn b/Scenes/SpaceShooter.tscn index 8c0b17b..ff1da35 100644 --- a/Scenes/SpaceShooter.tscn +++ b/Scenes/SpaceShooter.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=34 format=3 uid="uid://det8556rpxhbv"] +[gd_scene load_steps=35 format=3 uid="uid://det8556rpxhbv"] [ext_resource type="PackedScene" uid="uid://tlr55u0gn20l" path="res://Packed-Scenes/PlayerShip.tscn" id="1_njb5h"] [ext_resource type="Texture2D" uid="uid://cg6n1hh3lj7rn" path="res://Textures/tile_nebula_green_dff.png" id="2_43vix"] @@ -20,6 +20,7 @@ [ext_resource type="Texture2D" uid="uid://bffseflkbu88e" path="res://Images/generic_arrow_long.png" id="18_b2vca"] [ext_resource type="Texture2D" uid="uid://c4l1soqbo0rud" path="res://Images/keyboard_arrows.png" id="19_dpw4m"] [ext_resource type="Texture2D" uid="uid://bnh0rcsf30nrm" path="res://Images/keyboard_w.png" id="20_3aqu5"] +[ext_resource type="Texture2D" uid="uid://b3ucjch8b7rve" path="res://Images/flair_disabled_cross.png" id="21_7mvgi"] [ext_resource type="Texture2D" uid="uid://cm7ru4t8ka3jn" path="res://Images/keyboard_a.png" id="21_of2rn"] [ext_resource type="Texture2D" uid="uid://c2n36lnm2f5he" path="res://Images/keyboard_s.png" id="22_1rcux"] [ext_resource type="Texture2D" uid="uid://uy20bgblsk4x" path="res://Images/keyboard_d.png" id="23_o81a8"] @@ -31,11 +32,11 @@ [sub_resource type="BoxShape3D" id="BoxShape3D_bw288"] -[sub_resource type="LabelSettings" id="LabelSettings_dqsad"] +[sub_resource type="LabelSettings" id="LabelSettings_vf3s8"] font_size = 50 -font_color = Color(1, 0, 0, 1) +font_color = Color(0.233592, 0.506913, 1, 1) outline_size = 3 -outline_color = Color(1, 0.999986, 0.00293482, 1) +outline_color = Color(0, 1, 0.00392157, 1) shadow_size = 10 shadow_offset = Vector2(5, 5) @@ -46,11 +47,11 @@ keycode = 4194309 [sub_resource type="Shortcut" id="Shortcut_soxs4"] events = [SubResource("InputEventKey_gjrl7")] -[sub_resource type="LabelSettings" id="LabelSettings_vf3s8"] +[sub_resource type="LabelSettings" id="LabelSettings_dqsad"] font_size = 50 -font_color = Color(0.233592, 0.506913, 1, 1) +font_color = Color(1, 0, 0, 1) outline_size = 3 -outline_color = Color(0, 1, 0.00392157, 1) +outline_color = Color(1, 0.999986, 0.00293482, 1) shadow_size = 10 shadow_offset = Vector2(5, 5) @@ -155,19 +156,17 @@ asteroidsContainer = NodePath("../Asteroids") process_mode = 3 script = ExtResource("15_uovst") -[node name="Ui" type="Node2D" parent="." node_paths=PackedStringArray("rtlAsteroids", "rtlLevel", "rtlLifes", "rtlNextLevel", "rtlPoints", "vBoxGameOver", "lblGameOver", "buttonRestart", "lblReachedPoints", "healthBar", "vBoxPause", "buttonResume", "buttonPauseRestart", "vBoxCountdown", "lblCountdown", "textAnyKey", "lblAnyKey")] +[node name="Ui" type="Node2D" parent="." node_paths=PackedStringArray("lblLevel", "lblPoints", "lblNextLevel", "vBoxGameOver", "lblGameOver", "buttonRestart", "lblReachedPoints", "barHealth", "vBoxPause", "buttonResume", "buttonPauseRestart", "vBoxCountdown", "lblCountdown", "textAnyKey", "lblAnyKey", "butExit", "barLevel")] process_mode = 3 script = ExtResource("15_xl7yx") -rtlAsteroids = NodePath("VBoxStats/rtlAsteroids") -rtlLevel = NodePath("VBoxStats/trlLevel") -rtlLifes = NodePath("VBoxStats/rtlLifes") -rtlNextLevel = NodePath("VBoxStats/rtlNextLevel") -rtlPoints = NodePath("VBoxStats/rtlPoints") +lblLevel = NodePath("VBoxStats/lblLevel") +lblPoints = NodePath("VBoxStats/lblPoints") +lblNextLevel = NodePath("VBoxStats/lblNextLevel") vBoxGameOver = NodePath("VBoxGameOver") lblGameOver = NodePath("VBoxGameOver/lblGameOver") -buttonRestart = NodePath("VBoxGameOver/RestartButton") +buttonRestart = NodePath("VBoxGameOver/butRestart") lblReachedPoints = NodePath("VBoxGameOver/lblReachedPoints") -healthBar = NodePath("VBoxHealth/HealthBar") +barHealth = NodePath("HBoxTop/VBoxBars/barHealth") vBoxPause = NodePath("VBoxPause") buttonResume = NodePath("VBoxPause/ButtonResume") buttonPauseRestart = NodePath("VBoxPause/PauseRestartButton") @@ -175,90 +174,69 @@ vBoxCountdown = NodePath("VBoxCountdown") lblCountdown = NodePath("VBoxCountdown/lblCountdown") textAnyKey = NodePath("VBoxCountdown/textPressKey") lblAnyKey = NodePath("VBoxCountdown/lblPressKey") +butExit = NodePath("VBoxGameOver/butExit") +barLevel = NodePath("HBoxTop/VBoxBars/barLevel") -[node name="VBoxStats" type="VBoxContainer" parent="Ui"] -anchors_preset = 2 -anchor_top = 1.0 -anchor_bottom = 1.0 -offset_left = 8.0 -offset_top = 1129.0 -offset_right = 160.0 -offset_bottom = 1269.0 -grow_vertical = 0 +[node name="HBoxTop" type="HBoxContainer" parent="Ui"] +offset_left = 160.0 +offset_top = 25.0 +offset_right = 660.0 +offset_bottom = 25.0 -[node name="rtlAsteroids" type="RichTextLabel" parent="Ui/VBoxStats"] +[node name="VBoxIcons" type="VBoxContainer" parent="Ui/HBoxTop"] +custom_minimum_size = Vector2(100, 50) layout_mode = 2 -size_flags_vertical = 3 -text = "Asteroids: 0" -scroll_active = false -shortcut_keys_enabled = false +tooltip_text = "10 / 10" -[node name="trlLevel" type="RichTextLabel" parent="Ui/VBoxStats"] +[node name="textLife" type="TextureRect" parent="Ui/HBoxTop/VBoxIcons"] layout_mode = 2 -size_flags_vertical = 3 -text = "Level: 1" -scroll_active = false -shortcut_keys_enabled = false -[node name="rtlLifes" type="RichTextLabel" parent="Ui/VBoxStats"] +[node name="textLevel" type="TextureRect" parent="Ui/HBoxTop/VBoxIcons"] layout_mode = 2 -size_flags_vertical = 3 -text = "Lives: 3" -scroll_active = false -shortcut_keys_enabled = false -[node name="rtlNextLevel" type="RichTextLabel" parent="Ui/VBoxStats"] +[node name="VBoxBars" type="VBoxContainer" parent="Ui/HBoxTop"] +custom_minimum_size = Vector2(100, 50) +layout_mode = 2 +tooltip_text = "10 / 10" + +[node name="barHealth" type="ProgressBar" parent="Ui/HBoxTop/VBoxBars"] layout_mode = 2 size_flags_vertical = 3 -text = "Next Level: 10" -scroll_active = false -shortcut_keys_enabled = false +max_value = 10.0 +value = 10.0 +rounded = true +show_percentage = false -[node name="rtlPoints" type="RichTextLabel" parent="Ui/VBoxStats"] +[node name="barLevel" type="ProgressBar" parent="Ui/HBoxTop/VBoxBars"] layout_mode = 2 size_flags_vertical = 3 -text = "Points: 0" -scroll_active = false -shortcut_keys_enabled = false +max_value = 10.0 +value = 10.0 +rounded = true +show_percentage = false -[node name="VBoxGameOver" type="VBoxContainer" parent="Ui"] -process_mode = 3 -anchors_preset = 8 -anchor_left = 0.5 -anchor_top = 0.5 -anchor_right = 0.5 -anchor_bottom = 0.5 -offset_left = 201.0 -offset_top = 451.0 -offset_right = 609.0 -offset_bottom = 749.0 -grow_horizontal = 2 -grow_vertical = 2 +[node name="VBoxStats" type="VBoxContainer" parent="Ui"] +anchors_preset = 2 +anchor_top = 1.0 +anchor_bottom = 1.0 +offset_left = 11.0 +offset_top = 1185.0 +offset_right = 211.0 +offset_bottom = 1265.0 +grow_vertical = 0 -[node name="lblGameOver" type="Label" parent="Ui/VBoxGameOver"] +[node name="lblLevel" type="Label" parent="Ui/VBoxStats"] layout_mode = 2 -text = "Game Over" -label_settings = SubResource("LabelSettings_dqsad") -horizontal_alignment = 1 -vertical_alignment = 1 +text = "Level: 1" -[node name="lblReachedPoints" type="Label" parent="Ui/VBoxGameOver"] -custom_minimum_size = Vector2(0, 100) +[node name="lblPoints" type="Label" parent="Ui/VBoxStats"] layout_mode = 2 -text = "You have reached level 1 and 0 points!" -horizontal_alignment = 1 -vertical_alignment = 1 -autowrap_mode = 3 +text = "Points: 0" -[node name="RestartButton" type="Button" parent="Ui/VBoxGameOver"] -custom_minimum_size = Vector2(200, 0) +[node name="lblNextLevel" type="Label" parent="Ui/VBoxStats"] layout_mode = 2 -size_flags_horizontal = 4 -size_flags_vertical = 6 -button_mask = 5 -shortcut = SubResource("Shortcut_soxs4") -text = "Restart" -icon = ExtResource("17_1t6sc") +text = "Next Level: 10 +" [node name="VBoxPause" type="VBoxContainer" parent="Ui"] anchors_preset = 8 @@ -300,29 +278,106 @@ shortcut = SubResource("Shortcut_soxs4") text = "Restart" icon = ExtResource("17_1t6sc") -[node name="VBoxHealth" type="VBoxContainer" parent="Ui"] +[node name="VBoxCountdown" type="VBoxContainer" parent="Ui"] +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 offset_left = 330.0 -offset_top = 14.0 -offset_right = 482.0 -offset_bottom = 18.0 +offset_top = 524.0 +offset_right = 496.0 +offset_bottom = 892.0 +grow_horizontal = 2 +grow_vertical = 2 +size_flags_horizontal = 4 +size_flags_vertical = 4 +alignment = 1 -[node name="HealthBar" type="ProgressBar" parent="Ui/VBoxHealth"] +[node name="lblCountdown" type="Label" parent="Ui/VBoxCountdown"] layout_mode = 2 -size_flags_vertical = 3 -max_value = 10.0 -value = 7.0 -rounded = true -show_percentage = false +size_flags_horizontal = 4 +text = "3" +label_settings = ExtResource("27_0p8jc") +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="textPressKey" type="TextureRect" parent="Ui/VBoxCountdown"] +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 4 +texture = ExtResource("28_g1v6s") +stretch_mode = 2 + +[node name="lblPressKey" type="Label" parent="Ui/VBoxCountdown"] +layout_mode = 2 +size_flags_horizontal = 4 +text = "Press any key to start" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="VBoxGameOver" type="VBoxContainer" parent="Ui"] +process_mode = 3 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = 201.0 +offset_top = 451.0 +offset_right = 609.0 +offset_bottom = 749.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="lblGameOver" type="Label" parent="Ui/VBoxGameOver"] +layout_mode = 2 +text = "Game Over" +label_settings = SubResource("LabelSettings_dqsad") +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="lblReachedPoints" type="Label" parent="Ui/VBoxGameOver"] +custom_minimum_size = Vector2(0, 100) +layout_mode = 2 +text = "You have reached level 1 and 0 points!" +horizontal_alignment = 1 +vertical_alignment = 1 +autowrap_mode = 3 + +[node name="butRestart" type="Button" parent="Ui/VBoxGameOver"] +custom_minimum_size = Vector2(200, 0) +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 6 +button_mask = 5 +shortcut = SubResource("Shortcut_soxs4") +text = "Restart" +icon = ExtResource("17_1t6sc") + +[node name="butExit" type="Button" parent="Ui/VBoxGameOver"] +process_mode = 3 +custom_minimum_size = Vector2(200, 0) +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 6 +button_mask = 5 +shortcut = SubResource("Shortcut_soxs4") +text = "Exit" +icon = ExtResource("21_7mvgi") [node name="BoxHelp" type="BoxContainer" parent="Ui"] -anchors_preset = 1 +anchors_preset = 3 anchor_left = 1.0 +anchor_top = 1.0 anchor_right = 1.0 -offset_left = 635.0 -offset_top = 12.0 -offset_right = 787.0 -offset_bottom = 212.0 +anchor_bottom = 1.0 +offset_left = 633.0 +offset_top = 1064.0 +offset_right = 785.0 +offset_bottom = 1264.0 grow_horizontal = 0 +grow_vertical = 0 [node name="VBoxHelp" type="VBoxContainer" parent="Ui/BoxHelp"] layout_mode = 2 @@ -385,41 +440,3 @@ texture = ExtResource("26_oxfmw") [node name="lblPause" type="Label" parent="Ui/BoxHelp/VBoxHelp/HBoxPause"] layout_mode = 2 text = "Pause" - -[node name="VBoxCountdown" type="VBoxContainer" parent="Ui"] -anchors_preset = 8 -anchor_left = 0.5 -anchor_top = 0.5 -anchor_right = 0.5 -anchor_bottom = 0.5 -offset_left = 330.0 -offset_top = 524.0 -offset_right = 496.0 -offset_bottom = 892.0 -grow_horizontal = 2 -grow_vertical = 2 -size_flags_horizontal = 4 -size_flags_vertical = 4 -alignment = 1 - -[node name="lblCountdown" type="Label" parent="Ui/VBoxCountdown"] -layout_mode = 2 -size_flags_horizontal = 4 -text = "3" -label_settings = ExtResource("27_0p8jc") -horizontal_alignment = 1 -vertical_alignment = 1 - -[node name="textPressKey" type="TextureRect" parent="Ui/VBoxCountdown"] -layout_mode = 2 -size_flags_horizontal = 4 -size_flags_vertical = 4 -texture = ExtResource("28_g1v6s") -stretch_mode = 2 - -[node name="lblPressKey" type="Label" parent="Ui/VBoxCountdown"] -layout_mode = 2 -size_flags_horizontal = 4 -text = "Press any key to start" -horizontal_alignment = 1 -vertical_alignment = 1 diff --git a/Scripts/GameManager.cs b/Scripts/GameManager.cs index 26218d6..c342753 100644 --- a/Scripts/GameManager.cs +++ b/Scripts/GameManager.cs @@ -30,7 +30,7 @@ public partial class GameManager : Node { private float spawnRate = 1f; private float spawnTimer; - public event EventHandler OnRefreshUi; + public event EventHandler OnRefreshStats; public event EventHandler OnNewCountdown; public event EventHandler OnGameOver; @@ -38,7 +38,7 @@ public partial class GameManager : Node { get => asteroidNumber; set { asteroidNumber = value; - OnRefreshUi?.Invoke(this, EventArgs.Empty); + OnRefreshStats?.Invoke(this, EventArgs.Empty); } } @@ -47,7 +47,7 @@ public partial class GameManager : Node { set { lives = value; if (lives <= 0) GameOver = true; - OnRefreshUi?.Invoke(this, EventArgs.Empty); + OnRefreshStats?.Invoke(this, EventArgs.Empty); } } @@ -56,7 +56,7 @@ public partial class GameManager : Node { set { points = value; if (points >= nextLevelPoints) NextLevel(); - OnRefreshUi?.Invoke(this, EventArgs.Empty); + OnRefreshStats?.Invoke(this, EventArgs.Empty); } } @@ -64,23 +64,25 @@ public partial class GameManager : Node { get => level; private set { level = value; - OnRefreshUi?.Invoke(this, EventArgs.Empty); + OnRefreshStats?.Invoke(this, EventArgs.Empty); } } + + public int LastLevelPoints { get; private set; } public int NextLevelPoints { get => nextLevelPoints; private set { nextLevelPoints = value; - OnRefreshUi?.Invoke(this, EventArgs.Empty); + OnRefreshStats?.Invoke(this, EventArgs.Empty); } } - public int AsteroidMaxNumber { + private int AsteroidMaxNumber { get => asteroidMaxNumber; - private set { + set { asteroidMaxNumber = value; - OnRefreshUi?.Invoke(this, EventArgs.Empty); + OnRefreshStats?.Invoke(this, EventArgs.Empty); } } @@ -90,11 +92,18 @@ public partial class GameManager : Node { set { gamePaused = value; GetTree().Paused = gamePaused; - OnRefreshUi?.Invoke(this, EventArgs.Empty); + OnRefreshStats?.Invoke(this, EventArgs.Empty); + } + } + + private bool countdown; + public bool Countdown { + get => countdown; + set { + countdown = value; + if (countdown) OnNewCountdown?.Invoke(this, EventArgs.Empty); } } - - public bool Countdown { get; set; } public static GameManager Instance { get; private set; } [Export] public bool Debug { get; private set; } = true; @@ -103,10 +112,8 @@ public partial class GameManager : Node { Instance = this; Lives = MaxLives; spawnTimer = spawnRate; - SoundManager.Instance.Play(SoundManager.Sound.BackgroundMusic); - OnRefreshUi?.Invoke(this, EventArgs.Empty); Countdown = true; - OnNewCountdown?.Invoke(this, EventArgs.Empty); + SoundManager.Instance.Play(SoundManager.Sound.BackgroundMusic); } public override void _Process(double delta) { @@ -131,6 +138,7 @@ public partial class GameManager : Node { private void NextLevel() { Ui.Instance.ShowMessage("Next Level!"); Level++; + LastLevelPoints = NextLevelPoints; NextLevelPoints = Level * 33; AsteroidMaxNumber = 3 + Level; spawnRate = 1f - Level * 0.1f; diff --git a/Scripts/Ui.cs b/Scripts/Ui.cs index ae2be67..0735107 100644 --- a/Scripts/Ui.cs +++ b/Scripts/Ui.cs @@ -6,16 +6,14 @@ using Godot; namespace GodotspaceShooter.Scripts; public partial class Ui : Node2D { - [Export] private RichTextLabel rtlAsteroids; - [Export] private RichTextLabel rtlLevel; - [Export] private RichTextLabel rtlLifes; - [Export] private RichTextLabel rtlNextLevel; - [Export] private RichTextLabel rtlPoints; + [Export] private Label lblLevel; + [Export] private Label lblPoints; + [Export] private Label lblNextLevel; [Export] private VBoxContainer vBoxGameOver; [Export] private Label lblGameOver; [Export] private Button buttonRestart; [Export] private Label lblReachedPoints; - [Export] private ProgressBar healthBar; + [Export] private ProgressBar barHealth; [Export] private VBoxContainer vBoxPause; [Export] private Button buttonResume; [Export] private Button buttonPauseRestart; @@ -23,6 +21,8 @@ public partial class Ui : Node2D [Export] private Label lblCountdown; [Export] private TextureRect textAnyKey; [Export] private Label lblAnyKey; + [Export] private Button butExit; + [Export] private ProgressBar barLevel; private const double countdownMaxTimer = 3; private double countdownTimer = countdownMaxTimer; @@ -35,9 +35,9 @@ public partial class Ui : Node2D if (GameManager.Instance is null) GD.PrintErr("No GameManager found!"); else { - GameManager.Instance.OnRefreshUi += GameManager_OnRefreshUi; - GameManager.Instance.OnNewCountdown += GameManagerOnNewCountdown; - GameManager.Instance.OnGameOver += GameManager_OnGameOver; + GameManager.Instance.OnRefreshStats += GameManager_RefreshStats; + GameManager.Instance.OnNewCountdown += GameManager_NewCountdown; + GameManager.Instance.OnGameOver += GameManager_GameOver; InputManager.Instance.StartCountdown += InputManager_StartCountdown; lblGameOver.Visible = GameManager.Instance.GameOver; buttonRestart.Visible = GameManager.Instance.GameOver; @@ -45,11 +45,14 @@ public partial class Ui : Node2D buttonRestart.Pressed += ButtonRestartOnPressed; buttonResume.Pressed += ButtonResumeOnPressed; buttonPauseRestart.Pressed += ButtonPauseRestartOnPressed; - GameManager_OnRefreshUi(this, EventArgs.Empty); + butExit.Pressed += ButExitOnPressed; + GameManager_RefreshStats(this, EventArgs.Empty); } } - private void GameManager_OnGameOver(object sender, EventArgs e) { + private void ButExitOnPressed() => GetTree().Quit(); + + private void GameManager_GameOver(object sender, EventArgs e) { GD.Print($"Game Over! You have reached level {GameManager.Instance.Level} and {GameManager.Instance.Points} points!"); lblReachedPoints.Text = $"You have reached level {GameManager.Instance.Level} and {GameManager.Instance.Points} points!"; foreach (CanvasItem canvasItem in vBoxGameOver.GetChildren().Cast()) canvasItem.Visible = true; @@ -62,11 +65,10 @@ public partial class Ui : Node2D countdownRunning = true; } - private void GameManagerOnNewCountdown(object sender, EventArgs e) { + private void GameManager_NewCountdown(object sender, EventArgs e) { lblCountdown.Text = countdownTimer.ToString(CultureInfo.InvariantCulture); + foreach (CanvasItem canvasItem in vBoxCountdown.GetChildren().Cast()) canvasItem.Visible = true; vBoxCountdown.Visible = true; - lblAnyKey.Visible = true; - textAnyKey.Visible = true; } public override void _Process(double delta) { @@ -74,6 +76,7 @@ public partial class Ui : Node2D countdownTimer -= delta; lblCountdown.Text = Mathf.RoundToInt(countdownTimer).ToString(); if (countdownTimer <= 0) { + foreach (CanvasItem canvasItem in vBoxCountdown.GetChildren().Cast()) canvasItem.Visible = false; vBoxCountdown.Visible = false; countdownRunning = false; GameManager.Instance.Countdown = false; @@ -81,14 +84,19 @@ public partial class Ui : Node2D } } - private void GameManager_OnRefreshUi(object sender, EventArgs e) { - rtlLifes.Text = $"Lives: {GameManager.Instance.Lives}"; - rtlAsteroids.Text = $"Asteroids: {GameManager.Instance.AsteroidNumber} / {GameManager.Instance.AsteroidMaxNumber}"; - rtlPoints.Text = $"Points: {GameManager.Instance.Points}"; - rtlNextLevel.Text = $"Next Level at: {GameManager.Instance.NextLevelPoints}"; - rtlLevel.Text = $"Actual Level: {GameManager.Instance.Level}"; - healthBar.MaxValue = GameManager.Instance.MaxLives; - healthBar.Value = GameManager.Instance.Lives; + private void GameManager_RefreshStats(object sender, EventArgs e) { + lblLevel.Text = $"Actual Level: {GameManager.Instance.Level}"; + lblPoints.Text = $"Points: {GameManager.Instance.Points}"; + lblNextLevel.Text = $"Next Level at: {GameManager.Instance.NextLevelPoints}"; + + barHealth.MaxValue = GameManager.Instance.MaxLives; + barHealth.Value = GameManager.Instance.Lives; + barHealth.TooltipText = $"{GameManager.Instance.Lives} / {GameManager.Instance.MaxLives}"; + + barLevel.MaxValue = GameManager.Instance.NextLevelPoints; + barLevel.Value = GameManager.Instance.Points - GameManager.Instance.LastLevelPoints; + barLevel.TooltipText = $"{GameManager.Instance.Points} / {GameManager.Instance.NextLevelPoints}"; + vBoxPause.Visible = GameManager.Instance.GamePaused; vBoxGameOver.Visible = GameManager.Instance.GameOver; } From be8f6fc1461931615d1218c323d9225c3b015f76 Mon Sep 17 00:00:00 2001 From: Sascha Date: Fri, 2 Feb 2024 10:21:47 +0100 Subject: [PATCH 14/14] Better visibility of Lifes, Level and Points --- Godot-space Shooter.csproj.old.5 | 2 +- Images/genericItem_color_087.png | Bin 0 -> 665 bytes Images/genericItem_color_087.png.import | 34 ++++ Images/genericItem_white_102.png | Bin 0 -> 2049 bytes Images/genericItem_white_102.png.import | 34 ++++ Images/generic_button_circle_fill.png | Bin 0 -> 651 bytes Images/generic_button_circle_fill.png.import | 34 ++++ Images/generic_joystick_left.png | Bin 0 -> 489 bytes Images/generic_joystick_left.png.import | 34 ++++ Packed-Scenes/PlayerShip.tscn | 4 +- Scenes/SpaceShooter.tscn | 190 +++++++++++-------- Scripts/Background.cs | 2 +- Scripts/GameManager.cs | 2 +- Scripts/PlayerShip.cs | 29 ++- Scripts/Ui.cs | 43 +++-- 15 files changed, 290 insertions(+), 118 deletions(-) create mode 100644 Images/genericItem_color_087.png create mode 100644 Images/genericItem_color_087.png.import create mode 100644 Images/genericItem_white_102.png create mode 100644 Images/genericItem_white_102.png.import create mode 100644 Images/generic_button_circle_fill.png create mode 100644 Images/generic_button_circle_fill.png.import create mode 100644 Images/generic_joystick_left.png create mode 100644 Images/generic_joystick_left.png.import diff --git a/Godot-space Shooter.csproj.old.5 b/Godot-space Shooter.csproj.old.5 index 9d3fa14..da29594 100644 --- a/Godot-space Shooter.csproj.old.5 +++ b/Godot-space Shooter.csproj.old.5 @@ -1,4 +1,4 @@ - + net8.0 true diff --git a/Images/genericItem_color_087.png b/Images/genericItem_color_087.png new file mode 100644 index 0000000000000000000000000000000000000000..2f118aaa614e8f1cd29f051324fe0b51c0c18038 GIT binary patch literal 665 zcmV;K0%rY*P)xq#pz3qjGKWD#`H;zGzmBDhdQ%t}PFX!HQajk@X%nII5I zBxIh-dW{{*P7m}@<%7R!`oBL_^?ywki$!|5T&jMJ1_0h8Jm&Lxl1c(2&k`&Cm7JBn zB7>aqq&CP|M2ZY@wAe25v<&iYw;S6apH8O<8RWzXtJSI}xZhPr@}Ote4M>Q)8x%M4 zted0RY(^)OiD9GBi1z#awRJk3wYA%A+G@27tJmw!ggnOMaU21_FqN=Iqfs;+1u{TAGM} zR{(exY03Qrfa6I-gOMa1GEWg1KyNKsSBXr3P-@AYGXK3&6VkKhOD}ZV0SuPZOU6=i zRm$D&bT3yy33kpF{001p?MObuGZ)S9NVRB^vVtFoN zY;SL5WO*)Qa(QrcZ!T$VVP|D7P)Z)9b1s0M%T00000NkvXXu0mjfXRkFT literal 0 HcmV?d00001 diff --git a/Images/genericItem_color_087.png.import b/Images/genericItem_color_087.png.import new file mode 100644 index 0000000..f63d8e5 --- /dev/null +++ b/Images/genericItem_color_087.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://5lrd2y05neel" +path="res://.godot/imported/genericItem_color_087.png-6687afb309b9ba66de3b8f9ed90efe28.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Images/genericItem_color_087.png" +dest_files=["res://.godot/imported/genericItem_color_087.png-6687afb309b9ba66de3b8f9ed90efe28.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/Images/genericItem_white_102.png b/Images/genericItem_white_102.png new file mode 100644 index 0000000000000000000000000000000000000000..2f4f833629b8929f74bd56327274fcd0d95e571b GIT binary patch literal 2049 zcmV+c2>$npP)f<43HcLdiF$q<_HDSTUFI${|@Ycn0u452C14nk9? z9fYP(9ZWhjh3W`(o3Sau!%)u@YR7E7UJn&&$L#0l=a?IWd63TcxqJ*Uh6fAc44;{r^f3KC10eW{~|`3&3d@9*vV`}_9o z?M=r+xdLHy}!TzpDVopVrj8h9C3W6LjV@@XMy}x?C=|Hc&B>#fl{}06TaPC@(KBJAv}} z`1s!--rU?QB|)u*Muf$EXk22j%}jJ!Z{y!tLLG>Mits@lNb|FOE~vM+w>viv)6TE2 zuXj!zY!g|ypvvr*qCz!;>-|(#1juPwfWU1Aw8;@h|1?xH1Ev(HX67`0ffB4?U0CFD zSEwcz+d`d)gbG+qFz@c}cA?OGiCIbBPxioOoUmd;h1vW+7z2?|5mp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0 zwSNGWlE88V-XAXj001p?MObuGZ)S9NVRB^vVtFoNY;SL5WO*)Qa(QrcZ!T$VVP|D7 fP)Z)9b1s0M%T00000NkvXXu0mjf*gm|E literal 0 HcmV?d00001 diff --git a/Images/genericItem_white_102.png.import b/Images/genericItem_white_102.png.import new file mode 100644 index 0000000..f91a15b --- /dev/null +++ b/Images/genericItem_white_102.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://34r8nb20e6y6" +path="res://.godot/imported/genericItem_white_102.png-95f126e969936aff31870ba984f94cba.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Images/genericItem_white_102.png" +dest_files=["res://.godot/imported/genericItem_white_102.png-95f126e969936aff31870ba984f94cba.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/Images/generic_button_circle_fill.png b/Images/generic_button_circle_fill.png new file mode 100644 index 0000000000000000000000000000000000000000..7cdad82a798a08072cd66f04472accc3845451a5 GIT binary patch literal 651 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I3?%1nZ+ru!SkfJR9T^xl_H+M9WCik#1AIbU z|C0iMnt;khw>EtPvII(k{DS@K`}60^-#;I(zn=g7etQO6){aLE42;h`T^vIq4!@m# zds4Fkk3-eWYj4r_|u zyR3V}cA#bMgoHR2i{0}(O4l=NIlp^vtb|IUw_{Z;Z^WmtrMoZRX|s!5$6zy?d-1vn zf;D^>JTLZs*?wEd@jS!J>Q=_$Sx^H6) zxR+Oa;M$z4%uG=k&l$Q4IhYmJ9n)B8sZe$PD7#QVUHYYWe@z;WE5us_Ca(IipI>?Z zbdMSao$o=Fmiv7ko;^J!ZgY@9+Vz=R?UrzL)oxzkpqu$=*Am9i5au>Z@&A_>t-7U9 z#<1e<^$X8uM;SKe>12#fD`4aOY|FJXscmf8|b|r?XkpIo~?$ zS=h?|$rpNlO)B+0*qb=J*H~z`^}Fo2uK_Xj|BY)IgMTufzx+m1!upybFgY-Iy85}S Ib4q9e0K=0x?f?J) literal 0 HcmV?d00001 diff --git a/Images/generic_button_circle_fill.png.import b/Images/generic_button_circle_fill.png.import new file mode 100644 index 0000000..13bb598 --- /dev/null +++ b/Images/generic_button_circle_fill.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dru38hr1dwoq8" +path="res://.godot/imported/generic_button_circle_fill.png-2b822fd87779eace62ffa3a06cff92b1.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Images/generic_button_circle_fill.png" +dest_files=["res://.godot/imported/generic_button_circle_fill.png-2b822fd87779eace62ffa3a06cff92b1.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/Images/generic_joystick_left.png b/Images/generic_joystick_left.png new file mode 100644 index 0000000000000000000000000000000000000000..f5a20f1d7adb080e05e924d12abe6172c7140b02 GIT binary patch literal 489 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I3?%1nZ+ru!SkfJR9T^xl_H+M9WCik#1AIbU z|C0iMnt;khw>EtPvII(k{DSlS`|qD$FF!y2y?#Bv{eA|1)d-*!jIN$8jv*0;-%h{X z*KEM!!o2gg=dAz#Z!Mj2iJ>p6IV>vkW3q~TWJ;RMmB&ddr3;wrI2kfdhlo8CQJB6f z>|_zcHQ$9I8(yaiY-p?{9d)!VulLsfHnBQv zpniPvGRB$usm@=s8^t%(G|Zj*@y7eqMkBA^`(2}K1Xoo#2dF36ZrLex`Q=d|JEKF2 zb8q^j@h-_!;WlDe7Al&0a+f26N7}qQ`#FM_f4(anTJk^Vpz70f-NT=C3>ly1CgvRZ zvn1-7X&ui3Y4em@;$1QiWSyL~S*uP8G?*P-)-T>@@t;c}?W|J6%NJd|E9%NqPllU4 z5ItvQ(jiikAG~^9ch-@onGX!U#Y?YxuXL|%0fWHHy0cS@+7o2%pX<9(WY@{W`e&W& qk moveVelocity; - [Export] private float rotationVelocity = 15f; - public float RotationVelocity => rotationVelocity; + private const float jetTimerMax = 0.5f; + private const float laserTimerMax = 1f; + private float laserTimer = laserTimerMax; + private float jetTimer = jetTimerMax; - [Export] public RigidBody3D PlayerRb; - [Export] private Node3D shots; + public float MoveVelocity { get; private set; } = 10f; + public float RotationVelocity { get; private set; } = 15f; public Vector3 MoveDirection { get; set; } public Vector3 RotationDirection { get; set; } @@ -36,9 +31,9 @@ public partial class PlayerShip : Node3D { public override void _Process(double delta) { if (Shooting) if (laser.Instantiate() is Node3D shot) { - shot.Position = PlayerRb.Position + new Vector3(0f, 0f, 0.74f); + shot.Position = rbPlayer.Position + new Vector3(0f, 0f, 0.74f); shots.AddChild(shot); - SoundManager.Instance.Play(SoundManager.Sound.Laser, PlayerRb.Position); + SoundManager.Instance.Play(SoundManager.Sound.Laser, rbPlayer.Position); Shooting = false; } } @@ -47,7 +42,7 @@ public partial class PlayerShip : Node3D { //Movement if (MoveDirection != Vector3.Zero) { jet.Visible = true; - KinematicCollision3D collision = PlayerRb.MoveAndCollide(MoveDirection * (float)delta); + KinematicCollision3D collision = rbPlayer.MoveAndCollide(MoveDirection * (float)delta); if (collision?.GetCollider() is Node3D collider) { Node3D parent = collider.GetParent(); Vector3 collisionPosition = collision.GetPosition(); @@ -67,7 +62,7 @@ public partial class PlayerShip : Node3D { } //Rotation - PlayerRb.RotationDegrees = RotationDirection; + rbPlayer.RotationDegrees = RotationDirection; } public void Explode(Vector3 collisionPosition) { diff --git a/Scripts/Ui.cs b/Scripts/Ui.cs index 0735107..57c600d 100644 --- a/Scripts/Ui.cs +++ b/Scripts/Ui.cs @@ -6,32 +6,34 @@ using Godot; namespace GodotspaceShooter.Scripts; public partial class Ui : Node2D { - [Export] private Label lblLevel; + [ExportCategory("Stats")] + [Export] private Label lblLevel; [Export] private Label lblPoints; - [Export] private Label lblNextLevel; + [Export] private ProgressBar barHealth; + [Export] private ProgressBar barLevel; + [ExportCategory("GameOver")] [Export] private VBoxContainer vBoxGameOver; [Export] private Label lblGameOver; - [Export] private Button buttonRestart; + [Export] private Button butGameOverRestart; [Export] private Label lblReachedPoints; - [Export] private ProgressBar barHealth; + [Export] private Button butGameOverExit; + [ExportCategory("Pause")] [Export] private VBoxContainer vBoxPause; [Export] private Button buttonResume; [Export] private Button buttonPauseRestart; + [Export] private Button butPauseExit; + [ExportCategory("Countdown")] [Export] private VBoxContainer vBoxCountdown; [Export] private Label lblCountdown; [Export] private TextureRect textAnyKey; [Export] private Label lblAnyKey; - [Export] private Button butExit; - [Export] private ProgressBar barLevel; private const double countdownMaxTimer = 3; private double countdownTimer = countdownMaxTimer; private bool countdownRunning; - public static Ui Instance { get; private set; } public override void _Ready() { - Instance = this; if (GameManager.Instance is null) GD.PrintErr("No GameManager found!"); else { @@ -40,17 +42,18 @@ public partial class Ui : Node2D GameManager.Instance.OnGameOver += GameManager_GameOver; InputManager.Instance.StartCountdown += InputManager_StartCountdown; lblGameOver.Visible = GameManager.Instance.GameOver; - buttonRestart.Visible = GameManager.Instance.GameOver; + butGameOverRestart.Visible = GameManager.Instance.GameOver; lblReachedPoints.Visible = GameManager.Instance.GameOver; - buttonRestart.Pressed += ButtonRestartOnPressed; + butGameOverRestart.Pressed += AllButtonRestartOnPressed; buttonResume.Pressed += ButtonResumeOnPressed; - buttonPauseRestart.Pressed += ButtonPauseRestartOnPressed; - butExit.Pressed += ButExitOnPressed; + buttonPauseRestart.Pressed += AllButtonRestartOnPressed; + butPauseExit.Pressed += AllButExitOnPressed; + butGameOverExit.Pressed += AllButExitOnPressed; GameManager_RefreshStats(this, EventArgs.Empty); } } - private void ButExitOnPressed() => GetTree().Quit(); + private void AllButExitOnPressed() => GetTree().Quit(); private void GameManager_GameOver(object sender, EventArgs e) { GD.Print($"Game Over! You have reached level {GameManager.Instance.Level} and {GameManager.Instance.Points} points!"); @@ -62,6 +65,7 @@ public partial class Ui : Node2D private void InputManager_StartCountdown(object sender, EventArgs e) { lblAnyKey.Visible = false; textAnyKey.Visible = false; + lblCountdown.Visible = true; countdownRunning = true; } @@ -69,6 +73,7 @@ public partial class Ui : Node2D lblCountdown.Text = countdownTimer.ToString(CultureInfo.InvariantCulture); foreach (CanvasItem canvasItem in vBoxCountdown.GetChildren().Cast()) canvasItem.Visible = true; vBoxCountdown.Visible = true; + lblCountdown.Visible = false; } public override void _Process(double delta) { @@ -85,9 +90,8 @@ public partial class Ui : Node2D } private void GameManager_RefreshStats(object sender, EventArgs e) { - lblLevel.Text = $"Actual Level: {GameManager.Instance.Level}"; - lblPoints.Text = $"Points: {GameManager.Instance.Points}"; - lblNextLevel.Text = $"Next Level at: {GameManager.Instance.NextLevelPoints}"; + lblLevel.Text = $"{GameManager.Instance.Level}"; + lblPoints.Text = $"{GameManager.Instance.Points}"; barHealth.MaxValue = GameManager.Instance.MaxLives; barHealth.Value = GameManager.Instance.Lives; @@ -101,12 +105,11 @@ public partial class Ui : Node2D vBoxGameOver.Visible = GameManager.Instance.GameOver; } - private void ButtonRestartOnPressed() => GetTree().ReloadCurrentScene(); - private void ButtonResumeOnPressed() => GameManager.Instance.GamePaused = false; - private void ButtonPauseRestartOnPressed() { + private static void ButtonResumeOnPressed() => GameManager.Instance.GamePaused = false; + private void AllButtonRestartOnPressed() { GameManager.Instance.GamePaused = false; GetTree().ReloadCurrentScene(); } - public void ShowMessage(string message) => GD.Print(message); + public static void ShowMessage(string message) => GD.Print(message); }