Downloads containing xlmmolten.j2as

Downloads
Name Author Game Mode Rating
TSF with JJ2+ Only: Anniversary Bash 19 Levels Jazz2Online Multiple N/A Download file
JJ2+ Only: Molten CoreFeatured Download SmokeNC Capture the flag 8.6 Download file

File preview

int nextBullet = 7;
array<bool> protection_toaster(32, false);

enum packet_types {packet_protection_create, packet_protection_lost, packet_protection_collect, packet_protection_request};

uint8 animShield = 0;

void loadAnims() {
	jjANIMSET@ shieldAnimSet = jjAnimSets[ANIM::CUSTOM[animShield]];
	if (shieldAnimSet.firstAnim == 0) {
		const int firstShieldTileID = jjTileCount;
		const int shieldFrameCount = 6;
		jjTilesFromTileset("lev145.j2t", 1090, shieldFrameCount);
		shieldAnimSet.allocate(array<uint> = {shieldFrameCount});
		const int firstShieldFrameID = jjAnimations[shieldAnimSet.firstAnim].firstFrame;
		for (int shieldFrameID = 0; shieldFrameID < shieldFrameCount; ++shieldFrameID) {
			jjPIXELMAP shieldImage(firstShieldTileID + shieldFrameID);
			jjANIMFRAME@ shieldFrame = jjAnimFrames[firstShieldFrameID + shieldFrameID];
			shieldImage.save(shieldFrame);
			shieldFrame.hotSpotX = -16;
			shieldFrame.hotSpotY = -24;
		}
	}
}

void onLevelBegin() {
	if (!jjIsServer) {
		jjSTREAM packet;
		packet.push(uint8(packet_protection_request));
		jjSendPacket(packet);
		for(int i = 0; i < jjLocalPlayerCount; i++) {
			jjSTREAM next_packet;
			next_packet.push(uint8(packet_protection_lost));
			next_packet.push(jjLocalPlayers[i].playerID);
			jjSendPacket(next_packet);
		}
	} else {
		if (jjGameMode != GAME::CTF) jjChat("/ctf");
	}
	jjWeapons[WEAPON::GUN9].spread = SPREAD::RFPU;
	jjWeapons[WEAPON::TOASTER].spread = SPREAD::RF;

}

