Downloads containing ab23btl01.j2as

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

File preview

const bool MLLESetupSuccessful = MLLE::Setup(); ///@MLLE-Generated
#include "MLLE-Include-1.5.asc" ///@MLLE-Generated
#pragma require "ab23btl01-MLLE-Data-2.j2l" ///@MLLE-Generated
#pragma require "ab23btl01-MLLE-Data-1.j2l" ///@MLLE-Generated
#pragma require "ab23btl01.j2l" ///@MLLE-Generated
#pragma name "Nail Gun"
#pragma require "Nail.j2a"
#pragma require "f_ar3.wav"
#pragma require "SpringMushroom.j2a"
#pragma require "S3K_87.wav"

bool gameIsActive() {
	return jjGameState == GAME::STARTED || jjGameState == GAME::OVERTIME;
}

void onLevelLoad() {
	jjUseLayer8Speeds = true;
	jjTexturedBGFadePositionY = 0.9;
	
	jjObjectPresets[OBJECT::APPLE].behavior = Glitter();
	jjObjectPresets[OBJECT::STEADYLIGHT].behavior = Glow();
	
	jjAnimSets[ANIM::CUSTOM[0]].load(0, "SpringMushroom.j2a");
	jjAnimSets[ANIM::CUSTOM[1]].load(0, "Nail.j2a");
	
	for (int i = 0; i < 8; i++) {
		jjAnimations[jjAnimSets[ANIM::SPRING] + i] = jjAnimations[jjAnimSets[ANIM::CUSTOM[0]] + i];
	}
	
	jjAnimations[jjAnimSets[ANIM::AMMO] + 62] = jjAnimations[jjAnimSets[ANIM::CUSTOM[1]] + 4];
	jjAnimations[jjAnimSets[ANIM::AMMO] + 61] = jjAnimations[jjAnimSets[ANIM::CUSTOM[1]] + 5];
	
	jjSampleLoad(SOUND::P2_CRUNCH, "f_ar3.wav");
	
	jjObjectPresets[OBJECT::BOUNCERBULLET].behavior = FixedBouncer();
	
	jjObjectPresets[OBJECT::FIREBALLBULLET].behavior = jjObjectPresets[OBJECT::FIREBALLBULLETPU].behavior = Nailgun();
	jjObjectPresets[OBJECT::FIREBALLBULLET].var[6] = 16;
	jjObjectPresets[OBJECT::FIREBALLBULLET].counterEnd = 58;
	jjObjectPresets[OBJECT::FIREBALLBULLET].killAnim = jjObjectPresets[OBJECT::BLASTERBULLET].killAnim;
	jjObjectPresets[OBJECT::FIREBALLBULLET].special = jjObjectPresets[OBJECT::FIREBALLBULLET].determineCurAnim(ANIM::CUSTOM[1], 0);
	jjObjectPresets[OBJECT::FIREBALLBULLET].xSpeed = jjObjectPresets[OBJECT::RFBULLET].xSpeed;
	jjObjectPresets[OBJECT::FIREBALLBULLET].ySpeed = jjObjectPresets[OBJECT::RFBULLET].ySpeed;
	jjObjectPresets[OBJECT::FIREBALLBULLET].xAcc = jjObjectPresets[OBJECT::RFBULLET].xAcc;
	jjObjectPresets[OBJECT::FIREBALLBULLET].yAcc = jjObjectPresets[OBJECT::RFBULLET].yAcc;
	jjObjectPresets[OBJECT::FIREBALLBULLETPU].var[6] = 8 + 16;
	jjObjectPresets[OBJECT::FIREBALLBULLETPU].counterEnd = 52;
	jjObjectPresets[OBJECT::FIREBALLBULLETPU].killAnim = jjObjectPresets[OBJECT::BLASTERBULLET].killAnim;
	jjObjectPresets[OBJECT::FIREBALLBULLETPU].special = jjObjectPresets[OBJECT::FIREBALLBULLETPU].determineCurAnim(ANIM::CUSTOM[1], 1);
	jjObjectPresets[OBJECT::FIREBALLBULLETPU].xSpeed = jjObjectPresets[OBJECT::RFBULLETPU].xSpeed;
	jjObjectPresets[OBJECT::FIREBALLBULLETPU].ySpeed = jjObjectPresets[OBJECT::RFBULLETPU].ySpeed;
	jjObjectPresets[OBJECT::FIREBALLBULLETPU].xAcc = jjObjectPresets[OBJECT::RFBULLETPU].xAcc;
	jjObjectPresets[OBJECT::FIREBALLBULLETPU].yAcc = jjObjectPresets[OBJECT::RFBULLETPU].yAcc;
	jjObjectPresets[OBJECT::FIREBALLBULLET].lightType = jjObjectPresets[OBJECT::FIREBALLBULLETPU].lightType = LIGHT::POINT;
	
	jjObjectPresets[OBJECT::GUN8AMMO3].lightType = LIGHT::POINT;
	
	jjObjectPresets[OBJECT::GUN8POWERUP].determineCurAnim(ANIM::CUSTOM[1], 3);
	jjObjectPresets[OBJECT::GUN8POWERUP].determineCurFrame();
	
	jjWeapons[WEAPON::GUN8].spread = SPREAD::NORMAL;
	jjWeapons[WEAPON::GUN8].style = WEAPON::NORMAL;
	jjWeapons[WEAPON::GUN8].gradualAim = false;
	jjWeapons[WEAPON::GUN8].defaultSample = false;
	
	jjANIMATION@ anim = jjAnimations[jjAnimSets[ANIM::AMMO] + 71];
	for (uint i = 0; i < anim.frameCount; ++i) {
		jjANIMFRAME@ frame = jjAnimFrames[anim + 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] = 0;
		sprite.save(frame);
	}
	
	auto proposedLayerOrder = jjLayerOrderGet();
	jjLAYER@ layer = jjLAYER(jjLayers[1]);
	proposedLayerOrder.insertAt(0, layer);
	jjLayerOrderSet(proposedLayerOrder);
	
	jjANIMATION@ animRain = jjAnimations[jjAnimSets[ANIM::COMMON] + 2];
	for (uint j = 0; j < animRain.frameCount; j++) {
		jjANIMFRAME@ frameRain = jjAnimFrames[animRain + j];
		jjPIXELMAP sprite(frameRain);
		for (uint x = 0; x < sprite.width; ++x) {
			for (uint y = 0; y < sprite.height; ++y) {
				sprite[x,y] = 0;
			}
		}
		sprite.save(frameRain);
	}
	
	generateCustomSpringSprites(jjAnimSets[ANIM::CUSTOM[2]], array<uint> = {40});
	turnIntoCustomSpring(jjObjectPresets[OBJECT::FROZENSPRING], 0, 19.f, false);
	
	jjObjectPresets[OBJECT::REDSPRING].behavior =
	jjObjectPresets[OBJECT::GREENSPRING].behavior =
	jjObjectPresets[OBJECT::BLUESPRING].behavior =
	jjObjectPresets[OBJECT::FROZENSPRING].behavior = SpringMushroom();
}

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();
}

