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

public class AnimationTerster : MonoBehaviour
{
    private const string AIR_BOOL = "inAir";
    private const string X_SPEED_FLOAT = "xSpeed";
    private const string Y_SPEED_FLOAT = "ySpeed";

    private const float SPD_ADJ = 0.05f;

    private float walk = 0;
    private float air = 0;

    private Animator animator;
    // Start is called before the first frame update
    void Start()
    {
        this.animator = this.GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update()
    {
        if (this.key(KeyCode.A))
        {
            this.animator.SetBool(AIR_BOOL, !this.animator.GetBool(AIR_BOOL));
            print("Adjusted falling to " + this.animator.GetBool(AIR_BOOL));
        } else if(this.key(KeyCode.Q))
        {
            this.walk = Mathf.Max(this.walk - SPD_ADJ, -1);
            this.animator.SetFloat(X_SPEED_FLOAT, this.walk);
            print("Adjusted walk to " + this.walk);
        } else if (this.key(KeyCode.W))
        {
            this.walk = Mathf.Min(this.walk + SPD_ADJ, 1);
            this.animator.SetFloat(X_SPEED_FLOAT, this.walk);
            print("Adjusted walk to " + this.walk);
        }
        else if (this.key(KeyCode.Z))
        {
            this.air = Mathf.Max(this.air - SPD_ADJ, -1);
            this.animator.SetFloat(Y_SPEED_FLOAT, this.air);
            print("Adjusted air to " + this.air);
        }
        else if (this.key(KeyCode.X))
        {
            this.air = Mathf.Min(this.air + SPD_ADJ, 1);
            this.animator.SetFloat(Y_SPEED_FLOAT, this.air);
            print("Adjusted air to " + this.air);
        }
    }

    private bool key(KeyCode key)
    {
        return Input.GetKeyUp(key);
    }
}