void onLevelLoad() {
	jjUseLayer8Speeds = true;
	for (int i = 0; i < 19; i++) {
		jjANIMATION@ anim = jjAnimations[jjAnimSets[ANIM::BIRD] + i];
		for (uint j = 0; j < anim.frameCount; j++) {
		jjANIMFRAME@ frame = jjAnimFrames[anim + j];
		jjPIXELMAP sprite(frame);
		for (uint x = 0; x < sprite.width; ++x) {
		for (uint y = 0; y < sprite.height; ++y) {
			if (sprite[x,y] >= 80 && sprite[x,y] <= 87) sprite[x,y] -= 56;
			else if (sprite[x,y] >= 24 && sprite[x,y] <= 31) sprite[x,y] += 16;
				}
			}
			sprite.save(frame);
		}
	}
	for (int i = 0; i < 19; i++) {
		jjANIMATION@ anim = jjAnimations[jjAnimSets[ANIM::COMMON] + i];
		for (uint j = 0; j < anim.frameCount; j++) {
			jjANIMFRAME@ frame = jjAnimFrames[anim + j];
			jjPIXELMAP sprite(frame);
			for (uint x = 0; x < sprite.width; ++x) {
				for (uint y = 0; y < sprite.height; ++y) {
					if (sprite[x,y] >= 72 && sprite[x,y] <= 74) sprite[x,y] = 241;
					else if (sprite[x,y] >= 75) sprite[x,y] -= 45;
				}
			}
			sprite.save(frame);
		}
		}

	for (int i = 0; i < 9; i++) {
		jjANIMATION@ anim = jjAnimations[jjAnimSets[ANIM::SPRING] + i];
		for (uint j = 0; j < anim.frameCount; j++) {
			jjANIMFRAME@ frame = jjAnimFrames[anim + j];
			jjPIXELMAP sprite(frame);
			for (uint x = 0; x < sprite.width; ++x) {
				for (uint y = 0; y < sprite.height; ++y) {
					if (sprite[x,y] >= 80 && sprite[x,y] <= 87) sprite[x,y] -= 40;
				}
			}
			sprite.save(frame);
		}
	}

	jjObjectPresets[OBJECT::GUN8AMMO3].behavior = MovingPickup();
	jjObjectPresets[OBJECT::FULLENERGY].behavior = MovingPickup();
	jjObjectPresets[OBJECT::SILVERCOIN].behavior = ProtectionFire();
	jjObjectPresets[OBJECT::SILVERCOIN].scriptedCollisions = true;
	jjObjectPresets[OBJECT::GOLDCOIN].behavior = ProtectionFire();
	jjObjectPresets[OBJECT::GOLDCOIN].scriptedCollisions = true;
	jjObjectPresets[OBJECT::APPLE].behavior = FireballSplash();
	jjObjectPresets[OBJECT::BANANA].behavior = FireballSplash();
	jjObjectPresets[OBJECT::BURGER].behavior = FireballSplash();
	jjObjectPresets[OBJECT::CAKE].behavior = FireballSplash();
	
	jjObjectPresets[OBJECT::ICEAMMO3].behavior = StillPickup();
	jjObjectPresets[OBJECT::ICEBULLET].behavior = BirdGun();
	jjObjectPresets[OBJECT::ICEBULLET].counterEnd = 175;
	jjObjectPresets[OBJECT::ICEBULLET].playerHandling = HANDLING::PLAYERBULLET;
	jjObjectPresets[OBJECT::ICEBULLET].freeze = 0;
	jjObjectPresets[OBJECT::ICEBULLET].freeze = 0;
	jjWeapons[WEAPON::ICE].maximum = 1;
	
	for (int i = 1; i <= 9; i++) {
		jjWeapons[i].comesFromBirds = false;
		jjWeapons[i].comesFromBirdsPowerup = false;
	}
	
	jjWeapons[WEAPON::GUN8].allowed = true;
	jjWeapons[WEAPON::GUN8].allowedPowerup = true;
	
	jjANIMATION@ anim = jjAnimations[jjAnimSets[ANIM::FACES] + 1];
	for (uint j = 0; j < anim.frameCount; j++) {
		jjANIMFRAME@ frame = jjAnimFrames[anim + j];
		jjPIXELMAP sprite(frame);
		for (uint x = 0; x < sprite.width; ++x) {
			for (uint y = 0; y < sprite.height; ++y) {
				if (sprite[x,y] >= 32 && sprite[x,y] <= 39) sprite[x,y] -= 8;
				else if (sprite[x,y] >= 24 && sprite[x,y] <= 31) sprite[x,y] += 16;
			}
		}
		sprite.save(frame);
	}
	jjAnimations[jjAnimSets[ANIM::AMMO] + 28] = jjAnimations[jjAnimSets[ANIM::FACES] + 1];
	jjAnimations[jjAnimSets[ANIM::AMMO] + 29] = jjAnimations[jjAnimSets[ANIM::FACES] + 1];
	
	if (!jjIsServer) {
		while (animShield != 256 && jjAnimSets[ANIM::CUSTOM[animShield]] != 0)
			animShield++;		
		if (animShield != 256) loadAnims();
	}
	
}

bool last_protection_toaster = false;
uint8 last_health = jjStartHealth;

