Momentum gain

Version:

4.0

Added on:

26 Aug 2019 11:51

Tags:

Description:
This simple script changes the running mechanics. Instead of simply holding a button in order to achieve greater movement velocity, you now have to build up enough momentum in order to be able to run. This can be accomplished in two ways - either by holding a movement key for a long enough duration (two seconds to be exact), or by gaining speed via some kind of enabling feature, for example a horizontal spring or pole. You lose your momentum if you release the movement key, change direction or bump into something.

EDIT: Minor improvement.

EDIT 2: Enabled intermediate running speeds between jogging and sprinting.
int warmupTime = 0;

void onPlayerInput(jjPLAYER@ play) {
  if ((play.keyLeft == true || play.keyRight == true) && play.xSpeed != 0) {
    warmupTime++;
  } else {
    warmupTime = 0;
  }

  if ((play.keyLeft == true && play.direction == 1) || (play.keyRight == true && play.direction == -1)) {
    warmupTime = 0;
  }

  if (warmupTime >= 35 || play.xSpeed > 8 || play.xSpeed < -8) {
    play.keyRun = true;
    if (warmupTime > 0 && warmupTime < 105 && play.xSpeed > -8 && play.xSpeed < 8) {
      play.xSpeed = play.xSpeed * 0.95;
    }
  } else {
    play.keyRun = false;
  }
}