Downloads containing ab26btl11.j2as

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

File preview

const bool MLLESetupSuccessful = MLLE::Setup(); ///@MLLE-Generated
#include "MLLE-Include-1.6.asc" ///@MLLE-Generated
#pragma require "SpaceWarbase.j2t" ///@MLLE-Generated
#pragma require "ab26btl11.j2l" ///@MLLE-Generated

const int8 ENERGY_FIELD_ENERGY = 10;

jjANIMSET@ customSpringSprite;
array<int> fastCustomSpringSpeeds(jjLocalPlayerCount);

class CannotBeShotDown : jjBEHAVIORINTERFACE {
	CannotBeShotDown(const jjBEHAVIOR &in behavior) {
		originalBehavior = behavior;
	}
	void onBehave(jjOBJ@ obj) {
		obj.behave(originalBehavior);
		if (obj.state == STATE::FLOATFALL)
			obj.state = STATE::FLOAT;
	}
	bool onObjectHit(jjOBJ@ obj, jjOBJ@ bullet, jjPLAYER@ player, int force) {
		if (bullet is null) {
			obj.behavior = originalBehavior;
			if (player.objectHit(obj, force, obj.playerHandling))
				return true;
			obj.behavior = this;
		}
		return false;
	}
	private jjBEHAVIOR originalBehavior;
}

class EnergyField : jjBEHAVIORINTERFACE {
	int elapsedDelayedStart = 0;
	int16 xTile = 0;
	int16 yTile = 0;
	
	void onBehave(jjOBJ@ obj) override {
		if (obj.state == STATE::START) {
			obj.energy = ENERGY_FIELD_ENERGY;
			xTile = int16(obj.xOrg) >> 5;
			yTile = int16(obj.yOrg) >> 5;
			if (jjParameterGet(xTile, yTile, 0, 1) == 0) {
				jjParameterSet(xTile, yTile, 0, 1, 1);
				
				jjPIXELMAP energyFieldSprite(uint(obj.xOrg) - 12, uint(obj.yOrg) - 6, 8, 192);
				jjANIMFRAME@ frame = jjAnimFrames[jjAnimations[jjAnimSets[ANIM::PICKUPS].firstAnim + 2].firstFrame];
				energyFieldSprite.save(frame);
				
				jjGenerateSettableTileArea(4, xTile, yTile, 1, 6);
				deactivateEnergyField();
			}
			elapsedDelayedStart = 0;
			obj.state = STATE::DELAYEDSTART;
		} else if (obj.state == STATE::DELAYEDSTART) {
			if (elapsedDelayedStart < 140) {
				elapsedDelayedStart++;
				if (jjGameTicks % 10 == 0) {
					setParticleProps(obj, jjAddParticle(PARTICLE::PIXEL), true);
					setParticleProps(obj, jjAddParticle(PARTICLE::PIXEL), false);
				}
			} else {
				activateEnergyField();
				obj.state = STATE::IDLE;
			}
		} else if (obj.state == STATE::KILL) {
			deactivateEnergyField();
		}
		obj.behave(BEHAVIOR::EVA, false);
	}
	
	// Draw justHit effects artificially, since animated tiles are being used instead of sprites
	void onDraw(jjOBJ@ obj) {
		if (obj.justHit > 0) {
			jjDrawRectangle(uint(obj.xOrg) - 10, uint(obj.yOrg) - 6, 4, 176, 15);
		}
	}
	
	bool onObjectHit(jjOBJ@ obj, jjOBJ@ bullet, jjPLAYER@ player, int force) {
		if (obj.state != STATE::IDLE) {
			return true;
		}
		if (bullet !is null) {
			bullet.state = STATE::EXPLODE;
			obj.justHit = 5;
			if (obj.energy > 1) {
				--obj.energy;
			} else {
				obj.state = STATE::KILL;
			}
		} else if (player !is null) {
			player.hurt();
			
			// Artificial measure to prevent players from getting stuck in the energy field when it's respawning
			if (player.xPos >= obj.xPos) {
				player.xPos += 1;
			} else {
				player.xPos -= 1;
			}
		}
		return true;
	}
	
	private void activateEnergyField() {
		jjTileSet(4, xTile, yTile, 16 + TILE::ANIMATED);
		jjTileSet(4, xTile, yTile + 1, 17 + TILE::ANIMATED);
		jjTileSet(4, xTile, yTile + 2, 18 + TILE::ANIMATED);
		jjTileSet(4, xTile, yTile + 3, 17 + TILE::ANIMATED);
		jjTileSet(4, xTile, yTile + 4, 18 + TILE::ANIMATED);
		jjTileSet(4, xTile, yTile + 5, 19 + TILE::ANIMATED);
	}
	