void onPlayer(jjPLAYER@ p) {
	array<uint> count(32, 0);

	if (last_protection_toaster != protection_toaster[p.playerID]) {
		if (protection_toaster[p.playerID] == true) {
			for (int i = 0; i < 3; i++) {
				jjSTREAM packet;
				packet.push(uint8(packet_protection_create));
				jjSendPacket(packet);
			}
		}
	}
	if (last_health != p.health) {
		if (protection_toaster[p.playerID]) {
			protection_toaster[p.playerID] = false;
			jjSTREAM packet;
			packet.push(uint8(packet_protection_lost));
			jjSendPacket(packet);
		}
	}
	for (int j = 1; j < jjObjectCount; j++) {
		jjOBJ@ o = jjObjects[j];
		if (o.isActive && o.eventID == OBJECT::SILVERCOIN) {
			for (uint i = 1; i < 32; i++) {
				if (protection_toaster[i] && o.creatorID == i && jjPlayers[i].isActive) {
					switch(count[i]) {
						case 0:
						{
							o.xPos = jjPlayers[i].xPos + 70*jjSin(-jjGameTicks*20);
							o.yPos = jjPlayers[i].yPos + 70*jjCos(-jjGameTicks*20);
							break;
						}
						case 1:
						{
							o.xPos = jjPlayers[i].xPos + 70*jjSin((-jjGameTicks-85-85)*20);
							o.yPos = jjPlayers[i].yPos + 70*jjCos((-jjGameTicks-85-85)*20);
							break;
						}
						case 2:
						{
							o.xPos = jjPlayers[i].xPos + 70*jjSin((-jjGameTicks-85-85-85-85)*20);
							o.yPos = jjPlayers[i].yPos + 70*jjCos((-jjGameTicks-85-85-85-85)*20);
							break;
						}

					}
					count[i]++;
				} else if (protection_toaster[i] && o.creatorID == i && !jjPlayers[i].isActive) {
					o.deactivate();
				} else if (protection_toaster[i] && o.creatorID == i && !jjPlayers[i].isActive && count[i] == 2) {
					protection_toaster[i] = false;
				}
			}
		}
	}
	p.powerup[WEAPON::GUN8] = true;
	last_protection_toaster = protection_toaster[p.playerID];
	last_health = p.health;

	if (p.shieldTime > 15*70) p.shieldTime = 15*70;
}

array<int> fireObjID(2, 0);

void onMain() {
	nextBullet--;
	if(nextBullet == 0) nextBullet = 4;
	uint obCount = 0;
	for (int i = 1; i < jjObjectCount; i++) {
		jjOBJ@ o = jjObjects[i];
		if (o.isActive && o.eventID == OBJECT::GUN8AMMO3) {
			if (o.xPos < 101*32) {
				o.xPos = 44*32+47*jjSin(-jjGameTicks*5+int(o.xOrg)*32/3);
				o.yPos = 25*32+16+40*jjCos(-jjGameTicks*5+int(o.xOrg)*32/3);
			}
			else if (o.xPos > 101*32) {
				o.xPos = 157*32+47*jjSin(jjGameTicks*5+int(o.xOrg)*32/3);
				o.yPos = 25*32+16+40*jjCos(jjGameTicks*5+int(o.xOrg)*32/3);
			}
		}
		else if (o.isActive && o.eventID == OBJECT::GOLDCOIN) {
			fireObjID[obCount] = o.objectID;
			obCount++;
		}
		else if (o.isActive && o.eventID == OBJECT::BIRD) {
			o.playerHandling = HANDLING::PLAYERBULLET;
			if(nextBullet == 1)
			{
				int bulletID2 = jjAddObject(6, o.xPos-25, o.yPos, o.var[0], CREATOR::PLAYER, BEHAVIOR::BULLET);
				jjOBJ@ bull2 = jjObjects[bulletID2];
				bull2.xAcc = -0.15;
				bull2.xSpeed = 0;
				bull2.yAcc = 0;
				bull2.ySpeed = 0;
				bull2.playerHandling = HANDLING::PLAYERBULLET;
				int bulletID3 = jjAddObject(6, o.xPos+25, o.yPos, o.var[0], CREATOR::PLAYER, BEHAVIOR::BULLET);
				jjOBJ@ bull3 = jjObjects[bulletID3];
				bull3.xAcc = 0.15;
				bull3.xSpeed = 0;
				bull3.yAcc = 0;
				bull3.ySpeed = 0;
				bull3.playerHandling = HANDLING::PLAYERBULLET;
				int bulletID4 = jjAddObject(6, o.xPos, o.yPos-13, o.var[0], CREATOR::PLAYER, BEHAVIOR::BULLET);
				jjOBJ@ bull4 = jjObjects[bulletID4];
				bull4.yAcc = -0.15;
				bull4.ySpeed = 0;
				bull4.xAcc = 0;
				bull4.xSpeed = 0;
				bull4.playerHandling = HANDLING::PLAYERBULLET;
				int bulletID5 = jjAddObject(6, o.xPos, o.yPos+13, o.var[0], CREATOR::PLAYER, BEHAVIOR::BULLET);
				jjOBJ@ bull5 = jjObjects[bulletID5];
				bull5.yAcc = 0.15;
				bull5.ySpeed = 0;
				bull5.xAcc = 0;
				bull5.xSpeed = 0;
				bull5.playerHandling = HANDLING::PLAYERBULLET;
			}
		}
	}
}

