#pragma strict
var speedX: int;
var direction: int;
var health: int;
var score: SpaceshipController;
var lives: SpaceshipController;

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);
	direction = 0;
	health = 20;
}

function Update () {

	if (transform.position.x > 9)
	{
		transform.Translate(Vector3.left * speedX * Time.deltaTime, Space.World);
	}
	else
	{
		if (direction == 0)
		{
			transform.Translate(Vector3.up * speedX * Time.deltaTime, Space.World);
			if (this.transform.position.y >= 8)
			{
				direction = 1;
			}
		}
		else
		{
			transform.Translate(Vector3.down * speedX * Time.deltaTime, Space.World);
			if (this.transform.position.y <= -8)
			{
				direction = 0;
			}
		}
	}	
}

function DecreaseMiddleHealth()
{
	health--;
	if(health == 0)
	{ 
		score.score = score.score + 10;
		Destroy(this.gameObject);
		Destroy(GameObject.FindGameObjectWithTag("Boss1TMid"));
		Destroy(GameObject.FindGameObjectWithTag("Boss1TRight"));
		Destroy(GameObject.FindGameObjectWithTag("Boss1TLeft"));
		Destroy(GameObject.FindGameObjectWithTag("Boss1Right"));
		Destroy(GameObject.FindGameObjectWithTag("Boss1Left"));
		if (Application.loadedLevelName == "LevelOne")
		{
			Application.LoadLevel("LevelTwo");
		}
	}
}