SupaLidlGame/Characters/States/PlayerState.cs

68 lines
2.1 KiB
C#
Raw Normal View History

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)
{
/*
if (@event is InputEventKey inputEventKey)
{
GD.Print("hello");
if (inputEventKey.Keycode == Key.G)
{
GD.Print("hi");
}
}*/
if (@event.IsActionPressed("equip"))
{
Character.Inventory.SelectedItem = Character.Inventory.GetNode<Items.Item>("Sword");
//Character.Inventory.AddItem();
}
if (@event.IsActionPressed("attack1"))
{
if (Character.Inventory.SelectedItem is not null)
{
Character.Inventory.SelectedItem.Use();
//return AttackState;
}
}
//if (this is PlayerAttackState)
//{
// if (@event.IsActionReleased("attack1"))
// {
// return IdleState;
// }
//}
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);
if (Character.Inventory.SelectedItem is Weapon weapon)
{
if (!weapon.IsUsing)
{
Character.Target = dirToMouse;
}
}
2022-11-13 15:42:04 -08:00
return base.Process(delta);
}
}
}