#pragma strict
var lives : SpaceshipController;
var score : SpaceshipController;
var speedX : float;

function Start () {
	score = GameObject.FindGameObjectWithTag("Player").GetComponent(SpaceshipController);
	lives = GameObject.FindGameObjectWithTag("Player").GetComponent(SpaceshipController);
	MovementController.init(Camera.main.ScreenToWorldPoint(Vector3(0,Screen.height,0)).y,
							Camera.main.ScreenToWorldPoint(Vector3(0,0,0)).y,
							Camera.main.ScreenToWorldPoint(Vector3(0,0,0)).x,
							Camera.main.ScreenToWorldPoint(Vector3(Screen.width,0,0)).x);
}

function Update () {
	if (transform.position.x < MovementController.Leftmost())
	{
		GameObject.Destroy(this.gameObject);
	}
	if (transform.position.y > MovementController.Topmost())
	{
		GameObject.Destroy(this.gameObject);
	}
	if (transform.position.y < MovementController.Bottommost())
	{
		GameObject.Destroy(this.gameObject);
	}
	
	transform.Translate(Vector3.left * speedX * Time.deltaTime, Space.World);
}

function OnTriggerEnter(otherObject:Collider)
{
	if (otherObject.gameObject.tag == "Player")
	{
		lives.lives = lives.lives - 1;
		GameObject.Destroy(this.gameObject);
		if (lives.lives <= 0)
		{	
			Application.LoadLevel("GameOverScreen");
		}
	}
}