I'm programming a little Mario game.
Now when the player is pressing left, the character is running left.
Now lets say the players press's up to jump. That immediately disables the left button that the player is still holding. Which is the problem.
Here is how I programed the keys
addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent arg0) {
int key=arg0.getKeyCode();
if(key==KeyEvent.VK_LEFT){
mario.moveLeft();
}else if(key==KeyEvent.VK_RIGHT){
mario.moveRight();
}else if(key==KeyEvent.VK_UP){
mario.startJumpSequence();
}else if(key==KeyEvent.VK_END){
running=false;
}
}
});
So how can I make Mario move left when the player presses left, but when the player presses up (still holding left) mario jumps and moves left?
Just to recap, I'm pressing left for Mario to move left. Now i want to jump as im moving left; as soon as I hit the up key, mario jumps but "forgets" to move left even though i never release "left".
How to fix this?
Thank you for your time and help in advance
jenia