So not sure i’m asking in the right place, but:
In the platformer i’m trying to make i want to be able to have the player sprite double jump and dash, essentially a double move.
I’d like this to occur when the player presses the appropriate key twice in a short enough time frame. But i’m not sure how to monitor this.
Currently for key presses i’ve got (or will have) booleans that become ‘true’ when a key is pressed and change to false when it is released.
For the double jump (stick with this for now), should i be recording when the key is pressed or released last, ie lastJumpPress = (some call to nano time or current update count) then compare the next jump press to this value and if it is within my desired reaction time upgrade to the double move?
some crappy pseudo code
private boolean jump = false;
private boolean doubleJump = false;
private boolean moveLeft = false;
private int currentJumpTime = 0;
private int oldJumpTime = 0;
//other bools for other movements
...//other code
addKeyListener(new KeyAdapter(){
public void keyPressed(KeyEvent e){
processKeyPress(e);}
public void keyReleased(KeyEvent e){
processKeyRelease(e);}
});
...//other code
private void processkeyPress(KeyEvent e){
int KeyCode = e.getKeyCode();
If(KeyCode == KeyEvent.VK_JUMP){ //it wont be 'jump' it will be VK_UP or something
currentJumpTime = getCurrentUpdate();
If((currentJumpTime - oldJumpTime) < 10) //for example, will likely be <1/10 second
doubleJump = true;
else
jump = true;
oldJumpTime = currentJumpTime;
}
private processKeyRelease(KeyEvent e){
//something similar that switchs both booleans back to false when key released
//some other code that adds upwards velocity based on whether jump or doubleJump is true
//this movement will then begin after the crouch part in the animation of sprite
//the length of the crouch part of animation is also how quickly the double press must be made
Am i on the right track or have a made a horrible omission?
Thanks.