Downloads containing ab20ctf19.j2as

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

File preview

#include "MLLE-Include-1.4.asc"
const bool MLLESetupSuccessful = MLLE::Setup();
#pragma require "ETs Planet1 v3.j2t"
#pragma require "ab20ctf19.j2l"
#pragma require "Nail.j2a"
#pragma require "f_ar3.wav"
#pragma require "SEenergyblast.asc"
#pragma require "weaponMega.j2a"
#include "SEenergyblast.asc"
#include "weaponMega.asc"
se::DefaultWeaponHook weaponHook;
funcdef jjPALCOLOR ColorFunction(jjPALCOLOR);

class vector2i {
	int x, y;
}
array<vector2i> oneWays;

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

void darkenLayer(jjLAYER@ layer, array<uint8>& freePaletteIndices, ColorFunction@ func) {
	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) & TILE::RAWRANGE;
			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 = func(jjPalette.color[pixel]);
						uint8 bestMatch = jjPalette.findNearestColor(color);
						if (!freePaletteIndices.isEmpty()) {
							jjPALCOLOR other = jjPalette.color[bestMatch];
							int red = other.red - color.red;
							int green = other.green - color.green;
							int blue = other.blue - color.blue;
							int distance = red * red + green * green + blue * blue;
							if (distance > 16) {
								bestMatch = freePaletteIndices[freePaletteIndices.length() - 1];
								jjPalette.color[bestMatch] = color;
								freePaletteIndices.removeLast();
							}
						}
						mapping[pixel] = bestMatch;
					}
					tile[k, j] = mapping[pixel];
				}
			}
		}
		tile.save(firstNewTile + i, true);
	}
	layer.generateSettableTileArea();
	for (int i = 0; i < layer.height; i++) {
		for (int j = 0; j < layer.widthReal; j++) {
			int tileID = layer.tileGet(j, i);
			int tileFlags = tileID & (TILE::HFLIPPED | TILE::VFLIPPED);
			tileID &= TILE::RAWRANGE;
			if (tileID != 0)
				layer.tileSet(j, i, firstNewTile + uniqueTileIDs.find(tileID) | tileFlags);
		}
	}
}
bool onDrawAmmo(jjPLAYER@ player, jjCANVAS@ canvas) {
	return weaponHook.drawAmmo(player, canvas);
}
void onLevelLoad() {
	jjTexturedBGTexture = TEXTURE::WISETYNESS;
	jjUseLayer8Speeds = true;

	se::energyBlast.loadAnims(jjAnimSets[ANIM::CUSTOM[2]]);
	se::energyBlast.loadSamples(array<SOUND::Sample> = {SOUND::P2_PTOEI});
	se::energyBlast.setAsWeapon(6, weaponHook);
	if (jjLayers[1].hasTileMap)
		darkenLayer(jjLayers[1], array<uint8>(), function(color) {
			color.setHSL(color.getHue(), color.getSat(), color.getLight() * 3 / 5);
			return color;
		});
	jjLayerOrderSet(array<jjLAYER@> = {jjLayers[2], jjLayers[3], jjLayers[4], jjLayers[1], jjLayers[5], jjLayers[6], jjLayers[7], jjLayers[8]});
	
	jjAnimSets[ANIM::CUSTOM[25]].load(0, "Nail.j2a");
	
	jjAnimations[jjAnimSets[ANIM::AMMO] + 49] = jjAnimations[jjAnimSets[ANIM::CUSTOM[25]] + 4];
	jjAnimations[jjAnimSets[ANIM::AMMO] + 48] = jjAnimations[jjAnimSets[ANIM::CUSTOM[25]] + 5];
	
	jjSampleLoad(SOUND::P2_CRUNCH, "f_ar3.wav");
	
	jjObjectPresets[OBJECT::RFBULLET].behavior = jjObjectPresets[OBJECT::RFBULLETPU].behavior = Nailgun();
	jjObjectPresets[OBJECT::RFBULLET].var[6] = 16;
	jjObjectPresets[OBJECT::RFBULLET].counterEnd = 60;
	jjObjectPresets[OBJECT::RFBULLET].killAnim = jjObjectPresets[OBJECT::BLASTERBULLET].killAnim;
	jjObjectPresets[OBJECT::RFBULLET].special = jjObjectPresets[OBJECT::RFBULLET].determineCurAnim(ANIM::CUSTOM[25], 0);
	jjObjectPresets[OBJECT::RFBULLETPU].var[6] = 8 + 16;
	jjObjectPresets[OBJECT::RFBULLETPU].counterEnd = 55;
	jjObjectPresets[OBJECT::RFBULLETPU].killAnim = jjObjectPresets[OBJECT::BLASTERBULLET].killAnim;
	jjObjectPresets[OBJECT::RFBULLETPU].special = jjObjectPresets[OBJECT::RFBULLETPU].determineCurAnim(ANIM::CUSTOM[25], 1);
	jjObjectPresets[OBJECT::RFBULLET].lightType = jjObjectPresets[OBJECT::RFBULLETPU].lightType = LIGHT::POINT;
	
	jjObjectPresets[OBJECT::RFAMMO3].lightType = LIGHT::POINT;
	
	jjObjectPresets[OBJECT::RFAMMO15].determineCurAnim(ANIM::CUSTOM[25], 2);
	jjObjectPresets[OBJECT::RFAMMO15].determineCurFrame();
	
	jjObjectPresets[OBJECT::RFPOWERUP].determineCurAnim(ANIM::CUSTOM[25], 3);
	jjObjectPresets[OBJECT::RFPOWERUP].determineCurFrame();
	
	jjWeapons[WEAPON::RF].spread = SPREAD::NORMAL;
	jjWeapons[WEAPON::RF].style = WEAPON::NORMAL;
	jjWeapons[WEAPON::RF].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);
	}
	
	jjAnimSets[ANIM::CUSTOM[26]].load(0, "TornadoGun.j2a");
	jjAnimations[jjAnimSets[ANIM::AMMO] + 62] = jjAnimations[jjAnimSets[ANIM::CUSTOM[26]] + 3];
	jjAnimations[jjAnimSets[ANIM::AMMO] + 61] = jjAnimations[jjAnimSets[ANIM::CUSTOM[26]] + 2];
	
	jjObjectPresets[OBJECT::FIREBALLBULLET].behavior = TornadoGun();
	jjObjectPresets[OBJECT::FIREBALLBULLET].special = jjObjectPresets[OBJECT::FIREBALLBULLET].determineCurAnim(ANIM::CUSTOM[26], 0);
	jjObjectPresets[OBJECT::FIREBALLBULLET].xSpeed = 4;
	jjObjectPresets[OBJECT::FIREBALLBULLET].counterEnd = 110;
	jjObjectPresets[OBJECT::FIREBALLBULLET].var[6] = 0;
	jjObjectPresets[OBJECT::FIREBALLBULLET].freeze = 0;
	jjObjectPresets[OBJECT::FIREBALLBULLET].eventID = OBJECT::FIREBALLBULLET;
	jjObjectPresets[OBJECT::FIREBALLBULLET].lightType = jjObjectPresets[OBJECT::FIREBALLBULLET].lightType;
	jjObjectPresets[OBJECT::FIREBALLBULLET].killAnim = jjObjectPresets[OBJECT::ICEBULLET].killAnim;
	jjObjectPresets[OBJECT::FIREBALLBULLET].lightType = LIGHT::POINT;
	
	jjObjectPresets[OBJECT::FIREBALLBULLETPU].behavior = TornadoGunPU();
	jjObjectPresets[OBJECT::FIREBALLBULLETPU].special = jjObjectPresets[OBJECT::FIREBALLBULLETPU].determineCurAnim(ANIM::CUSTOM[26], 1);
	jjObjectPresets[OBJECT::FIREBALLBULLETPU].xSpeed = 6;
	jjObjectPresets[OBJECT::FIREBALLBULLETPU].counterEnd = 120;
	jjObjectPresets[OBJECT::FIREBALLBULLETPU].var[6] = 8;
	jjObjectPresets[OBJECT::FIREBALLBULLETPU].freeze = 0;
	jjObjectPresets[OBJECT::FIREBALLBULLETPU].eventID = OBJECT::FIREBALLBULLET;
	jjObjectPresets[OBJECT::FIREBALLBULLETPU].killAnim = jjObjectPresets[OBJECT::ICEBULLET].killAnim;
	jjObjectPresets[OBJECT::FIREBALLBULLETPU].lightType = LIGHT::POINT2;
	
	jjObjectPresets[OBJECT::GUN8POWERUP].determineCurAnim(ANIM::CUSTOM[26], 4);
	jjObjectPresets[OBJECT::GUN8POWERUP].determineCurFrame();

	jjWeapons[WEAPON::GUN8].defaultSample = false;
	jjWeapons[WEAPON::GUN8].spread = SPREAD::NORMAL;
	jjWeapons[WEAPON::GUN8].style = WEAPON::NORMAL;
	jjWeapons[WEAPON::GUN8].multiplier = 1;
	jjWeapons[WEAPON::GUN8].gradualAim = false;
	
	generateCustomSpringSprites(jjAnimSets[ANIM::CUSTOM[0]], array<uint> = {160, 40});
	turnIntoCustomSpring(jjObjectPresets[OBJECT::FROZENSPRING], 0, 40.f, false);
	turnIntoCustomSpring(jjObjectPresets[OBJECT::HORREDSPRING], 1, 20.f, false);
}

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.causesRicochet = obj.isBlastable = obj.isTarget = obj.scriptedCollisions = obj.triggersTNT = false;
	obj.deactivates = obj.isFreezable = true;
	obj.eventID = OBJECT::REDSPRING;
	obj.bulletHandling = HANDLING::IGNOREBULLET;
	obj.playerHandling = HANDLING::SPECIAL;
	obj.lightType = LIGHT::NORMAL;
	obj.determineCurFrame();
}
void handleFastCustomSpringSpeeds(jjPLAYER@ player) {
	if (player.ySpeed < -32.f) {
		fastCustomSpringSpeeds[player.localPlayerID] = int(ceil((player.ySpeed + 32.f) / -0.125f));
	} else if (fastCustomSpringSpeeds[player.localPlayerID] != 0) {
		if (player.ySpeed < -31.f) {
			fastCustomSpringSpeeds[player.localPlayerID]--;
			player.ySpeed = -32.f;
		} else {
			fastCustomSpringSpeeds[player.localPlayerID] = 0;
		}
	}
}

