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 0000000..ef26da1
Binary files /dev/null and b/Images/keyboard_any.png differ
diff --git a/Images/keyboard_any.png.import b/Images/keyboard_any.png.import
new file mode 100644
index 0000000..2e56f52
--- /dev/null
+++ b/Images/keyboard_any.png.import
@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://c5tms7y368pit"
+path="res://.godot/imported/keyboard_any.png-2a9a0ec0e27526a6030a1d6924359c1a.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://Images/keyboard_any.png"
+dest_files=["res://.godot/imported/keyboard_any.png-2a9a0ec0e27526a6030a1d6924359c1a.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/Material/lblSettingsCountdown.tres b/Material/lblSettingsCountdown.tres
new file mode 100644
index 0000000..ae116c5
--- /dev/null
+++ b/Material/lblSettingsCountdown.tres
@@ -0,0 +1,8 @@
+[gd_resource type="LabelSettings" format=3 uid="uid://cdqcuhuk1yclm"]
+
+[resource]
+font_size = 200
+outline_size = 5
+outline_color = Color(1, 1, 0, 1)
+shadow_size = 10
+shadow_offset = Vector2(5, 5)
diff --git a/Scenes/SpaceShooter.tscn b/Scenes/SpaceShooter.tscn
index 9b721c6..a692d67 100644
--- a/Scenes/SpaceShooter.tscn
+++ b/Scenes/SpaceShooter.tscn
@@ -1,4 +1,4 @@
-[gd_scene load_steps=32 format=3 uid="uid://det8556rpxhbv"]
+[gd_scene load_steps=34 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"]
@@ -26,6 +26,8 @@
[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"]
+[ext_resource type="LabelSettings" uid="uid://cdqcuhuk1yclm" path="res://Material/lblSettingsCountdown.tres" id="27_0p8jc"]
+[ext_resource type="Texture2D" uid="uid://c5tms7y368pit" path="res://Images/keyboard_any.png" id="28_g1v6s"]
[sub_resource type="BoxShape3D" id="BoxShape3D_bw288"]
@@ -153,7 +155,7 @@ 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")]
+[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")]
process_mode = 3
script = ExtResource("15_xl7yx")
rtlAsteroids = NodePath("VBoxStats/rtlAsteroids")
@@ -169,6 +171,10 @@ healthBar = NodePath("VBoxHealth/HealthBar")
vBoxPause = NodePath("VBoxPause")
buttonResume = NodePath("VBoxPause/ButtonResume")
buttonPauseRestart = NodePath("VBoxPause/PauseRestartButton")
+vBoxCountdown = NodePath("VBoxCountdown")
+lblCountdown = NodePath("VBoxCountdown/lblCountdown")
+textAnyKey = NodePath("VBoxCountdown/textPressKey")
+lblAnyKey = NodePath("VBoxCountdown/lblPressKey")
[node name="VBoxStats" type="VBoxContainer" parent="Ui"]
anchors_preset = 2
@@ -216,6 +222,7 @@ 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
@@ -379,3 +386,41 @@ 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 984e88d..e247153 100644
--- a/Scripts/GameManager.cs
+++ b/Scripts/GameManager.cs
@@ -32,6 +32,7 @@ public partial class GameManager : Node {
private float spawnTimer;
public event EventHandler RefreshUi;
+ public event EventHandler NewCountdown;
public int AsteroidNumber {
get => 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}";