Powerups as Pickups

Version:

3.0

Added on:

05 Feb 2015 04: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.
  1. array<uint8> BasicPickups = {OBJECT::BOUNCERAMMO3, OBJECT::ICEAMMO3, OBJECT::SEEKERAMMO3, OBJECT::RFAMMO3, OBJECT::TOASTERAMMO3, OBJECT::TNTAMMO3, OBJECT::GUN8AMMO3, OBJECT::GUN9AMMO3};
  2. array<uint8> Powerups = {OBJECT::BOUNCERPOWERUP, OBJECT::ICEPOWERUP, OBJECT::SEEKERPOWERUP, OBJECT::RFPOWERUP, OBJECT::TOASTERPOWERUP, OBJECT::TNTPOWERUP, OBJECT::GUN8POWERUP, OBJECT::GUN9POWERUP};
  3. array<uint> PowerupPickupAnimations = {24, 28, 33, 48, 56, 59, 61, 67};
  4. void onLevelLoad() {
  5.   for (uint i = 0; i < BasicPickups.length; ++i) {
  6.     jjWeapons[i + 2].maximum = 50;
  7.     jjOBJ@ pickup = jjObjectPresets[BasicPickups[i]];
  8.     jjOBJ@ powerup = jjObjectPresets[Powerups[i]];
  9.     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
  10.     pickup.var[4] = powerup.var[4] = i + 2; //firetype
  11.     powerup.var[5] = 1; //is powerup
  12.     powerup.behavior = pickup.behavior;
  13.     powerup.playerHandling = pickup.playerHandling;
  14.     powerup.bulletHandling = pickup.bulletHandling;
  15.     powerup.killAnim = pickup.killAnim;
  16.     powerup.determineCurAnim(ANIM::AMMO, PowerupPickupAnimations[i]);
  17.     powerup.determineCurFrame();
  18.     powerup.scriptedCollisions = pickup.scriptedCollisions = true;
  19.   }
  20. }
  21.  
  22. int min(int a, int b) {
  23.   if (a < b) return a;
  24.   return b;
  25. }
  26. void onObjectHit(jjOBJ@ obj, jjOBJ@ bull, jjPLAYER@ play, int force) {
  27.   int fireType = obj.var[4];
  28.   if (play.ammo[fireType] >= jjWeapons[fireType].maximum) return;
  29.   if (play.ammo[fireType] == 0) play.currWeapon = fireType;
  30.   play.ammo[fireType] = min(jjWeapons[fireType].maximum, play.ammo[fireType] + 3);
  31.   play.powerup[fireType] = (obj.var[5] == 1);
  32.   obj.behavior = BEHAVIOR::EXPLOSION2;
  33.   obj.playerHandling = HANDLING::EXPLOSION;
  34.   obj.frameID = 0;
  35.   jjSample(obj.xPos, obj.yPos, SOUND::COMMON_PICKUPW1);
  36. }
  37.  
  38. //make code work for pickups in crates too:
  39. 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.
  40.   for (int i = jjObjectCount - 1; i >= 1; --i) {
  41.     jjOBJ@ obj = jjObjects[i];
  42.     if (obj.behavior == BEHAVIOR::PICKUP || obj.behavior == BEHAVIOR::FLICKERGEM && (BasicPickups.find(obj.eventID) > -1 || Powerups.find(obj.eventID) > -1))
  43.       if (obj.playerHandling == HANDLING::PICKUP) //not DELAYEDPICKUP
  44.         obj.scriptedCollisions = true; //both behaviors set this to false shortly after coming out of a crate
  45.   }
  46. }