using UnityEngine;
using System.Collections;

// Smack is a face plant.

[RequireComponent(typeof(BoxCollider))]
[RequireComponent(typeof(Rigidbody))]
public class Trick_SmackSensor : MonoBehaviour {
	public BoxCollider sensor;
	public Rigidbody rb;

	public float maxVelocity	= 1f;
	public float cooldown 		= 0f;
	public float maxCooldown	= 3f;
	public float splatCooldown	= 1f;
	public float baseScore 		= 100f;

	public bool touchdown		= false;

	public Collider otherCollider;

	void Start()
	{
		rb = GetComponent<Rigidbody> ();
		sensor = GetComponent<BoxCollider> ();
		sensor.isTrigger = true;
	}

	void FixedUpdate()
	{
		if (touchdown) {
			cooldown = Mathf.Max (0,cooldown - Time.fixedDeltaTime);

			if (cooldown <= 0)
			{
				if(Mathf.Abs(rb.velocity.y) <= maxVelocity)
				{
					ScoreManager.NewTrick ("Splat", baseScore);

				}
				touchdown = false;
				cooldown +=	maxCooldown;
			}
		}
	}

	void OnTriggerEnter(Collider other)
	{
		// Already hit that.
		if (other == otherCollider)
			return;
		touchdown = true;
		otherCollider = other;
		cooldown = splatCooldown;
	}

}