void onLevelBegin() {
	for (int i = 1; i < 255; i++) {
		jjOBJ@ preset = jjObjectPresets[i];
		if (preset.playerHandling == HANDLING::PICKUP && preset.eventID != OBJECT::CARROT) {
			preset.behavior = CannotBeShotDown(preset.behavior);
		} else if (preset.eventID == OBJECT::CARROT) {
			preset.behavior = CannotBeBuried();
		}
	}
	array<jjLAYER@> layers = jjLayerOrderGet();
	singleColorLayer(layers[0], 10);
	
	jjSampleLoad(SOUND::COMMON_SPRING1, "S3K_87.wav");
}

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 CannotBeBuried : jjBEHAVIORINTERFACE {
	void onBehave(jjOBJ@ obj) {
		obj.behave(BEHAVIOR::PICKUP);
		if (jjMaskedPixel(int(obj.xPos), int(obj.yPos + 8))) {
			obj.state = STATE::FLOAT;
		}
		if (obj.state == STATE::FLOATFALL) {
			obj.var[1] = 1;
		}
		if (obj.var[1] == 0) {
			if (obj.xOrg > 75*32) {
				obj.xPos = obj.xOrg + 16;
			}
			if (obj.yOrg < 25*32) {
				obj.xPos = obj.xOrg + 16;
				obj.yPos = obj.yOrg + 16;
			}
		}
		if (obj.ySpeed < -8) obj.ySpeed = -8;
	}
}

class Glitter : jjBEHAVIORINTERFACE {
	void onBehave(jjOBJ@ obj) {
		obj.playerHandling = HANDLING::PARTICLE;
		obj.yPos = obj.yOrg + 32;
	}
}

class Glow : jjBEHAVIORINTERFACE {
	void onBehave(jjOBJ@ obj) {
		obj.behave(BEHAVIOR::STEADYLIGHT);
		obj.lightType = jjLowDetail? LIGHT::NONE : LIGHT::BRIGHT;
	}
}

class FixedBouncer : jjBEHAVIORINTERFACE {
	void onBehave(jjOBJ@ obj) {
		obj.behave(BEHAVIOR::BOUNCERBULLET);
		float xSpeed = obj.xSpeed;
		float ySpeed = obj.ySpeed;
		if (xSpeed * obj.xSpeed < 0.f && ySpeed * obj.ySpeed < 0.f) {
			if (!jjMaskedPixel(int(obj.xPos + obj.xSpeed), int(obj.yPos + ySpeed))) {
				obj.var[0] = obj.var[0] - 1;
				obj.ySpeed = ySpeed;
				if (ySpeed > 0.f)
					obj.yPos += ySpeed;
			}
		}
	}
}

