Recharging Blaster Weapon like in JJ3D

Version:

2.0

Added on:

09 Apr 2015 20:35

Tags:

Description:
It's just a simple recharging blaster weapon like in Jazz Jackrabbit 3D.
v2.0: The blaster recharge can look some sort of like in JJ3D and simply look like in JJ2
  1. int blasterOption = 0;
  2. enum blasterOptionEnum {simple, advanced};
  3.  
  4. const int Q = 0x51;
  5. const int E = 0x45;
  6.  
  7. bool qKeyHeld;
  8. bool eKeyHeld;
  9.  
  10. void onLevelLoad() {
  11.   jjWeapons[WEAPON::BLASTER].infinite = false;
  12.   jjWeapons[WEAPON::BLASTER].maximum = 50;
  13.   blasterOption = advanced;
  14. }
  15.  
  16. bool wasPoweredUp = false;
  17.  
  18. void onPlayer(jjPLAYER@ p) {
  19.   if (p.ammo[WEAPON::BLASTER] < jjWeapons[WEAPON::BLASTER].maximum) {
  20.     if (jjGameTicks % 140 == 0) p.ammo[WEAPON::BLASTER] = p.ammo[WEAPON::BLASTER] + 1;
  21.     }
  22.   if (p.ammo[WEAPON::BLASTER] == 1 && p.powerup[WEAPON::BLASTER]) wasPoweredUp = true;
  23.   if (wasPoweredUp) p.powerup[WEAPON::BLASTER] = true;
  24.   if (qKeyHeld) blasterOption = advanced;
  25.   if (eKeyHeld) blasterOption = simple;  
  26.  
  27.   qKeyHeld = jjKey[Q];
  28.   eKeyHeld = jjKey[E];
  29. }
  30.  
  31. int hudWidth = jjSubscreenWidth-20;
  32.  
  33. bool onDrawAmmo(jjPLAYER@ p, jjCANVAS@ canvas) {
  34.   if (p.currWeapon == WEAPON::BLASTER && blasterOption == advanced) {
  35.       if (!p.powerup[WEAPON::BLASTER]) {
  36.       if (p.charCurr == CHAR::SPAZ || p.charCurr == CHAR::JAZZ)
  37.         canvas.drawSprite(jjSubscreenWidth-20, jjSubscreenHeight-25, ANIM::AMMO, p.charCurr == CHAR::SPAZ ? 19 : 18, 0, 0, SPRITE::NORMAL, 0);
  38.       if (jjIsTSF) {
  39.         if (p.charCurr == CHAR::LORI)
  40.           canvas.drawSprite(jjSubscreenWidth-20, jjSubscreenHeight-25, ANIM::PLUS_AMMO, 5, 0, 0, SPRITE::NORMAL, 0);
  41.       }
  42.     } else {
  43.       if (p.charCurr == CHAR::SPAZ || p.charCurr == CHAR::JAZZ)
  44.         canvas.drawSprite(jjSubscreenWidth-20, jjSubscreenHeight-25, ANIM::AMMO, p.charCurr == CHAR::SPAZ ? 19 : 18, 3, 0, SPRITE::NORMAL, 0);
  45.       if (jjIsTSF) {
  46.         if (p.charCurr == CHAR::LORI)
  47.           canvas.drawSprite(jjSubscreenWidth-20, jjSubscreenHeight-25, ANIM::PLUS_AMMO, 6, 2, 0, SPRITE::NORMAL, 0);
  48.       }
  49.     }
  50.     for (int i = 0; i < (p.ammo[WEAPON::BLASTER] / 2); i++) {
  51.       canvas.drawString((hudWidth - (i * 10)), jjSubscreenHeight-5, "/", STRING::SMALL, STRING::NORMAL);
  52.     }
  53.     return true;
  54.   } else return false;
  55. }
  56.