Trailer : Adobe flash cs4 Game tutorial : Velocity








var Key:KeyObject=new KeyObject(stage);



ship.stop();



var speed:Number=0;



var friction:Number=.98;



stage.addEventListener(Event.ENTER_FRAME,onenter);



function onenter(e:Event):void {



if (ship.x>590) {

ship.x=-20;

}

if (ship.x<-30) { ship.x=580; } if (ship.y>510) {

ship.y=-20;

}

if (ship.y<-30) { ship.y=500; } if (Key.isDown(Key.LEFT)) { ship.rotation-=5; } if (Key.isDown(Key.RIGHT)) { ship.rotation+=5; } if (Key.isDown(Key.UP)) { speed-=.5; ship.gotoAndStop(2); }else{ ship.gotoAndStop(1); } var angle:Number = ship.rotation*Math.PI/180; var vx:Number=Math.cos(angle)*speed; var vy:Number=Math.sin(angle)*speed; ship.x+=vx; ship.y+=vy; speed*=friction; if (Math.abs(speed)<0.0009) { speed=0; } }

Blog Archive