Running uses stamina

Version:

2.0

Added on:

28 Oct 2013 20:00

Tags:

No tags added for this snippet.

Description:
Have a look at the title.
int stamina = 0;
int staminaMax = 100; //Increase this value to have more stamina.

void onPlayer(jjPLAYER@ p) {
  if (jjGameTicks%10==0 && p.xSpeed == 0) stamina++;
  if (stamina < 0) stamina = 0;
  if (stamina > staminaMax) stamina = staminaMax;
  if (p.keyRun == true && p.keyLeft == true && p.xSpeed < 4 || p.keyRun == true && p.keyRight == true && p.xSpeed > 4) {
    if (jjGameTicks%7 == 0) {
      stamina--;
    }
  }
  if (p.keyRun == false && p.keyLeft == true && p.xSpeed < 0 || p.keyRun == false && p.keyRight == true && p.xSpeed > 0) {
    if (jjGameTicks%17 == 0) stamina++;
  }
  if (stamina < 1 && p.xSpeed > 4) p.xSpeed = 4;
  if (stamina < 1 && p.xSpeed < -4) p.xSpeed = -4;
}

bool onDrawHealth(jjPLAYER@ p, jjCANVAS@ screen) {
  screen.drawString(100, 470, "STAMINA: " + stamina + "/100", STRING::SMALL, STRING::NORMAL);
  return true;
}

void onLevelLoad() {
  stamina = staminaMax;
}