PDA

View Full Version : Two player fighting on keyboard



Chibineas
June 24th, 2006, 12:14 AM
I am making a game where two people control characters on the keyboard. Player one uses numbers (with the getASCII method) and the other one uses the arrow keys and the Key class. For some reason, the first character's motion is really choppy and whenever the arrow keys are pressed (by player two). What's wrong?

Here's my engine in a nutshell:
onClipEvent(keyDown){
key = Key.getASCII();
}
onClipEvent(keyUp){
key = 999;
}
//move p1 left if 'a' is pressed
onClipEvent(enterFrame){
if(key == 97){
playerOne.moveLeft();
}else{
playerOne.stand();
}
//move p2 left if LEFT is pressed
if(Key.isDown(Key.LEFT)){
playerTwo.moveLeft();
}else{
playerTwo.stand();
}
}

u_avi_15
June 24th, 2006, 12:39 AM
an fla would make it a lot easier to toy with:)

u_avi_15
June 24th, 2006, 12:44 AM
you could take a look at:
http://www.flashkit.com/movies/Games/Full_Game_Source/The_Figh-Weston_L-10743/index.php

Stilianos
June 24th, 2006, 12:44 AM
This would be much easier for you:)

onClipEvent(enterFrame){//player one//
if (Key.isDown(68)) {
_x += speed;
this._xscale = 100;//change this to change the size of caracter//
}
if (Key.isDown(65)) {
_x -= speed;
this._xscale = -100;//change this to change the size of caracter//
}

onClipEvent(enterFrame){//player two//
if (Key.isDown(Key.LEFT)) {
_x += speed;
this._xscale = 100;//change this to change the size of caracter//
}
if (Key.isDown(Key.RIGHT)) {
_x -= speed;
this._xscale = -100;//change this to change the size of caracter//
}