2022-11-10 20:29:53 -08:00
|
|
|
using Godot;
|
2023-06-10 22:15:28 -07:00
|
|
|
using GodotUtilities;
|
2022-11-25 11:59:55 -08:00
|
|
|
using SupaLidlGame.Utils;
|
2023-06-10 22:15:28 -07:00
|
|
|
using SupaLidlGame.BoundingBoxes;
|
2022-11-10 20:29:53 -08:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
namespace SupaLidlGame.Characters;
|
|
|
|
|
2023-06-10 22:15:28 -07:00
|
|
|
[Scene]
|
|
|
|
public sealed partial class Player : Character
|
2022-11-10 20:29:53 -08:00
|
|
|
{
|
2023-06-03 18:21:46 -07:00
|
|
|
private AnimatedSprite2D _sprite;
|
|
|
|
private string _spriteAnim;
|
2022-11-19 21:21:12 -08:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
[Export]
|
|
|
|
public PlayerCamera Camera { get; set; }
|
2022-11-25 11:59:55 -08:00
|
|
|
|
2023-06-10 22:15:28 -07:00
|
|
|
[Export]
|
|
|
|
public Marker2D DirectionMarker { get; private set; }
|
|
|
|
|
|
|
|
public InteractionRay InteractionRay { get; private set; }
|
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
public string Animation
|
|
|
|
{
|
|
|
|
get => _sprite.Animation;
|
|
|
|
set
|
2022-11-19 21:21:12 -08:00
|
|
|
{
|
2023-06-03 18:21:46 -07:00
|
|
|
// 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)
|
2022-11-19 21:21:12 -08:00
|
|
|
{
|
2023-06-03 18:21:46 -07:00
|
|
|
_spriteAnim = value;
|
|
|
|
return;
|
2022-11-19 21:21:12 -08:00
|
|
|
}
|
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
_sprite.Play(value);
|
2022-11-19 21:21:12 -08:00
|
|
|
}
|
2023-06-03 18:21:46 -07:00
|
|
|
}
|
2022-11-19 21:21:12 -08:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
public override void _Ready()
|
|
|
|
{
|
2023-06-10 22:15:28 -07:00
|
|
|
InteractionRay = GetNode<InteractionRay>("Direction2D/InteractionRay");
|
2023-06-03 18:21:46 -07:00
|
|
|
_sprite = GetNode<AnimatedSprite2D>("Sprite");
|
|
|
|
if (_spriteAnim != default)
|
2022-11-19 21:21:12 -08:00
|
|
|
{
|
2023-06-03 18:21:46 -07:00
|
|
|
_sprite.Animation = _spriteAnim;
|
2022-11-25 09:11:46 -08:00
|
|
|
}
|
2023-06-10 22:15:28 -07:00
|
|
|
base._Ready();
|
2023-06-13 02:55:30 -07:00
|
|
|
Death += (Events.HealthChangedArgs args) =>
|
|
|
|
{
|
|
|
|
Visible = false;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void _Input(InputEvent @event)
|
|
|
|
{
|
|
|
|
if (StateMachine != null)
|
|
|
|
{
|
|
|
|
StateMachine.Input(@event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Spawn()
|
|
|
|
{
|
|
|
|
Health = 100;
|
|
|
|
Visible = true;
|
2023-06-03 18:21:46 -07:00
|
|
|
}
|
2022-11-25 09:11:46 -08:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
public override void ModifyVelocity()
|
|
|
|
{
|
|
|
|
if (StateMachine.CurrentState is SupaLidlGame.State.Character.PlayerRollState)
|
2022-11-25 09:11:46 -08:00
|
|
|
{
|
2023-06-03 18:21:46 -07:00
|
|
|
Velocity *= 2;
|
2022-11-25 09:11:46 -08:00
|
|
|
}
|
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
base.ModifyVelocity();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Stun(float time)
|
|
|
|
{
|
|
|
|
base.Stun(time);
|
|
|
|
Camera.Shake(2, 0.8f);
|
|
|
|
// TODO: implement visual effects for stun
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Die()
|
|
|
|
{
|
|
|
|
GD.Print("died");
|
|
|
|
//base.Die();
|
2022-11-13 15:42:04 -08:00
|
|
|
}
|
2023-06-10 22:15:28 -07:00
|
|
|
|
|
|
|
protected override void DrawTarget()
|
|
|
|
{
|
|
|
|
base.DrawTarget();
|
|
|
|
DirectionMarker.GlobalRotation = DirectionMarker.GlobalPosition
|
|
|
|
.DirectionTo(GetGlobalMousePosition())
|
|
|
|
.Angle();
|
|
|
|
}
|
2022-11-10 20:29:53 -08:00
|
|
|
}
|