bool LoadWeaponMega1() {
	if (!SafeToReplaceWeapon(WEAPON::BLASTER))
		return false;
	
	Preset1.behavior = ApplyBoomerang;
	Preset2.behavior = ApplyBoomerang;
	Preset1.special = Preset1.determineCurAnim(AnimSet, 0);
	Preset2.special = Preset2.determineCurAnim(AnimSet, 0);
	Preset1.isBlastable = false; Preset2.isBlastable = false;
	
	return true;
}
const bool WeaponMega1Loaded = LoadWeaponMega1();

void ApplyBoomerang(jjOBJ@ obj) { obj.behavior = Boomerang(obj); obj.behave(); }
class Boomerang : WeaponMega {
	float xSpeed, ySpeed;
	uint counter = 0;
	Boomerang(jjOBJ@ objectOfAttachment) {
		@obj = @objectOfAttachment;
		xSpeed = (obj.xSpeed + obj.var[7] / 65536.f) * 32;
		ySpeed = obj.ySpeed * 32;
		obj.state = STATE::FLY;
	}
	void onBehave(jjOBJ@) override {
		counter += 8;
		
		const float lastX = obj.xPos, lastY = obj.yPos;
		obj.xPos = obj.xOrg + jjSin(counter) * xSpeed;
		obj.yPos = obj.yOrg + jjSin(counter) * ySpeed;
		obj.xSpeed = obj.xPos - lastX;
		obj.ySpeed = obj.yPos - lastY;
		
		obj.frameID = ((jjGameTicks + obj.objectID) / 3) & 7;
		if (obj.frameID >= 4)
			obj.frameID = 7 - obj.frameID;
		obj.curFrame = jjAnimations[obj.curAnim] + obj.frameID;
		
		if (counter >= 512 || maskedPixelAtBullet() || obj.state == STATE::EXPLODE) {
			obj.delete();
			if (obj.creatorType == CREATOR::PLAYER) {
				const jjPLAYER@ play = jjPlayers[obj.creator];
				if (abs(obj.xPos - play.xPos) <= 20 && abs(obj.yPos - play.yPos) <= 20)
					return; //inside shooter; no explosion anim needed
			}
			jjObjects[jjAddObject(OBJECT::EXPLOSION, obj.xPos, obj.yPos, obj.objectID, CREATOR::OBJECT)].curAnim = obj.killAnim;
		} else if (counter == 256 && obj.creatorType == CREATOR::PLAYER) {
			xSpeed = obj.xPos - (obj.xOrg = jjPlayers[obj.creator].xPos);
			ySpeed = obj.yPos - (obj.yOrg = jjPlayers[obj.creator].yPos);
		}
	}
	void onDraw(jjOBJ@) override {
		jjDrawRotatedSpriteFromCurFrame(obj.xPos, obj.yPos, obj.curFrame, getBulletAngle(), getBulletDirection(), 1, SPRITE::SINGLEHUE, !isPowerup() ? 65 : 72);
	}
}