	private void deactivateEnergyField() {
		jjTileSet(4, xTile, yTile, 609);
		jjTileSet(4, xTile, yTile + 1, 0);
		jjTileSet(4, xTile, yTile + 2, 0);
		jjTileSet(4, xTile, yTile + 3, 0);
		jjTileSet(4, xTile, yTile + 4, 0);
		jjTileSet(4, xTile, yTile + 5, 629);
	}
	
	private void setParticleProps(jjOBJ@ obj, jjPARTICLE@ particle, bool isUpperHead) {
		if (particle !is null) {
			particle.xPos = obj.xPos - 8;
			particle.yPos = isUpperHead ? obj.yPos : obj.yPos + 144;
			particle.ySpeed = isUpperHead ? 1 : -1;
			particle.pixel.color[1] = 40;
			particle.pixel.size = 1;
		}
	}
}

class WarpOrb : jjBEHAVIORINTERFACE {
	void onBehave(jjOBJ@ obj) {
		obj.behave(BEHAVIOR::PICKUP, false);
		if (obj.state == STATE::FLOATFALL) obj.state = STATE::FLOAT;
	}
	void onDraw(jjOBJ@ obj) {
		int frame = obj.objectID * 8 + jjGameTicks;
		frame = (frame + int(obj.xPos) + int(obj.yPos) * 256)*16;
		jjDrawTile(obj.xPos - 16, (obj.yPos + jjSin(frame) * 4) - 16, 118);
	}
	bool onObjectHit(jjOBJ@ obj, jjOBJ@ bullet, jjPLAYER@ player, int force) {
		player.warpToID(0);
		jjSample(player.xPos, player.yPos, SOUND::COMMON_PICKUP1, 63, 17500);
		obj.frameID = 0;
		obj.behavior = BEHAVIOR::EXPLOSION2;
		return true;
	}
}

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 handleFastCustomSpringSpeeds(jjPLAYER@ play) {
	if (play.ySpeed < -32.f) {
		fastCustomSpringSpeeds[play.localPlayerID] = int(ceil((play.ySpeed + 32.f) / -0.125f));
	} else if (fastCustomSpringSpeeds[play.localPlayerID] != 0) {
		if (play.ySpeed < -31.f) {
			fastCustomSpringSpeeds[play.localPlayerID]--;
			play.ySpeed = -32.f;
		} else {
			fastCustomSpringSpeeds[play.localPlayerID] = 0;
		}
	}
}

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 onLevelBegin() {
	for (int i = 1; i < 255; i++) {
		jjOBJ@ preset = jjObjectPresets[i];
		if (preset.playerHandling == HANDLING::PICKUP) {
			preset.behavior = CannotBeShotDown(preset.behavior);
		}
	}
}

void onLevelLoad() {
	jjUseLayer8Speeds = true;
	jjObjectPresets[OBJECT::APPLE].behavior = WarpOrb();
	jjObjectPresets[OBJECT::APPLE].lightType = LIGHT::FLICKER;
	jjObjectPresets[OBJECT::APPLE].scriptedCollisions = true;
	jjObjectPresets[OBJECT::BANANA].behavior =  function(obj){obj.behavior = EnergyField();};
	jjObjectPresets[OBJECT::BANANA].lightType = LIGHT::FLICKER;
	jjObjectPresets[OBJECT::BANANA].scriptedCollisions = true;
	jjObjectPresets[OBJECT::BANANA].bulletHandling = HANDLING::DETECTBULLET;
	jjObjectPresets[OBJECT::BANANA].playerHandling = HANDLING::SPECIAL;
	generateCustomSpringSprites(jjAnimSets[ANIM::CUSTOM[0]], array<uint> = {88, 40});
	turnIntoCustomSpring(jjObjectPresets[OBJECT::FROZENSPRING], 0, 36.0f, false);
	turnIntoCustomSpring(jjObjectPresets[OBJECT::HORREDSPRING], 1, 19.0f, false);
}

void onPlayer(jjPLAYER@ play) {
	handleFastCustomSpringSpeeds(play);
}

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.isTarget = obj.scriptedCollisions = obj.triggersTNT = false;
	obj.isBlastable = false;
	obj.deactivates = true;
	obj.isFreezable = true;
	obj.bulletHandling = HANDLING::IGNOREBULLET;
	obj.playerHandling = HANDLING::SPECIAL;
	obj.lightType = LIGHT::NORMAL;
	obj.determineCurFrame();
}