I got my AS2 code messed up when translating to AS3..
Help?
/** * Car Movement - Accelerate, Brake, Rotate & Reverse * * Version: 1.0 * Author: Philip Radvan * URL: http://www.freeactionscript.com */
//Settings var speed:Number = 0; var speedMax:Number = 6; var speedMaxReverse:Number = -2; var speedAcceleration:Number = .15; var speedDeceleration:Number = .90; var groundFriction:Number = .95;
var steering:Number = 0; var steeringMax:Number = 1; var steeringAcceleration:Number = .10; var steeringFriction:Number = .98;
var velocityX:Number = 0; var velocityY:Number = 0; var radiance:Number = 180/Math.PI;
/** * Main game loop */ function runGame():Void { // UP Arrow or W (accelerate) if (Key.isDown(Key.UP) || Key.isDown(87)){ //check if below speedMax if (speed < speedMax){ //speed up speed += speedAcceleration; //check if above speedMax if (speed > speedMax){ //reset to speedMax speed = speedMax; } } } // DOWN Arrow or S (reverse) if (Key.isDown(Key.DOWN) || Key.isDown(83)){ //check if below speedMaxReverse if (speed > speedMaxReverse){ //speed up (in reverse) speed -= speedAcceleration; //check if above speedMaxReverse if (speed < speedMaxReverse){ //reset to speedMaxReverse speed = speedMaxReverse; } } } // LEFT Arrow or A (turn left) if (Key.isDown(Key.LEFT) || Key.isDown(65)){ //turn left steering -= steeringAcceleration; //check if above steeringMax if (steering > steeringMax){ //reset to steeringMax steering = steeringMax; } } // RIGHT Arrow or D (turn right) if (Key.isDown(Key.RIGHT) || Key.isDown(68)){ //turn right steering += steeringAcceleration; //check if above steeringMax if (steering < -steeringMax){ //reset to steeringMax steering = -steeringMax; } } // SPACE (brake) if (Key.isDown(Key.SPACE)){ speed *= speedDeceleration; } // friction speed *= groundFriction; // ideal changes var idealXMovement = speed*Math.cos(radiance); var idealYMovement = speed*Math.sin(radiance); // real change velocityX += (idealXMovement-velocityX)*groundFriction; velocityY += (idealYMovement-velocityY)*groundFriction; // update position player_mc._x += velocityX; player_mc._y += velocityY;
// rotate radiance += (steering*speed)*.025; player_mc._rotation = radiance*180/Math.PI; //Fix Steering (make car go straight after driver stops turning) steering -= (steering*0.1); }
/** * onEnterFrame function to repeat runGame() over and over */ player_mc.onEnterFrame = function() { runGame() }