bool LoadWeaponMega3() {
	if (!SafeToReplaceWeapon(WEAPON::ICE))
		return false;
	
	jjWeapons[WEAPON::ICE].style = WEAPON::POPCORN;
	jjWeapons[WEAPON::ICE].spread = SPREAD::TOASTER;
	jjWeapons[WEAPON::ICE].multiplier = 4;
	jjWeapons[WEAPON::ICE].gradualAim = true;
	
	Preset1.behavior = ApplyIceCloud;
	Preset2.behavior = ApplyIceCloud;
	Preset1.special = Preset1.determineCurAnim(AnimSet, 0);
	Preset2.special = Preset2.determineCurAnim(AnimSet, 0);
	Preset1.determineCurFrame(); Preset2.determineCurFrame();
	Preset1.isBlastable = true; Preset2.isBlastable = true;
	//Preset1.var[6] = Preset1.var[6] | 16; //"fireball"
	//Preset2.var[6] = Preset2.var[6] | 16;
	Preset1.counterEnd = 120; //lifetime
	Preset2.counterEnd = 200;
	
	return true;
}
const bool WeaponMega3Loaded = LoadWeaponMega3();

void ApplyIceCloud(jjOBJ@ obj) { obj.behavior = IceCloud(obj); obj.behave(); }
class IceCloud : WeaponMega {
	IceCloud(jjOBJ@ objectOfAttachment) {
		@obj = @objectOfAttachment;
		obj.xSpeed += obj.var[7] / 65536.f;
		if (obj.creatorType == CREATOR::PLAYER)
			obj.ySpeed += int(jjPlayers[obj.creatorID].ySpeed) / 2;
		obj.state = STATE::FLY;
	}
	void onBehave(jjOBJ@) override {
		obj.xPos += obj.xSpeed *= 0.96;
		obj.yPos += obj.ySpeed *= 0.96;
		if (obj.frameID < 3 && ++obj.age & 15 == 15) {
			++obj.frameID; ++obj.curFrame;
		}
		if (--obj.counterEnd == 0 || obj.state == STATE::EXPLODE) {
			int playerID;
			if (isPowerup() && (playerID = getNearestEnemy(256)) >= 0) {
				obj.frameID = 0;
				obj.killAnim = (obj.curAnim += 1) + 1;
				obj.counterEnd = 100;
				obj.freeze = 0;
				const jjPLAYER@ target = jjPlayers[playerID];
				obj.xSpeed = (target.xPos - obj.xPos) / 25;
				obj.ySpeed = (target.yPos - obj.yPos) / 25;
				obj.xAcc = obj.yAcc = obj.var[7] = 0;
				obj.behavior = BEHAVIOR::BULLET;
			} else {
				obj.counter = 0;
				obj.frameID = 0;
				obj.curAnim += 2;
				obj.behavior = BEHAVIOR::EXPLOSION;
			}
			jjSample(obj.xPos, obj.yPos, SOUND::COMMON_ICECRUSH);
		} else if (jjGameTicks & 1 == 0) {
			jjPARTICLE@ part = jjAddParticle(PARTICLE::ICETRAIL);
			if (part !is null) {
				part.yPos = obj.yPos;
				part.xPos = obj.xPos + (jjRandom() & 31) - 15;
			}
		}
	}
	void onDraw(jjOBJ@) override {
		jjDrawSpriteFromCurFrame(obj.xPos, obj.yPos, obj.curFrame, 1, SPRITE::TRANSLUCENT);
		if (obj.frameID == 3 && isPowerup())
			jjDrawSpriteFromCurFrame(obj.xPos, obj.yPos, jjAnimations[obj.curAnim + 1], 0, SPRITE::TRANSLUCENTCOLOR, 15);
	}
}

