Talking about Metro Siberia Underground game, Actionscript 3, Flash and Game development.
More than 4 years ago I played a really fun game called Metro Siberia Underground, basically an helicopter game, and made an AS2 prototype.
Now I ported it into AS3 because I think the prototype can be improved or ported into other languages, and because I always liked one-button games.
The code is not commented because the entire logic behind it has been already explained in the original post.
package {
import flash.display.Sprite;
import flash.filters.GlowFilter;
import flash.events.Event;
import flash.events.MouseEvent;
public class Main extends Sprite {
private var shipFilter:GlowFilter=new GlowFilter(0x00ff00,0.8,4,4,2,3,false,false);
private var smokeFilter:GlowFilter=new GlowFilter(0xff0000,0.8,4,4,2,3,false,false);
private var fuelFilter:GlowFilter=new GlowFilter(0x00ffff,0.8,4,4,2,3,false,false);
private var rockFilter:GlowFilter=new GlowFilter(0xffffff,0.8,4,4,2,3,false,false);
private var scoreFilter:GlowFilter=new GlowFilter(0xff00ff,0.8,2,4,2,3,false,false);
private var gravity:Number=0.1;
private var thrust:Number=0.25;
private var yspeed:Number=0;
private var xspeed:Number=5;
private var distance:Number=0;
private var smokeInterval:Number=10;
private var framesPassed:Number=0;
private var fuelFrequency:Number=10;
private var gasoline:Number=500;
private var rockFrequency:Number=50;
private var engines:Boolean=false;
private var ship:Ship=new Ship();
private var score:Score=new Score();
private var rockCanvas:Sprite=new Sprite();
private var fuelCanvas:Sprite=new Sprite();
private var smokeCanvas:Sprite=new Sprite();
private var fuelVector:Vector.=new Vector.();
private var rockVector:Vector.=new Vector.();
private var smokeVector:Vector.=new Vector.();
public function Main() {
addChild(ship);
ship.x=120;
ship.y=240;
ship.filters=new Array(shipFilter);
addChild(score);
addChild(rockCanvas);
addChild(fuelCanvas);
addChild(smokeCanvas);
score.filters=new Array(scoreFilter);
addEventListener(Event.ENTER_FRAME,update);
stage.addEventListener(MouseEvent.MOUSE_DOWN,engineOn);
stage.addEventListener(MouseEvent.MOUSE_UP,engineOff);
}
private function engineOn(e:MouseEvent):void {
engines=true;
framesPassed=smokeInterval;
}
private function engineOff(e:MouseEvent):void {
engines=false;
smokeInterval=10;
}
private function update(e:Event):void {
if (Math.random()*10000)&&(engines)) {
yspeed-=thrust;
smokeInterval-=0.25;
gasoline-=1;
framesPassed++;
if (smokeInterval=0; i--) {
fuelVector[i].x-=xspeed*1.2;
var dist_x:Number=ship.x+28*Math.cos(angle)-fuelVector[i].x;
var dist_y:Number=ship.y+28*Math.sin(angle)-fuelVector[i].y;
var dist:Number = Math.sqrt(dist_x*dist_x+dist_y*dist_y);
if (dist<10) {
gasoline+=100;
fuelCanvas.removeChild(fuelVector[i]);
fuelVector.splice(i,1);
}
else {
if (fuelVector[i].x<-10) {
fuelCanvas.removeChild(fuelVector[i]);
fuelVector.splice(i,1);
}
}
}
for (i=rockVector.length-1; i>=0; i--) {
rockVector[i].x-=xspeed;
if (rockVector[i].x<-20) {
rockCanvas.removeChild(rockVector[i]);
rockVector.splice(i,1);
}
}
for (i=smokeVector.length-1; i>=0; i--) {
smokeVector[i].x-=xspeed;
smokeVector[i].width+=0.2;
smokeVector[i].height+=0.2;
smokeVector[i].alpha-=0.04;
if (smokeVector[i].alpha<0) {
smokeCanvas.removeChild(smokeVector[i]);
smokeVector.splice(i,1);
}
}
if (ship.y>480 || ship.y<0 || rockCanvas.hitTestPoint(ship.x+28*Math.cos(angle), ship.y+28*Math.sin(angle), true) || rockCanvas.hitTestPoint(ship.x+8*Math.cos(angle+Math.PI/2), ship.y+8*Math.sin(angle+Math.PI/2), true) || rockCanvas.hitTestPoint(ship.x+8*Math.cos(angle-Math.PI/2), ship.y+8*Math.sin(angle-Math.PI/2), true)) {
yspeed=0;
ship.y=200;
gasoline=500;
distance=0;
rockVector=new Vector.();
removeChild(rockCanvas);
rockCanvas=new Sprite();
addChild(rockCanvas);
fuelVector=new Vector.();
removeChild(fuelCanvas);
fuelCanvas=new Sprite();
addChild(fuelCanvas);
smokeVector=new Vector.();
removeChild(smokeCanvas);
smokeCanvas=new Sprite();
addChild(smokeCanvas);
}
}
}
}
and this is the result:
Press mouse button to fly. I am also thinking about a Box2D helicopter game, it would be interesting.
Never miss an update! Subscribe, and I will bother you by email only when a new game or full source code comes out.