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

public enum EaterType {Dog, Boy, Cat};

public class EatItem : MonoBehaviour {
	public EaterType eater;
	public int score;
	public int multiplier;

	public AudioClip[] goodMeals;
	public AudioClip bleugh;

	// Use this for initialization
	void Start () {
		score = 0;
		multiplier = 1;
	}
	
	// Update is called once per frame
	void Update () {
		
	}

	public void Reset() {
		GetComponent<EdgeCollider2D> ().isTrigger = true;
	}

	void OnTriggerEnter2D (Collider2D other) {
		if (other.tag == "GoodItem") {
			score += multiplier;
			multiplier = Mathf.Min (multiplier + 1, 3);
			if (eater == EaterType.Boy) {
				AudioSource audio = GetComponent<AudioSource> ();
				audio.clip = goodMeals[Random.Range (0, goodMeals.Length)];
				if (!audio.isPlaying)
					audio.Play ();
			}
		} else {
			score -= 2;
			multiplier = 1;
			if (eater == EaterType.Boy) {
				AudioSource audio = GetComponent<AudioSource> ();
				audio.clip = bleugh;
				if (!audio.isPlaying)
					audio.Play ();
			}
		}
		if (eater != EaterType.Cat || other.tag == "GoodItem") {
			other.GetComponent<StartNoclip> ().alreadyDead = true;
			Destroy (other.gameObject, 0.1f);
		} else {
			GetComponent<EdgeCollider2D> ().isTrigger = false;
			Invoke ("Reset", 0.1f);
		}
	}
}