bool onDrawAmmo(jjPLAYER@ p, jjCANVAS@ canvas) {
	if (p.currWeapon == WEAPON::ICE) {
		canvas.drawString(jjResolutionWidth - 80, jjResolutionHeight - 14, "x" + p.ammo[WEAPON::ICE], STRING::MEDIUM, STRING::NORMAL);
		canvas.drawSprite(jjResolutionWidth - 104, jjResolutionHeight - 2, ANIM::AMMO, 28, jjGameTicks >> 2, 0, SPRITE::NORMAL, 0);
		return true;
	}
	return false;
}

class Phoenix : jjBEHAVIORINTERFACE {
	void onBehave(jjOBJ@ obj) {
		obj.behave(BEHAVIOR::BIRD);
		obj.light = 12;
		obj.lightType = LIGHT::BRIGHT;
		
		if (obj.state == STATE::HIT) {
			obj.particlePixelExplosion(1);
			jjSample(obj.xPos, obj.yPos, SOUND::BILSBOSS_FIRESTART);
			obj.delete();
		}
		
		if (obj.state == STATE::FLY) {
			jjPARTICLE@ cinders = jjAddParticle(PARTICLE::FIRE);
			cinders.xPos = (obj.xPos - 16) + (jjRandom() % 32);
			cinders.yPos = obj.yPos + (jjRandom() % 32);
			cinders.ySpeed = 0.5;
		}
	}
}

class MovingPickup : jjBEHAVIORINTERFACE {
	void onBehave(jjOBJ@ obj) {
		obj.behave(BEHAVIOR::PICKUP);
		
		obj.light = 12;
		obj.lightType = LIGHT::BRIGHT;
        obj.xSpeed=obj.ySpeed=0;
		
		if (obj.eventID == OBJECT::GUN8AMMO3) {
			jjPARTICLE@ cinders = jjAddParticle(PARTICLE::FIRE);
			cinders.xPos = (obj.xPos - 16) + (jjRandom() % 16);
			cinders.yPos = obj.yPos + (jjRandom() % 16);
			cinders.ySpeed = 0.5;
		} else if (obj.eventID == OBJECT::FULLENERGY) {
			obj.xPos=obj.xOrg+0*jjSin(-jjGameTicks*5+int(obj.xOrg)*32/3);
			obj.yPos=obj.yOrg+0*jjCos(-jjGameTicks*5+int(obj.xOrg)*32/3);
		}
	}
}

enum movement_type {left, right};

