mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 10:35:34 +00:00
FSM Player movement
This commit is contained in:
parent
7d9db8cfb6
commit
c59a480ffd
10 changed files with 131 additions and 36 deletions
|
|
@ -16,12 +16,19 @@ public partial class PlayerWeaponProvider : Node2D
|
|||
|
||||
public Weapon EquippedWeapon { get; set; }
|
||||
|
||||
//private PlayerMovement _parent;
|
||||
private CharacterBody2D _parent;
|
||||
|
||||
//public Vector2 FacingDirection
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Init(CharacterBody2D parent)
|
||||
{
|
||||
_parent = parent;
|
||||
|
||||
_inventoryManager = this.GetInventoryManager();
|
||||
|
||||
_inventoryManager.WeaponEquip += this.EquipWeapon;
|
||||
|
|
@ -35,11 +42,6 @@ public partial class PlayerWeaponProvider : Node2D
|
|||
};
|
||||
}
|
||||
|
||||
public void Init(PlayerMovement parent)
|
||||
{
|
||||
//_parent = parent;
|
||||
}
|
||||
|
||||
public void AddWeapon(Weapon weapon)
|
||||
{
|
||||
EquippedWeapons.Add(weapon);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using Cirno.Scripts.Components.Actors;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.FSM.Player;
|
||||
|
|
@ -17,12 +18,32 @@ public partial class Active : PlayerFSMState
|
|||
[Export] private string _nextWeaponActionName = "next_weapon";
|
||||
[Export] private string _previousWeaponActionName = "previous_weapon";
|
||||
|
||||
private PlayerWeaponProvider _weaponProvider;
|
||||
|
||||
private bool _isStrafing { get; set; }
|
||||
|
||||
[Export]
|
||||
public int Speed { get; set; } = 45;
|
||||
|
||||
[Export]
|
||||
public int StrafeSpeed { get; set; } = 35;
|
||||
|
||||
public int MovementSpeed => _isStrafing ? StrafeSpeed : Speed;
|
||||
|
||||
public override void Init(ActorStateMachine stateMachine)
|
||||
{
|
||||
base.Init(stateMachine);
|
||||
|
||||
_weaponProvider = stateMachine.GetNode<PlayerWeaponProvider>("WeaponProvider");
|
||||
|
||||
_weaponProvider.Init(stateMachine);
|
||||
}
|
||||
|
||||
public override void EnterState()
|
||||
{
|
||||
// enable sprite
|
||||
// enable crosshair
|
||||
GD.Print(this.State.ToString());
|
||||
}
|
||||
|
||||
public override void ExitState()
|
||||
|
|
@ -32,7 +53,9 @@ public partial class Active : PlayerFSMState
|
|||
|
||||
public override void PhysicsProcessState(double delta)
|
||||
{
|
||||
_stateMachine.Velocity = _movementDirection * MovementSpeed;
|
||||
|
||||
_stateMachine.MoveAndSlide();
|
||||
}
|
||||
|
||||
public override void ProcessState(double delta)
|
||||
|
|
@ -63,7 +86,7 @@ public partial class Active : PlayerFSMState
|
|||
}
|
||||
}
|
||||
|
||||
// HandleShoot();
|
||||
HandleShoot();
|
||||
// FindInteractable();
|
||||
|
||||
// if (Input.IsActionJustPressed(_nextWeaponActionName))
|
||||
|
|
@ -112,6 +135,12 @@ public partial class Active : PlayerFSMState
|
|||
|
||||
}
|
||||
|
||||
private void HandleShoot()
|
||||
{
|
||||
if (!Input.IsActionPressed(_shootActionName)) return;
|
||||
_weaponProvider.Shoot(this._facingDirection);
|
||||
}
|
||||
|
||||
public Vector2 GetInput()
|
||||
{
|
||||
return Input.GetVector("left", "right", "up", "down");
|
||||
|
|
|
|||
27
Scripts/Components/FSM/Player/Init.cs
Normal file
27
Scripts/Components/FSM/Player/Init.cs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
using System;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.FSM.Player;
|
||||
|
||||
public partial class Init : PlayerFSMState
|
||||
{
|
||||
public override void EnterState()
|
||||
{
|
||||
GD.Print(this.State.ToString());
|
||||
}
|
||||
|
||||
public override void ExitState()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void PhysicsProcessState(double delta)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void ProcessState(double delta)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
1
Scripts/Components/FSM/Player/Init.cs.uid
Normal file
1
Scripts/Components/FSM/Player/Init.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://chwqogny2v8t1
|
||||
|
|
@ -5,8 +5,13 @@ namespace Cirno.Scripts.Components.FSM;
|
|||
|
||||
public partial class PlayerStateMachine : ActorStateMachine
|
||||
{
|
||||
[Export]
|
||||
public PlayerState InitialState { get; private set; }
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
base._Ready();
|
||||
|
||||
this.SetState((int)InitialState);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue