SupaLidlGame/Characters/States/PlayerAttackState.cs

60 lines
1.5 KiB
C#
Raw Normal View History

2022-11-13 15:42:04 -08:00
using Godot;
2022-11-19 21:21:12 -08:00
using SupaLidlGame.Items;
2022-11-13 15:42:04 -08:00
namespace SupaLidlGame.Characters.State
{
public partial class PlayerAttackState : PlayerState
{
2022-11-19 21:21:12 -08:00
private double _attackTime = 0;
2022-11-13 15:42:04 -08:00
public override CharacterState Enter(CharacterState previousState)
{
2022-11-19 21:21:12 -08:00
if (Character.Inventory.SelectedItem is Weapon weapon)
{
_attackTime = weapon.UseTime;
weapon.Visible = true;
Character.Inventory.SelectedItem.Use();
}
else
{
return IdleState;
}
2022-11-13 15:42:04 -08:00
return base.Enter(previousState);
}
public override void Exit(CharacterState nextState)
{
2022-11-19 21:21:12 -08:00
if (Character.Inventory.SelectedItem is null)
{
}
Character.Inventory.SelectedItem.Deuse();
if (Character.Inventory.SelectedItem is Weapon weapon)
{
//weapon.Visible = false;
}
2022-11-13 15:42:04 -08:00
base.Exit(nextState);
}
public override CharacterState Input(InputEvent @event)
{
return base.Input(@event);
}
public override CharacterState PhysicsProcess(double delta)
{
2022-11-19 21:21:12 -08:00
Character.Velocity *= 0.5f;
2022-11-13 15:42:04 -08:00
return base.PhysicsProcess(delta);
}
public override CharacterState Process(double delta)
{
2022-11-19 21:21:12 -08:00
if ((_attackTime -= delta) <= 0)
{
return IdleState;
}
2022-11-13 15:42:04 -08:00
return base.Process(delta);
}
}
}