-
2 Player Car Game
I want to make a 2 player car game, and I have one player, the buttons are up, down, left and right. I want the second player's buttons to be w, s , a, and d. How can I do this? This is the movement script, please change it so that the buttons I listed will be used for the same script.
onClipEvent (enterFrame) {
// This code will advance the car forward.
if (Key.isDown(Key.UP)) {
speed += .5;
}
// This will make the car go backwards
if (Key.isDown(Key.DOWN)) {
speed -= .5;
}
// The car will start to slow down after the speed of 10
if (Math.abs(speed)>5) {
speed *= .5;
}
// This will change the angle of the car
if (Key.isDown(Key.LEFT)) {
_rotation -= 4;
}
if (Key.isDown(Key.RIGHT)) {
_rotation += 4;
}
// here is where the hittest is for the boundary
speed *= .98;
x = Math.sin(_rotation*(Math.PI/180))*speed;
y = Math.cos(_rotation*(Math.PI/180))*speed*-1;
if (!_root.land.hitTest(_x+x, _y+y, true)) {
_x += x;
_y += y;
} else {
speed *= -.6;
}
}
-
-
Amiga freak
Here's the numbers for each key: http://docs.sarkis-webdesign.com/fla...pendix_c2.html
use them like: if (Key.isDown(87)) { for W
-
You'll also want to make sure that you differentiate between the players speed and rotation variables. If you give that code to both of them, and only change the keycodes, one player pressing forward will set the speed variable for the other one too so they both go forward!
..unless they're local variables.
-
Amiga freak
Last edited by Ironclaw; 03-26-2006 at 12:19 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|