uint spreadShotCountdown = 0; uint R = 125; uint G = 220; uint B = 250; uint light = 100; #pragma require "BubbleGun.j2a" void onLevelLoad() { jjObjectPresets[OBJECT::ELECTROBULLETPU].eventID = OBJECT::ELECTROBULLET; jjLayerOrderSet(array = {jjLayers[3], jjLayers[4], jjLayers[1], jjLayers[5], jjLayers[6], jjLayers[2], jjLayers[7], jjLayers[8]}); jjWeapons[WEAPON::GUN8].spread = SPREAD::NORMAL; jjWeapons[WEAPON::GUN9].allowed = true; jjWeapons[WEAPON::GUN9].allowedPowerup = true; jjObjectPresets[OBJECT::CHIPS].scriptedCollisions = true; jjObjectPresets[OBJECT::CHIPS].behavior = SpreadShot(); jjAnimSets[ANIM::CUSTOM[0]].load(0, "BubbleGun.j2a"); jjAnimSets[ANIM::CUSTOM[1]].load(1, "BubbleGun.j2a"); jjAnimSets[ANIM::CUSTOM[2]].load(2, "BubbleGun.j2a"); jjAnimations[jjAnimSets[ANIM::AMMO] + 29] = jjAnimations[jjAnimSets[ANIM::AMMO] + 8]; jjAnimations[jjAnimSets[ANIM::AMMO] + 28] = jjAnimations[jjAnimSets[ANIM::CUSTOM[0]] + 0]; jjObjectPresets[OBJECT::ICEBULLET].special = jjObjectPresets[OBJECT::ICEBULLET].determineCurAnim(ANIM::AMMO, 8); jjObjectPresets[OBJECT::ICEBULLET].behavior = BubbleGun; jjObjectPresets[OBJECT::ICEBULLET].xSpeed = 2; jjObjectPresets[OBJECT::ICEBULLET].counterEnd = 105; jjObjectPresets[OBJECT::ICEBULLET].var[6] = 0; jjObjectPresets[OBJECT::ICEBULLET].freeze = 0; jjObjectPresets[OBJECT::ICEBULLET].lightType = jjObjectPresets[OBJECT::BLASTERBULLET].lightType; jjObjectPresets[OBJECT::ICEBULLETPU].special = jjObjectPresets[OBJECT::ICEBULLETPU].determineCurAnim(ANIM::CUSTOM[0], 0); jjObjectPresets[OBJECT::ICEBULLETPU].behavior = BubbleGunPU; jjObjectPresets[OBJECT::ICEBULLETPU].xSpeed = 3; jjObjectPresets[OBJECT::ICEBULLETPU].counterEnd = 105; jjObjectPresets[OBJECT::ICEBULLETPU].var[6] = 0; jjObjectPresets[OBJECT::ICEBULLETPU].freeze = 0; jjObjectPresets[OBJECT::ICEBULLETPU].lightType = jjObjectPresets[OBJECT::BLASTERBULLET].lightType; jjObjectPresets[OBJECT::ICEPOWERUP].determineCurAnim(ANIM::CUSTOM[1], 0, true); jjWeapons[WEAPON::ICE].spread = SPREAD::NORMAL; jjWeapons[WEAPON::ICE].defaultSample = false; jjANIMATION@ anim = jjAnimations[jjAnimSets[ANIM::AMMO] + 8]; for (uint j = 0; j < anim.frameCount; j++) { jjANIMFRAME@ frame = jjAnimFrames[anim + j]; jjPIXELMAP sprite(frame); for (uint x = 0; x < sprite.width; ++x) { for (uint y = 0; y < sprite.height; ++y) { if (sprite[x,y] >= 32 && sprite[x,y] <= 39) sprite[x,y] -= 8; } } sprite.save(frame); } jjANIMATION@ anim2 = jjAnimations[jjAnimSets[ANIM::CUSTOM[0]] + 0]; for (uint j = 0; j < anim2.frameCount; j++) { jjANIMFRAME@ frame2 = jjAnimFrames[anim2 + j]; jjPIXELMAP sprite2(frame2); for (uint x = 0; x < sprite2.width; ++x) { for (uint y = 0; y < sprite2.height; ++y) { if (sprite2[x,y] >= 80 && sprite2[x,y] <= 87) sprite2[x,y] -= 40; } } sprite2.save(frame2); } jjANIMATION@ anim3 = jjAnimations[jjAnimSets[ANIM::CUSTOM[1]] + 0]; for (uint j = 0; j < anim3.frameCount; j++) { jjANIMFRAME@ frame3 = jjAnimFrames[anim3 + j]; jjPIXELMAP sprite3(frame3); for (uint x = 0; x < sprite3.width; ++x) { for (uint y = 0; y < sprite3.height; ++y) { if (sprite3[x,y] >= 80 && sprite3[x,y] <= 87) sprite3[x,y] -= 40; } } sprite3.save(frame3); } generateCustomSpringSprites(jjAnimSets[ANIM::CUSTOM[0]], array = {64}); turnIntoCustomSpring(jjObjectPresets[OBJECT::FROZENSPRING], 0, 34.f, false); } void resetSpread() { jjWeapons[WEAPON::BLASTER].spread = SPREAD::NORMAL; jjWeapons[WEAPON::BOUNCER].spread = SPREAD::NORMAL; jjWeapons[WEAPON::ICE].spread = SPREAD::ICE; jjWeapons[WEAPON::SEEKER].spread = SPREAD::NORMAL; jjWeapons[WEAPON::RF].spread = SPREAD::RF; jjWeapons[WEAPON::TNT].spread = SPREAD::NORMAL; jjWeapons[WEAPON::TOASTER].spread = SPREAD::TOASTER; jjWeapons[WEAPON::GUN8].spread = SPREAD::NORMAL; jjWeapons[WEAPON::GUN9].spread = SPREAD::NORMAL; } uint16 angle = 0; void onPlayer(jjPLAYER@ p) { handleFastCustomSpringSpeeds(p); p.lightType = LIGHT::NONE; p.lighting = light; p.powerup[9] = true; if (spreadShotCountdown > 0 && jjGameTicks % 70 == 0) { spreadShotCountdown--; if (spreadShotCountdown == 0) { resetSpread(); } } else if (spreadShotCountdown == 15) { for (uint i = 1; i <= 9; i++) { jjWeapons[i].spread = SPREAD::RFPU; } } if (spreadShotCountdown > 0) { jjTEXTAPPEARANCE normal(STRING::NORMAL); int x = int(p.cameraX); int y = int(p.cameraY); jjDrawSprite(x + jjResolutionWidth - 72, y + jjResolutionHeight - 270, ANIM::PICKUPS, 87, jjGameTicks >> 2, 0, SPRITE::NORMAL, 0, 1); jjDrawString(x + jjResolutionWidth - 55, y + jjResolutionHeight - 274, "" + spreadShotCountdown, STRING::MEDIUM, normal, 0, SPRITE::PALSHIFT, 0, 1); } if (p.health == 0) { spreadShotCountdown == 0; resetSpread(); } angle += 12; } class SpreadShot : jjBEHAVIORINTERFACE { void onBehave(jjOBJ@ obj) { obj.behave(BEHAVIOR::PICKUP, false); obj.light = 12; obj.lightType = LIGHT::BRIGHT; obj.xPos=obj.xOrg+0*jjSin(-jjGameTicks*5+int(obj.xOrg)*32/3); obj.yPos=obj.yOrg+0*jjCos(-jjGameTicks*5+int(obj.xOrg)*32/3); } void onDraw(jjOBJ@ obj) { jjDrawRotatedSprite(obj.xPos, obj.yPos + 10, ANIM::AMMO, 37, jjGameTicks >> 2, angle, 1, 1, SPRITE::NORMAL, 0, 1); jjDrawRotatedSprite(obj.xPos, obj.yPos, ANIM::AMMO, 37, jjGameTicks >> 2, angle, 1, 1, SPRITE::NORMAL, 0, 1); jjDrawRotatedSprite(obj.xPos, obj.yPos - 10, ANIM::AMMO, 37, jjGameTicks >> 2, angle, 1, 1, SPRITE::NORMAL, 0, 1); } bool onObjectHit(jjOBJ@ obj, jjOBJ@ bullet, jjPLAYER@ p, int force) { obj.bulletHandling = HANDLING::IGNOREBULLET; obj.behavior = BEHAVIOR::EXPLOSION2; obj.scriptedCollisions = false; obj.frameID = 0; if (p.isLocal) spreadShotCountdown = 15; jjSamplePriority(SOUND::COMMON_PICKUP1); return true; } } void BubbleGun(jjOBJ@ bubble) { if (bubble.state == STATE::START) { bubble.state = STATE::FLY; if (jjPlayers[bubble.creatorID].isLocal) jjSample(bubble.xPos, bubble.yPos, SOUND::COMMON_PLOP2, 0, 0); } if (bubble.state == STATE::FLY) jjDrawSpriteFromCurFrame(bubble.xPos, bubble.yPos, bubble.curFrame, bubble.direction, SPRITE::NORMAL); if (jjMaskedPixel(int(bubble.xPos) + int(bubble.xSpeed), int(bubble.yPos)) || jjMaskedPixel(int(bubble.xPos) - int(bubble.xSpeed), int(bubble.yPos)) || jjMaskedPixel(int(bubble.xPos), int(bubble.yPos) + int(bubble.ySpeed)) || jjMaskedPixel(int(bubble.xPos), int(bubble.yPos) - int(bubble.ySpeed))) { jjSample(bubble.xPos, bubble.yPos, SOUND::P2_SPLOUT, 0, 0); } bubble.behave(BEHAVIOR::WATERSHIELDBULLET, false); if (bubble.state == STATE::FLY && bubble.counter > 0) { switch (bubble.direction) { case 1: bubble.xSpeed = bubble.xSpeed - 0.04; bubble.ySpeed = bubble.ySpeed - 0.04; break; case -1: bubble.xSpeed = bubble.xSpeed + 0.04; bubble.ySpeed = bubble.ySpeed - 0.04; break; } } bubble.killAnim = jjObjectPresets[OBJECT::WATERSHIELDBULLET].killAnim; } void BubbleGunPU(jjOBJ@ bubble) { if (bubble.state == STATE::START) { bubble.state = STATE::FLY; if (jjPlayers[bubble.creatorID].isLocal) jjSample(bubble.xPos, bubble.yPos, SOUND::COMMON_PLOP2, 0, 0); } if (bubble.state == STATE::FLY) jjDrawSpriteFromCurFrame(bubble.xPos, bubble.yPos, bubble.curFrame, bubble.direction, SPRITE::NORMAL); if (jjMaskedPixel(int(bubble.xPos) + int(bubble.xSpeed), int(bubble.yPos)) || jjMaskedPixel(int(bubble.xPos) - int(bubble.xSpeed), int(bubble.yPos)) || jjMaskedPixel(int(bubble.xPos), int(bubble.yPos) + int(bubble.ySpeed)) || jjMaskedPixel(int(bubble.xPos), int(bubble.yPos) - int(bubble.ySpeed))) { jjSample(bubble.xPos, bubble.yPos, SOUND::P2_SPLOUT, 0, 0); } bubble.behave(BEHAVIOR::WATERSHIELDBULLET, false); if (bubble.state == STATE::FLY && bubble.counter > 0) { switch (bubble.direction) { case 1: bubble.xSpeed = bubble.xSpeed - 0.1; bubble.ySpeed = bubble.ySpeed - 0.08; break; case -1: bubble.xSpeed = bubble.xSpeed + 0.1; bubble.ySpeed = bubble.ySpeed - 0.08; break; } } bubble.killAnim = jjObjectPresets[OBJECT::WATERSHIELDBULLET].killAnim; } jjANIMSET@ customSpringSprite; array fastCustomSpringSpeeds(jjLocalPlayerCount); bool generateCustomSpringSprites(jjANIMSET@ anim, const array &in colors) { int length = colors.length(); bool success = (@customSpringSprite = anim).allocate(array(length * 3, 5)) !is null; if (success) { uint srcSet = jjAnimSets[ANIM::SPRING]; for (int i = 0; i < length; i++) { uint color = colors[i]; uint destAnimOffset = anim + i * 3; for (int j = 0; j < 3; j++) { uint srcAnim = jjAnimations[srcSet + j]; uint destAnim = jjAnimations[destAnimOffset + j]; for (int k = 0; k < 5; k++) { jjPIXELMAP image(jjAnimFrames[destAnim + k] = jjAnimFrames[srcAnim + k]); int width = image.width; int height = image.height; for (int l = 0; l < height; l++) { for (int m = 0; m < width; m++) { int pixel = image[m, l]; if (pixel >= 32 && pixel < 40) image[m, l] = color + (pixel & 7); } } if (!image.save(jjAnimFrames[destAnim + k])) return false; } } } } return success; } void initializeCustomSpring(jjOBJ@ obj) { int anim = obj.curAnim; obj.behave(obj.behavior = BEHAVIOR::SPRING, false); if (obj.curAnim != anim) { obj.curAnim = anim + 2; obj.determineCurFrame(); } obj.draw(); } void turnIntoCustomSpring(jjOBJ@ obj, uint color, float power, bool horizontal) { if (horizontal) { obj.xSpeed = power; obj.ySpeed = 0.f; } else { obj.xSpeed = 0.f; obj.ySpeed = -power; if (obj.state == STATE::START && obj.creatorType == CREATOR::LEVEL) { int x = int(obj.xPos) >> 5; int y = int(obj.yPos) >> 5; if (jjParameterGet(x, y, 0, 1) != 0) { jjParameterSet(x, y, 0, 1, 0); obj.yPos -= 4.f; obj.ySpeed = power; } } } obj.behavior = initializeCustomSpring; obj.curAnim = customSpringSprite + color * 3 + (horizontal ? 1 : 0); obj.energy = obj.frameID = obj.freeze = obj.justHit = obj.light = obj.points = 0; obj.causesRicochet = obj.isBlastable = obj.isTarget = obj.scriptedCollisions = obj.triggersTNT = false; obj.deactivates = obj.isFreezable = true; obj.bulletHandling = HANDLING::IGNOREBULLET; obj.playerHandling = HANDLING::SPECIAL; obj.lightType = LIGHT::NORMAL; obj.determineCurFrame(); } void handleFastCustomSpringSpeeds(jjPLAYER@ player) { if (player.ySpeed < -32.f) { fastCustomSpringSpeeds[player.localPlayerID] = int(ceil((player.ySpeed + 30.f) / -0.125f)); } else if (fastCustomSpringSpeeds[player.localPlayerID] != 0) { if (player.ySpeed < -31.f) { fastCustomSpringSpeeds[player.localPlayerID]--; player.ySpeed = -64.f; } else { fastCustomSpringSpeeds[player.localPlayerID] = 0; } } }