#pragma strict

var isJumping:boolean;
var mainController:MainController;

function Start ()
{
	isJumping = true;
	mainController = GameObject.FindGameObjectWithTag("MainCamera").GetComponent("MainController");
}

function Update ()
{
	if (Input.GetKeyDown(KeyCode.Space) && !isJumping) {
		rigidbody.AddForce(Vector3.up * 30, ForceMode.Impulse);
		isJumping = true;
	}
		
	if (transform.position.y > -1.45)
		rigidbody.AddForce(Vector3.down * 40, ForceMode.Force);		
}

function OnTriggerEnter(otherObject:Collider)
{
	if (isJumping && otherObject.tag.Equals("Floor")) {
		rigidbody.velocity = Vector3.zero;
		transform.position = Vector3(-13, -3.45, 0);
		isJumping = false;
	}
	else {
		if(otherObject.tag.Equals("Bouncy"))
			mainController.score -= 2;
	
		mainController.lives--;
		Destroy(otherObject.gameObject);
	}
}