2022-11-19 21:21:12 -08:00
|
|
|
using Godot;
|
|
|
|
using SupaLidlGame.Items;
|
|
|
|
|
2022-11-13 15:42:04 -08:00
|
|
|
namespace SupaLidlGame.Characters.State
|
|
|
|
{
|
|
|
|
public partial class PlayerState : CharacterState
|
|
|
|
{
|
|
|
|
//public PlayerMachine PlayerMachine => Machine as PlayerMachine;
|
|
|
|
protected Player _player => Character as Player;
|
|
|
|
|
2022-11-19 21:21:12 -08:00
|
|
|
[Export]
|
|
|
|
public PlayerIdleState IdleState { get; set; }
|
|
|
|
|
|
|
|
public override CharacterState Input(InputEvent @event)
|
|
|
|
{
|
2022-11-25 11:59:55 -08:00
|
|
|
#if DEBUG
|
2022-11-19 21:21:12 -08:00
|
|
|
if (@event.IsActionPressed("equip"))
|
|
|
|
{
|
2023-03-26 21:11:38 -07:00
|
|
|
//Character.Inventory.SelectedItem = Character.Inventory.GetNode<Items.Item>("Sword");
|
|
|
|
//Character.Inventory.SelectedItem = Character.
|
|
|
|
Character.Inventory.SelectFirstItem();
|
2022-11-19 21:21:12 -08:00
|
|
|
}
|
2022-11-25 11:59:55 -08:00
|
|
|
#endif
|
2022-11-19 21:21:12 -08:00
|
|
|
|
|
|
|
return base.Input(@event);
|
|
|
|
}
|
|
|
|
|
2022-11-13 15:42:04 -08:00
|
|
|
public override CharacterState Process(double delta)
|
|
|
|
{
|
|
|
|
Character.Direction = Godot.Input.GetVector("ui_left", "ui_right",
|
|
|
|
"ui_up", "ui_down");
|
2022-11-19 21:21:12 -08:00
|
|
|
Vector2 mousePos = Character.GetGlobalMousePosition();
|
|
|
|
Vector2 dirToMouse = Character.GlobalPosition.DirectionTo(mousePos);
|
2023-03-26 21:11:38 -07:00
|
|
|
if (Character.Inventory.PrimaryItem is Weapon weapon)
|
2022-11-19 21:21:12 -08:00
|
|
|
{
|
|
|
|
if (!weapon.IsUsing)
|
|
|
|
{
|
|
|
|
Character.Target = dirToMouse;
|
|
|
|
}
|
|
|
|
}
|
2022-11-25 09:11:46 -08:00
|
|
|
|
2022-11-25 11:59:55 -08:00
|
|
|
if (Godot.Input.IsActionPressed("attack1"))
|
|
|
|
{
|
2023-03-26 21:11:38 -07:00
|
|
|
if (Character.Inventory.PrimaryItem is not null)
|
2022-11-25 11:59:55 -08:00
|
|
|
{
|
|
|
|
Character.UseCurrentItem();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-13 15:42:04 -08:00
|
|
|
return base.Process(delta);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|