Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by Gamma

How would I make it so that if you clicked the UP arrow, the player would jump once, and if you click it again the player would jump twice with a different amount of velocity than the first jump and a different kind of frame.

1 decade ago by tarrent

You should record 'pairs' of jumps, for example if 1st jump is pressed, the 2nd jump press would be associated with it. Maybe a 'stack' structure would be ok to record these,

// stack to record 2 consecutive jumps
var jumpStack = [];

if(ig.input.pressed('jump')) {
  // record 'pairs' of jumps
  if(jumpStack.length == 0) {
    jumpStack.push(1);
  
    // do code for 1st jump here...
  }

  // pop if 'pair' of jump has been recorded
  if(jumpStack.length == 1) {
    // empty jump stack for next 'pair' of jumps
    jumpStack = [];

   // do code for 2nd jump here...
  }
}

'Hope this algo helps :)

1 decade ago by jswart

Quote from tarrent
You should record 'pairs' of jumps, for example if 1st jump is pressed, the 2nd jump press would be associated with it. Maybe a 'stack' structure would be ok to record these,

// stack to record 2 consecutive jumps
var jumpStack = [];

if(ig.input.pressed('jump')) {
  // record 'pairs' of jumps
  if(jumpStack.length == 0) {
    jumpStack.push(1);
  
    // do code for 1st jump here...
  }

  // pop if 'pair' of jump has been recorded
  if(jumpStack.length == 1) {
    // empty jump stack for next 'pair' of jumps
    jumpStack = [];

   // do code for 2nd jump here...
  }
}

'Hope this algo helps :)


This is a good idea but I wouldn't use an array. I would just use an integer counter.

jumpCounter = 0;

if(ig.input.pressed('jump')) {
    if ( jumpCounter == 2 ) {
        // do stuff for double jump here
        jumpCounter = 0;  // reset counter
    }
    else {
    // do stuff for regular jump
        // ...
    }
    jumpCounter++;
}

You would also probably want to add a timer to make sure the double jump is entered within a period of time, and then if the delta from jump 2 is outside of the limit reset the jumpCounter to 0.

1 decade ago by Gamma

Thanks for the help guys!

1 decade ago by ShawnSwander

you also could set a booleon varriable and have an
//pseudocode
 if key pressed &&if(player.is_in_the_air) 

somewhat of a minor game-state change.

1 decade ago by jswart

Quote from ShawnSwander
you also could set a booleon varriable and have an
//pseudocode
 if key pressed &&if(player.is_in_the_air) 

somewhat of a minor game-state change.


This is a good idea. You would need to write it like this though:

if ( key_pressed && player.is_in_the_air ) {
    // do stuff
}
Page 1 of 1
« first « previous next › last »