diff --git a/Cirno.sln.DotSettings.user b/Cirno.sln.DotSettings.user
index b2b86807..863ccdb4 100644
--- a/Cirno.sln.DotSettings.user
+++ b/Cirno.sln.DotSettings.user
@@ -7,6 +7,7 @@
ForceIncluded
ForceIncluded
ForceIncluded
+ ForceIncluded
ForceIncluded
ForceIncluded
ForceIncluded
diff --git a/Scenes/Actors/fsm_player.tscn b/Scenes/Actors/fsm_player.tscn
index 9387fd42..68f9289c 100644
--- a/Scenes/Actors/fsm_player.tscn
+++ b/Scenes/Actors/fsm_player.tscn
@@ -200,6 +200,7 @@ MaxResource = 32.0
shape = SubResource("CircleShape2D_igu66")
[node name="InteractionProvider" type="Area2D" parent="." node_paths=PackedStringArray("_inputProvider", "_errorSound")]
+visible = false
collision_layer = 2
collision_mask = 4
script = ExtResource("22_12cwd")
diff --git a/Scripts/Components/Actors/InputProvider.cs b/Scripts/Components/Actors/InputProvider.cs
index 11556bc9..cba09d62 100644
--- a/Scripts/Components/Actors/InputProvider.cs
+++ b/Scripts/Components/Actors/InputProvider.cs
@@ -9,11 +9,13 @@ public abstract partial class InputProvider : Node2D
public abstract bool GetActionJustPressed(string action);
public abstract bool GetActionPressed(string action);
-
+ public abstract bool GetInventoryJustPressed();
public abstract bool GetShootPressed();
+ public abstract bool GetShootJustPressed();
public abstract bool GetUseJustPressed();
public abstract bool GetScanJustPressed();
public abstract bool GetStrafePressed();
public abstract bool GetWeaponNextJustPressed();
public abstract bool GetWeaponPreviousJustPressed();
+ public abstract bool GetPauseJustPressed();
}
\ No newline at end of file
diff --git a/Scripts/Components/Actors/KeyboardInputProvider.cs b/Scripts/Components/Actors/KeyboardInputProvider.cs
index 06f32dd1..d1c045d2 100644
--- a/Scripts/Components/Actors/KeyboardInputProvider.cs
+++ b/Scripts/Components/Actors/KeyboardInputProvider.cs
@@ -31,6 +31,8 @@ public partial class KeyboardInputProvider : InputProvider
[Export] private string _strafeActionName = "strafe";
[Export] private string _nextWeaponActionName = "next_weapon";
[Export] private string _previousWeaponActionName = "previous_weapon";
+ [Export] private string _inventoryActionName = "inventory";
+ [Export] private string _pauseActionName = "pause";
public override Vector2 GetMovementInput()
{
@@ -60,10 +62,20 @@ public partial class KeyboardInputProvider : InputProvider
return Input.IsActionPressed(action);
}
+ public override bool GetInventoryJustPressed()
+ {
+ return GetActionJustPressed(_inventoryActionName);
+ }
+
public override bool GetShootPressed()
{
return GetActionPressed(_shootActionName);
}
+
+ public override bool GetShootJustPressed()
+ {
+ return GetActionJustPressed(_shootActionName);
+ }
public override bool GetUseJustPressed()
{
@@ -89,4 +101,9 @@ public partial class KeyboardInputProvider : InputProvider
return GetActionJustPressed(_previousWeaponActionName);
}
+ public override bool GetPauseJustPressed()
+ {
+ return GetActionJustPressed(_pauseActionName);
+ }
+
}
\ No newline at end of file
diff --git a/Scripts/Components/FSM/Player/Active.cs b/Scripts/Components/FSM/Player/Active.cs
index 92cb875b..c4903fb7 100644
--- a/Scripts/Components/FSM/Player/Active.cs
+++ b/Scripts/Components/FSM/Player/Active.cs
@@ -35,11 +35,15 @@ public partial class Active : PlayerFSMState
public int MovementSpeed => _isStrafing ? StrafeSpeed : Speed;
private PlayerStateMachine _player;
+
+ private Hud _hud;
public override void Init(ActorStateMachine stateMachine)
{
base.Init(stateMachine);
+ _hud = Hud.Instance;
+
_player = (PlayerStateMachine)stateMachine;
_damageReceiver.Death += () =>
@@ -50,11 +54,13 @@ public partial class Active : PlayerFSMState
_damageReceiver.HealthChanged += (value, maxValue) =>
{
_animationProvider.Blink();
+ _hud.UpdateHealth(value, maxValue);
};
_damageReceiver.ShieldChanged += (value, maxValue) =>
{
_animationProvider.PlayShieldAnimation();
+ _hud.UpdateShield(value, maxValue);
};
_damageReceiver.Init();
@@ -128,6 +134,21 @@ public partial class Active : PlayerFSMState
// _crosshair.Position = CalculateCrosshairPosition();
+ if (_inputProvider.GetInventoryJustPressed())
+ {
+ GameManager.Instance.ChangeState(GameState.Inventory);
+ }
+
+ if (_inputProvider.GetPauseJustPressed())
+ {
+ //CallDeferred(MethodName.PauseDeferred);
+ PauseDeferred();
+ }
+ }
+
+ private void PauseDeferred()
+ {
+ GameManager.Instance.Pause();
}
private void HandleShoot()
diff --git a/Scripts/Components/FSM/Player/Dead.cs b/Scripts/Components/FSM/Player/Dead.cs
index f6d25dbb..32d88b37 100644
--- a/Scripts/Components/FSM/Player/Dead.cs
+++ b/Scripts/Components/FSM/Player/Dead.cs
@@ -1,4 +1,5 @@
-using Godot;
+using Cirno.Scripts.Components.Actors;
+using Godot;
namespace Cirno.Scripts.Components.FSM.Player;
@@ -6,33 +7,58 @@ public partial class Dead : PlayerFSMState
{
[Export]
private PlayerAnimationProvider _animationProvider;
+
+ [Export]
+ private InputProvider _inputProvider;
+
+ [Export]
+ private ActorResourceProvider _healthProvider;
+
+ private GameManager _gameManager;
+ private Hud _hud;
public override void Init(ActorStateMachine stateMachine)
{
base.Init(stateMachine);
- // get hud?
+ _gameManager = GameManager.Instance;
+ _hud = Hud.Instance;
}
public override void EnterState()
{
_animationProvider.PlayDeathAnimation();
// show game over
+
+ _hud.ShowGameOver();
}
public override void ExitState()
{
// Hide game over
+ _hud.HideGameOver();
}
public override void ProcessState(double delta)
{
// wait for button
-
+ if (_inputProvider.GetShootJustPressed())
+ {
+ Respawn();
+ }
}
public override void PhysicsProcessState(double delta)
{
}
+
+ public void Respawn()
+ {
+ _stateMachine.GlobalPosition = _gameManager.LastCheckpointPosition;
+ _healthProvider.FillResource();
+ _gameManager.ClearBullets();
+
+ _stateMachine.SetState((int)PlayerState.Active);
+ }
}
\ No newline at end of file
diff --git a/Scripts/GameManager.cs b/Scripts/GameManager.cs
index 609906d8..55b47065 100644
--- a/Scripts/GameManager.cs
+++ b/Scripts/GameManager.cs
@@ -41,6 +41,9 @@ public partial class GameManager : Node2D
//public AlarmManager AlarmManager => _alarmManager;
+ [Export]
+ public string PauseActionName { get; private set; } = "pause";
+
private Node2D _bulletsContainer;
public Node2D BulletsContainer => _bulletsContainer;
@@ -49,6 +52,8 @@ public partial class GameManager : Node2D
[Signal]
public delegate void PlayerRespawnedEventHandler();
+
+ public Vector2 LastCheckpointPosition { get; set; }
// Called when the node enters the scene tree for the first time.
public override void _Ready()
@@ -104,20 +109,17 @@ public partial class GameManager : Node2D
{
}
-
- // Called every frame. 'delta' is the elapsed time since the previous frame.
+
public override void _Process(double delta)
{
- if (GameState is GameState.Playing && Input.IsActionJustPressed("pause"))
+ if (GameState is GameState.Paused && Input.IsActionJustPressed(PauseActionName))
{
- TogglePause();
+ Unpause();
}
}
private void DelayPlayerSpawn()
{
- //await Task.Delay(500);
-
if (SpawnMarkers.Any())
{
SpawnPlayer();
@@ -244,17 +246,17 @@ public partial class GameManager : Node2D
AddChild(_bulletsContainer);
}
- public void TogglePause()
- {
- if (GameState == GameState.Paused)
- {
- Unpause();
- }
- else if (GameState == GameState.Playing)
- {
- Pause();
- }
- }
+ // public void TogglePause()
+ // {
+ // if (GameState == GameState.Paused)
+ // {
+ // Unpause();
+ // }
+ // else if (GameState == GameState.Playing)
+ // {
+ // Pause();
+ // }
+ // }
public void Pause()
{
@@ -268,7 +270,8 @@ public partial class GameManager : Node2D
{
if (GameState == GameState.Paused)
{
- ChangeState(GameState.Playing);
+ CallDeferred(MethodName.ChangeState, (int)GameState.Playing);
+ //ChangeState(GameState.Playing);
}
}
@@ -290,22 +293,19 @@ public partial class GameManager : Node2D
{
if (state == GameState) return;
GameState = state;
- EmitSignal(nameof(GameStateChange), (int)GameState);
+ EmitSignal(SignalName.GameStateChange, (int)state);
GD.Print($"Game state changed to {state}");
switch (state)
{
- case GameState.Menu:
- GetTree().SetPause(false);
- break;
case GameState.Paused:
case GameState.Dialogue:
+ case GameState.Inventory:
GetTree().SetPause(true);
break;
case GameState.Playing:
- GetTree().SetPause(false);
- break;
case GameState.Controlling:
+ case GameState.Menu:
GetTree().SetPause(false);
break;
}
@@ -327,5 +327,6 @@ public enum GameState
Paused,
Playing,
Dialogue,
- Controlling
+ Controlling,
+ Inventory
}
\ No newline at end of file
diff --git a/Scripts/Hud.cs b/Scripts/Hud.cs
index 976bd4d9..6b49a72c 100644
--- a/Scripts/Hud.cs
+++ b/Scripts/Hud.cs
@@ -8,6 +8,7 @@ using Cirno.Scripts.UI;
public partial class Hud : CanvasLayer
{
+ public static Hud Instance { get; private set; }
[Signal]
public delegate void StartGameEventHandler();
@@ -48,10 +49,11 @@ public partial class Hud : CanvasLayer
private PauseMenu _pauseMenu;
- private bool _playerDead = false;
+ private bool _playerDead = false; // useless
public override void _Ready()
{
+ Instance = this;
// Assuming the HUD has a Label node named "HealthLabel"
//_healthLabel = GetNode