Downloads containing petrolBomb.mut

Downloads
Name Author Game Mode Rating
JJ2+ Only: Szmol Weapon Pack vol. 1 szmol96 Mutator N/A Download file

File preview

#pragma name "Petrol Bomb"
#pragma require "petrolBomb.j2a"
#pragma require "glass_shatter.wav"

/**Petrol Bomb**/
/**Author: szmol96**/

enum packet_type {packet_bombExplode};
uint customAnimID = 0;

void findCustomAnimID() { //This function is copied from Bunny Must Die! guns
	while (jjAnimSets[ANIM::CUSTOM[customAnimID]].firstAnim != 0) ++customAnimID;
	
	jjAnimSets[ANIM::CUSTOM[customAnimID]].load(0, "petrolBomb.j2a");
}

void sendBombPacket(int posX, int16 posY, int32 playNum) {
	jjSTREAM packet;
	packet.push(uint8(packet_bombExplode));
	packet.push(posX);
	packet.push(posY);
	packet.push(playNum);
	jjSendPacket(packet);
}

void pBomb(jjOBJ@ bomb) {
	jjPLAYER@ p = jjPlayers[bomb.creatorID];
	jjPLAYER@ lp = jjLocalPlayers[0];
	
	if (bomb.state == STATE::START) {
		bomb.direction = p.direction;
		bomb.xSpeed = p.direction * 5 + p.xSpeed / 1.5;
		bomb.ySpeed = -5 + p.ySpeed / 2.2;
		jjSample(bomb.xPos, bomb.yPos, SOUND::COMMON_FOEW1, 63, 0);
		bomb.state = STATE::FLOATFALL;
	}
	
	bomb.xPos = bomb.xPos + bomb.xSpeed;
	bomb.yPos = bomb.yPos + bomb.ySpeed;
	
	if (bomb.ySpeed < 8) bomb.ySpeed += 0.25;
	
	if (jjMaskedPixel(bomb.xPos + bomb.xSpeed, bomb.yPos + bomb.ySpeed)) {
		if (p.playerID == lp.playerID) {
			if (jjIsServer) {
				for (uint8 i = 0; i < 10; ++i) {
					addFlame(bomb.xPos, bomb.yPos, bomb.creatorID, i);
				}
			}
			sendBombPacket(bomb.xPos, bomb.yPos, bomb.creatorID);
		}
		jjSample(bomb.xPos, bomb.yPos, SOUND::ORANGE_GLAS1L, 63, 0);
		bomb.particlePixelExplosion(0);
		bomb.delete();
	}
	
	bomb.age++;
	if (bomb.age % 3 == 1) bomb.frameID++;
	
	bomb.determineCurFrame(true);
	bomb.draw();
}

void bombFlame(jjOBJ@ flame) {
	jjPLAYER@ p = jjPlayers[flame.creatorID];
	jjPLAYER@ lp = jjLocalPlayers[0];

	if (flame.state == STATE::START) {
		flame.age = 0;
		flame.state = STATE::FLY;
	}
	
	flame.xPos = flame.xPos + flame.xSpeed;
	flame.yPos = flame.yPos + flame.ySpeed;

	if (!jjMaskedPixel(flame.xPos + flame.xSpeed, flame.yPos + flame.ySpeed)) {
		if (flame.ySpeed < 4) flame.ySpeed += 0.1;
	} else {
		if (flame.ySpeed < 0) {
			flame.ySpeed = ((jjRandom() % 0.999));
		} else {
			flame.xSpeed = 0;
			flame.ySpeed = 0;
		}
	}
	
	if (flame.doesCollide(lp, false)) lp.hurt(1, false, p);
	
	if (flame.age > ((jjRandom() % 750) + 650)) flame.state = STATE::EXPLODE;
	
	if (flame.state == STATE::EXPLODE) {
		flame.behavior = BEHAVIOR::EXPLOSION2;
		flame.frameID = 0;
	}
	
	if (jjGameTicks % 5 == 0) flame.frameID++;
	flame.age++;
	flame.determineCurFrame(true);
	flame.draw();
}

