Recharging Blaster Weapon like in JJ3D

Version:

2.0

Added on:

09 Apr 2015 18: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
int blasterOption = 0;
enum blasterOptionEnum {simple, advanced};

const int Q = 0x51;
const int E = 0x45;

bool qKeyHeld;
bool eKeyHeld;
  
void onLevelLoad() {
  jjWeapons[WEAPON::BLASTER].infinite = false;
  jjWeapons[WEAPON::BLASTER].maximum = 50;
  blasterOption = advanced;
}

bool wasPoweredUp = false;
  
void onPlayer(jjPLAYER@ p) {
  if (p.ammo[WEAPON::BLASTER] < jjWeapons[WEAPON::BLASTER].maximum) {
    if (jjGameTicks % 140 == 0) p.ammo[WEAPON::BLASTER] = p.ammo[WEAPON::BLASTER] + 1;
    }
  if (p.ammo[WEAPON::BLASTER] == 1 && p.powerup[WEAPON::BLASTER]) wasPoweredUp = true;
  if (wasPoweredUp) p.powerup[WEAPON::BLASTER] = true;
  if (qKeyHeld) blasterOption = advanced;
  if (eKeyHeld) blasterOption = simple;  
  
  qKeyHeld = jjKey[Q];
  eKeyHeld = jjKey[E];
}

int hudWidth = jjSubscreenWidth-20;

bool onDrawAmmo(jjPLAYER@ p, jjCANVAS@ canvas) {
  if (p.currWeapon == WEAPON::BLASTER && blasterOption == advanced) {
      if (!p.powerup[WEAPON::BLASTER]) {
      if (p.charCurr == CHAR::SPAZ || p.charCurr == CHAR::JAZZ)
        canvas.drawSprite(jjSubscreenWidth-20, jjSubscreenHeight-25, ANIM::AMMO, p.charCurr == CHAR::SPAZ ? 19 : 18, 0, 0, SPRITE::NORMAL, 0);
      if (jjIsTSF) {
        if (p.charCurr == CHAR::LORI)
          canvas.drawSprite(jjSubscreenWidth-20, jjSubscreenHeight-25, ANIM::PLUS_AMMO, 5, 0, 0, SPRITE::NORMAL, 0);
      }
    } else {
      if (p.charCurr == CHAR::SPAZ || p.charCurr == CHAR::JAZZ)
        canvas.drawSprite(jjSubscreenWidth-20, jjSubscreenHeight-25, ANIM::AMMO, p.charCurr == CHAR::SPAZ ? 19 : 18, 3, 0, SPRITE::NORMAL, 0);
      if (jjIsTSF) {
        if (p.charCurr == CHAR::LORI)
          canvas.drawSprite(jjSubscreenWidth-20, jjSubscreenHeight-25, ANIM::PLUS_AMMO, 6, 2, 0, SPRITE::NORMAL, 0);
      }
    }
    for (int i = 0; i < (p.ammo[WEAPON::BLASTER] / 2); i++) {
      canvas.drawString((hudWidth - (i * 10)), jjSubscreenHeight-5, "/", STRING::SMALL, STRING::NORMAL);
    }
    return true;
  } else return false;
}