class Nailgun : jjBEHAVIORINTERFACE {
	void onBehave(jjOBJ@ obj) {
		obj.behave(obj.state == STATE::EXPLODE? BEHAVIOR::BULLET : BEHAVIOR::RFBULLET, obj.state == STATE::EXPLODE? true:false);
		jjPLAYER@ creator = jjPlayers[obj.creatorID];
		
		obj.var[0] = int(atan2(-obj.ySpeed, obj.xSpeed) * (512.f * 0.318309886142228f));
		
		obj.xAcc = (obj.eventID == OBJECT::FIREBALLBULLETPU? 0.4:0.35) * obj.direction;
		if (obj.ySpeed < 0 && obj.direction == 0 && obj.xSpeed == 0) obj.yAcc = -0.6;
		
		
		if (obj.state != STATE::EXPLODE) {
			if (obj.counter == 1 && creator.isLocal) {
				jjSample(creator.xPos, creator.yPos, SOUND::P2_CRUNCH, 48, obj.eventID == OBJECT::FIREBALLBULLETPU? 19000:17500);
				obj.var[2] = 0;
				obj.playerHandling = HANDLING::PLAYERBULLET;
			}
			
			jjDrawRotatedSprite(obj.xPos, obj.yPos, ANIM::CUSTOM[1], obj.eventID == OBJECT::FIREBALLBULLETPU? 1:0, 0, obj.var[0], 1, 1, SPRITE::NORMAL);
			
			/*float dx = jjLocalPlayers[0].xPos - obj.xPos, dy = jjLocalPlayers[0].yPos - obj.yPos;
			if ((dx * dx + dy * dy < 64 * 24) && !creator.isLocal && jjLocalPlayers[0].blink == 0 && (jjLocalPlayers[0].team != creator.team || jjFriendlyFire || jjGameMode != GAME::CTF) && gameIsActive()) {
				jjLocalPlayers[0].xPos = obj.xPos - (24 * obj.direction);
				jjLocalPlayers[0].ySpeed = obj.ySpeed;
			}*/
			
			if (jjMaskedPixel(int(obj.xPos + obj.xSpeed + obj.var[7] / 65536.f), int(obj.yPos))) {
				obj.xSpeed = 0;
				obj.var[7] = 0;
				obj.playerHandling = HANDLING::PARTICLE;
				obj.bePlatform((obj.xPos - (18 * obj.direction)), obj.yPos, 36, 8);
				if (obj.var[2] == 0) {
					jjSample(obj.xPos, obj.yPos, SOUND::COMMON_METALHIT, 0, 0);
					obj.counter = 1;
					obj.counterEnd = obj.eventID == OBJECT::FIREBALLBULLETPU? 120:110;
					obj.var[2] = 1;
				}
			}
			else if (jjMaskedPixel(int(obj.xPos), int(obj.yPos + obj.ySpeed))) {
				obj.ySpeed = 0;
				obj.playerHandling = HANDLING::PARTICLE;
				if (obj.var[2] == 0) {
					jjSample(obj.xPos, obj.yPos, SOUND::COMMON_METALHIT, 0, 0);
					obj.counter = 1;
					obj.counterEnd = obj.eventID == OBJECT::FIREBALLBULLETPU? 120:110;
					obj.var[2] = 1;
				}
			}
		} else {
			obj.clearPlatform();
			obj.var[2] = 0;
			obj.counterEnd = obj.eventID == OBJECT::FIREBALLBULLETPU? 55:60;
		}
	}
}

class SpringMushroom : jjBEHAVIORINTERFACE {
	void onBehave(jjOBJ@ obj) {
		obj.behave(BEHAVIOR::SPRING);
		if (obj.state == STATE::SPRING && !jjLowDetail) {
			jjPARTICLE@ spores = jjAddParticle(PARTICLE::FIRE);
			if (spores !is null) {
				spores.xPos = int(obj.xPos - 14) + (jjRandom()%14)*2;
				spores.yPos = int(obj.yPos - 14) + jjRandom()%14;
				if (jjRandom()%2 > 0)
					spores.ySpeed = -1;
				else spores.ySpeed = -0.6;
				spores.fire.color = 64;
				spores.fire.colorStop = 72;
			}
		}
	}
}

void onMain() {
	array<jjLAYER@> layers = jjLayerOrderGet();
	layers[0].spriteMode = jjLowDetail || jjColorDepth == 8? SPRITE::INVISIBLE : SPRITE::BLEND_OVERLAY;
	layers[0].spriteParam = int(abs(jjSin(jjGameTicks*5)*255));
	
	jjIsSnowing = !jjLowDetail;
	jjSnowingType = jjGameTicks % 7 == 0? SNOWING::FLOWER : SNOWING::RAIN;
	jjSnowingIntensity = 0;
	jjIsSnowingOutdoorsOnly = true;
	
	for (int i = 0; i < 1024; i++) {
		jjPARTICLE@ particle = jjParticles[i];
		if (particle.type == PARTICLE::FLOWER) {
			particle.xSpeed = -0.25;
			particle.ySpeed = 1;
			particle.flower.petals = 3;
			particle.flower.color = 144;
			if (particle.flower.size > 48) particle.flower.size = 48;
		}
		if (particle.type == PARTICLE::RAIN) {
			particle.type = PARTICLE::INACTIVE;
		}
	}
}

void singleColorLayer(jjLAYER@ layer, int color) {
	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());
	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) {
					tile[k, j] = color;
				}
			}
		}
		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));
		}
	}
}