A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Racing game - Please Help! How do you change the controls of the car to letter keys?

  1. #1

    Angry

    Racing game - Please Help! How do you change the controls of the car to letter keys like w is accelorate and s is slow down - etc. Right now the controls are in a bad place and i cant chage them to letter keys. Here are the game files: http://www.1matthew.com/flash/racesummer.rar . The game is posted at: http://www.1matthew.com/flash/racesummer.swf I'm still building the game. the actionscript for the blue car is:

    onClipEvent (enterFrame) {
    // make the car go forward
    if (Key.isDown(Key.HOME)) {
    speed += .5;
    }
    // make the car go backwards
    if (Key.isDown(Key.END)) {
    speed -= 1;
    }
    // tells the car to slow down after the speed of 20
    if (Math.abs(speed)>6) {
    speed *= .7;
    }
    // you can change the rotation of the car to your desire
    if (Key.isDown(Key.DELETEKEY)) {
    _rotation -= 5;
    }
    if (Key.isDown(Key.PGDN)) {
    _rotation += 5;
    }
    // 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
    Slackware 9.0 Runes_Tooth's Avatar
    Join Date
    Mar 2002
    Location
    Crono Triggyarr
    Posts
    508
    For letters you will have to use ASCII values.

    Try searching for ASCII in the search box.

  3. #3
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    You can use key codes for this, to get a list of the key codes you can make a movie clip with this clip event

    onClipEvent(keyUp) {
    trace(Key.getCode());
    }

    then you can use these values in your game, like

    if (Key.isDown(82)) {
    // do someting
    }

  4. #4
    Senior Member
    Join Date
    May 2002
    Location
    Sioux Falls, SD
    Posts
    1,155

  5. #5

    Smile

    Thanks everyone!

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