Downloads containing ab21ctf01.j2as

Downloads
Name Author Game Mode Rating
TSF with JJ2+ Only: Anniversary Bash 21 Levels Jazz2Online Multiple N/A Download file

File preview

  1. #include "MLLE-Include-1.4.asc"
  2. const bool MLLESetupSuccessful = MLLE::Setup();
  3. #pragma require "ab21ctf01-MLLE-Data-1.j2l"
  4. #pragma require "ab21ctf01.j2l"
  5.  
  6. bool mist = true;
  7. const string Filename = "mist.asdat";
  8.  
  9. funcdef jjPALCOLOR ColorFunction(jjPALCOLOR);
  10.  
  11. void onLevelLoad() {
  12.         jjUseLayer8Speeds = true;
  13.        
  14.         generateCustomSpringSprites(jjAnimSets[ANIM::CUSTOM[0]], array<uint> = {40});
  15.         turnIntoCustomSpring(jjObjectPresets[OBJECT::FROZENSPRING], 0, 19.75f, false);
  16.  
  17.         jjPIXELMAP rain(32,32);
  18.         for (uint x = 0; x < rain.width; ++x) {
  19.                 for (uint y = 0; y < rain.height; ++y) {
  20.                         if (x == 16) {
  21.                                 if (y <= 16) rain[x,y] = 75;
  22.                                 else if (y > 16 && y <= 24) rain[x,y] = 74;
  23.                                 else rain[x,y] = 0;
  24.                         } else {
  25.                                 rain[x,y] = 0;
  26.                         }
  27.                 }
  28.         }
  29.        
  30.         jjANIMATION@ anim = jjAnimations[jjAnimSets[ANIM::COMMON].firstAnim + 2];
  31.         for (uint frameID = 0; frameID < anim.frameCount; ++frameID) {
  32.                 jjANIMFRAME@ frame = jjAnimFrames[anim.firstFrame + frameID];
  33.                 rain.save(frame);
  34.                 frame.hotSpotX = -frame.width/2;
  35.                 frame.hotSpotY = -frame.height;
  36.         }
  37.        
  38.         jjObjectPresets[OBJECT::BOUNCERPOWERUP].direction = 0;
  39.         jjObjectPresets[OBJECT::RFPOWERUP].direction = 1;
  40.        
  41.         jjObjectPresets[OBJECT::AMBIENTSOUND].behavior = Emitter();
  42.        
  43.         for (int i = 1; i < 255; i++) {
  44.                 if (jjObjectPresets[i].playerHandling == HANDLING::PICKUP && jjObjectPresets[i].behavior == BEHAVIOR::PICKUP) {
  45.                         jjObjectPresets[i].behavior = CannotBeBuried();
  46.                 }
  47.         }
  48.        
  49.         jjSTREAM savedSettings(Filename);
  50.         while (!savedSettings.isEmpty()) {
  51.                 savedSettings.pop(mist);
  52.         }
  53.        
  54.         jjAnimSets[ANIM::DEVILDEVAN].load();
  55.        
  56.  
  57. }
  58.  
  59. void onLevelReload() {
  60.         MLLE::Palette.apply();
  61. }
  62.  
  63. void onLevelBegin() {
  64.         array<jjLAYER@> layers = jjLayerOrderGet();
  65.        
  66.         if (layers[6].hasTileMap) {
  67.                 darkenLayer(layers[6], array<uint8>(), function(color) {
  68.                         color.setHSL(color.getHue(), color.getSat(), color.getLight() * 6 / 10);
  69.                         return color;
  70.                 });
  71.         }
  72.        
  73.         for (int i = 1; i < jjObjectCount; i++) {
  74.                 if (jjObjects[i].eventID == OBJECT::CTFBASE || jjObjects[i].behavior == BEHAVIOR::FLAG) jjObjects[i].yOrg -= 12;
  75.         }
  76. }
  77.  
  78. jjANIMSET@ customSpringSprite;
  79. array<int> fastCustomSpringSpeeds(jjLocalPlayerCount);
  80. bool generateCustomSpringSprites(jjANIMSET@ anim, const array<uint> &in colors) {
  81.         int length = colors.length();
  82.         bool success = (@customSpringSprite = anim).allocate(array<uint>(length * 3, 5)) !is null;
  83.         if (success) {
  84.                 uint srcSet = jjAnimSets[ANIM::SPRING];
  85.                 for (int i = 0; i < length; i++) {
  86.                         uint color = colors[i];
  87.                         uint destAnimOffset = anim + i * 3;
  88.                         for (int j = 0; j < 3; j++) {
  89.                                 uint srcAnim = jjAnimations[srcSet + j];
  90.                                 uint destAnim = jjAnimations[destAnimOffset + j];
  91.                                 for (int k = 0; k < 5; k++) {
  92.                                         jjPIXELMAP image(jjAnimFrames[destAnim + k] = jjAnimFrames[srcAnim + k]);
  93.                                         int width = image.width;
  94.                                         int height = image.height;
  95.                                         for (int l = 0; l < height; l++) {
  96.                                                 for (int m = 0; m < width; m++) {
  97.                                                         int pixel = image[m, l];
  98.                                                         if (pixel >= 32 && pixel < 40)
  99.                                                                 image[m, l] = color + (pixel & 7);
  100.                                                 }
  101.                                         }
  102.                                         if (!image.save(jjAnimFrames[destAnim + k]))
  103.                                                 return false;
  104.                                 }
  105.                         }
  106.                 }
  107.         }
  108.         return success;
  109. }
  110. void initializeCustomSpring(jjOBJ@ obj) {
  111.         int anim = obj.curAnim;
  112.         obj.behave(obj.behavior = BEHAVIOR::SPRING, false);
  113.         if (obj.curAnim != anim) {
  114.                 obj.curAnim = anim + 2;
  115.                 obj.determineCurFrame();
  116.         }
  117.         obj.draw();
  118. }
  119. void turnIntoCustomSpring(jjOBJ@ obj, uint color, float power, bool horizontal) {
  120.         if (horizontal) {
  121.                 obj.xSpeed = power;
  122.                 obj.ySpeed = 0.f;
  123.         } else {
  124.                 obj.xSpeed = 0.f;
  125.                 obj.ySpeed = -power;
  126.                 if (obj.state == STATE::START && obj.creatorType == CREATOR::LEVEL) {
  127.                         int x = int(obj.xPos) >> 5;
  128.                         int y = int(obj.yPos) >> 5;
  129.                         if (jjParameterGet(x, y, 0, 1) != 0) {
  130.                                 jjParameterSet(x, y, 0, 1, 0);
  131.                                 obj.yPos -= 4.f;
  132.                                 obj.ySpeed = power;
  133.                         }
  134.                 }
  135.         }
  136.         obj.behavior = initializeCustomSpring;
  137.         obj.curAnim = customSpringSprite + color * 3 + (horizontal ? 1 : 0);
  138.         obj.energy = obj.frameID = obj.freeze = obj.justHit = obj.light = obj.points = 0;
  139.         obj.isBlastable = obj.isTarget = obj.scriptedCollisions = obj.triggersTNT = false;
  140.         obj.deactivates = obj.isFreezable = true;
  141.         obj.bulletHandling = HANDLING::IGNOREBULLET;
  142.         obj.playerHandling = HANDLING::SPECIAL;
  143.         obj.lightType = LIGHT::NORMAL;
  144.         obj.determineCurFrame();
  145. }
  146.  
  147. class Emitter : jjBEHAVIORINTERFACE {
  148.         void onBehave(jjOBJ@ emitter) {
  149.                 emitter.behave(jjLowDetail && jjGameTicks >= 2? BEHAVIOR::INACTIVE : BEHAVIOR::AMBIENTSOUND, false);
  150.                 if (!jjLowDetail) {
  151.                         jjPARTICLE@ smoke = jjAddParticle(PARTICLE::SMOKE);
  152.                         if (smoke !is null) {
  153.                                 smoke.xPos = int(emitter.xPos + 8);
  154.                                 smoke.yPos = int(emitter.yPos - 28);
  155.                                 smoke.ySpeed = -0.2;
  156.                         }
  157.                 }
  158.         }
  159. }
  160.  
  161. class CannotBeBuried : jjBEHAVIORINTERFACE {
  162.         void onBehave(jjOBJ@ obj) {
  163.                 obj.behave(BEHAVIOR::PICKUP);
  164.                 if (jjMaskedPixel(int(obj.xPos), int(obj.yPos) + 8)) {
  165.                         obj.state = STATE::FLOAT;
  166.                 }
  167.         }
  168. }
  169.  
  170. void onPlayer(jjPLAYER@ play) {
  171.         for (int i = 0; i < 1024; i++) {
  172.                 jjPARTICLE@ particle = jjParticles[i];
  173.                 if (particle.type == PARTICLE::RAIN) {
  174.                         particle.xSpeed = 0;
  175.                         particle.ySpeed = play.ySpeed < 0? 10 : int(10 + play.ySpeed);
  176.                 }
  177.         }
  178. }
  179.  
  180. void darkenLayer(jjLAYER@ layer, array<uint8>& freePaletteIndices, ColorFunction@ func) {
  181.         array<int> tileIDs, uniqueTileIDs;
  182.         for (int i = 0; i < layer.height; i++) {
  183.                 for (int j = 0; j < layer.width; j++) {
  184.                         int tileID = layer.tileGet(j, i);
  185.                         if (tileID != 0)
  186.                                 tileIDs.insertLast(tileID);
  187.                 }
  188.         }
  189.         int prev = 0;
  190.         tileIDs.sortAsc();
  191.         for (uint i = 0; i < tileIDs.length(); i++) {
  192.                 if (tileIDs[i] != prev)
  193.                         uniqueTileIDs.insertLast(prev = tileIDs[i]);
  194.         }
  195.         uint firstNewTile = jjTileCount;
  196.         jjTilesFromTileset(jjTilesetFileName, 1, uniqueTileIDs.length());
  197.         array<uint8> mapping(256);
  198.         for (uint i = 0; i < uniqueTileIDs.length(); i++) {
  199.                 jjPIXELMAP tile(uniqueTileIDs[i]);
  200.                 for (int j = 0; j < 32; j++) {
  201.                         for (int k = 0; k < 32; k++) {
  202.                                 uint8 pixel = tile[k, j];
  203.                                 if (pixel != 0) {
  204.                                         if (mapping[pixel] == 0) {
  205.                                                 jjPALCOLOR color = func(jjPalette.color[pixel]);
  206.                                                 uint8 bestMatch = jjPalette.findNearestColor(color);
  207.                                                 if (!freePaletteIndices.isEmpty()) {
  208.                                                         jjPALCOLOR other = jjPalette.color[bestMatch];
  209.                                                         int red = other.red - color.red;
  210.                                                         int green = other.green - color.green;
  211.                                                         int blue = other.blue - color.blue;
  212.                                                         int distance = red * red + green * green + blue * blue;
  213.                                                         if (distance > 16) {
  214.                                                                 bestMatch = freePaletteIndices[freePaletteIndices.length() - 1];
  215.                                                                 jjPalette.color[bestMatch] = color;
  216.                                                                 freePaletteIndices.removeLast();
  217.                                                         }
  218.                                                 }
  219.                                                 mapping[pixel] = bestMatch;
  220.                                         }
  221.                                 tile[k, j] = mapping[pixel];
  222.                                 }
  223.                         }
  224.                 }
  225.                 tile.save(firstNewTile + i);
  226.         }
  227.         layer.generateSettableTileArea();
  228.         for (int i = 0; i < layer.height; i++) {
  229.                 for (int j = 0; j < layer.widthReal; j++) {
  230.                         int tileID = layer.tileGet(j, i);
  231.                         if (tileID != 0)
  232.                                 layer.tileSet(j, i, firstNewTile + uniqueTileIDs.find(tileID));
  233.                 }
  234.         }
  235. }
  236.  
  237. void onMain() {
  238.         if (jjGameTicks == 210 && (jjFPS < 59 || (jjFPS > 60 && jjFPS < 90)) && mist && jjColorDepth == 16 && !jjLowDetail) {
  239.                 jjConsole("|You may want to toggle the mist with ||!mist|||||| to address performance issues.");
  240.         }
  241.  
  242.         jjTexturedBGFadePositionY = jjLowDetail? 0.5:0.4;
  243.  
  244.         array<jjLAYER@> layers = jjLayerOrderGet();
  245.        
  246.         if (jjColorDepth == 16 && mist) layers[7].hasTiles = true;
  247.         else layers[7].hasTiles = false;
  248.        
  249.         if (jjColorDepth == 16 && !mist) layers[8].hasTiles = true;
  250.         else layers[8].hasTiles = false;
  251.  
  252.         layers[7].yOffset += 0.1f;
  253.         layers[11].xOffset += 0.4f;
  254.         layers[12].xOffset += 0.25f;
  255.         if (layers[7].yOffset % (layers[7].height*32) == 0) layers[7].yOffset = 0;
  256.         if (layers[11].xOffset % (layers[11].widthReal*32) == 0) layers[11].xOffset = 0;
  257.         if (layers[12].xOffset % (layers[12].widthReal*32) == 0) layers[12].xOffset = 0;
  258.        
  259.         jjIsSnowing = !jjLowDetail;
  260.        
  261.         for (int i = 1; i < jjObjectCount; i++) {
  262.                 jjOBJ@ obj = jjObjects[i];
  263.                 if (obj.eventID == OBJECT::STEADYLIGHT) {
  264.                         obj.xPos = obj.xOrg + 8;
  265.                         obj.yPos = obj.yOrg - 4;
  266.                         jjDrawSprite(obj.xPos + 1, obj.yPos, ANIM::AMMO, 13, jjGameTicks >> 3, 0, SPRITE::NORMAL, 0, 5, 5);
  267.                 }
  268.         }
  269. }
  270.  
  271. bool onLocalChat(string &in text, CHAT::Type type) {
  272.         if (jjRegexMatch(text, "!mist", true)) {
  273.                 if (mist) {
  274.                         jjConsole("Mist disabled!");
  275.                         mist = false;
  276.                         jjSTREAM stream;
  277.                         stream.push(mist);
  278.                         stream.save(Filename);
  279.                 }
  280.                 else {
  281.                         jjConsole("Mist enabled!");
  282.                         mist = true;
  283.                         jjSTREAM stream;
  284.                         stream.push(mist);
  285.                         stream.save(Filename);
  286.                 }
  287.         return true;
  288.         }
  289.         else return false;
  290. }
  291.  
  292. class Dragon {
  293.         private float xPos, yPos, xOrg, yOrg, minScale, maxScale;
  294.         private int direction, color;
  295.        
  296.         void setParameters(Dragon@ dragon, float xOrg, float yOrg, float minScale, float maxScale, int direction, int color) {
  297.                 dragon.xOrg = xOrg;
  298.                 dragon.yOrg = yOrg;
  299.                 dragon.minScale = minScale;
  300.                 dragon.maxScale = maxScale;
  301.                 dragon.direction = direction;
  302.                 dragon.color = color;
  303.         }
  304.        
  305.         void getPosition(Dragon@ dragon) {
  306.                 dragon.xPos = jjSin(jjGameTicks)*64*dragon.direction + dragon.xOrg;
  307.                 dragon.yPos = jjCos(jjGameTicks)*16*dragon.direction + dragon.yOrg;
  308.         }
  309.        
  310.         void draw(Dragon@ dragon, jjCANVAS@ canvas) {
  311.                 canvas.drawResizedSprite(int(dragon.xPos), int(dragon.yPos), ANIM::DEVILDEVAN, dragon.yPos > (dragon.yOrg + 0.24) && dragon.yPos < (dragon.yOrg + 2.8)? 9:5, jjGameTicks >> 3, dragon.yPos >= (dragon.yOrg + 2.8)? maxScale:-minScale, dragon.yPos >= (dragon.yOrg + 2.8)? maxScale:minScale, SPRITE::SINGLECOLOR, dragon.color);
  312.         }
  313. }
  314.  
  315. void onDrawLayer6(jjPLAYER@ play, jjCANVAS@ canvas) {
  316.         Dragon dragon;
  317.        
  318.         dragon.setParameters(dragon, 560, 320, 0.3, 0.45, -1, 229);
  319.         dragon.getPosition(dragon);
  320.        
  321.         dragon.draw(dragon, canvas);
  322. }
  323.  
  324. void onDrawLayer7(jjPLAYER@ play, jjCANVAS@ canvas) {
  325.         Dragon dragon;
  326.  
  327.         dragon.setParameters(dragon, 100, 130, 0.18, 0.25, 1, 95);
  328.         dragon.getPosition(dragon);
  329.        
  330.         dragon.draw(dragon, canvas);
  331. }
  332.