using Godot; using GodotUtilities; using SupaLidlGame.Utils; using SupaLidlGame.BoundingBoxes; namespace SupaLidlGame.Characters; [Scene] public sealed partial class Player : Character { private AnimatedSprite2D _sprite; private string _spriteAnim; [Export] public PlayerCamera Camera { get; set; } [Export] public Marker2D DirectionMarker { get; private set; } public InteractionRay InteractionRay { get; private set; } 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; } _sprite.Play(value); } } public override void _Ready() { InteractionRay = GetNode("Direction2D/InteractionRay"); _sprite = GetNode("Sprite"); if (_spriteAnim != default) { _sprite.Animation = _spriteAnim; } base._Ready(); 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; } public override void ModifyVelocity() { if (StateMachine.CurrentState is SupaLidlGame.State.Character.PlayerRollState) { Velocity *= 2; } 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 OnReceivedDamage( float damage, Character inflictor, float knockback, Vector2 knockbackOrigin = default, Vector2 knockbackVector = default) { if (damage >= 10 && IsAlive) { Camera.Shake(2, 0.5f); } base.OnReceivedDamage( damage, inflictor, knockback, knockbackOrigin, knockbackVector); } public override void Die() { GD.Print("died"); //base.Die(); } protected override void DrawTarget() { base.DrawTarget(); DirectionMarker.GlobalRotation = DirectionMarker.GlobalPosition .DirectionTo(GetGlobalMousePosition()) .Angle(); } }