using System;
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UIElements;

public class PlayerController : MonoBehaviour
{
    float dir = 1.0f;
    [SerializeField] float carSpeed = 20.0f;
    bool startGame = true;
    [SerializeField] float verticalAxis;
    [SerializeField] float horizontalAxis;


    // Start is called before the first frame update
    void Start()
    {
        Debug.Log("Start");
    }

    // Update is called once per frame
    void Update()
    {
        //FPS: frame per seconds
        Debug.Log(1.0 / Time.deltaTime);
        Debug.Log("Update");
        // if reaches the end of the road, change the direction and come back to the original
        // position
        //if (transform.position.z <= 175.0f)
        //{
        //transform.position += new Vector3(0.0f, 0.0f, 1.0f * dir);
        // new Vector3(0.0f, 0.0f, 1.0f * dir * Time.deltaTime * carSpeed)
        if (Input.GetKeyDown(KeyCode.Space)) {
            startGame = false;
        } else if((Input.GetKeyDown(KeyCode.S)))
        {
            startGame = true;
        }

        verticalAxis = Input.GetAxis("Vertical"); // press up, down key
        horizontalAxis = Input.GetAxis("Horizontal");//press left arrow, right arrow

        if (startGame)
        {
            transform.Translate(Vector3.forward * dir * 
                Time.deltaTime * carSpeed * verticalAxis);
        }

        // Vector3.right = (1.0, 0.0, 0.0)
        // Vector3.left = (-1.0, 0.0, 0.0)
        // Vector3.up = (0.0, 1.0, 0.0)
        // Vector3.down = (0.0, -1.0, 0.0)
        // Vector3.forward = (0.0, 0.0, 1.0)
        // Vector3.back = (0.0, 0.0, -1.0)
        //}

        if (transform.position.z >= 175.0f || transform.position.z <= -5.0f)
        {
            dir = dir *  -1.0f;
        }
    }
}
