Limited air supply underwater

Version:

7.0

Added on:

25 Feb 2014 20:47

Tags:

Description:
Does what the title says. You can easily adjust the time it takes to drown to your liking by changing the p.timerStart() value.

EDIT: Updated the script with modifications to the shield functionality in water. Akin to Sonic 3, the bubble shield will grant you unlimited oxygen underwater (for as long as the shield lasts), whereas the fire, lightning and laser shields will fade immediately upon entering the water.

EDIT: Rewrote the whole code. Uses a uint to measure oxygen supply as opposed to the player timer. Air supply now displays as a bubble meter underneath the player health.
uint limitedOxygen = 0;

bool onDrawHealth(jjPLAYER@ play, jjCANVAS@ canvas) {
  if (limitedOxygen > 0 && limitedOxygen < 420) {
  canvas.drawSprite(jjSubscreenWidth-12, jjSubscreenHeight-454, ANIM::AMMO, 8, 3, 0, SPRITE::NORMAL, 0); canvas.drawSprite(jjSubscreenWidth-28, jjSubscreenHeight-454, ANIM::AMMO, 8, 3, 0, SPRITE::NORMAL, 0); canvas.drawSprite(jjSubscreenWidth-44, jjSubscreenHeight-454, ANIM::AMMO, 8, 3, 0, SPRITE::NORMAL, 0); canvas.drawSprite(jjSubscreenWidth-60, jjSubscreenHeight-454, ANIM::AMMO, 8, 3, 0, SPRITE::NORMAL, 0);
 canvas.drawSprite(jjSubscreenWidth-76, jjSubscreenHeight-454, ANIM::AMMO, 8, 3, 0, SPRITE::NORMAL, 0);
  }

  if (limitedOxygen > 420 && limitedOxygen < 840) {
  canvas.drawSprite(jjSubscreenWidth-12, jjSubscreenHeight-454, ANIM::AMMO, 8, 3, 0, SPRITE::NORMAL, 0); canvas.drawSprite(jjSubscreenWidth-28, jjSubscreenHeight-454, ANIM::AMMO, 8, 3, 0, SPRITE::NORMAL, 0); canvas.drawSprite(jjSubscreenWidth-44, jjSubscreenHeight-454, ANIM::AMMO, 8, 3, 0, SPRITE::NORMAL, 0); canvas.drawSprite(jjSubscreenWidth-60, jjSubscreenHeight-454, ANIM::AMMO, 8, 3, 0, SPRITE::NORMAL, 0);
  }

  if (limitedOxygen > 840 && limitedOxygen < 1260) {
  canvas.drawSprite(jjSubscreenWidth-12, jjSubscreenHeight-454, ANIM::AMMO, 8, 3, 0, SPRITE::NORMAL, 0); canvas.drawSprite(jjSubscreenWidth-28, jjSubscreenHeight-454, ANIM::AMMO, 8, 3, 0, SPRITE::NORMAL, 0); canvas.drawSprite(jjSubscreenWidth-44, jjSubscreenHeight-454, ANIM::AMMO, 8, 3, 0, SPRITE::NORMAL, 0);
  }

  if (limitedOxygen > 1260 && limitedOxygen < 1680) {
  canvas.drawSprite(jjSubscreenWidth-12, jjSubscreenHeight-454, ANIM::AMMO, 8, 3, 0, SPRITE::NORMAL, 0); canvas.drawSprite(jjSubscreenWidth-28, jjSubscreenHeight-454, ANIM::AMMO, 8, 3, 0, SPRITE::NORMAL, 0); 
  }

  if (limitedOxygen > 1680 && limitedOxygen < 2100) {
  canvas.drawSprite(jjSubscreenWidth-12, jjSubscreenHeight-454, ANIM::AMMO, 8, 3, 0, SPRITE::NORMAL, 0);
  }

  return false;
}

void onPlayer(jjPLAYER@ play) {
  if (play.yPos > jjWaterLevel) {
    switch(play.shieldType) {
      case 0: limitedOxygen++; play.shieldTime = 0; play.shieldType = 0; break;
      case 1: limitedOxygen++; play.shieldTime = 0; play.shieldType = 0; break;
      case 2: limitedOxygen = 0; break;
      case 3: limitedOxygen++; play.shieldTime = 0; play.shieldType = 0; break;
      case 4: limitedOxygen++; play.shieldTime = 0; play.shieldType = 0; break;
    }
  }
  else { limitedOxygen = 0;
  }

  if (limitedOxygen == 2100) {
    play.kill();
  }

  if (play.health == 0) limitedOxygen = 0;

}