using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

[RequireComponent(typeof(Rigidbody2D))]
public class PlayerController : MonoBehaviour
{
    [Header("Movement Settings")]
    public float moveSpeed = 5f;

    private Rigidbody2D rb;
    private Vector2 moveInput;

    void Awake()
    {
        rb = GetComponent<Rigidbody2D>();
        rb.gravityScale = 0f;  // Disable gravity for top-down
        rb.freezeRotation = true;
    }

    void Update()
    {
        // Read input from new Input System
        if (Keyboard.current != null)
        {
            moveInput.x = (Keyboard.current.aKey.isPressed ? -1 : 0) +
                          (Keyboard.current.dKey.isPressed ? 1 : 0);
            moveInput.y = (Keyboard.current.sKey.isPressed ? -1 : 0) +
                          (Keyboard.current.wKey.isPressed ? 1 : 0);

            moveInput = moveInput.normalized;
        }
    }

    void FixedUpdate()
    {
        rb.MovePosition(rb.position + moveInput * moveSpeed * Time.fixedDeltaTime);
    }
}
