Downloads containing lhfrogav.j2as

Downloads
Name Author Game Mode Rating
TSF with JJ2+ Only: Frogavia V2.5Featured Download TreyLina Battle 9.1 Download file

File preview

  1. #include "MLLE-Include-1.5w.asc" ///@MLLE-Generated
  2. #pragma require "lhfrogav.j2l" ///@MLLE-Generated
  3. #include "SEfirework-mlle.asc" ///@MLLE-Generated
  4. #pragma require "SEfirework-mlle.asc" ///@MLLE-Generated
  5. class CustomWeaponHook : se::DefaultWeaponHook {
  6.         bool drawAmmo(jjPLAYER@ player, jjCANVAS@ canvas) override {
  7.                 int x, y;
  8.                 STRING::Size font;
  9.                 string text;
  10.                 const jjWEAPON@ weapon = jjWeapons[player.currWeapon];
  11.                 if (jjSubscreenWidth > 400) {
  12.                         x = jjSubscreenWidth - 88;
  13.                         y = jjSubscreenHeight - 14;
  14.                         font = STRING::MEDIUM;
  15.                 } else {
  16.                         x = jjSubscreenWidth - 48;
  17.                         y = jjSubscreenHeight - 9;
  18.                         font = STRING::SMALL;
  19.                 }
  20.                 if (weapon.infinite || weapon.replacedByShield && player.shieldTime > 0) {
  21.                         text = "x^";
  22.                 } else {
  23.                         int ammo = player.ammo[WEAPON::CURRENT];
  24.                         text = "x" + (ammo > 0 ? ammo : 0);
  25.                 }
  26.                 drawAmmoSprite(canvas, x, y, getWeaponAnimation(player.currWeapon, player.powerup[WEAPON::CURRENT]));
  27.                 canvas.drawString(x + 8, y, text, font);
  28.                 return true;
  29.         }
  30. }
  31. array<int> lastFired(jjLocalPlayerCount);
  32. array<int> lenientLastFired(jjLocalPlayerCount);
  33. array<int> lastSugarRush(jjLocalPlayerCount);
  34. array<bool> missileFired(jjLocalPlayerCount);
  35. array<bool> selectPressed(jjLocalPlayerCount);
  36. array<bool> tongueUsed(jjLocalPlayerCount);
  37. bool canFire(const jjPLAYER@ player) {
  38.         switch (jjWeapons[player.currWeapon].style) {
  39.                 case WEAPON::MISSILE:
  40.                         return !missileFired[player.localPlayerID];
  41.                 case WEAPON::POPCORN:
  42.                         return jjGameTicks - lenientLastFired[player.localPlayerID] >= 6;
  43.                 case WEAPON::CAPPED:
  44.                         return jjGameTicks - lastFired[player.localPlayerID] >= player.fastfire;
  45.         }
  46.         return jjGameTicks - lenientLastFired[player.localPlayerID] >= player.fastfire;
  47. }
  48. void processFiring(const jjPLAYER@ player) {
  49.         if (jjWeapons[player.currWeapon].style == WEAPON::MISSILE)
  50.                 missileFired[player.localPlayerID] = true;
  51.         lastFired[player.localPlayerID] = jjGameTicks;
  52.         lenientLastFired[player.localPlayerID] = jjGameTicks;
  53. }
  54. void processNotFiring(const jjPLAYER@ player) {
  55.         missileFired[player.localPlayerID] = false;
  56.         lenientLastFired[player.localPlayerID] = -252000;
  57. }
  58. void cycleWeapon(jjPLAYER@ player) {
  59.         auto initial = player.currWeapon;
  60.         do {
  61.                 player.currWeapon = player.currWeapon % 9 + 1;
  62.         } while (player.currWeapon != initial && getRealAmmo(player, WEAPON::CURRENT) == 0);
  63. }
  64. jjANIMATION@ getWeaponAnimation(int weapon, bool powerup) {
  65.         int modifier = powerup ? 1 : 0;
  66.         switch (weapon) {
  67.                 case WEAPON::BLASTER:
  68.                         return jjAnimations[powerup ? jjAnimSets[ANIM::AMMO] + 18 : jjAnimSets[ANIM::PICKUPS] + 29];
  69.                 case WEAPON::BOUNCER:
  70.                         return jjAnimations[jjAnimSets[ANIM::AMMO] + 25 - modifier];
  71.                 case WEAPON::ICE:
  72.                         return jjAnimations[jjAnimSets[ANIM::CUSTOM[0]] + modifier];
  73.                 case WEAPON::SEEKER:
  74.                         return jjAnimations[jjAnimSets[ANIM::AMMO] + 34 - modifier];
  75.                 case WEAPON::RF:
  76.                         return jjAnimations[jjAnimSets[ANIM::AMMO] + 49 - modifier];
  77.                 case WEAPON::TOASTER:
  78.                         return jjAnimations[jjAnimSets[ANIM::AMMO] + 57 - modifier];
  79.                 case WEAPON::TNT:
  80.                         return jjAnimations[jjAnimSets[ANIM::AMMO] + 59];
  81.                 case WEAPON::GUN8:
  82.                         return jjAnimations[jjAnimSets[ANIM::AMMO] + 62 - modifier];
  83.                 case WEAPON::GUN9:
  84.                         return jjAnimations[jjAnimSets[ANIM::AMMO] + 68 - modifier];
  85.         }
  86.         return null;
  87. }
  88. int getWeaponEventID(int weapon, bool powerup, bool &out pepper) {
  89.         auto spread = jjWeapons[weapon].spread;
  90.         if (spread == SPREAD::PEPPERSPRAY || spread == SPREAD::GUN8 && !jjAllowsFireball) {
  91.                 pepper = true;
  92.                 return OBJECT::BULLET;
  93.         }
  94.         pepper = false;
  95.         int modifier = powerup ? 8 : 0;
  96.         switch (weapon) {
  97.                 case WEAPON::BLASTER:
  98.                         return OBJECT::BLASTERBULLET + modifier;
  99.                 case WEAPON::BOUNCER:
  100.                         return OBJECT::BOUNCERBULLET + modifier;
  101.                 case WEAPON::ICE:
  102.                         return OBJECT::ICEBULLET + modifier;
  103.                 case WEAPON::SEEKER:
  104.                         return OBJECT::SEEKERBULLET + modifier;
  105.                 case WEAPON::RF:
  106.                         return OBJECT::RFBULLET + modifier;
  107.                 case WEAPON::TOASTER:
  108.                         return OBJECT::TOASTERBULLET + modifier;
  109.                 case WEAPON::TNT:
  110.                         return OBJECT::TNT;
  111.                 case WEAPON::GUN8:
  112.                         return OBJECT::FIREBALLBULLET + modifier;
  113.                 case WEAPON::GUN9:
  114.                         return OBJECT::ELECTROBULLET + modifier;
  115.         }
  116.         return 0;
  117. }
  118. void drawAmmoSprite(jjCANVAS@ canvas, int x, int y, const jjANIMATION@ anim) {
  119.         if (anim !is null)
  120.                 canvas.drawSpriteFromCurFrame(x, y, anim + (::jjGameTicks >> 2) % anim.frameCount);
  121. }
  122. void fireBullet(const jjPLAYER@ player, int angle, float x, float y) {
  123.         bool pepper;
  124.         auto eventID = getWeaponEventID(player.currWeapon, player.powerup[WEAPON::CURRENT], pepper);
  125.         int id = jjAddObject(eventID, x, y, player.playerID, CREATOR::PLAYER, pepper ? BEHAVIOR::PEPPERBULLET : BEHAVIOR::DEFAULT);
  126.         if (id > 0) {
  127.                 auto@ obj = jjObjects[id];
  128.                 if (pepper) {
  129.                         bool powerup = jjStrongPowerups && player.powerup[WEAPON::CURRENT];
  130.                         obj.playerHandling = HANDLING::PLAYERBULLET;
  131.                         obj.determineCurAnim(ANIM::AMMO, powerup ? 10 : 9);
  132.                         obj.determineCurFrame();
  133.                         obj.animSpeed = player.powerup[WEAPON::CURRENT] ? 2 : 1;
  134.                         obj.var[3] = 8;
  135.                         obj.xSpeed = 4.f;
  136.                         if (powerup) {
  137.                                 obj.lightType = LIGHT::POINT2;
  138.                                 obj.state = STATE::FLY;
  139.                                 obj.var[6] = obj.var[6] | 8;
  140.                         }
  141.                 }
  142.                 float speed = obj.xSpeed;
  143.                 float acc = obj.xAcc;
  144.                 obj.xSpeed = jjCos(angle << 7) * speed;
  145.                 obj.ySpeed -= jjSin(angle << 7) * speed;
  146.                 obj.xAcc = jjCos(angle << 7) * acc;
  147.                 obj.yAcc -= jjSin(angle << 7) * acc;
  148.                 obj.direction = angle < 2 ? 1 : angle > 2 ? -1 : 0;
  149.         }
  150. }
  151. int getRealAmmo(const jjPLAYER@ player, int weapon) {
  152.         if (weapon == WEAPON::CURRENT)
  153.                 weapon = player.currWeapon;
  154.         auto@ preset = jjWeapons[weapon];
  155.         int multiplier = preset.multiplier;
  156.         preset.multiplier = 1;
  157.         int result = player.ammo[weapon];
  158.         preset.multiplier = multiplier;
  159.         return result;
  160. }
  161. void decrementRealAmmo(jjPLAYER@ player, int weapon) {
  162.         if (weapon == WEAPON::CURRENT)
  163.                 weapon = player.currWeapon;
  164.         auto@ preset = jjWeapons[weapon];
  165.         int multiplier = preset.multiplier;
  166.         preset.multiplier = 1;
  167.         player.ammo[weapon] = player.ammo[weapon] - 1;
  168.         preset.multiplier = multiplier;
  169. }
  170. void coinMorph(jjOBJ@ obj) {
  171.         if (obj.state == STATE::DEACTIVATE) {
  172.                 obj.deactivate();
  173.                 return;
  174.         }
  175.         if (obj.state == STATE::START) {
  176.                 int x = int(obj.xOrg) >>> 5;
  177.                 int y = int(obj.yOrg) >>> 5;
  178.                 if (jjParameterGet(x, y, 17, 1) == 0) {
  179.                         obj.delete();
  180.                         return;
  181.                 }
  182.                 obj.state = STATE::STILL;
  183.                 obj.var[0] = jjParameterGet(x, y, 8, 8);
  184.                 obj.var[1] = jjParameterGet(x, y, 0, 8);
  185.                 obj.var[2] = jjParameterGet(x, y, 16, 1);
  186.                 obj.var[3] = jjParameterGet(x, y, 18, 1);
  187.                 obj.xPos -= 16.f;
  188.                 obj.yPos -= 16.f;
  189.                 obj.putOnGround(true);
  190.                 return;
  191.         }
  192.         auto@ bunny = jjAnimations[obj.curAnim];
  193.         auto@ booth = jjAnimations[obj.special];
  194.         obj.counter++;
  195.         if (obj.counter & 7 == 0) {
  196.                 obj.frameID++;
  197.                 if (obj.frameID >= int(bunny.frameCount))
  198.                         obj.frameID = 0;
  199.                 obj.determineCurFrame();
  200.         }
  201.         jjDrawSpriteFromCurFrame(obj.xPos - 1.f, obj.yPos + 3.f, booth + (obj.counter >> 3) % booth.frameCount, obj.direction, SPRITE::PALSHIFT, 16);
  202.         jjDrawSpriteFromCurFrame(obj.xPos, obj.yPos, obj.curFrame + bunny.frameCount, obj.direction);
  203.         jjDrawSpriteFromCurFrame(obj.xPos, obj.yPos, obj.curFrame, obj.direction, SPRITE::PALSHIFT, 40);
  204.         if (obj.var[0] != 0) {
  205.                 jjTEXTAPPEARANCE style(STRING::BOUNCE);
  206.                 style.align = STRING::CENTER;
  207.                 jjDrawString(obj.xPos - 4.f, obj.yPos - 12.f, formatInt(obj.var[0]), STRING::SMALL, style, 0, SPRITE::PALSHIFT, 224);
  208.         }
  209.         for (int i = 0; i < jjLocalPlayerCount; i++) {
  210.                 auto@ player = jjLocalPlayers[i];
  211.                 float dx = player.xPos - obj.xPos;
  212.                 float dy = player.yPos - obj.yPos;
  213.                 if (dx * dx + dy * dy < 1024.f && (player.charCurr != CHAR::BIRD || jjGameTicks - lastSugarRush[player.localPlayerID] >= 1400) && player.testForCoins(obj.var[0])) {
  214.                         if (player.charCurr == CHAR::BIRD) {
  215.                                 player.startSugarRush();
  216.                                 lastSugarRush[player.localPlayerID] = jjGameTicks;
  217.                         } else {
  218.                                 player.morphTo(CHAR::BIRD);
  219.                                 jjSample(player.xPos, player.yPos, SOUND::COMMON_BUBBLGN1);
  220.                                 lastSugarRush[player.localPlayerID] = -1400;
  221.                         }
  222.                 }
  223.         }
  224. }
  225. bool onDrawAmmo(jjPLAYER@ player, jjCANVAS@ canvas) {
  226.         return MLLE::WeaponHook.drawAmmo(player, canvas);
  227. }
  228. void onLevelLoad() {
  229.         @MLLE::WeaponHook = CustomWeaponHook();
  230.         MLLE::Setup(array<MLLEWeaponApply@> = {null, null, se::FireworkMLLEWrapper(), null, null, null, null, null, null});
  231.         jjCharacters[CHAR::FROG].canHurt = true;
  232.         jjCharacters[CHAR::FROG].canRun = true;
  233.         jjCharacters[CHAR::BIRD].canHurt = true;
  234.         jjCharacters[CHAR::BIRD].canRun = true;
  235.         jjObjectPresets[OBJECT::WARP].behavior = coinMorph;
  236. }
  237. void onPlayerInput(jjPLAYER@ player) {
  238.         auto@ weapon = jjWeapons[player.currWeapon];
  239.         auto style = weapon.style;
  240.         if (player.charCurr == CHAR::FROG || player.charCurr == CHAR::BIRD) {
  241.                 if (player.keySelect) {
  242.                         if (!selectPressed[player.localPlayerID]) {
  243.                                 selectPressed[player.localPlayerID] = true;
  244.                                 cycleWeapon(player);
  245.                         }
  246.                 } else {
  247.                         selectPressed[player.localPlayerID] = false;
  248.                 }
  249.         }
  250.         if (player.charCurr == CHAR::BIRD) {
  251.                 if (player.keyFire) {
  252.                         player.keyFire = false;
  253.                         if (canFire(player) && player.currWeapon != WEAPON::BLASTER) {
  254.                                 int anim = player.curAnim - jjAnimSets[ANIM::BIRD];
  255.                                 if (anim >= 9 && anim != 10 && anim != 19) {
  256.                                         if (anim != 9)
  257.                                                 player.keyUp = true;
  258.                                         player.fireBullet();
  259.                                         processFiring(player);
  260.                                         if (getRealAmmo(player, WEAPON::CURRENT) == 0 && !weapon.infinite)
  261.                                                 cycleWeapon(player);
  262.                                 }
  263.                         }
  264.                 } else {
  265.                         processNotFiring(player);
  266.                 }
  267.                 if (player.keyJump) {
  268.                         player.keyFire = true;
  269.                         player.keyJump = false;
  270.                 }
  271.         }
  272. }
  273. void onPlayer(jjPLAYER@ player) {
  274.         if (player.xSpeed > 6.f)
  275.                 player.xSpeed = 6.f;
  276.         if (player.xSpeed < -6.f)
  277.                 player.xSpeed = -6.f;
  278.         if (player.charCurr == CHAR::FROG) {
  279.                 int anim = player.curAnim - jjAnimSets[ANIM::FROG] + (jjIsTSF ? 0 : 1);
  280.                 if (anim >= 8 && anim <= 10 && player.frameID == 6) {
  281.                         if (!tongueUsed[player.localPlayerID]) {
  282.                                 tongueUsed[player.localPlayerID] = true;
  283.                                 if (player.currWeapon != WEAPON::BLASTER) {
  284.                                         if (getRealAmmo(player, WEAPON::CURRENT) > 0) {
  285.                                                 decrementRealAmmo(player, WEAPON::CURRENT);
  286.                                                 int angle = anim == 10 ? 2 : player.direction < 0 ? anim - 5 : 9 - anim;
  287.                                                 float x = player.xPos + jjCos(angle << 7) * 76.f + (player.direction < 0 ? 4.f : -4.f);
  288.                                                 float y = player.yPos - jjSin(angle << 7) * 76.f + 8.f;
  289.                                                 jjSTREAM packet;
  290.                                                 packet.push(uint8(player.playerID));
  291.                                                 packet.push(uint8(player.currWeapon));
  292.                                                 packet.push(bool(player.powerup[WEAPON::CURRENT]));
  293.                                                 packet.push(uint(player.ammo[WEAPON::CURRENT]));
  294.                                                 packet.push(uint8(angle));
  295.                                                 packet.push(float(x));
  296.                                                 packet.push(float(y));
  297.                                                 jjSendPacket(packet);
  298.                                                 fireBullet(player, angle, x, y);
  299.                                         }
  300.                                         if (getRealAmmo(player, WEAPON::CURRENT) == 0 && !jjWeapons[player.currWeapon].infinite)
  301.                                                 cycleWeapon(player);
  302.                                 }
  303.                         }
  304.                 } else {
  305.                         tongueUsed[player.localPlayerID] = false;
  306.                 }
  307.         } else if (player.charCurr != CHAR::BIRD) {
  308.                 player.morphTo(CHAR::FROG);
  309.         }
  310. }
  311. void onReceive(jjSTREAM &in packet, int clientID) {
  312.         jjSTREAM backup = packet;
  313.         uint8 playerID, weapon, angle;
  314.         uint ammo;
  315.         bool powerup;
  316.         float x, y;
  317.         if (!packet.pop(playerID) || !packet.pop(weapon) || !packet.pop(powerup) || !packet.pop(ammo) || !packet.pop(angle) || !packet.pop(x) || !packet.pop(y))
  318.                 return;
  319.         if (playerID >= 32 || weapon <= 1 || weapon >= 10 || angle >= 5)
  320.                 return;
  321.         auto@ player = jjPlayers[playerID];
  322.         if (jjIsServer && player.clientID != clientID || player.isLocal)
  323.                 return;
  324.         if (jjIsServer)
  325.                 jjSendPacket(backup, -clientID);
  326.         player.currWeapon = weapon;
  327.         player.powerup[weapon] = powerup;
  328.         player.ammo[weapon] = ammo;
  329.         fireBullet(player, angle, x, y);
  330. }
  331. void onLevelBegin() {
  332.   jjSugarRushAllowed = true;
  333. }