Create a Flash game like Metro Siberia Underground – AS3 version
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.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
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.<Fuel>=new Vector.<Fuel>(); private var rockVector:Vector.<Rock>=new Vector.<Rock>(); private var smokeVector:Vector.<Smoke>=new Vector.<Smoke>(); 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()*1000<fuelFrequency) { var fuel:Fuel=new Fuel(); fuel.y=Math.random()*400+40; fuel.x=650; fuel.filters=new Array(fuelFilter); fuelCanvas.addChild(fuel); fuelVector.push(fuel); } if (Math.random()*1000<rockFrequency) { var rock:Rock=new Rock(); rock.y=Math.random()*400+40; rock.x=670; rock.rotation=Math.random()*360; rock.filters=new Array(rockFilter); rockCanvas.addChild(rock); rockVector.push(rock); } distance+=xspeed; score.scoreText.text="Distance: "+distance+" - "+"Fuel: "+gasoline; if ((gasoline>0)&&(engines)) { yspeed-=thrust; smokeInterval-=0.25; gasoline-=1; framesPassed++; if (smokeInterval<framesPassed) { var smoke:Smoke=new Smoke(); smoke.x=ship.x; smoke.y=ship.y; smoke.filters=new Array(smokeFilter); smokeCanvas.addChild(smoke); smokeVector.push(smoke); framesPassed=0; smokeInterval-=0.01; } } yspeed+=gravity; ship.y+=yspeed; angle=Math.atan2(yspeed,xspeed); ship.rotation=angle*180/Math.PI; for (var i:int=fuelVector.length-1; i>=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.<Rock>(); removeChild(rockCanvas); rockCanvas=new Sprite(); addChild(rockCanvas); fuelVector=new Vector.<Fuel>(); removeChild(fuelCanvas); fuelCanvas=new Sprite(); addChild(fuelCanvas); smokeVector=new Vector.<Smoke>(); 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.
They can be easily customized to meet the unique requirements of your project.





(8 votes, average: 4.88 out of 5)








This post has 6 comments
Gordon
I already made a “Box2D helicopter game” called Rubble Racer (http://irregulargames.com/rubble-racer/) ;)
Mario
Waiting for helicopter game tutorial :)
Yakup TA?LIBEYAZ
is a great application
Franklin
How can I add a game menu to this? I tried adding a scene in flash cs6 but it doesn’t work, I’ve been trying for hours.
Any help?
benny qibal
thnks so much i love your blog + for your share, thankyu guys
(New Game) Little Spaceship - Talk Arcades
[...] good job swapping two MovieClips, adding your logo and leaderboard :-) http://www.emanueleferonato.com/2012…d-as3-version/ __________________ Click to publish! Free Multiplayer Online Games | Play & Download Online [...]