Downloads containing dischargeGun.mut

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

File preview

#pragma name "Discharge Gun"
#pragma require "dischargeGun.j2a"

/**Discharge Gun**/
/**Author: szmol96**/

uint customAnimID = 0;
int8 fastfireBackup = 0;
bool curElectro = false;
uint8 prevFrame = 0;
uint8 warmUp = 0;
uint16 heat = 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, "dischargeGun.j2a");
}

void electricalDischarge(jjOBJ@ obj) {
	jjPLAYER@ p = jjPlayers[obj.creatorID];
	jjPLAYER@ lp = jjLocalPlayers[0];
	
	if (obj.state == STATE::START) {
		if (p.light == 1) {
			obj.delete();
			return;
		}
		obj.age = 0;
		obj.frameID = (jjRandom() % 4);
		if (obj.frameID == prevFrame) {
			obj.frameID++;
		}
		prevFrame = obj.frameID;
		
		obj.xAcc = obj.xSpeed;
		obj.yAcc = obj.ySpeed;
		obj.direction = p.direction;
		
		jjPARTICLE@ spark1 = jjAddParticle(PARTICLE::SPARK);
		if (spark1 !is null) {
			spark1.spark.color = 32;
			spark1.spark.colorDelta = 1;
			spark1.spark.colorStop = 38;
			if (abs(obj.yAcc) < abs(obj.xAcc)) {
				spark1.xPos = (obj.xPos + obj.direction * 128) + obj.direction *  64 * jjCos(jjRandom() % 512);
				spark1.yPos = obj.yPos + jjCos(jjRandom() % 512);
			} else {
				spark1.xPos = obj.xPos + jjCos(jjRandom() % 512);
				spark1.yPos = (obj.yPos - 64) + 64 * jjCos(jjRandom() % 512);
			}
			spark1.xSpeed = 2 * jjCos(jjRandom() % 512);
			spark1.ySpeed = 2 * jjCos(jjRandom() % 512);
		}
		jjPARTICLE@ spark2 = jjAddParticle(PARTICLE::SPARK);
		if (spark2 !is null) {
			spark2.spark.color = 32;
			spark2.spark.colorDelta = 1;
			spark2.spark.colorStop = 38;
			if (abs(obj.yAcc) < abs(obj.xAcc)) {
				spark2.xPos = (obj.xPos + obj.direction * 128) + obj.direction *  64 * jjCos(jjRandom() % 512);
				spark2.yPos = obj.yPos + jjCos(jjRandom() % 512);
			} else {
				spark2.xPos = obj.xPos + jjCos(jjRandom() % 512);
				spark2.yPos = (obj.yPos - 64) + 64 * jjCos(jjRandom() % 512);
			}
			spark2.xSpeed = jjCos(jjRandom() % 512);
			spark2.ySpeed = jjCos(jjRandom() % 512);
		}
		
		jjSample(obj.xPos, obj.yPos, SOUND::COMMON_ELECTRICHIT, 63, 0);
		if (heat < 464 && p.playerID == lp.playerID) heat += 12;
		obj.state = STATE::FLY;
	}
	
	
	obj.xPos = p.xPos + abs(obj.xAcc) * 5 * p.direction;
	obj.yPos = p.yPos + obj.yAcc * 5;
	obj.direction = p.direction;
	
	if (obj.age > 8) obj.delete();
	
	obj.age++;
	
	obj.determineCurFrame(true);
	obj.draw();
}

void onLevelLoad() {
	findCustomAnimID();
	
	jjAnimations[jjAnimSets[ANIM::AMMO] + 67] = jjAnimations[jjAnimSets[ANIM::CUSTOM[customAnimID]] + 3];
	jjAnimations[jjAnimSets[ANIM::AMMO] + 68] = jjAnimations[jjAnimSets[ANIM::CUSTOM[customAnimID]] + 3];
	jjAnimations[jjAnimSets[ANIM::PICKUPS] + 67] = jjAnimations[jjAnimSets[ANIM::CUSTOM[customAnimID]] + 4];
	
	jjObjectPresets[OBJECT::ELECTROBULLET].determineCurAnim(ANIM::CUSTOM[customAnimID], 0, true);
	jjObjectPresets[OBJECT::ELECTROBULLET].special = jjObjectPresets[OBJECT::ELECTROBULLET].determineCurAnim(ANIM::CUSTOM[customAnimID], 1, false);
	jjObjectPresets[OBJECT::ELECTROBULLET].playerHandling = HANDLING::PLAYERBULLET;
	jjObjectPresets[OBJECT::ELECTROBULLET].var[6] = 8 + 16;
	jjObjectPresets[OBJECT::ELECTROBULLET].behavior = electricalDischarge;
}

void onLevelBegin() {
	jjWeapons[9].allowed = true;
	jjWeapons[9].allowedPowerup = true;
	jjWeapons[9].spread = SPREAD::NORMAL;
	jjWeapons[9].style = WEAPON::CAPPED;
	jjWeapons[9].multiplier = 2;
	jjWeapons[9].defaultSample = false;
}

void onPlayer(jjPLAYER@ p) {
	if (p.currWeapon == 9) {
		if (!curElectro) {
			fastfireBackup = p.fastfire;
		}
		p.fastfire = 6;
	} else {
		if (curElectro) {
			p.fastfire = fastfireBackup;
		}
	}
	
	if (p.powerup[9]) p.powerup[9] = false;
	
	if (warmUp < 35) {
		p.light = 1;
	} else {
		p.light = 2;
	}
	
	if (heat > 460) p.hurt();
	if (!(p.keyFire && p.currWeapon == 9) && heat > 0 && jjGameTicks % 2 == 0) heat--;
	
	if (p.health < 1) heat = 0;
	
	curElectro = (p.currWeapon == 9);
}

void onPlayerInput(jjPLAYER@ p) {
	if (p.keyFire) {
		if (warmUp < 70 && p.currWeapon == 9) {
			if (warmUp == 0) jjSample(p.xPos, p.yPos, SOUND::BONUS_BONUS1, 32, 0);
			warmUp++;
		}
	} else {
		warmUp = 0;
	}
}

bool onDrawAmmo(jjPLAYER@ p, jjCANVAS@ canvas) {
	canvas.drawSprite(jjResolutionWidth - 128, jjResolutionHeight + 1, ANIM::CUSTOM[customAnimID], 2, 0, 0, SPRITE::NORMAL, 0);
	canvas.drawRotatedSprite(jjResolutionWidth - 128, jjResolutionHeight, ANIM::CUSTOM[customAnimID], 2, 1, 240 - heat, 1, 1, SPRITE::NORMAL, 0);
	
	return false;
}