class ProtectionFire : jjBEHAVIORINTERFACE {
	uint angle = 0;
	array<uint> movement = {left, right};
	void onBehave(jjOBJ@ obj) {
	
		angle += 4;
		if (angle >= 360) angle = 0;
	
		if (obj.eventID == OBJECT::SILVERCOIN) {
			uint z = (jjGameTicks/7) % 8 ;
			obj.determineCurAnim(ANIM::AMMO,14,true);
			//obj.frameID = 2;	
			//obj.determineCurFrame();
			//obj.draw();
               jjDrawRotatedSprite(obj.xPos, obj.yPos, ANIM::AMMO, 14, z, 256+(512/3.14)*atan2(-jjPlayers[obj.creatorID].yPos+obj.yPos, jjPlayers[obj.creatorID].xPos-obj.xPos));
		} else if (obj.eventID == OBJECT::GOLDCOIN) {
			if (obj.behavior != BEHAVIOR::EXPLOSION2) {
				float z = jjGameTicks % 1024 ;
				uint e = (jjGameTicks/7) % 6 ;
				if (!jjIsServer && jjAnimSets[ANIM::CUSTOM[animShield]] != 0) {
					jjDrawRotatedSprite(obj.xPos, obj.yPos, ANIM::CUSTOM[animShield], 0, e,0);
					obj.determineCurAnim(ANIM::CUSTOM[animShield], 0);
				}
				jjPARTICLE@ cinders = jjAddParticle(PARTICLE::FIRE);
				cinders.xPos = (obj.xPos - 16) + (jjRandom() % 16);
				cinders.yPos = obj.yPos + (jjRandom() % 16);
				cinders.ySpeed = 0.5;
				if (obj.objectID == fireObjID[0]) {
					if (movement[0] == left) obj.xPos -= 2;
					else if (movement[0] == right) obj.xPos += 2;
					
					if (obj.xPos > 56*32 && obj.xPos < 58*32) movement[0] = right;
					else if (obj.xPos > 144*32 && obj.xPos < 146*32) movement[0] = left;
				} else if (obj.objectID == fireObjID[1]) {
					if (movement[1] == left) obj.xPos -= 2;
					else if (movement[1] == right) obj.xPos += 2;
					
					if (obj.xPos > 56*32 && obj.xPos < 58*32) movement[1] = right;
					else if (obj.xPos > 144*32 && obj.xPos < 146*32) movement[1] = left;
				}
			}
		}
		
		obj.light = 12;
		obj.lightType = LIGHT::BRIGHT;
        obj.xSpeed=obj.ySpeed=0;

	}
}

