pause menu fininshed

pull/32/head
Sascha 2024-01-24 17:41:32 +07:00
parent 6b91f6ded8
commit 6fa2fd932a
5 changed files with 54 additions and 48 deletions

@ -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

@ -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<PackedScene> 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);
}
}

@ -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;
}
}

@ -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;
}
}

@ -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;
}