using UnityEngine;
using System.Collections;
using com.deeperbeige.lib;

namespace com.deeperbeige.whiteout
{
	internal class Ball : MonoBehaviour
	{
		private BallPath ballPath;

		private void Start ()
		{
			ballPath = transform.parent.GetComponent<BallPath> ();
			// play one of the splat sounds in the group
		//	Sounds.Play ("ball-rolling");
		}

		private void OnCollisionEnter (Collision collision)
		{
			switch (collision.gameObject.name)
			{
				case "Ball":
					ballPath.Explode ();
				// play one of the splat sounds in the group
				Sounds.Play ("splat");
					break;
			}
		}

		private void OnTriggerEnter (Collider otherCollider)
		{
			switch (otherCollider.gameObject.name)
			{
				case "Target":
					Player otherPlayer = otherCollider.transform.parent.GetComponent<Player> ();
					if (ballPath.player.playerID == otherPlayer.playerID) return;
		
					ballPath.Explode ();
					Debug.Log ("Player " + ballPath.player.playerID + " hit player " + otherPlayer.playerID);
				    // play one of the spat sounds in the group
				    Sounds.Play ("splat");
					ballPath.player.IncrementScore ();
				    Sounds.Play ("score-ding");
					ballPath.Explode();

					//life is decremented when hit
					ballPath.player.decrementLife ();
					break;

				case "Goal":
					ballPath.Explode();
                    ballPath.player.IncrementScore ();
              Sounds.Play ("score-ding");
					Debug.Log("Player 1 scored a goal");
					break;
			}
		}
	}
}
