This is my second example using 45 lines of code. As you can tell the coding is a lot more advanced and includes rotation and friction.
Thanks people and send me money . Ill use it wisely :)
After comments im including the code i put on the car to enable the movement
onClipEvent(load){
var speed = 0;
}
onClipEvent (enterFrame) {
if(Key.isDown(Key.UP)){
speed += 1.5;
}
if (Key.isDown (Key.RIGHT)) {
if (speed < 5 && speed >= 0) {
_rotation += 2 * speed;
} if (speed < 0) {
_rotation += 7.5 * speed / 15;
} else {
_rotation += 7.5;
}
speed *= 0.95;
}
if(Key.isDown(Key.LEFT)){
if (speed < 5 && speed >= 0) {
_rotation -= 2 * speed;
} if (speed < 0) {
_rotation -= 7.5 * speed / 15;
} else {
_rotation -= 7.5;
}
speed *= 0.95;
}
if(Key.isDown(Key.DOWN)){
speed -= 0.8;
}
speed = speed * 0.98;
x += Math.sin (rotation * Math.PI / 180) * speed;
y += Math.cos (rotation * Math.PI / 180) * -speed;
if (Math.abs (speed) > 20) {
speed = 20;
}
if (speed < -10) {
speed = -10;
}
if (Key.isDown (Key.CONTROL)) {
speed -= speed / 10;
}
}
Enjoy.