void addFlame(float x, float y, uint16 crID, uint16 dir) {
	jjOBJ@ flame1;
	
	@flame1 = jjObjects[jjAddObject(OBJECT::TOASTERBULLET, x, y, crID, CREATOR::PLAYER)];
	flame1.xSpeed = jjSin((1023 / 10) * dir + 128) * 2;
	flame1.ySpeed = jjCos((1023 / 10) * dir + 128) * 2;
	flame1.determineCurAnim(ANIM::CUSTOM[customAnimID], 1, true);
	flame1.killAnim = jjObjectPresets[0].determineCurAnim(ANIM::CUSTOM[customAnimID], 2, false);
	flame1.playerHandling = HANDLING::PARTICLE;
	flame1.var[6] = 16;
	flame1.behavior = bombFlame;
}

void onLevelLoad() {
	findCustomAnimID();
	jjSampleLoad(SOUND::ORANGE_GLAS1L, "glass_shatter.WAV");
	
	jjAnimations[jjAnimSets[ANIM::AMMO] + 59] = jjAnimations[jjAnimSets[ANIM::CUSTOM[customAnimID]] + 3];
	
	jjObjectPresets[OBJECT::TNT].determineCurAnim(ANIM::CUSTOM[customAnimID], 0, true);
	jjObjectPresets[OBJECT::TNT].special = 0;
	jjObjectPresets[OBJECT::TNT].playerHandling = HANDLING::PLAYERBULLET;
	jjObjectPresets[OBJECT::TNT].var[6] = 8;
	jjObjectPresets[OBJECT::TNT].lightType = LIGHT::NONE;
	jjObjectPresets[OBJECT::TNT].behavior = pBomb;
	
	jjObjectPresets[OBJECT::TNTAMMO3].scriptedCollisions = true;
	jjObjectPresets[OBJECT::TNTAMMO3].playerHandling = HANDLING::SPECIAL;
}

void onLevelBegin() {
	jjWeapons[7].allowed = true;
	jjWeapons[7].allowedPowerup = true;
	jjWeapons[7].style = WEAPON::MISSILE;
	jjWeapons[7].maximum = 3;
	jjWeapons[7].defaultSample = false;
}

void onObjectHit(jjOBJ@ obj, jjOBJ@ bullet, jjPLAYER@ p, int force) {
	if (obj.eventID == OBJECT::TNTAMMO3) {
		if (bullet is null) {
			if (p.ammo[7] < 3) {
				p.ammo[7] = p.ammo[7] + 1;
				jjSample(obj.xPos, obj.yPos, SOUND::COMMON_PICKUPW1, 63, 0);
				obj.behavior = BEHAVIOR::EXPLOSION2;
			}
		}
	}
}

void onReceive(jjSTREAM &in packet, int clientID) {
	uint8 type;
	packet.pop(type);
	if (jjIsServer) {
		switch (type) {
			case packet_bombExplode:
			{
				int posX;
				int16 posY;
				int32 playNum;
				packet.pop(posX);
				packet.pop(posY);
				packet.pop(playNum);
				for (uint8 i = 0; i < 10; ++i) {
					addFlame(posX, posY, playNum, i);
				}
				sendBombPacket(posX, posY, playNum);
			}
			break;
		}
	} else {
		switch (type) {
			case packet_bombExplode:
			{
				int posX;
				int16 posY;
				int32 playNum;
				packet.pop(posX);
				packet.pop(posY);
				packet.pop(playNum);
				for (uint8 i = 0; i < 10; ++i) {
					addFlame(posX, posY, playNum, i);
				}
            }
			break;
      }
   }
}

bool onDrawAmmo(jjPLAYER@ p, jjCANVAS@ canvas) {
	if (p.currWeapon == 7) {
		for (uint8 i = 0; i < p.ammo[7]; ++i) {
			canvas.drawSprite(jjResolutionWidth - 80 + i * 14, jjResolutionHeight - 16, ANIM::CUSTOM[customAnimID], 0, 1, 0, SPRITE::NORMAL, 0);
		}
		
		return true;
	}
	return false;
}