/*	 pixel, 2004
	mailto:pixel@fm.com.ua
*/
_quality = "medium";
_root.createEmptyMovieClip('back', 0);
back.beginFill(0x000000);
back.moveTo(0, 0);
back.lineTo(0, 300);
back.lineTo(400, 300);
back.lineTo(400, 0);
back.endFill();
_root.createEmptyMovieClip('start', 5);
start.lineStyle(2, 0xFFFFFF);
start.beginFill(0x000000);
start.lineTo(75, 0);
start.lineTo(75, 25);
start.lineTo(0, 25);
start.lineTo(0, 0);
start.endFill();
start.createTextField('start', 0, 0, 4, 75, 20);
start.start.text = "start";
form = new TextFormat();
form.color = 0xFFFFFF;
form.font = "Verdana";
form.size = 10;
start.start.selectable = 0;
form.align = "center";
start.start.setTextFormat(form);
start._x = back._width/2-start._width/2;
start._y = back._height/2-start._height/2;
start.onPress = function() {
	for (i=1; i<=ship.metcount; i++) {
		removeMovieClip(_root.empty['meteor'+i]);
	}
	ship.met = 0;
	ship.metcount = 0;
	ship.lives = 3;
	ship.scores = 0;
	pan.lives.text = 'lives '+ship.lives;
	pan.lives.setTextFormat(format);
	pan.scores.text = 'scores '+ship.scores;
	pan.scores.setTextFormat(format);
	ship.lev = 1;
	beginLev(ship.lev);
	ship._visible = 1;
	this._visible = 0;
};
_root.createEmptyMovieClip('empty', 1);
empty.createEmptyMovieClip('ship', 9999998);
ship = _root.empty.ship;
ship._x = _root.back._width/2-ship._width/2;
ship._y = _root.back._height/2-ship._height/2;
ship.lineStyle(1, 0xFFFFFF);
ship.beginFill(0x000000);
ship.moveTo(0, -7.5);
ship.lineTo(-5, 7.5);
ship.lineTo(0, 5);
ship.lineTo(5, 7.5);
ship.lineTo(0, -7.5);
ship.endFill();
ship._visible = 0;
ship.createEmptyMovieClip('fire', 1);
fire = ship.fire;
fire.lineStyle(0, 0xFFFFFF);
fire.moveTo(-1.25, 6.25);
fire.lineTo(0, 10);
fire.lineTo(1.25, 6.25);
fire._visible = 0;
ship.power = 0.1;
ship.slower = 0.99;
ship.maxspeed = 2;
ship.count = 0;
ship.lastshoot = 0;
ship.shells = 0;
ship.maxshells = 4;
ship.metcount = 0;
ship.mets = 0;
ship.lev = 1;
ship.scores = 0;
ship.lives = 3;
_root.createEmptyMovieClip('pan', 9999999);
pan._y = back._height+1;
pan.beginFill(0x000000, 100);
pan.lineTo(back._width, 0);
pan.lineTo(back._width, 18);
pan.lineTo(0, 18);
pan.lineTo(0, 0);
pan.endFill();
format = new TextFormat();
format.size = 9;
format.color = 0xFFFFFF;
format.font = "Verdana";
pan.createTextField('lives', 0, 10, 1.5, 50, 20);
pan.createTextField('scores', 1, 110, 1.5, 100, 20);
pan.createTextField('level', 2, 60, 1.5, 50, 20);
pan.lives.text = 'lives '+ship.lives;
pan.lives.setTextFormat(format);
pan.scores.text = 'scores '+ship.scores;
pan.scores.setTextFormat(format);
pan.level.text = 'level '+ship.lev;
pan.level.setTextFormat(format);
empty.createEmptyMovieClip('bullet', -1);
bullet = _root.empty.bullet;
function kill(mc, bul, newsize) {
	ship.shells--;
	removeMovieClip(_root.empty['bullet'+bul]);
	if (newsize>0) {
		createMeteor(newsize, mc._x, mc._y);
		createMeteor(newsize, mc._x, mc._y);
	}
	if (newsize == 2) {
		ship.scores += 10;
		pan.scores.text = 'scores '+ship.scores;
		pan.scores.setTextFormat(format);
	}
	if (newsize == 1) {
		ship.scores += 20;
		pan.scores.text = 'scores '+ship.scores;
		pan.scores.setTextFormat(format);
	}
	if (newsize == 0) {
		ship.scores += 50;
		pan.scores.text = 'scores '+ship.scores;
		pan.scores.setTextFormat(format);
	}
	removeMovieClip(mc);
	ship.mets--;
	if (ship.mets == 0) {
		ship.lev++;
		beginLev(ship.lev);
	}
}
function newship() {
	ship._visible = 1;
	ship._x = _root.back._width/2;
	ship._y = _root.back._height/2;
	clearInterval(ship.inter);
	ship.xSpeed = 0;
	ship.ySpeed = 0;
}
function createMeteor(size, xx, yy) {
	empty.createEmptyMovieClip('meteor'+ship.metcount, 100+ship.metcount);
	meteor = _root.empty['meteor'+ship.metcount];
	meteor.beginFill(0x000000);
	meteor.lineStyle(1, 0xFFFFFF);
	x1 = (random(15)-20)/4*(size+1);
	y1 = (random(15)-20)/4*(size+1);
	meteor.moveTo(x1, y1);
	meteor.lineTo((random(10)-5)/4*(size+1), (random(15)-20)/4*(size+1));
	meteor.lineTo((random(15)+5)/4*(size+1), (random(15)-20)/4*(size+1));
	meteor.lineTo((random(15)+5)/4*(size+1), (random(10)-5)/4*(size+1));
	meteor.lineTo((random(15)+5)/4*(size+1), (random(15)+5)/4*(size+1));
	meteor.lineTo((random(10)-5)/4*(size+1), (random(15)+5)/4*(size+1));
	meteor.lineTo((random(15)-20)/4*(size+1), (random(15)+5)/4*(size+1));
	meteor.lineTo((random(15)-20)/4*(size+1), (random(10)-5)/4*(size+1));
	meteor.lineTo(x1, x2);
	meteor.endFill();
	meteor._x = xx;
	meteor._y = yy;
	meteor.ro = random(5)-2.5;
	meteor.xspeed = random(29)/10-1.55;
	meteor.yspeed = random(29)/10-1.5;
	meteor.onEnterFrame = function() {
		this._x += this.xspeed;
		this._y += this.yspeed;
		this._rotation += this.ro;
		if (this._x>_root.back._width) {
			this._x = 0;
		}
		if (this._x<0) {
			this._x = _root.back._width-1;
		}
		if (this._y>_root.back._height) {
			this._y = 1;
		}
		if (this._y<0) {
			this._y = _root.back._height;
		}
		for (h=0; h<ship.maxshells*2; h++) {
			if (this.hitTest(_root.empty['bullet'+h].bullet)) {
				kill(this, h, size-1);
			}
		}
		if (this.hitTest(ship) and ship._visible == 1) {
			ship._visible = 0;
			ship.inter = setInterval(newship, 2000);
			if (ship.lives == 0) {
				ship._visible = 0;
				start._visible = 1;
			} else {
				ship.lives--;
				pan.lives.text = 'lives '+ship.lives;
				pan.lives.setTextFormat(format);
				kill(this, null, size-1);
			}
		}
	};
	ship.metcount++;
	ship.mets++;
}
ship.onEnterFrame = function() {
	if (key.isDown(key.LEFT)) {
		ship._rotation -= 2;
	}
	if (key.isDown(key.RIGHT)) {
		ship._rotation += 2;
	}
	if (key.isDown(key.SPACE) and getTimer()-ship.lastshoot>=200 and ship.shells<ship.maxshells and ship._visible == 1) {
		ship.lastshoot = getTimer();
		duplicateMovieClip("bullet", 'bullet'+ship.count, ship.count);
		ship.shells++;
		_root.empty['bullet'+ship.count].createEmptyMovieClip('bullet', 0);
		_root.empty['bullet'+ship.count].bullet.lineStyle(3, 0xFFFFFF);
		_root.empty['bullet'+ship.count].bullet.lineTo(0, 1);
		_root.empty['bullet'+ship.count]._x = ship._x;
		_root.empty['bullet'+ship.count]._y = ship._y;
		_root.empty['bullet'+ship.count]._rotation = ship._rotation;
		_root.empty['bullet'+ship.count].onEnterFrame = function() {
			this.bullet._y -= 3;
			c = this.bullet._y;
			a = Math.cos(this._rotation*Math.PI/180)*c;
			b = Math.sin(this._rotation*Math.PI/180)*c;
			if ((this._y+a)<0) {
				this._y = _root.back._height-a;
			}
			if ((this._y+a)>_root.back._height) {
				this._y = 0-a;
			}
			if ((this._x-b)<0) {
				this._x = _root.back._width+b;
			}
			if ((this._x-b)>_root.back._width) {
				this._x = 0+b;
			}
			this.num++;
			if (this.num>=200) {
				ship.shells--;
				removeMovieClip(this);
			}
		};
		ship.count++;
		if (ship.count>=ship.maxshells*2) {
			ship.count = 0;
		}
	}
	if (key.isDown(key.UP)) {
		ship.xSpeed += ship.power*Math.sin(ship._rotation*(Math.PI/180));
		ship.ySpeed += ship.power*Math.cos(ship._rotation*(Math.PI/180));
		fire._visible = 1;
	} else {
		ship.xSpeed *= ship.slower;
		ship.ySpeed *= ship.slower;
		fire._visible = 0;
	}
	if (key.isDown(key.CONTROL)) {
		ship.xSpeed = 0;
		ship.ySpeed = 0;
	}
	ship.speed = Math.sqrt((ship.xSpeed*ship.xSpeed)+(ship.ySpeed*ship.ySpeed));
	if (ship.speed>ship.maxspeed) {
		ship.xspeed *= ship.maxspeed/ship.speed;
		ship.yspeed *= ship.maxspeed/ship.speed;
	}
	ship._y -= ship.yspeed;
	ship._x += ship.xspeed;
	if (ship._y>_root.back._height) {
		ship._y = 0;
	}
	if (ship._x>_root.back._width) {
		ship._x = 0;
	}
	if (ship._y<0) {
		ship._y = _root.back._height;
	}
	if (ship._x<0) {
		ship._x = _root.back._width;
	}
};
function beginLev(met) {
	ship.metcount = 0;
	ship.mets = 0;
	ship.shells = 0;
	for (i=1; i<=met; i++) {
		createMeteor(3, random(1)*_root.back._width, random(1)*_root.back._height);
	}
	pan.level.text = 'level '+ship.lev;
	pan.level.setTextFormat(format);
}
beginLev(5);
