using UnityEngine;
using System.Collections;

public class BoatManager : MonoBehaviour 
{
	public static bool deadBoat;			//Si le bateau est mort
	public GameObject explosion;			//Le Prefab "Explosion"
	public static int boatSpeed = -3;		//La vitesse de translation du prefab "EnsembleBateau"
	public int boatLife = 50;				//La vie du du prefab "EnsembleBateau"
	public int point;						//Le nombre de point que rapporte les collisions
	
	public static bool offside = false;		// Permet de verifier si les bateau dépasse notre "BateauPlayer"
	
	// Use this for initialization
	void Start () 
	{
		
	}
	
	// Update is called once per frame
	void Update () 
	{	
		if(GameManager.loose || GameManager.betweenLevel || GameManager.gameOver || GameManager.win)
		{
			Destroy (transform.parent.gameObject);
		}
		
		transform.Translate(new Vector3(0,0,boatSpeed)*Time.deltaTime,Space.World);
	}
	
	void OnTriggerEnter(Collider ObjetInfo)
	{
		if(ObjetInfo.gameObject.tag == "fond")		//Si "Ensemble bateau" touche le "Fond"
		{
			GameManager.alcohol -= 10;				// On perd 10 de vie
			Destroy(transform.parent.gameObject);
			offside = true;
		}
		if(ObjetInfo.gameObject.tag == "bottle")	//Si "Ensemble bateau" touche une de nos bouteilles
		{
			Destroy(ObjetInfo.gameObject);
			AudioClip bottleSound = (AudioClip) Resources.Load("Sounds/Bouteille", typeof(AudioClip));
			audio.PlayOneShot(bottleSound);
			
			boatLife -=  15;						// "Ensemble bateau" perd 15 de vie
			point = 15;								//on gagne 15 points
			GameManager.score += point;

			if(boatLife <= 0)
			{		
				deadBoat = true;
				AudioClip explosionSound = (AudioClip) Resources.Load("Sounds/Explosion", typeof(AudioClip));
				audio.PlayOneShot(explosionSound);
				Destroy(transform.parent.gameObject);
				Destroy(gameObject);
				GameObject particule = (GameObject) Instantiate(explosion,transform.position,transform.rotation);
			}
		}
	}
}