using UnityEngine;

namespace Patterns_And_Principles.Patterns.The_State_Pattern.Script._02_RealWorldUsage.Player
{
    public class PlayerController : MonoBehaviour
    {
        private Rigidbody rb;
        public float speed = 5f;

        private void Awake()
        {
            rb = GetComponent<Rigidbody>();
        }

        private void FixedUpdate()
        {
            Vector3 movement = Vector3.zero;

            if (Input.GetKey(KeyCode.W))
            {
                movement += Vector3.forward;
            }

            if (Input.GetKey(KeyCode.S))
            {
                movement += Vector3.back;
            }

            if (Input.GetKey(KeyCode.A))
            {
                movement += Vector3.left;
            }

            if (Input.GetKey(KeyCode.D))
            {
                movement += Vector3.right;
            }

            rb.MovePosition(rb.position + movement.normalized * speed * Time.fixedDeltaTime);
        }
    }
}