Limited air supply underwater

Version:

7.0

Added on:

25 Feb 2014 21: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.
  1. uint limitedOxygen = 0;
  2.  
  3. bool onDrawHealth(jjPLAYER@ play, jjCANVAS@ canvas) {
  4.   if (limitedOxygen > 0 && limitedOxygen < 420) {
  5.   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);
  6.  canvas.drawSprite(jjSubscreenWidth-76, jjSubscreenHeight-454, ANIM::AMMO, 8, 3, 0, SPRITE::NORMAL, 0);
  7.   }
  8.  
  9.   if (limitedOxygen > 420 && limitedOxygen < 840) {
  10.   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);
  11.   }
  12.  
  13.   if (limitedOxygen > 840 && limitedOxygen < 1260) {
  14.   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);
  15.   }
  16.  
  17.   if (limitedOxygen > 1260 && limitedOxygen < 1680) {
  18.   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);
  19.   }
  20.  
  21.   if (limitedOxygen > 1680 && limitedOxygen < 2100) {
  22.   canvas.drawSprite(jjSubscreenWidth-12, jjSubscreenHeight-454, ANIM::AMMO, 8, 3, 0, SPRITE::NORMAL, 0);
  23.   }
  24.  
  25.   return false;
  26. }
  27.  
  28. void onPlayer(jjPLAYER@ play) {
  29.   if (play.yPos > jjWaterLevel) {
  30.     switch(play.shieldType) {
  31.       case 0: limitedOxygen++; play.shieldTime = 0; play.shieldType = 0; break;
  32.       case 1: limitedOxygen++; play.shieldTime = 0; play.shieldType = 0; break;
  33.       case 2: limitedOxygen = 0; break;
  34.       case 3: limitedOxygen++; play.shieldTime = 0; play.shieldType = 0; break;
  35.       case 4: limitedOxygen++; play.shieldTime = 0; play.shieldType = 0; break;
  36.     }
  37.   }
  38.   else { limitedOxygen = 0;
  39.   }
  40.  
  41.   if (limitedOxygen == 2100) {
  42.     play.kill();
  43.   }
  44.  
  45.   if (play.health == 0) limitedOxygen = 0;
  46.  
  47. }