class FireballSplash : jjBEHAVIORINTERFACE {
	void onBehave(jjOBJ@ obj) {	
		if (obj.eventID == OBJECT::APPLE) {
			float a = 0.1;
			float v = 0;
			float s = 8;
			float z =( jjGameTicks+70*1) % (70*2);
			uint j = (jjGameTicks/7)%3 ;
			uint e = (jjGameTicks/7)%10; 
			obj.playerHandling = HANDLING::HURT;
			obj.xPos = obj.xOrg + v*(z); 
			obj.yPos = obj.yOrg +a*(z)*(z) -s*(z);
			if (0 < z && z < 48) {
				jjDrawSprite(obj.xOrg  , obj.yOrg +-17, ANIM::COMMON, 3, e*1.5, 1);
				jjDrawRotatedSprite(obj.xPos , obj.yPos, ANIM::BILSBOSS, 3, j,256); 
			}
			
			else if (76 < z && z < (76+40)) {
				obj.determineCurAnim(ANIM::COMMON,3,true);
				obj.determineCurFrame();
				jjDrawSprite(obj.xOrg , obj.yOrg + -17, ANIM::COMMON, 3, e*1.5, 1);
				jjDrawRotatedSprite(obj.xPos, obj.yPos, ANIM::BILSBOSS, 3, j,-256); 
			}
			else jjDrawRotatedSprite(obj.xPos, obj.yPos, ANIM::BILSBOSS, 3, j,-256); 
		}	
		else if (obj.eventID == OBJECT::BANANA) {
			float a = 0.1;
			float v = 0;
			float s = 8;
			float z =( jjGameTicks) % (70*3);
			uint j = (jjGameTicks/7)%3 ;
			uint e = (jjGameTicks/7)%10; 
			obj.playerHandling = HANDLING::HURT;
			obj.xPos = obj.xOrg + v*(z); 
			obj.yPos = obj.yOrg +a*(z)*(z) -s*(z);
			if (0 < z && z < 48) {
				jjDrawSprite(obj.xOrg  , obj.yOrg +-17, ANIM::COMMON, 3, e*1.5, 1);
				jjDrawRotatedSprite(obj.xPos , obj.yPos, ANIM::BILSBOSS, 3, j,256); 
			}
			
			else if ( 76 < z && z < (76+40)) {
				obj.determineCurAnim(ANIM::COMMON,3,true);
				obj.determineCurFrame();
				jjDrawSprite(obj.xOrg , obj.yOrg + -17, ANIM::COMMON, 3, e*1.5, 1);
				jjDrawRotatedSprite(obj.xPos, obj.yPos, ANIM::BILSBOSS, 3, j,-256); 
			}
			else jjDrawRotatedSprite(obj.xPos, obj.yPos, ANIM::BILSBOSS, 3, j,-256); 
		}	
		else if (obj.eventID == OBJECT::BURGER) {
			float a = 0.1;
			float v = 8;
			float s = 8;
			float z = jjGameTicks % (70*4);
			uint j = (jjGameTicks/7)%3 ;
			uint e = (jjGameTicks/7)%10; 
			obj.playerHandling = HANDLING::HURT;
			obj.xPos = obj.xOrg + v*(z); 
			obj.yPos = obj.yOrg +a*(z)*(z) -s*(z);
			if (0 < z && z < 48) {
				jjDrawSprite(obj.xOrg +16 , obj.yOrg -17, ANIM::COMMON, 3, e*1.5, 1);
				jjDrawRotatedSprite(obj.xPos , obj.yPos, ANIM::BILSBOSS, 3, j,-(512/3.14)*atan((2*a*z-s)/v)); 
			}
			
			else if (76 < z && z < (76+40)) {
				obj.determineCurAnim(ANIM::COMMON,3,true);
				obj.determineCurFrame();
				jjDrawSprite(obj.xOrg +622, obj.yOrg - 17, ANIM::COMMON, 3, e*1.5, 1);
				jjDrawRotatedSprite(obj.xPos, obj.yPos, ANIM::BILSBOSS, 3, j,-(512/3.14)*atan((2*a*z-s)/v)); 
			}
			else jjDrawRotatedSprite(obj.xPos, obj.yPos, ANIM::BILSBOSS, 3, j,-(512/3.14)*atan((2*a*z-s)/v)); 
		} else if (obj.eventID == OBJECT::CAKE) {
			float a = 0.1;
			float v = 8;
			float s = 8;
			float z = (jjGameTicks+70*2) % (70*4);
			uint j = (jjGameTicks/7)%3 ;
			uint e = (jjGameTicks/7)%10; 
			obj.xPos = obj.xOrg - v*(z); 
			obj.yPos = obj.yOrg +a*(z)*(z) -s*(z);
			obj.playerHandling = HANDLING::HURT;
			obj.determineCurAnim(ANIM::BILSBOSS,3,true);	
			obj.determineCurFrame();
			if ( 0 < z && z < 48) {
				jjDrawSprite(obj.xOrg -16 , obj.yOrg -17, ANIM::COMMON, 3, e*1.5,-1);
				jjDrawRotatedSprite(obj.xPos, obj.yPos, ANIM::BILSBOSS, 3, j,-(512/3.14)*atan((2*a*z-s)/(-v))+512);  
			}
			
			else if (76 < z && z < (76+40)) {
				obj.determineCurAnim(ANIM::COMMON,3,true);
				obj.determineCurFrame();
				jjDrawSprite(obj.xOrg -622, obj.yOrg - 17, ANIM::COMMON, 3, e*1.5, 1);
				jjDrawRotatedSprite(obj.xPos, obj.yPos, ANIM::BILSBOSS, 3, j,-(512/3.14)*atan((2*a*z-s)/(-v))+512); 
			}
			else jjDrawRotatedSprite(obj.xPos, obj.yPos, ANIM::BILSBOSS, 3, j,-(512/3.14)*atan((2*a*z-s)/(-v))+512); 
		}
	}
}


