SupaLidlGame/Characters/Player.cs

80 lines
2.0 KiB
C#
Raw Normal View History

2022-11-10 20:29:53 -08:00
using Godot;
2022-11-25 11:59:55 -08:00
using SupaLidlGame.Utils;
2022-11-10 20:29:53 -08:00
namespace SupaLidlGame.Characters
{
2022-11-13 15:42:04 -08:00
public partial class Player : Character
{
2022-11-19 21:21:12 -08:00
private AnimatedSprite2D _sprite;
private string _spriteAnim;
2022-11-25 11:59:55 -08:00
[Export]
public PlayerCamera Camera { get; set; }
2022-11-19 21:21:12 -08:00
public string Animation
{
get => _sprite.Animation;
set
{
// the Player.Animation property might be set before this node is
// even ready, so if _sprite is null, then we just hold the new
// animation in a temp value, which will be assigned once this
// node is ready
if (_sprite is null)
{
_spriteAnim = value;
return;
}
2023-03-19 13:54:48 -07:00
_sprite.Play(value);
2022-11-19 21:21:12 -08:00
}
}
2022-11-13 15:42:04 -08:00
public override void _Ready()
{
2022-11-19 21:21:12 -08:00
_sprite = GetNode<AnimatedSprite2D>("Sprite");
if (_spriteAnim != default)
{
_sprite.Animation = _spriteAnim;
}
}
public override void ModifyVelocity()
{
if (StateMachine.State is State.PlayerRollState)
{
Velocity *= 2;
}
2022-11-10 20:29:53 -08:00
2022-11-25 09:11:46 -08:00
base.ModifyVelocity();
}
public override void Stun(float time)
{
base.Stun(time);
2023-03-19 23:36:36 -07:00
Camera.Shake(2, 0.8f);
2022-11-25 09:11:46 -08:00
// TODO: implement visual effects for stun
}
public override void Die()
{
2022-12-04 20:12:34 -08:00
GD.Print("died");
2022-11-25 09:11:46 -08:00
//base.Die();
2022-11-13 15:42:04 -08:00
}
2023-03-26 21:11:38 -07:00
public bool IsUsingAnyWeapon()
{
bool checkItem(Items.Item item)
{
if (item is Items.Weapon weapon)
{
return weapon.IsUsing;
}
return false;
}
return checkItem(Inventory.PrimaryItem) ||
checkItem(Inventory.OffhandItem);
}
2022-11-13 15:42:04 -08:00
}
2022-11-10 20:29:53 -08:00
}