bool LoadWeaponMega9() {
	if (!SafeToReplaceWeapon(WEAPON::GUN9))
		return false;
	
	Preset1.behavior = Meteor;
	Preset2.behavior = Meteor;
	Preset1.determineCurAnim(AnimSet, 0);
	Preset2.determineCurAnim(AnimSet, 1);
	Preset1.special = 0; Preset2.special = 0;
	Preset1.determineCurFrame(); Preset2.determineCurFrame();
	Preset1.xSpeed = 4; Preset2.xSpeed = 5;
	Preset1.ySpeed = 6; Preset2.ySpeed = 7;
	Preset1.playerHandling = Preset2.playerHandling = HANDLING::PARTICLE;
	Preset1.counter = Preset2.counter = 0;
	Preset1.lightType = Preset2.lightType = LIGHT::NORMAL;
	Preset1.light = Preset2.light = 10;
	Preset1.var[6] = 0; Preset2.var[6] = 8;
	
	return true;
}
const bool WeaponMega9Loaded = LoadWeaponMega9();

void Meteor(jjOBJ@ obj) {
	if (obj.state == STATE::START) {
		obj.state = STATE::DELAYEDSTART;
		obj.xSpeed += obj.var[7] / 65536.f;
		obj.yPos -= 120;
		jjObjects[jjAddObject(OBJECT::EXPLOSION, obj.xPos, obj.yPos + 60, obj.objectID)].curAnim = obj.curAnim + 2;
	} else if (obj.state == STATE::DELAYEDSTART) {
		if (++obj.counter > 12) {
			obj.state = STATE::FLY;
			obj.playerHandling = HANDLING::PLAYERBULLET;
		}
	} else if (++obj.counter > 75 || obj.state == STATE::EXPLODE) {
		obj.frameID = 4;
		obj.curAnim = jjAnimSets[ANIM::AMMO] + 77; //TNT
		obj.behavior = BEHAVIOR::EXPLOSION;
	} else {
		obj.xPos += obj.xSpeed;
		obj.yPos += obj.ySpeed += 0.1f;
		obj.var[10] = obj.var[10] + 1; //ricochet
		obj.frameID = obj.objectID + jjGameTicks / 4;
		obj.determineCurFrame();
		jjDrawSpriteFromCurFrame(obj.xPos, obj.yPos, obj.curFrame, obj.direction, SPRITE::NORMAL, 0, 1);
	}
}

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::RFBULLETPU? 0.4:0.35) * obj.direction;
		if (obj.ySpeed < 0 && obj.direction == 0 && obj.xSpeed == 0) obj.yAcc = -0.5;
		
		
		if (obj.state != STATE::EXPLODE) {
			if (obj.counter == 1 && creator.isLocal) {
				jjSample(creator.xPos, creator.yPos, SOUND::P2_CRUNCH, 48, obj.eventID == OBJECT::RFBULLETPU? 19000:17500);
				obj.var[2] = 0;
				obj.playerHandling = HANDLING::PLAYERBULLET;
			}
			
			jjDrawRotatedSprite(obj.xPos, obj.yPos, ANIM::CUSTOM[25], obj.eventID == OBJECT::RFBULLETPU? 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, obj.yPos, 32, 8);
				if (obj.var[2] == 0) {
					jjSample(obj.xPos, obj.yPos, SOUND::COMMON_METALHIT, 0, 0);
					obj.counter = 1;
					if (obj.eventID == OBJECT::RFBULLETPU) obj.counterEnd = 130;
					else obj.counterEnd = 105;
					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;
					if (obj.eventID == OBJECT::RFBULLETPU) obj.counterEnd = 130;
					else obj.counterEnd = 105;
					obj.var[2] = 1;
				}
			}
		} else {
			obj.clearPlatform();
			obj.var[2] = 0;
			obj.counterEnd = obj.eventID == OBJECT::RFBULLETPU? 55:60;
		}
	}
}