class BirdGun : jjBEHAVIORINTERFACE {
	void onBehave(jjOBJ@ obj) {
		uint f = 1;
		obj.behave(BEHAVIOR::BULLET, obj.state == STATE::FLY? false:true);
		obj.var[0] = int(atan2(-obj.ySpeed, obj.xSpeed) * (512.f * 0.318309886142228f));
		obj.var[6]=8;
	
		if (obj.state == STATE::FLY) {
			int z =jjGameTicks%150;
			int e =(obj.counter/7)%8;
			jjDrawSprite(obj.xPos, obj.yPos, ANIM::BIRD, 9, e, obj.direction);
			switch (obj.direction) {
				case 1: obj.xSpeed = 13; obj.ySpeed = 0; break;
				case -1: obj.xSpeed = -13; obj.ySpeed = 0; break;
			}
			if (obj.ySpeed < -1)
				obj.ySpeed = 0;
			if ((obj.counter % 6) < 1) {
				int l = jjAddObject(OBJECT::FIRESHIELDBULLET, obj.xPos, obj.yPos, obj.creatorID, CREATOR::PLAYER);
				jjOBJ@ o = jjObjects[l];
				o.xAcc = o.yAcc = 0;
				o.xSpeed = 0;
				o.ySpeed = 9;
				o.counterEnd = 200;
				o.var[6]= 8;
				int	k = jjAddObject(OBJECT::FIRESHIELDBULLET, obj.xPos, obj.yPos, obj.creatorID, CREATOR::PLAYER);
				jjOBJ@ b = jjObjects[k];
				b.xAcc = b.yAcc = 0;
				b.xSpeed = 0;
				b.ySpeed = -9;
				b.counterEnd = 200;
				b.var[6]= 8;	
			}
		}
	}
}

class StillPickup : jjBEHAVIORINTERFACE {
	void onBehave(jjOBJ@ obj) {
		if (obj.xPos > 100*32)
			obj.direction = 1;
		if (obj.xPos < 100*32)
			obj.direction = -1;
	
		if (obj.state == STATE::FLOATFALL) obj.state = STATE::FLOAT;
		obj.behave(BEHAVIOR::PICKUP);
	}
}

void onObjectHit(jjOBJ@ obj, jjOBJ@ bullet, jjPLAYER@ p, int force) {
    if (obj.eventID == OBJECT::SILVERCOIN) {
		if (jjPlayers[obj.creatorID].team != p.team)  p.hurt(1, false, jjPlayers[obj.creatorID]);
	}

	else if (obj.eventID == OBJECT::GOLDCOIN) {
		if (protection_toaster[p.playerID] == false) {
			protection_toaster[p.playerID] = true;
			obj.scriptedCollisions = false;
			obj.behavior = BEHAVIOR::EXPLOSION2;
			obj.frameID = 0;
			jjSTREAM packet;
			packet.push(uint8(packet_protection_collect));
			jjSendPacket(packet);
			p.warpToTile(int(p.xPos) / 32, (int(p.yPos) / 32) - 11);
			p.ySpeed = 0;
			obj.deactivate();
		}
	} 
}

