Powerups as Pickups

Version:

3.0

Added on:

05 Feb 2015 03:57

Tags:

Description:
Replaces all Powerup monitors with special +3 Ammo pickups. Your powerup status for any given ammo type (except blaster) will reflect whichever ammo pickup you last collected, specifically whether it was itself powered-up or not. Updated (v3.0) to work for ammo that comes out of crates.
array<uint8> BasicPickups = {OBJECT::BOUNCERAMMO3, OBJECT::ICEAMMO3, OBJECT::SEEKERAMMO3, OBJECT::RFAMMO3, OBJECT::TOASTERAMMO3, OBJECT::TNTAMMO3, OBJECT::GUN8AMMO3, OBJECT::GUN9AMMO3};
array<uint8> Powerups = {OBJECT::BOUNCERPOWERUP, OBJECT::ICEPOWERUP, OBJECT::SEEKERPOWERUP, OBJECT::RFPOWERUP, OBJECT::TOASTERPOWERUP, OBJECT::TNTPOWERUP, OBJECT::GUN8POWERUP, OBJECT::GUN9POWERUP};
array<uint> PowerupPickupAnimations = {24, 28, 33, 48, 56, 59, 61, 67};
void onLevelLoad() {
  for (uint i = 0; i < BasicPickups.length; ++i) {
    jjWeapons[i + 2].maximum = 50;
    jjOBJ@ pickup = jjObjectPresets[BasicPickups[i]];
    jjOBJ@ powerup = jjObjectPresets[Powerups[i]];
    pickup.var[3] = powerup.var[3] = 0; //so that JJ2 doesn't realize it's an ammo pickup and recolor it according to powerup status
    pickup.var[4] = powerup.var[4] = i + 2; //firetype
    powerup.var[5] = 1; //is powerup
    powerup.behavior = pickup.behavior;
    powerup.playerHandling = pickup.playerHandling;
    powerup.bulletHandling = pickup.bulletHandling;
    powerup.killAnim = pickup.killAnim;
    powerup.determineCurAnim(ANIM::AMMO, PowerupPickupAnimations[i]);
    powerup.determineCurFrame();
    powerup.scriptedCollisions = pickup.scriptedCollisions = true;
  }
}

int min(int a, int b) {
  if (a < b) return a;
  return b;
}
void onObjectHit(jjOBJ@ obj, jjOBJ@ bull, jjPLAYER@ play, int force) {
  int fireType = obj.var[4];
  if (play.ammo[fireType] >= jjWeapons[fireType].maximum) return;
  if (play.ammo[fireType] == 0) play.currWeapon = fireType;
  play.ammo[fireType] = min(jjWeapons[fireType].maximum, play.ammo[fireType] + 3);
  play.powerup[fireType] = (obj.var[5] == 1);
  obj.behavior = BEHAVIOR::EXPLOSION2;
  obj.playerHandling = HANDLING::EXPLOSION;
  obj.frameID = 0;
  jjSample(obj.xPos, obj.yPos, SOUND::COMMON_PICKUPW1);
}

//make code work for pickups in crates too:
void onMain() { //JJ2+ v4.3 has a bug related to changing jjObjectPresets[OBJECT::FLICKERGEM].behavior, so this needs to be done in an onMain loop. Messy, but it works.
  for (int i = jjObjectCount - 1; i >= 1; --i) {
    jjOBJ@ obj = jjObjects[i];
    if (obj.behavior == BEHAVIOR::PICKUP || obj.behavior == BEHAVIOR::FLICKERGEM && (BasicPickups.find(obj.eventID) > -1 || Powerups.find(obj.eventID) > -1))
      if (obj.playerHandling == HANDLING::PICKUP) //not DELAYEDPICKUP
        obj.scriptedCollisions = true; //both behaviors set this to false shortly after coming out of a crate
  }
}