Name | Author | Game Mode | Rating | |||||
---|---|---|---|---|---|---|---|---|
Fishing Village | PurpleJazz | Capture the flag | 9 |
#include "MLLE-Include-1.4.asc"
const bool MLLESetupSuccessful = MLLE::Setup();
#pragma require "xlmbeach1.j2t"
#pragma require "Lomat.j2t"
#pragma require "xlmfishing-MLLE-Data-2.j2l"
#pragma require "xlmfishing-MLLE-Data-1.j2l"
#pragma require "xlmfishing.j2l"
#pragma require "rain9.wav"
#pragma require "lightning2.wav"
#pragma require "splash01.wav"
#pragma require "SEroller.asc"
#pragma require "SEfirework.asc"
#include "SEroller.asc"
#include "SEfirework.asc"
#include "limitedoxygen.asc"
se::DefaultWeaponHook weaponHook;
bool layersInitialized = false;
/*******************************************************************/
class Level {
private int lightningDelay = 90;
private int waterHeight = 80*32;
private float lightningOffset = 0;
private bool lightning = false;
private int sample = 0;
private jjPAL standard, palette;
private int hue, sat, light;
void darkenLayer(jjLAYER@ layer, float factor) {
array<int> tileIDs, uniqueTileIDs;
for (int i = 0; i < layer.height; i++) {
for (int j = 0; j < layer.width; j++) {
int tileID = layer.tileGet(j, i);
if (tileID != 0)
tileIDs.insertLast(tileID);
}
}
int prev = 0;
tileIDs.sortAsc();
for (uint i = 0; i < tileIDs.length(); i++) {
if (tileIDs[i] != prev)
uniqueTileIDs.insertLast(prev = tileIDs[i]);
}
uint firstNewTile = jjTileCount;
jjTilesFromTileset(jjTilesetFileName, 1, uniqueTileIDs.length());
array<uint8> mapping(256);
for (uint i = 0; i < uniqueTileIDs.length(); i++) {
jjPIXELMAP tile(uniqueTileIDs[i]);
for (int j = 0; j < 32; j++) {
for (int k = 0; k < 32; k++) {
uint8 pixel = tile[k, j];
if (pixel != 0) {
if (mapping[pixel] == 0) {
jjPALCOLOR color = jjPalette.color[pixel];
color.red = uint8(color.red / factor);
color.green = uint8(color.green / factor);
color.blue = uint8(color.blue / factor);
mapping[pixel] = jjPalette.findNearestColor(color);
}
tile[k, j] = mapping[pixel];
}
}
}
tile.save(firstNewTile + i);
}
layer.generateSettableTileArea();
for (int i = 0; i < layer.height; i++) {
for (int j = 0; j < layer.widthReal; j++) {
int tileID = layer.tileGet(j, i);
if (tileID != 0)
layer.tileSet(j, i, firstNewTile + uniqueTileIDs.find(tileID));
}
}
}
void doStuffWithLayers() {
auto proposedLayerOrder = jjLayerOrderGet();
for (int i = 2; i < 6; i++) {
jjLAYER@ layer = jjLAYER(jjLayers[1]);
layer.xSpeed = (0.09/i)*1.85;
layer.ySpeed = (0.05/i)*1.85;
layer.xOffset = jjRandom() & 127;
layer.yOffset = jjLayers[1].yOffset + i*24;
proposedLayerOrder.insertAt(proposedLayerOrder.length - 3, layer);
}
jjLayerOrderSet(proposedLayerOrder);
proposedLayerOrder[proposedLayerOrder.length - 2].hasTiles = false;
jjTileType[822] = 1;
}
void handleInvisibleBarriers(jjPLAYER@ play) {
const int bounds = 16;
if (play.xPos > ((jjLayerWidth[4]*32) - bounds) || play.xPos < bounds) {
play.xPos = play.xPos < (bounds+1)? bounds : (jjLayerWidth[4]*32) - bounds;
play.xSpeed = 0;
play.specialMove = 0;
}
if (jjEventGet(int(play.xPos/32), int(play.yPos/32)) == AREA::PATH) {
int direction = jjParameterGet(int(play.xPos/32), int(play.yPos/32), 6, 3);
if (direction > 0) {
play.xSpeed = -2;
} else {
play.xSpeed = 2;
}
}
}
void handleVerticalRain() {
jjIsSnowing = !jjLowDetail;
for (int i = 0; i < 1024; i++) {
jjPARTICLE@ particle = jjParticles[i];
if (particle.type == PARTICLE::RAIN) {
particle.xSpeed = 0;
particle.ySpeed = jjLocalPlayers[0].ySpeed < 0? 10 : int(10 + jjLocalPlayers[0].ySpeed);
if (jjMaskedVLine(int(particle.xPos), int(particle.yPos - 1000), 992) || jjMaskedHLine(int(particle.xPos), 2, int(particle.yPos - 8))) {
particle.type = PARTICLE::INACTIVE;
}
}
}
}
void loadSamples() {
jjSampleLoad(SOUND::WIND_WIND2A, "rain9.wav");
jjSampleLoad(SOUND::BILSBOSS_THUNDER, "lightning2.wav");
jjSampleLoad(SOUND::COMMON_WATER, "splash01.wav");
}
void makeRainLookRealistic() {
jjANIMATION@ animBubble = jjAnimations[jjAnimSets[ANIM::COMMON] + 1];
for (uint i = 0; i < animBubble.frameCount; ++i) {
jjANIMFRAME@ frame = jjAnimFrames[animBubble + i];
jjPIXELMAP sprite(frame);
for (uint x = 0; x < sprite.width; ++x)
for (uint y = 0; y < sprite.height; ++y)
if (sprite[x,y] != 0) sprite[x,y] += 115;
sprite.save(frame);
}
jjPIXELMAP rain(32,32);
for (uint x = 0; x < rain.width; ++x) {
for (uint y = 0; y < rain.height; ++y) {
if (x == 16) {
if (y <= 24) rain[x,y] = 75;
else rain[x,y] = 74;
} else {
rain[x,y] = 0;
}
}
}
jjANIMATION@ animRain = jjAnimations[jjAnimSets[ANIM::COMMON].firstAnim + 2];
for (uint frameID = 0; frameID < animRain.frameCount; ++frameID) {
jjANIMFRAME@ frame = jjAnimFrames[animRain.firstFrame + frameID];
rain.save(frame);
frame.hotSpotX = -frame.width/2;
frame.hotSpotY = -frame.height;
}
}
void processLevelEffects(jjPLAYER@ play) {
play.lightType = LIGHT::NONE;
if (!jjLowDetail) {
if (play.yPos > int(jjWaterLevel + 64)) {
play.lighting = 80 - int((play.yPos - jjWaterLevel)/24);
} else {
play.lighting = 80;
}
if (jjGameTicks > 7) {
sample = jjSampleLooped(play.xPos, play.yPos > jjWaterLevel? jjWaterLevel : play.yPos, SOUND::WIND_WIND2A, sample, 36, 0);
}
} else {
play.lighting = 100;
}
array<jjLAYER@> layers = jjLayerOrderGet();
int lightningLayer = layers.length - 2;
layers[lightningLayer].xOffset = lightningOffset;
if (!jjLowDetail) {
if (lightning && lightningDelay > 0) lightningDelay--;
if (jjGameTicks % 1000 >= 940 && jjGameTicks % 1000 <= 979) {
if (jjGameTicks % 5 == 0) {
layers[lightningLayer].hasTiles = true;
if (play.yPos < jjWaterLevel + 600) play.lighting = play.yPos < jjWaterLevel + 64? 130:115;
}
else {
layers[lightningLayer].hasTiles = false;
if (play.yPos < jjWaterLevel + 600) play.lighting = play.yPos < jjWaterLevel + 64? 105:85;
}
if (jjGameTicks % 18 == 0) lightningOffset = jjRandom()%800;
}
if (jjGameTicks % 1000 >= 980) {
lightning = true;
lightningDelay = 90;
}
if (lightning && lightningDelay == 0) {
for (int i = 0; i < 2; i++) {
jjSample(play.xPos, play.yPos < jjWaterLevel? play.yPos : jjWaterLevel, SOUND::BILSBOSS_THUNDER, 31 + jjRandom()%32, 0);
}
lightning = false;
}
}
}
void relocateCTFBases() {
for (int i = 1; i < jjObjectCount; i++) {
if (jjObjects[i].eventID == OBJECT::CTFBASE || jjObjects[i].behavior == BEHAVIOR::FLAG) jjObjects[i].yOrg += 16;
}
}
void relocateObjects() {
for (int i = 1; i < jjObjectCount; i++) {
jjOBJ@ obj = jjObjects[i];
if (obj.eventID == OBJECT::TOASTERPOWERUP) {
obj.xPos = obj.xOrg + (obj.xOrg > int(jjLayerWidth[4]/2)? 12:-12);
obj.direction = obj.xOrg > int(jjLayerWidth[4]/2)? 1:-1;
}
}
}
void removeSpritePaletteReferences() {
array<int> mapping(256);
for (int i = 1; i < 96; i++) {
jjPALCOLOR color = jjPalette.color[i];
int best = 0x40000;
for (int j = 96; j < 256; j++) {
jjPALCOLOR match = jjPalette.color[j];
int red = int(match.red) - color.red;
int green = int(match.green) - color.green;
int blue = int(match.blue) - color.blue;
int dist = red * red + green * green + blue * blue;
if (dist < best) {
best = dist;
mapping[i] = j;
}
}
}
for (int i = 96; i < 256; i++) {
mapping[i] = i;
}
for (uint i = 1; i < jjTileCount; i++) {
jjPIXELMAP tile(i);
for (int j = 0; j < 32; j++) {
for (int k = 0; k < 32; k++) {
tile[k, j] = mapping[tile[k, j]];
}
}
tile.save(i, true);
}
}
void setLayerSettings() {
array<jjLAYER@> layers = jjLayerOrderGet();
layers[0].hasTiles = jjLowDetail || jjColorDepth == 8? true:false;
layers[0].yOffset = layers[8].yOffset = waterHeight - jjWaterLevel;
layers[6].hasTiles = layers[7].hasTiles = jjColorDepth == 16? true:false;
jjWaterLayer = jjLowDetail || jjColorDepth == 8? 0:2;
}
void setLevelPalette() {
standard.load("Diam2.j2t");
jjPalette.copyFrom(16, 40, 16, standard, 1);
jjPalette.copyFrom(59, 37, 59, standard, 1);
palette.load("ICJungS.j2t");
for (int n = 96; n <= 254; n++) {
hue = jjPalette.color[n].getHue();
sat = jjPalette.color[n].getSat();
light = jjPalette.color[n].getLight();
if (n < 176 || n > 207) palette.color[n].setHSL(hue, sat / 4, int(light * 2));
}
jjPalette.copyFrom(96, 80, 96, palette, 1);
jjPalette.copyFrom(208, 46, 208, palette, 1);
jjPalette.gradient(128,137,94, 17,29,41, 176, 32);
jjPalette.apply();
}
void setCustomObjects() {
RollerEdit roller;
FireworkEdit firework;
roller.loadAnims(jjAnimSets[ANIM::CUSTOM[0]]);
roller.loadSamples(array<SOUND::Sample> = {SOUND::ORANGE_SWEEP2L});
roller.setAsWeapon(3, weaponHook);
firework.loadAnims(jjAnimSets[ANIM::CUSTOM[1]]);
firework.loadSamples(array<SOUND::Sample> = {SOUND::ORANGE_BOEML, SOUND::ORANGE_BOEMR});
firework.setAsWeapon(4, weaponHook);
generateCustomSpringSprites(jjAnimSets[ANIM::CUSTOM[2]], array<uint> = {40, 16, 88});
turnIntoCustomSpring(jjObjectPresets[OBJECT::FROZENSPRING], 0, 19.f, false);
turnIntoCustomSpring(jjObjectPresets[OBJECT::HORREDSPRING], 1, 22.f, false);
turnIntoCustomSpring(jjObjectPresets[OBJECT::HORGREENSPRING], 2, 28.f, false);
jjObjectPresets[OBJECT::HORREDSPRING].causesRicochet = jjObjectPresets[OBJECT::HORGREENSPRING].causesRicochet = false;
for (int i = 1; i < 255; i++) {
if (jjObjectPresets[i].playerHandling == HANDLING::PICKUP) {
jjObjectPresets[i].behavior = CannotBeShotDown(jjObjectPresets[i].behavior);
}
}
}
void setWaterProperties() {
jjSetWaterLevel(waterHeight,true);
jjWaterLighting = WATERLIGHT::GLOBAL;
jjSetWaterGradient(160,200,150, 10,20,5);
}
void setSkyProperties() {
jjUseLayer8Speeds = true;
jjTexturedBGTexture = TEXTURE::PSYCH;
jjTexturedBGFadePositionY = 0.42;
}
void warpPlayersInSP() {
if (jjGameMode == GAME::COOP || jjGameMode == GAME::SP) {
for (int i = 0; i < 4; i++) {
if (jjLocalPlayers[i].yOrg < 32) jjLocalPlayers[i].warpToID(255, true);
}
}
}
}
/*******************************************************************/
class RollerEdit : se::RollerWeapon {
protected void behaveCommon(::jjOBJ@ obj, int mask, float verticalTolerance, float maxSpeed) const override {
switch (obj.state) {
case STATE::START:
if (obj.creatorType == CREATOR::PLAYER && ::jjPlayers[obj.creatorID].isLocal)
::jjSample(obj.xPos, obj.yPos, obj.yPos < jjWaterLevel? getSample() : SOUND::COMMON_SWISH6);
if (obj.xSpeed == 0.f) {
if (obj.var[7] != 0)
obj.direction = obj.var[7] < 0 ? -1 : 1;
else if (::jjGameConnection != GAME::LOCAL)
obj.direction = 1;
else if (obj.creatorType == CREATOR::PLAYER)
obj.direction = ::jjPlayers[obj.creatorID].direction;
else if (obj.creatorType == CREATOR::OBJECT)
obj.direction = ::jjObjects[obj.creatorID].direction;
}
obj.xAcc = ::jjObjectPresets[obj.eventID].xAcc;
if (obj.direction < 0)
obj.xAcc = -obj.xAcc;
obj.yAcc = ::jjObjectPresets[obj.eventID].yAcc;
obj.xSpeed += obj.var[7] / 1e5f;
obj.state = STATE::ROTATE;
case STATE::ROTATE:
if (move(obj, mask, verticalTolerance, maxSpeed) || obj.counter++ > int(obj.counterEnd))
obj.state = STATE::EXPLODE;
if (::jjGameTicks % 3 == 0) {
obj.frameID++;
if (obj.frameID >= int(::jjAnimations[obj.curAnim].frameCount))
obj.frameID = 0;
}
obj.determineCurFrame();
obj.draw();
break;
case STATE::EXPLODE:
obj.curAnim = obj.killAnim;
if (obj.curAnim == 0) {
obj.delete();
} else {
if (obj.playerHandling != HANDLING::EXPLOSION) {
obj.frameID = obj.freeze = 0;
obj.isTarget = obj.triggersTNT = false;
obj.playerHandling = HANDLING::EXPLOSION;
}
if (::jjGameTicks & 3 == 0)
obj.frameID++;
if (obj.frameID < int(::jjAnimations[obj.curAnim].frameCount)) {
obj.determineCurFrame();
obj.draw();
} else {
obj.delete();
}
}
break;
case STATE::KILL:
case STATE::DEACTIVATE:
obj.delete();
break;
}
}
}
class FireworkEdit : se::FireworkWeapon {
protected void behave(::jjOBJ@ obj) const override {
switch (obj.state) {
case STATE::START:
if (obj.creatorType == CREATOR::PLAYER && ::jjPlayers[obj.creatorID].isLocal)
::jjSample(obj.xPos, obj.yPos, obj.yPos > jjWaterLevel ? SOUND::AMMO_MISSILE : getSamples()[0], obj.yPos > jjWaterLevel? 32:0, 0);
obj.counterEnd = ::jjObjectPresets[obj.eventID].counterEnd;
obj.yAcc = -0.25f;
obj.xSpeed += obj.var[7] / 2e5f;
obj.state = STATE::ROCKETFLY;
case STATE::ROCKETFLY:
if (obj.xAcc * obj.xSpeed >= 0.f)
obj.xSpeed = obj.xAcc = 0.f;
else
obj.xPos += obj.xSpeed += obj.xAcc;
if (obj.ySpeed < -9.f) {
obj.yAcc = 0.f;
obj.ySpeed = -9.f;
}
obj.yPos += obj.ySpeed += obj.yAcc;
if (::jjMaskedPixel(int(obj.xPos), int(obj.yPos)) && ::jjEventAtLastMaskedPixel != AREA::ONEWAY) {
obj.xPos -= obj.xSpeed;
obj.yPos -= obj.ySpeed;
obj.state = STATE::EXTRA;
} else if (obj.counter++ > int(obj.counterEnd)) {
obj.state = STATE::EXTRA;
}
obj.draw();
break;
case STATE::EXTRA:
case STATE::EXPLODE:
::jjSample(obj.xPos, obj.yPos, obj.yPos > jjWaterLevel ? SOUND::AMMO_BOEM1 : getSamples()[1]);
for (int i = 0; i < 6; i++) {
::jjSample(obj.xPos + ::jjSin((i << 10) / 6) * 320.f, obj.yPos + ::jjCos((i << 10) / 6) * 320.f, obj.yPos > jjWaterLevel ? SOUND::AMMO_BOEM1 : getSamples()[1]);
}
{
array<int> colors = {34, 81, 24, 50};
int particles = 12 + (obj.var[6] >> 1 & 4);
for (int i = 0; i < particles; i++) {
int id = ::jjAddObject(obj.eventID, obj.xPos, obj.yPos, obj.creatorID, obj.creatorType, @::jjVOIDFUNCOBJ(behaveParticle));
if (id > 0) {
::jjOBJ@ other = @::jjObjects[id];
other.animSpeed >>= 1;
other.counterEnd -= 10;
other.curAnim = obj.killAnim;
other.determineCurFrame();
other.var[1] = colors[obj.var[6] >> 2 & 2 | i & 1];
other.xSpeed = ::jjSin((i << 10) / particles) * 6.f;
other.ySpeed = ::jjCos((i << 10) / particles) * 6.f;
other.xAcc = other.xSpeed / -64.f;
other.yAcc = other.ySpeed / -64.f;
if (obj.state == STATE::EXPLODE)
other.playerHandling = HANDLING::PARTICLE;
}
}
}
obj.draw();
case STATE::KILL:
case STATE::DEACTIVATE:
obj.delete();
break;
}
}
}
jjANIMSET@ customSpringSprite;
array<int> fastCustomSpringSpeeds(jjLocalPlayerCount);
bool generateCustomSpringSprites(jjANIMSET@ anim, const array<uint> &in colors) {
int length = colors.length();
bool success = (@customSpringSprite = anim).allocate(array<uint>(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.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();
}
class CannotBeShotDown : jjBEHAVIORINTERFACE {
jjBEHAVIOR originalBehavior;
CannotBeShotDown(jjBEHAVIOR behavior) {
originalBehavior = behavior;
}
void onBehave(jjOBJ@ obj) override {
obj.behave(originalBehavior);
if (obj.state == STATE::FLOATFALL)
obj.state = STATE::FLOAT;
if (obj.eventID == OBJECT::FULLENERGY)
obj.xPos = obj.xOrg - 16;
}
bool onObjectHit(jjOBJ@ obj, jjOBJ@ bullet, jjPLAYER@ player, int force) {
obj.behavior = originalBehavior;
if (bullet is null)
player.objectHit(obj, force, obj.playerHandling);
else
bullet.objectHit(obj, obj.playerHandling);
obj.behavior = CannotBeShotDown(obj.behavior);
return true;
}
}
/*******************************************************************/
Level level;
void onLevelLoad() {
level.loadSamples();
level.makeRainLookRealistic();
level.removeSpritePaletteReferences();
level.setCustomObjects();
level.setWaterProperties();
level.setSkyProperties();
}
void onLevelBegin() {
level.doStuffWithLayers();
level.relocateCTFBases();
level.setLevelPalette();
level.warpPlayersInSP();
water::maxOxygen = 1800;
if (!layersInitialized) {
level.darkenLayer(jjLayers[6], 1.65);
level.darkenLayer(jjLayers[7], 3.25);
layersInitialized = true;
}
}
void onLevelReload() {
onLevelLoad();
onLevelBegin();
}
void onPlayer(jjPLAYER@ play) {
weaponHook.processPlayer(play);
water::limitedOxygen(play);
level.handleInvisibleBarriers(play);
level.processLevelEffects(play);
}
void onPlayerInput(jjPLAYER@ play) {
weaponHook.processPlayerInput(play);
}
void onMain() {
weaponHook.processMain();
level.handleVerticalRain();
level.relocateObjects();
level.setLayerSettings();
}
void onReceive(jjSTREAM &in packet, int clientID) {
weaponHook.processPacket(packet, clientID);
}
bool onDrawAmmo(jjPLAYER@ play, jjCANVAS@ canvas) {
return weaponHook.drawAmmo(play, canvas);
}
bool onDrawHealth(jjPLAYER@ play, jjCANVAS@ canvas) {
water::drawOxygenTimer(play, canvas);
return false;
}
Jazz2Online © 1999-INFINITY (Site Credits). We have a Privacy Policy. Jazz Jackrabbit, Jazz Jackrabbit 2, Jazz Jackrabbit Advance and all related trademarks and media are ™ and © Epic Games. Lori Jackrabbit is © Dean Dodrill. J2O development powered by Loops of Fury and Chemical Beats.
Eat your lima beans, Johnny.