class TornadoGun : jjBEHAVIORINTERFACE {
	void onBehave(jjOBJ@ obj) {
		obj.behave(BEHAVIOR::BULLET);
		jjPLAYER@ creator = jjPlayers[obj.creatorID];
		if (obj.state == STATE::FLY) {
			if (obj.counter == 1 && creator.isLocal) {
				jjSample(creator.xPos, creator.yPos, SOUND::INTRO_BLOW, 48, 25000);
				jjSample(creator.xPos, creator.yPos, SOUND::COMMON_BIRDFLY, 48, 25000);
			}
			
			switch (obj.direction) {
				case 1: obj.xSpeed = obj.xSpeed - 0.05; obj.ySpeed = obj.ySpeed - 0.1; break;
				case -1: obj.xSpeed = obj.xSpeed + 0.05; obj.ySpeed = obj.ySpeed - 0.1; break;
			}
			
			float pdx = jjLocalPlayers[0].xPos - obj.xPos, pdy = jjLocalPlayers[0].yPos - obj.yPos;
			if ((pdx * pdx + pdy * pdy < 64 * 64) && !creator.isLocal && jjLocalPlayers[0].blink == 0 && (jjLocalPlayers[0].team != creator.team || jjFriendlyFire || jjGameMode != GAME::CTF) && gameIsActive()) {
				jjLocalPlayers[0].ySpeed -= 2.5;
				jjLocalPlayers[0].xSpeed += 2.5 * obj.direction;
			}
		}
		if (obj.state == STATE::EXPLODE) {
			if (obj.var[0] == 0) {
				jjSample(obj.xPos, obj.yPos, SOUND::COMMON_SWISH4, 36, 15000);
				obj.var[0] = 1;
			}
		}
	}
}

