Now that it was all drawn I could begin coding so I created my Actionscript layer. I decided that first I would code my car, however it wouldn't be easy as I wanted it to move exactly like a car rather then a dot along a road.
This proved to be incredibly tricky needing lots of vars and functions howwever I finally got it to work with gradual acceleration, stearing and reversing. This is my proudest achievement in actionscript to date. Below are all the vars I used for this part of my code:
var speed = 0;
var acceleration = 0.2;
var maxSpeed = 10;
var maxReverse = -5
var carRotation
var leftPressed
var rightPressed
var upPressed
var downPressed
var friction = 0.85
var rotationSpeed = 12
I decided it would be easier to create vars stating that a button is pressed and then creating a function using that var then to just simply have the key code scripting. Below is an example of what I did:
if ( event.keyCode == 37){
leftPressed = true;
}
if (leftPressed){
mc_car.rotation -= carRotation;
}
Thats all for now my next post will be about me conquering collision detection.
No comments:
Post a Comment