A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Second Player Car Movement

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

    Second Player Car Movement

    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
    Senior Member DrDoom's Avatar
    Join Date
    Apr 2006
    Posts
    144
    Use the flash key codes listed in the help file.

    W is 87 so you would say if(Key.isDown(87)) {

    A is 65
    S is 83
    D is 68

    Key.LEFT, for example, is nothing special. Its just a variable within the Key class with the value of 36 (the flash key code for the left arrow button). Key.isDown(Key.LEFT) is actually just the same as Key.isDown(36).

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