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;
|
2023-07-24 00:56:01 -07:00
|
|
|
using SupaLidlGame.Extensions;
|
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 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; }
|
|
|
|
|
2023-07-21 02:54:13 -07:00
|
|
|
[Export]
|
|
|
|
public AnimationTree AnimationTree { get; private set; }
|
2023-06-10 22:15:28 -07:00
|
|
|
|
2023-07-21 02:54:13 -07:00
|
|
|
public InteractionRay InteractionRay { get; private set; }
|
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-08-07 02:38:51 -07:00
|
|
|
Death += async (Events.HurtArgs args) =>
|
2023-06-13 02:55:30 -07:00
|
|
|
{
|
2023-07-24 00:30:33 -07:00
|
|
|
HurtAnimation.Play("death");
|
|
|
|
await ToSignal(HurtAnimation, "animation_finished");
|
2023-06-13 02:55:30 -07:00
|
|
|
};
|
2023-07-21 02:54:13 -07:00
|
|
|
|
|
|
|
base._Ready();
|
|
|
|
|
|
|
|
Inventory.UsedItem += (Items.Item item) =>
|
|
|
|
{
|
|
|
|
if (item is Items.Weapons.Sword)
|
|
|
|
{
|
|
|
|
AttackAnimation.Play("sword");
|
|
|
|
}
|
|
|
|
};
|
2023-08-13 16:49:18 -07:00
|
|
|
|
|
|
|
HealthChanged += (args) =>
|
|
|
|
{
|
|
|
|
var signal = Events.EventBus.SignalName.PlayerHealthChanged;
|
|
|
|
this.GetEventBus().EmitSignal(signal, args);
|
|
|
|
};
|
2023-06-13 02:55:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void _Input(InputEvent @event)
|
|
|
|
{
|
|
|
|
if (StateMachine != null)
|
|
|
|
{
|
|
|
|
StateMachine.Input(@event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Spawn()
|
|
|
|
{
|
|
|
|
Health = 100;
|
2023-08-07 02:38:51 -07:00
|
|
|
HurtAnimation.Play("spawn");
|
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()
|
|
|
|
{
|
|
|
|
base.ModifyVelocity();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Stun(float time)
|
|
|
|
{
|
|
|
|
base.Stun(time);
|
|
|
|
Camera.Shake(2, 0.8f);
|
|
|
|
// TODO: implement visual effects for stun
|
|
|
|
}
|
|
|
|
|
2023-08-07 02:38:51 -07:00
|
|
|
protected override void OnReceivedDamage(
|
2023-07-19 00:17:25 -07:00
|
|
|
float damage,
|
|
|
|
Character inflictor,
|
|
|
|
float knockback,
|
2023-07-21 02:54:13 -07:00
|
|
|
Vector2 knockbackDir = default)
|
2023-07-19 00:17:25 -07:00
|
|
|
{
|
|
|
|
if (damage >= 10 && IsAlive)
|
|
|
|
{
|
|
|
|
Camera.Shake(2, 0.5f);
|
|
|
|
}
|
2023-07-21 02:54:13 -07:00
|
|
|
|
|
|
|
GetNode<GpuParticles2D>("Effects/HurtParticles")
|
|
|
|
.SetDirection(knockbackDir);
|
|
|
|
|
|
|
|
base.OnReceivedDamage(damage, inflictor, knockback, knockbackDir);
|
2023-07-19 00:17:25 -07:00
|
|
|
}
|
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
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();
|
|
|
|
}
|
2023-07-24 00:56:01 -07:00
|
|
|
|
|
|
|
public override void Footstep()
|
|
|
|
{
|
|
|
|
GetNode<AudioStreamPlayer2D>("Effects/Footstep")
|
|
|
|
.OnWorld()
|
|
|
|
.WithPitchDeviation(0.125f)
|
|
|
|
.Play();
|
|
|
|
}
|
2022-11-10 20:29:53 -08:00
|
|
|
}
|