SupaLidlGame/State/Character/CharacterState.cs

71 lines
2.0 KiB
C#
Raw Normal View History

2022-11-13 15:42:04 -08:00
using Godot;
2023-05-25 15:28:33 -07:00
namespace SupaLidlGame.State.Character
2022-11-13 15:42:04 -08:00
{
2023-05-25 15:28:33 -07:00
public abstract partial class CharacterState : Node, IState<CharacterState>
2022-11-13 15:42:04 -08:00
{
2023-05-25 15:28:33 -07:00
[Export]
public Characters.Character Character { get; set; }
2022-11-13 15:42:04 -08:00
2023-05-25 15:28:33 -07:00
public virtual IState<CharacterState> Enter(IState<CharacterState> prev) => null;
2022-11-13 15:42:04 -08:00
2023-05-25 15:28:33 -07:00
public virtual void Exit(IState<CharacterState> next)
{
}
2022-11-13 15:42:04 -08:00
2022-11-25 09:11:46 -08:00
public virtual CharacterState Process(double delta)
{
if (Character.StunTime > 0)
{
Character.StunTime -= delta;
}
2023-05-28 17:54:48 -07:00
var item = Character.Inventory.SelectedItem;
var offhand = Character.Inventory.OffhandItem;
// angle towards item use angle or offhand use angle if not used
bool targetTowards(Items.Item item)
{
if (item is Items.Weapon weapon)
{
if (weapon.IsUsing)
{
Character.Target = weapon.UseDirection;
return true;
}
}
return false;
}
var _ = targetTowards(item) || targetTowards(offhand);
2022-11-25 09:11:46 -08:00
return null;
}
2022-11-13 15:42:04 -08:00
public virtual CharacterState PhysicsProcess(double delta)
{
2022-11-25 09:11:46 -08:00
Character.Velocity = Character.NetImpulse;
if (Character.NetImpulse.LengthSquared() < Mathf.Pow(Character.Speed, 2))
{
Character.Velocity += Character.Direction.Normalized()
* Character.Speed;
2023-03-19 14:13:20 -07:00
// we should only modify velocity that is in the player's control
Character.ModifyVelocity();
2022-11-25 09:11:46 -08:00
}
Character.NetImpulse = Character.NetImpulse.MoveToward(
Vector2.Zero,
(float)delta * Character.Speed * Character.Friction);
2022-11-13 15:42:04 -08:00
Character.MoveAndSlide();
2022-11-25 09:11:46 -08:00
2022-11-13 15:42:04 -08:00
return null;
}
public virtual CharacterState Input(InputEvent @event) => null;
}
}