Downloads containing weaponMega6.mut

Downloads
Name Author Game Mode Rating
JJ2+ Only: Weapon MegaFeatured Download Violet CLM Mutator 8.7 Download file

File preview

#pragma name "Weapon Mega: Crackerjack"
#pragma require "weaponMega6.mut"
#include "weaponMega.asc"

bool LoadWeaponMega6() {
	if (!SafeToReplaceWeapon(WEAPON::TOASTER))
		return false;
		
	jjWeapons[WEAPON::TOASTER].defaultSample = false;
	jjWeapons[WEAPON::TOASTER].spread = SPREAD::NORMAL;
	jjWeapons[WEAPON::TOASTER].style = WEAPON::NORMAL;
	jjWeapons[WEAPON::TOASTER].multiplier = 1;
	jjWeapons[WEAPON::TOASTER].replacedByBubbles = false;
	jjWeapons[WEAPON::TOASTER].gradualAim = true;
	
	Preset1.behavior = ApplyCrackerjack;
	Preset2.behavior = ApplyCrackerjack;
	Preset1.special = Preset1.determineCurAnim(AnimSet, 0);
	Preset2.special = Preset2.determineCurAnim(AnimSet, 1);
	Preset1.xSpeed = Preset2.xSpeed = 1.25;
	Preset1.determineCurFrame(); Preset2.determineCurFrame();
	Preset1.var[6] = 0; Preset2.var[6] = 8;
	
	return true;
}
const bool WeaponMega6Loaded = LoadWeaponMega6();

void ApplyCrackerjack(jjOBJ@ obj) { obj.behavior = Crackerjack(obj); obj.behave(); }
class Crackerjack : WeaponMega {
	Crackerjack(jjOBJ@ objectOfAttachment) {
		@obj = @objectOfAttachment;
		obj.state = STATE::FLY;
		obj.xSpeed += obj.var[7] / 65536.f;
		obj.xPos += obj.xSpeed * 2; obj.yPos += obj.ySpeed * 2;
	}
	void onBehave(jjOBJ@) override {
		if (obj.state == STATE::EXPLODE || maskedPixelAtBullet())
			blast(jjAnimSets[ANIM::AMMO] + 5);
		else {
			const float parentX = (obj.creatorType == CREATOR::PLAYER) ? jjPlayers[obj.creatorID].xPos : obj.xOrg;
			const float parentY = (obj.creatorType == CREATOR::PLAYER) ? jjPlayers[obj.creatorID].yPos : obj.yOrg;
			if (abs(obj.xPos - parentX) >= 160 || abs(obj.yPos - parentY) >= 128)
				obj.state = STATE::EXPLODE;
			else {
				obj.xPos += obj.xSpeed;
				obj.yPos += obj.ySpeed;
				
				obj.var[10] = obj.var[10] + 1; //ricochet
				
				if (jjGameTicks % 3 == 0)
					for (uint i = jjObjectCount - 1; i > 0; --i) {
						jjOBJ@ other = jjObjects[i];
						if (other.isActive && other.playerHandling == HANDLING::PLAYERBULLET && other.state != STATE::EXPLODE && (other.var[6] & 16) == 0 && other.creatorType == CREATOR::PLAYER && playerIsEnemy(jjPlayers[other.creator]) && obj.doesCollide(other, true)) {
							jjBEHAVIORINTERFACE@ castEnemyIntermediate = cast<jjBEHAVIORINTERFACE>(other.behavior);
							WeaponMega@ castEnemy = (castEnemyIntermediate is null) ? null : cast<WeaponMega>(castEnemyIntermediate);
							if (castEnemy !is null)
								castEnemy.blast(obj.curAnim + (isPowerup() ? 1 : 2));
							else
								other.state = STATE::EXPLODE;
						}
					}
			}
		} 
	}
	void onDraw(jjOBJ@) override {
		int frameID = (jjGameTicks >> 2) & 3;
		if (frameID == 0) frameID = 2;
		jjDrawRotatedSpriteFromCurFrame(obj.xPos, obj.yPos, obj.curFrame + frameID, getBulletAngle(), getBulletDirection());
	}
}