2022-11-13 15:42:04 -08:00
|
|
|
using Godot;
|
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
namespace SupaLidlGame.State.Character;
|
|
|
|
|
|
|
|
public abstract partial class CharacterState : Node, IState<CharacterState>
|
2022-11-13 15:42:04 -08:00
|
|
|
{
|
2023-06-03 18:21:46 -07:00
|
|
|
[Export]
|
|
|
|
public Characters.Character Character { get; set; }
|
2022-11-13 15:42:04 -08:00
|
|
|
|
2023-09-16 22:14:23 -07:00
|
|
|
public bool CanEnterWhileUsingItem { get; set; }
|
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
public virtual IState<CharacterState> Enter(IState<CharacterState> prev) => null;
|
2022-11-13 15:42:04 -08:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
public virtual void Exit(IState<CharacterState> next)
|
|
|
|
{
|
2023-05-25 15:28:33 -07:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
}
|
2022-11-13 15:42:04 -08:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
public virtual CharacterState Process(double delta)
|
|
|
|
{
|
|
|
|
var item = Character.Inventory.SelectedItem;
|
2023-05-28 17:54:48 -07:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
bool targetTowards(Items.Item item)
|
|
|
|
{
|
|
|
|
if (item is Items.Weapon weapon)
|
2023-05-28 17:54:48 -07:00
|
|
|
{
|
2023-06-03 18:21:46 -07:00
|
|
|
if (weapon.IsUsing)
|
2023-05-28 17:54:48 -07:00
|
|
|
{
|
2023-09-10 17:08:14 -07:00
|
|
|
if (weapon.ShouldFreezeAngleOnUse)
|
|
|
|
{
|
|
|
|
Character.Target = weapon.UseDirection;
|
|
|
|
}
|
2023-06-03 18:21:46 -07:00
|
|
|
return true;
|
2023-05-28 17:54:48 -07:00
|
|
|
}
|
|
|
|
}
|
2023-06-03 18:21:46 -07:00
|
|
|
return false;
|
2022-11-25 09:11:46 -08:00
|
|
|
}
|
2022-11-13 15:42:04 -08:00
|
|
|
|
2023-08-10 23:08:41 -07:00
|
|
|
targetTowards(item);
|
2022-11-25 09:11:46 -08:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
return null;
|
|
|
|
}
|
2022-11-25 09:11:46 -08:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
public virtual CharacterState PhysicsProcess(double delta)
|
|
|
|
{
|
2023-07-31 01:12:47 -07:00
|
|
|
if (!Character.IsAlive)
|
2023-06-13 02:55:30 -07:00
|
|
|
{
|
|
|
|
Character.Velocity = Vector2.Zero;
|
|
|
|
Character.MoveAndSlide();
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
Character.Velocity = Character.NetImpulse;
|
2022-11-25 09:11:46 -08:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
if (Character.NetImpulse.LengthSquared() < Mathf.Pow(Character.Speed, 2))
|
|
|
|
{
|
|
|
|
Character.Velocity += Character.Direction.Normalized()
|
|
|
|
* Character.Speed;
|
|
|
|
// we should only modify velocity that is in the player's control
|
|
|
|
Character.ModifyVelocity();
|
2022-11-13 15:42:04 -08:00
|
|
|
}
|
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
Character.NetImpulse = Character.NetImpulse.MoveToward(
|
|
|
|
Vector2.Zero,
|
|
|
|
(float)delta * Character.Speed * Character.Friction);
|
|
|
|
|
|
|
|
Character.MoveAndSlide();
|
|
|
|
|
|
|
|
return null;
|
2022-11-13 15:42:04 -08:00
|
|
|
}
|
2023-06-03 18:21:46 -07:00
|
|
|
|
|
|
|
public virtual CharacterState Input(InputEvent @event) => null;
|
2024-01-06 14:13:11 -08:00
|
|
|
|
|
|
|
public virtual CharacterState UnhandledInput(InputEvent @event) => null;
|
2022-11-13 15:42:04 -08:00
|
|
|
}
|