using System;
using Godot;

namespace AceFieldNewHorizon.Scripts.Entities;

public partial class Player : CharacterBody2D
{
    [Export] public float Speed = 400.0f;
    [Export] public float RotationSpeed = 3.0f;

    public override void _Process(double delta)
    {
        // Get direction to mouse and calculate angle
        var mousePos = GetGlobalMousePosition();
        var direction = GlobalPosition.DirectionTo(mousePos);
        Rotation = direction.Angle();
    }

    public override void _PhysicsProcess(double delta)
    {
        // Get movement input
        var moveForward = Input.GetActionStrength("move_up") - Input.GetActionStrength("move_down");
        
        // Calculate movement direction based on rotation
        Velocity = Vector2.Right.Rotated(Rotation) * moveForward * Speed;
        
        MoveAndSlide();
    }
}