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

public class PlayerSpriteScript : MonoBehaviour {

	public float frameRateAnimation = 24;

	float timerSecondAnimation = 1;

	public List<Sprite> spritesIdle;
	int idleCounter = 0;
	public List<Sprite> spritesBoom;
	int boomCounter = 0;
	bool boomPlaying = false;

	SpriteRenderer ownRenderer;


	// Use this for initialization
	void Start () {

		ownRenderer = GetComponent<SpriteRenderer> ();


		
	}
	
	// Update is called once per frame
	void Update () {

		timerSecondAnimation -= Time.deltaTime * frameRateAnimation;
		if (timerSecondAnimation <= 0) {

			if (boomPlaying == false)
				PlayIdleAnimation ();
			else
				PlayPuffAnimation ();
			timerSecondAnimation = 1;
		}

		if (Input.GetKeyDown (KeyCode.Space))
			boomPlaying = true;
		
	}

	void FixedUpdate()
	{
		

	}


	void PlayIdleAnimation()
	{
		ownRenderer.sprite = spritesIdle [idleCounter];

		idleCounter++;

		if (idleCounter >= spritesIdle.Count)
			idleCounter = 0;


	}

	void PlayPuffAnimation()
	{
		ownRenderer.sprite = spritesBoom [boomCounter];
		boomCounter++;

		if (boomCounter >= spritesBoom.Count) {
			boomCounter = 0;
			idleCounter = 0;
			boomPlaying = false;

		}



	}

	public void SpriteFlipperFunc(int flipperVar)
	{
		Vector2 newScale = gameObject.transform.localScale;

		newScale.x = Mathf.Abs (newScale.x) * flipperVar;

		gameObject.transform.localScale = newScale;

	}


}
