stop();
function startLevel() {
	// ship stationary
	ship.dx = 0.0;
	ship.dy = 0.0;
	// new arrays
	bullets = new Array();
	rocks = new Array();
	// start using movie clip level 0
	level = 0;
	
	// add new rocks = number of level + 1
	for(i=0;i
		newRock(100,0,0);
	}
	// all to fire right away
	timeOfLastFire = 0;
}
	
function shipTurn(amt) {
	// rotate the ship
	ship._rotation += amt;
}
//function shipThrust() {
	// thrust ship in direction it faces
	//ship.dx += Math.cos(2.0*Math.PI*(ship._rotation-90)/360.0);
	//ship.dy += Math.sin(2.0*Math.PI*(ship._rotation-90)/360.0);
	// show engines firing
	//ship.gotoAndPlay("thrust");
//}
function shipBreak() {
	// stop ship
	ship.dx = 0;
	ship.dy = 0;
}
function shipFire() {
	// make sure enough time has passed since last fire
	if (timeOfLastFire+200 < getTimer()) {
		// remember time of this fire
		timeOfLastFire = getTimer();
		// create bullet
		level++;
		attachMovie("bullet","bullet"+level,level);
		// set bullet location and direction
		clip = _root["bullet"+level];
		clip._x = ship._x;
		clip._y = ship._y;
		clip.dx = 10.0*Math.cos(2.0*Math.PI*(ship._rotation-90)/360.0);
		clip.dy = 10.0*Math.sin(2.0*Math.PI*(ship._rotation-90)/360.0);
		// add to bullets array
		bullets.push(clip);
	}
}
function shipMove() {
	// move ship horizontally and wrap
	ship._x += ship.dx;
	if (ship._x > 550) ship._x -= 550;
	if (ship._x < 0) ship._x += 550;
	// move ship vertically and wrap
	ship._y += ship.dy;
	if (ship._y > 400) ship._y -= 400;
	if (ship._y < 0) ship._y += 400;
}
function bulletsMove() {
	// loop through all bullets
	for(i=bullets.length-1;i>=0;i--) {
		// move ship horizontally and vertically
		bullets[i]._x += bullets[i].dx;
		bullets[i]._y += bullets[i].dy; 
		// see whether the bullet is off the edge of the screen
		if ((bullets[i]._x > 550) or (bullets[i]._x < 0) or (bullets[i]._y > 400) or (bullets[i]._y < 0)) {
			// remove clip and array item
			bullets[i].removeMovieClip();
			bullets.splice(i,1);
		}
	}
}
function newRock(size,x,y) {
	// create rock clip
	level++;
	rockNum = int(Math.random()*3+1);
	attachMovie("rock"+rockNum,"rock"+level,level);
	// set rock location and size
	clip = _root["rock"+level];
	clip._x = x;
	clip._y = y;
	clip._xscale = size;
	clip._yscale = size;
	// set rock speed and direction
	clip.dx = Math.Random()*gameLevel+.5;
	if (Math.random() < .5) clip.dx *= -1;
	clip.dy = Math.Random()*gameLevel+.5;
	if (Math.random() < .5) clip.dy *= -1;
	// set rock spin
	clip.spin = Math.random()*6-3;
	// add rock to rocks array
	rocks.push(clip);
}
function rocksMove() {
	// loop through all rocks
	for(i=rocks.length-1;i>=0;i--) {
		clip = rocks[i].clip;
		// move rock horizontally and wrap
		rocks[i]._x += rocks[i].dx;
		if (rocks[i]._x > 550) rocks[i]._x -= 550;
		if (rocks[i]._x < 0) rocks[i]._x +=  550;
	
		// move rock vertically and wrap
		rocks[i]._y += rocks[i].dy;
		if (rocks[i]._y >330) rocks[i]._y -= 330;
		if (rocks[i]._y < 0) rocks[i]._y += 330;
		// spin rock
		rocks[i]._rotation += rocks[i].spin;
	}
}
function checkHits() {
	// loop through all rocks
	for(i=rocks.length-1;i>=0;i--) {
		// loop through all bullets
		for(j=bullets.length-1;j>=0;j--) {
			// see whether bullet hit rock
			if (rocks[i].hitTest(bullets[j]._x,bullets[j]._y,true)) {
				// remove bullet
				bullets[j].removeMovieClip();
				bullets.splice(j,1);
				// get size and location of new rocks
				newsize = rocks[i]._xscale / 2;
				x = rocks[i]._x;
				y = rocks[i]._y;
				// remove rock
				rocks[i].removeMovieClip();
				rocks.splice(i,1);
				// create two new rocks in its place
				if (newsize >= 25)  {
					newRock(newsize,x,y);
					newRock(newsize,x,y);
				}
				// increase score
				score++;
				// no need to keep checking bullets against this rock
				break;
			}
		}
		// see whether rock hits ship
		if (rocks[i].hitTest(ship._x,ship._y,true)) {
			// see whether there are not more lives
			if (lives < 1) {
				removeAll();
				gotoAndPlay("game over");
			// life left, deduct life
			} else {
				removeAll();
				lives--;
				gotoAndPlay("ship hit");
			}
		}
	}
	// see whether there are no more rocks
	if (rocks.length == 0) {
		removeAll();
		gotoAndPlay("level over");
		gameLevel++;
	}
}
function removeAll() {
	// remove all bullets
	for(i=0;i
		bullets[i].removeMovieClip();
	}
	// remove all rocks
	for(i=0;i
		rocks[i].removeMovieClip();
	}
}