using Godot; using testing.interfaces; public partial class Player : CharacterBody2D, IDamageable { [Export] public EntityStats? BaseStats { get; set; } [Export] public PackedScene? BulletScene { get; set; } // Create a reference for your Sprite private Sprite2D _sprite = null!; private StatsComponent _stats = null!; private PlayerBuildComponent? _build; public override void _Ready() { AddToGroup("player"); _stats = GetNode("StatsComponent"); _stats.Initialize(BaseStats); _sprite = GetNode("Sprite2D"); _build = GetNodeOrNull("PlayerBuildComponent"); } public override void _PhysicsProcess(double delta) { Vector2 direction = Input.GetVector("left", "right", "up", "down"); float moveSpeed = _stats.RuntimeStats.MoveSpeed; if (_build != null) { moveSpeed = _build.GetModifiedMoveSpeed(moveSpeed); } Velocity = direction * moveSpeed; MoveAndSlide(); } public override void _Process(double delta) { // Get the mouse position Vector2 mousePos = GetGlobalMousePosition(); // If the mouse is to the left of the player, flip the sprite. // If it's to the right, keep it un-flipped. _sprite.FlipH = mousePos.X < GlobalPosition.X; } public void TakeDamage(float amount) { // For right now, just subtract it from the runtime stats we set up earlier! if (_stats?.RuntimeStats != null) { _stats.RuntimeStats.MaxHealth -= amount; GD.Print($"Ouch! Player took {amount} damage. Health remaining: {_stats.RuntimeStats.MaxHealth}"); if (_stats.RuntimeStats.MaxHealth <= 0) { GD.Print("Player Died!"); QueueFree(); // Deletes the player } } } }