mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-08 21:45:55 +00:00
Inventory close and open by button
This commit is contained in:
parent
0687b6de99
commit
80a13d047d
11 changed files with 165 additions and 53 deletions
|
|
@ -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();
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue