Very unfinished Asteroids game made with API.I'm still working on the shooting and more asteroids to be appearing....and other stuff....
136 lines of code.
_root.createEmptyMovieClip("ship", 1);
with (ship) {
lineStyle(2, 0xFFFFFF, 100);
beginFill(0x000000, 50);
moveTo(-1, -19);
lineTo(-12, 13);
lineTo(11, 13);
lineTo(-1, -19);
_x = 350;
_y = 225;
endFill();
}
_root.ship.onEnterFrame = function() {
with (ship) {
this.speed = 0;
if (Key.isDown(Key.UP)) {
speed = 25;
}
if (Math.abs(speed)>75) {
this.speed *= .7;
}
if (Key.isDown(Key.LEFT)) {
this._rotation -= 15;
}
if (Key.isDown(Key.RIGHT)) {
this._rotation += 15;
}
speed *= .60;
x = Math.sin(_rotation*(Math.PI/180))*speed;
y = Math.cos(_rotation*(Math.PI/180))*speed*-1
;
if (!_root.land.hitTest(_x+x, _y+y, true)) {
_x += x;
_y += y;
} else {
speed *= -.8;
}
if (_x>700) {
_x = 0;
}
if (_x<0) {
_x = 700;
}
if (_y>450) {
_y = 0;
}
if (_y<0) {
_y = 450;
}
ship.swapDepths(3);
}
};
_root.createEmptyMovieClip("ast", 2);
with (ast) {
lineStyle(2, 0xFFFFFF, 100);
beginFill(0x000000, 50);
moveTo(-1, -21);
lineTo(-20, -11);
lineTo(-28, 8);
lineTo(-17, 27);
lineTo(11, 32);
lineTo(24, 18);
lineTo(22, -9);
lineTo(-1, -21);
endFill();
}
_root.ast.onEnterFrame = function() {
with (ast) {
this._rotation += 3;
_x += 1;
_y -= 1;
if (_x>700) {
_x = 0;
}
if (_x<0) {
_x = 700;
}
if (_y>450) {
_y = 0;
}
if (_y<0) {
_y = 450;
}
}
};
_root.createEmptyMovieClip("bullet", 3);
with (bullet) {
lineStyle(2, 0xFFFFFF, 100);
beginFill(0xFFFFFF, 100);
moveTo(-4.34999999999999, -3.89999999999998);
curveTo(0, -7, 0, -3);
curveTo(1, 2, -3, 1);
curveTo(-8, -1, -3, -4);
endFill();
}
_root.bullet.onLoad = function() {
with (bullet) {
spd = 50;
_x = _root.ship._x;
_y = _root.ship._y;
_rotation = _root.ship._rotation;
}
};
_root.bullet.onEnterFrame = function() {
with (bullet) {
if (_name == "bullet") {
_x = -1000;
} else {
if (_rotation>180) {
_y += (spd*Math.cos(Math.PI/180*_rotation));
_x -= (spd*Math.sin(Math.PI/180*_rotation));
} else {
_y -= (spd*Math.cos(Math.PI/180*_rotation));
_x += (spd*Math.sin(Math.PI/180*_rotation));
}
}
if (_x>Stage.width || _x<0 || _y<0 || _y>Stage.height) {
this.removeMovieClip();
}
}
};
_root.bullet.onLoad = function() {
with (bullet) {
var bc = 0;
}
};
_root.bullet.onEnterFrame = function() {
with (bullet) {
_root.onMouseDown = function() {
bc++;
if (bc>1010) {
bc = 0;
}
duplicateMovieClip("bullet", "b"+bc, bc);
};
}
};
And yes,I'm sure there is a problem for the bullet at the bottom.