void onReceive(jjSTREAM &in packet, int clientID) {
	uint8 type;
	packet.pop(type);
	if (jjIsServer) {
		switch(type) {
			case packet_protection_create: 
			{
				int playerID;
				for (int i = 0; i < 32; i++) {
					if (jjPlayers[i].isActive && jjPlayers[i].clientID == clientID) {
						playerID = jjPlayers[i].playerID;
					}
				}
				jjAddObject(OBJECT::SILVERCOIN, jjPlayers[playerID].xPos - 32, jjPlayers[playerID].yPos, playerID, CREATOR::LEVEL);
				protection_toaster[playerID] = true;
		
				jjSTREAM next_packet;
				next_packet.push(uint8(packet_protection_create));
				next_packet.push(playerID);
				for (int i = 1; i < 32; i++) {
					if (jjPlayers[i].isActive) {
						jjSendPacket(next_packet, i);
					}
				}
				break;
			}
			case packet_protection_lost:
			{
				int playerID;
				for (int i = 0; i < 32; i++) {
					if (jjPlayers[i].isActive && jjPlayers[i].clientID == clientID) {
						playerID = jjPlayers[i].playerID;
					}
				}
				
				protection_toaster[playerID] = false;
				for (int object = 1; object < jjObjectCount; object++) {
					jjOBJ@ o = jjObjects[object];
					if (o.eventID == OBJECT::SILVERCOIN && o.creatorID == playerID) {
						o.deactivate();
					}
				}
				
				jjSTREAM next_packet;
				next_packet.push(uint8(packet_protection_lost));
				next_packet.push(playerID);
				for (int i = 1; i < 32; i++) {
					if (jjPlayers[i].isActive) {
						jjSendPacket(next_packet, i);
					}
				}
				break;
			}
			case packet_protection_collect:
			{
				int playerID;
				for (int i = 0; i < 32; i++) {
					if (jjPlayers[i].isActive && jjPlayers[i].clientID == clientID) {
						playerID = jjPlayers[i].playerID;
					}
				}
			
				for (uint i = 1; i < jjObjectCount; i++) {
					jjOBJ@ o = jjObjects[i];
					if (o.eventID == OBJECT::GOLDCOIN) {
						o.scriptedCollisions = false;
						o.behavior = BEHAVIOR::EXPLOSION2;
						o.frameID = 0;
						o.deactivate();
					}
				}
				
				jjSTREAM next_packet;
				next_packet.push(uint8(packet_protection_collect));
				for (int i = 1; i < 32; i++) {
					if (jjPlayers[i].isActive && i != playerID) {
						jjSendPacket(next_packet, i);
					}
				}
				break;
			}
			case packet_protection_request:
			{
				int playerID;
				for (int play = 0; play < 32; play++) {
					if (jjPlayers[play].isActive && jjPlayers[play].clientID == clientID) {
						playerID = jjPlayers[play].playerID;
					}
				}
				
				jjSTREAM next_packet;
				
				for (int i = 0; i < 32; i++) {
					if (jjPlayers[i].isActive) {
						if (protection_toaster[i] == true) {
							for (int j = 0; j < 3; j++) {
								next_packet.push(uint8(packet_protection_create));
								next_packet.push(i);
								jjSendPacket(next_packet, playerID);
							}
						}
					}
				}
				break;
			}
		}
		
	} else {
		switch(type) {
			case packet_protection_create:
			{
				int playerID; packet.pop(playerID);
				protection_toaster[playerID] = true;
				jjAddObject(OBJECT::SILVERCOIN, jjPlayers[playerID].xPos - 32, jjPlayers[playerID].yPos, playerID, CREATOR::LEVEL);
				break;
			}
			case packet_protection_lost:
			{
				int playerID; packet.pop(playerID);
				
				protection_toaster[playerID] = false;
				for (int object = 1; object < jjObjectCount; object++) {
					jjOBJ@ obj = jjObjects[object];
					if (obj.eventID == OBJECT::SILVERCOIN && obj.creatorID == playerID) {
						for (int i = 1; i < 50; i++) {
							int q = jjAddObject(OBJECT::FIRESHIELDBULLET, obj.xPos, obj.yPos, obj.creatorID, CREATOR::PLAYER, BEHAVIOR::BULLET);
							jjOBJ@ o = jjObjects[q];
							o.xAcc = o.yAcc = 0;
							o.xSpeed = cos(360*(i/4))* 10;
							o.ySpeed = sin(360*(i/4))* 10;
							o.counterEnd = 30;
							if (jjLocalPlayers[0].playerID == playerID) o.playerHandling = HANDLING::PLAYERBULLET;
							else o.playerHandling = HANDLING::ENEMYBULLET;
						}
						obj.deactivate();
					}
				}
				break;
			}
			case packet_protection_collect:
			{
				for (uint i = 1; i < jjObjectCount; i++) {
					jjOBJ@ o = jjObjects[i];
					if (o.eventID == OBJECT::GOLDCOIN) {
						o.scriptedCollisions = false;
						o.behavior = BEHAVIOR::EXPLOSION2;
						o.frameID = 0;
						o.deactivate();
					}
				}
				break;
			}
		}
	}
}