Bubble Gun

Version:

2.0

Added on:

24 Feb 2015 22:39

Tags:

Description:
Adding the code for the Bubble Gun as a snippet here for convenience in case anyone wants to use it in their own levels.
  1. void onLevelLoad() { //formalities
  2.   jjObjectPresets[OBJECT::FIREBALLBULLET].special = jjObjectPresets[OBJECT::FIREBALLBULLET].determineCurAnim(ANIM::AMMO, 8);
  3.   jjObjectPresets[OBJECT::FIREBALLBULLET].behavior = BubbleGun;
  4.   jjObjectPresets[OBJECT::FIREBALLBULLET].xSpeed = 1.25;
  5.   jjObjectPresets[OBJECT::FIREBALLBULLET].ySpeed = 0;
  6.   jjObjectPresets[OBJECT::FIREBALLBULLET].counterEnd = 105;
  7.  
  8.   jjObjectPresets[OBJECT::FIREBALLBULLETPU].special = jjObjectPresets[OBJECT::FIREBALLBULLETPU].determineCurAnim(ANIM::AMMO, 8);
  9.   jjObjectPresets[OBJECT::FIREBALLBULLETPU].behavior = BubbleGunPU;
  10.   jjObjectPresets[OBJECT::FIREBALLBULLETPU].xSpeed = 1.5;
  11.   jjObjectPresets[OBJECT::FIREBALLBULLETPU].ySpeed = 0;
  12.   jjObjectPresets[OBJECT::FIREBALLBULLETPU].counterEnd = 105;
  13.  
  14.   jjObjectPresets[OBJECT::GUN8AMMO3].determineCurAnim(ANIM::AMMO, 8, true);
  15.   jjObjectPresets[OBJECT::GUN8POWERUP].behavior = BubbleMonitor; //display the gun8 powerup as a bubble powerup
  16. }
  17.  
  18. void onLevelBegin() {
  19.   if (jjIsServer || jjGameMode == GAME::Mode::SP) jjChat("/fireball on"); //fireball needs to be enabled for this weapon to work
  20. }
  21.  
  22. void BubbleGun(jjOBJ@ bubble) {
  23.     if (bubble.state == STATE::START) {
  24.     bubble.state = STATE::FLY;
  25.     if (jjSoundEnabled) jjSample(bubble.xPos, bubble.yPos, SOUND::COMMON_PLOP2, 0, 0);
  26.   }
  27.  
  28.   bubble.behave(BEHAVIOR::WATERSHIELDBULLET);
  29.  
  30.   if (jjMaskedPixel(bubble.xPos + bubble.xSpeed, bubble.yPos) || jjMaskedPixel(bubble.xPos - bubble.xSpeed, bubble.yPos) || jjMaskedPixel(bubble.xPos, bubble.yPos + bubble.ySpeed) || jjMaskedPixel(bubble.xPos, bubble.yPos - bubble.ySpeed)) {
  31.     if (jjSoundEnabled) jjSample(bubble.xPos, bubble.yPos, SOUND::P2_SPLOUT, 0, 0);
  32.   }
  33.  
  34.   bubble.killAnim = jjObjectPresets[OBJECT::WATERSHIELDBULLET].killAnim;
  35.  
  36.   bubble.determineCurFrame();
  37.  
  38.   bubble.animSpeed = 1; //for SP
  39.   bubble.var[6] = 0; //for MP
  40. }
  41.  
  42. void BubbleGunPU(jjOBJ@ bubble) {
  43.   if (bubble.state == STATE::START) {
  44.     bubble.state = STATE::FLY;
  45.     if (jjSoundEnabled) jjSample(bubble.xPos, bubble.yPos, SOUND::COMMON_PLOP2, 0, 0);
  46.   }
  47.  
  48.   bubble.behave(BEHAVIOR::WATERSHIELDBULLET);
  49.  
  50.   if (bubble.state == STATE::FLY && bubble.counter > 0) { //controls on the arc of the bullet
  51.     switch (bubble.direction) {
  52.       case 0: bubble.ySpeed = bubble.ySpeed - 0.08; break;
  53.       case 1: bubble.xSpeed = bubble.xSpeed - 0.1; bubble.ySpeed = bubble.ySpeed - 0.08; break;
  54.       case -1: bubble.xSpeed = bubble.xSpeed + 0.1; bubble.ySpeed = bubble.ySpeed - 0.08; break;
  55.     }
  56.   }
  57.  
  58.   if (jjMaskedPixel(bubble.xPos + bubble.xSpeed, bubble.yPos) || jjMaskedPixel(bubble.xPos - bubble.xSpeed, bubble.yPos) || jjMaskedPixel(bubble.xPos, bubble.yPos + bubble.ySpeed) || jjMaskedPixel(bubble.xPos, bubble.yPos - bubble.ySpeed)) {
  59.     if (jjSoundEnabled) jjSample(bubble.xPos, bubble.yPos, SOUND::P2_SPLOUT, 0, 0);
  60.   }
  61.  
  62.   bubble.killAnim = jjObjectPresets[OBJECT::WATERSHIELDBULLET].killAnim;
  63.  
  64.   jjDrawSpriteFromCurFrame(bubble.xPos, bubble.yPos, bubble.curFrame, bubble.direction, SPRITE::NEONGLOW, 2);
  65.   bubble.determineCurFrame();
  66.  
  67.   bubble.animSpeed = 2; //for SP
  68.   bubble.var[6] = 8; //for MP
  69. }
  70.  
  71. void BubbleMonitor(jjOBJ@ obj) {
  72.   obj.behave(BEHAVIOR::MONITOR);
  73.   if (obj.justHit == 0) {
  74.     jjDrawSprite(obj.xPos+7, obj.yPos-1, ANIM::AMMO, 8, 3); //cheeky!
  75.   }
  76. }
  77.  
  78. bool onDrawAmmo(jjPLAYER@ play, jjCANVAS@ canvas) { //displays the bubble sprite on the gun icon
  79.   if (play.currWeapon == WEAPON::GUN8 && !play.noFire) {
  80.     canvas.drawSprite(
  81.       jjSubscreenWidth - 88,
  82.       jjSubscreenHeight - 14,
  83.       ANIM::AMMO, 8, play.powerup[WEAPON::GUN8] == true? 4:3,
  84.       SPRITE::NORMAL
  85.     );
  86.    
  87.     canvas.drawString(
  88.       jjSubscreenWidth - 80,
  89.       jjSubscreenHeight - 14,
  90.       "x" + play.ammo[WEAPON::GUN8],
  91.       STRING::MEDIUM,
  92.       STRING::NORMAL
  93.     );
  94.     return true;
  95.   }
  96.   else return false;
  97. }