Wall jump

Version:

1.0

Added on:

09 Nov 2018 19:38

Tags:

Description:
Lets all rabbit players slide down walls and jump off of them, similar to the wall jump mechanics in Hollow Knight.
  1. class PlayerWallJumpProperties {
  2.   uint Stage = 0;
  3.   bool FacingRight;
  4.   int LastSlidingTick = 0;
  5.   bool PressingJumpOneTickAgo = false;
  6.   PlayerWallJumpProperties(){}
  7. }
  8. array<PlayerWallJumpProperties> PlayerWallJumpPropertiesArray(jjLocalPlayerCount);
  9.  
  10. void onPlayer(jjPLAYER@ play) {
  11.   PlayerWallJumpProperties@ wallJumpProperties = @PlayerWallJumpPropertiesArray[play.localPlayerID];
  12.   const bool pressingJump = play.keyJump;
  13.   if (
  14.     pressingJump &&
  15.     !wallJumpProperties.PressingJumpOneTickAgo &&
  16.     wallJumpProperties.Stage < 2 &&
  17.     (jjGameTicks - wallJumpProperties.LastSlidingTick) < 10 //10 = number of ticks after technically letting go of the wall during which you can still start the jump. Higher numbers are more generous.
  18.   ) {
  19.     wallJumpProperties.Stage = 2;
  20.     jjSample(play.xPos, play.yPos, SOUND::COMMON_JUMP);
  21.     play.ySpeed = play.jumpStrength;
  22.     play.helicopter = 0;
  23.     play.doubleJumpCount = 0;
  24.   } else if (wallJumpProperties.Stage > 1) {
  25.     if (++wallJumpProperties.Stage == 20)
  26.       wallJumpProperties.Stage = 0;
  27.     else {
  28.       play.keyRight = wallJumpProperties.FacingRight;
  29.       play.keyLeft = !wallJumpProperties.FacingRight;
  30.       play.keyJump = true;
  31.       play.helicopter = 0;
  32.     }
  33.   } else {
  34.     const auto anim = play.curAnim - jjAnimSets[play.setID];
  35.     const int xPosToTest = int(play.xPos) + (play.keyRight ? 13 : -13);
  36.     uint16 tileIDToTest;
  37.     if (
  38.       (anim == RABBIT::FALL || anim == RABBIT::HELICOPTER) &&
  39.       (play.keyRight || play.keyLeft) &&
  40.       (jjMaskedPixel(xPosToTest, int(play.yPos)-8) && jjMaskedPixel(xPosToTest, int(play.yPos)+8))
  41.       //put any additional conditions, e.g. events or tiles you can't slide on, here.
  42.     ) {
  43.       play.helicopter = 0;
  44.       wallJumpProperties.Stage = 1;
  45.       wallJumpProperties.FacingRight = play.keyLeft;
  46.       play.ySpeed = 0.25; //modify as desired if you don't like this sliding speed
  47.       play.keyJump = false;
  48.       wallJumpProperties.LastSlidingTick = jjGameTicks;
  49.     } else if (wallJumpProperties.Stage == 1)
  50.       wallJumpProperties.Stage = 0;
  51.   }
  52.   if (play.invisibility = wallJumpProperties.Stage == 1) { //this works for SP, but for MP you'd probably instead want to give everyone SPRITE::INVISIBLE all the time and draw non-local players in an onMain loop.
  53.     if (play.blink == 0 || ((jjRenderFrame >> 2) & 1) == 1) {
  54.       const int vDir = !play.antiGrav ? 1 : -1;
  55.       jjDrawRotatedSprite(play.xPos - play.direction * 3, play.yPos, play.setID, RABBIT::SKID1, jjGameTicks>>4, 256 * play.direction * vDir, -play.direction, vDir, SPRITE::PLAYER, play.playerID);
  56.     }
  57.   }
  58.   wallJumpProperties.PressingJumpOneTickAgo = pressingJump;
  59. }