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

public class PlayerManager : MonoBehaviour {
	
	private float movingSpeed;
	private float vertical;
	private float horizontal;
	private Animator dogAni;

	private AudioSource bark;
	public ParticleSystem particleSys;
	//private ParticleSystem.MinMaxGradient grad;

	// Use this for initialization
	void Start () {
		movingSpeed = 12.0f;
		dogAni = GetComponent<Animator>();
		bark = GetComponent<AudioSource>();
		//grad = particleSys.colorOverLifetime.color;
	}
	
	// Update is called once per frame
	void Update () {
		vertical = Input.GetAxis("Vertical") * movingSpeed;
		horizontal = Input.GetAxis("Horizontal") * movingSpeed;
		if (vertical == 0 && horizontal == 0) {
			dogAni.SetInteger ("dogDir", 5);
			
		} else if (Mathf.Abs(vertical) > Mathf.Abs(horizontal)) {
			if (vertical > 0) {
				dogAni.SetInteger ("dogDir", 0);
			} else {
				dogAni.SetInteger ("dogDir", 2);
			}
		} else if (Mathf.Abs(vertical) < Mathf.Abs(horizontal)) {
			if (horizontal > 0) {
				dogAni.SetInteger ("dogDir", 3);
			} else {
				dogAni.SetInteger ("dogDir", 1);
			}
		}
		vertical *= Time.deltaTime;
		horizontal *= Time.deltaTime;
		transform.Translate(0, vertical, 0);
		transform.Translate(horizontal, 0 , 0);

		if(Input.GetKeyUp(KeyCode.Space)){
//			Color temp = grad.colorMax;
//			temp = new Color(0, 255, 65, 255);
//			grad.colorMax = temp;
//			Debug.Log(grad.colorMax);
			particleSys.startColor = new Color(0, 255, 65, 255);
			particleSys.Play();
			bark.Play();
		}
		if(Input.GetKeyUp(KeyCode.Alpha1)){
//			Color temp = grad.colorMax;
//			temp = new Color(255, 0, 0, 255);
//			grad.colorMax = temp;
			particleSys.startColor = new Color(255, 0, 0, 255);
			particleSys.Play();	
			bark.Play();
		}
		if(Input.GetKeyUp(KeyCode.Alpha2)){
//			Color temp = grad.colorMax;
//			temp = new Color(54, 152, 255, 255);
//			grad.colorMax = temp;
			particleSys.startColor = new Color(54, 152, 255, 255);
			particleSys.Play();	
			bark.Play();
		}

	}
}
