A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: 2 Player Car Game

Hybrid View

  1. #1
    Junior Member
    Join Date
    Mar 2006
    Posts
    24

    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;
    }
    }

  2. #2
    Junior Member
    Join Date
    Mar 2006
    Posts
    24
    Please?

  3. #3
    Amiga freak Ironclaw's Avatar
    Join Date
    Jan 2001
    Location
    Sweden
    Posts
    1,651
    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

  4. #4
    Member
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    82
    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.

  5. #5
    Amiga freak Ironclaw's Avatar
    Join Date
    Jan 2001
    Location
    Sweden
    Posts
    1,651
    - message deleted -
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center