class TornadoGunPU : jjBEHAVIORINTERFACE {
	void onBehave(jjOBJ@ obj) {
		obj.behave(BEHAVIOR::BULLET);
		jjPLAYER@ creator = jjPlayers[obj.creatorID];
		if (obj.state == STATE::FLY) {
			if (obj.counter == 1 && creator.isLocal) {
				jjSample(creator.xPos, creator.yPos, SOUND::INTRO_BLOW, 48, 30000);
				jjSample(creator.xPos, creator.yPos, SOUND::COMMON_BIRDFLY, 48, 30000);
			}

			switch (obj.direction) {
				case 1: obj.xSpeed = obj.xSpeed - 0.05; obj.ySpeed = obj.ySpeed - 0.1; break;
				case -1: obj.xSpeed = obj.xSpeed + 0.05; obj.ySpeed = obj.ySpeed - 0.1; break;
			}
			
			float pdx = jjLocalPlayers[0].xPos - obj.xPos, pdy = jjLocalPlayers[0].yPos - obj.yPos;
			if ((pdx * pdx + pdy * pdy < 96 * 96) && !creator.isLocal && jjLocalPlayers[0].blink == 0 && (jjLocalPlayers[0].team != creator.team || jjFriendlyFire || jjGameMode != GAME::CTF) && gameIsActive()) {
				jjLocalPlayers[0].ySpeed -= 5;
				jjLocalPlayers[0].xSpeed += 5 * obj.direction;
			}
		}
		if (obj.state == STATE::EXPLODE) {
			if (obj.var[0] == 0) {
				jjSample(obj.xPos, obj.yPos, SOUND::COMMON_SWISH4, 36, 15000);
				obj.var[0] = 1;
			}
		}
	}
}

void onMain() {
	weaponHook.processMain();
}
void onPlayer(jjPLAYER@ player) {
	if (jjEventGet(int(player.xPos) >> 5, int(player.yPos) >> 5) == AREA::SUCKERTUBE)
		player.alreadyDoubleJumped = false;
	weaponHook.processPlayer(player);
	handleFastCustomSpringSpeeds(player);
	
	for (uint i = 0; i < oneWays.length(); i++) {
		jjEventSet(oneWays[i].x, oneWays[i].y, AREA::ONEWAY);
	}
	oneWays.resize(0);
	int px = int(player.xPos), py = int(player.yPos);
	bool masked;
	for (int i = -11 + int(player.ySpeed); i <= 14; i++) {
		if (masked = jjMaskedHLine(px - 14, 28, py + i))
			break;
	}
	if (!masked) {
		for (int i = 8; i <= 16; i += 8) {
			for (int j = 12; j <= 20; j += 8) {
				int x = (px + player.direction * j) >>> 5, y = (py + i) >>> 5;
				if (x >= 0 && y >= 0 && x < jjLayerWidth[4] && y < jjLayerHeight[4] && jjEventGet(x, y) == AREA::ONEWAY) {
					vector2i point;
					jjEventSet(point.x = x, point.y = y, 0);
					oneWays.insertLast(point);
				}
			}
		}
	}
}
void onPlayerInput(jjPLAYER@ player) {
	weaponHook.processPlayerInput(player);
}
void onReceive(jjSTREAM &in packet, int clientID) {
	weaponHook.processPacket(packet, clientID);
}