using UnityEngine;
using System.Collections;

public class FeedPowerFly : MonoBehaviour {

	public Gameplay gamep;
	public AudioClip fly;
	public AudioClip hit;
	public AudioClip eat;
	public AudioSource fly_audio;
	public CharacterMotor engine;

	private bool was_flying = false;

	// Use this for initialization
	void Start () {

	}

	void OnTriggerEnter(Collider other) {
		if (engine.IsJumping() && !was_flying)
		{
			fly_audio.clip = fly;
			was_flying = true;
			if(fly_audio.isPlaying) fly_audio.Stop();
			fly_audio.Play();
		} else {
			if(was_flying && !engine.IsJumping()) {
				fly_audio.Stop();
				was_flying = false;
			}
		}

		Debug.Log ("hit!"+other.gameObject.tag+"|"+other.gameObject.name);
		if(other.gameObject.tag == "Foodstuff") {
			fly_audio.clip = eat;
			if(fly_audio.isPlaying) fly_audio.Stop();
			fly_audio.Play();
			Debug.Log ("nom!");
			Destroy(other.gameObject);
			gamep.power += 100;
		}
		if(other.gameObject.tag == "Dangerstuff") {
			Debug.Log ("autch!");
			fly_audio.clip = hit;
			if(fly_audio.isPlaying) fly_audio.Stop();
			fly_audio.Play();
			gamep.power -= 500;
		}
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}
