Downloads containing weaponMega7.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: Gravity Well"
#pragma require "weaponMega7.mut"
#include "weaponMega.asc"

bool LoadWeaponMega7() {
	if (!SafeToReplaceWeapon(WEAPON::TNT))
		return false;
		
	jjWeapons[WEAPON::TNT].defaultSample = false;
	
	Preset1.behavior = function(obj){obj.behavior = GravityWell(obj); obj.behave();};
	Preset1.special = Preset1.determineCurAnim(AnimSet, 0);
	Preset1.determineCurFrame();
	Preset1.state = STATE::IDLE; //why bother with START, really
	Preset1.var[6] = 16; //fireball-ish
	Preset1.animSpeed = 1; //do damage to objects (as opposed to players)
	Preset1.counter = 0;
	Preset1.xSpeed = 1; //needed to get a direction
	Preset1.playerHandling = HANDLING::PLAYERBULLET;
	Preset1.eventID = OBJECT::BULLET; //to prevent using /tntdamage
	
	return true;
}
const bool WeaponMega7Loaded = LoadWeaponMega7();

class GravityWell : WeaponMega {
	GravityWell(jjOBJ@ objectOfAttachment) {
		@obj = @objectOfAttachment;
	}
	void onBehave(jjOBJ@) override {
		obj.frameID = ++obj.counter / 7;
		obj.age = jjSampleLooped(obj.xPos, obj.yPos, SOUND::COMMON_MONITOR, obj.age, 63, 5000);
		
		if (obj.counter > 175) {
			jjSample(obj.xPos, obj.yPos, SOUND::COMMON_SHLDOF3);
			obj.particlePixelExplosion(88);
			obj.delete();
		} else {
			for (uint i = jjObjectCount - 1; i > 0; --i) {
				jjOBJ@ other = jjObjects[i];
				if (other.isActive && other.eventID <= OBJECT::BULLET && other.isBlastable && other.state != STATE::EXPLODE && (other.creatorType != CREATOR::PLAYER || playerIsEnemy(jjPlayers[other.creator]))) {
					float d, dx, dy;
					if (withinRange(other.xPos, other.yPos, d, dx, dy)) {
						const float angle = atan2(dy, dx);
						other.xSpeed += 64 / d * cos(angle);
						other.ySpeed += 64 / d * sin(angle);
					}
				}
			}
			for (uint i = 0; i < 32; ++i) {
				jjPLAYER@ other = jjPlayers[i];
				if (other.isInGame && other.blink == 0 && playerIsEnemy(other)) {
					float d, dx, dy;
					if (withinRange(other.xPos, other.yPos, d, dx, dy)) {
						const float angle = atan2(dy, dx);
						other.xSpeed += 24 / d * cos(angle);
						other.ySpeed += 10 / d * sin(angle);
					}
				}
			}
		}
	}
	void onDraw(jjOBJ@) override {
		if (obj.frameID <= 6) {
			obj.curFrame = jjAnimations[obj.curAnim] + obj.frameID;
			jjDrawSpriteFromCurFrame(obj.xPos, obj.yPos, obj.curFrame);
		} else {
			while (obj.frameID > 6) obj.frameID -= 3;
			obj.curFrame = jjAnimations[obj.curAnim] + obj.frameID;
			jjDrawRotatedSpriteFromCurFrame(obj.xPos, obj.yPos, obj.curFrame, (obj.counter - 7*7) * (obj.xSpeed >= 0 ? -32 : 32));
			obj.lightType = LIGHT::RING2;
			obj.light = 15 - (obj.counter & 7) * 2;
		}
	}
	bool withinRange(float x, float y, float &out d, float &out dx, float &out dy) const {
		dx = obj.xPos - x;
		dy = obj.yPos - y;
		return (d = sqrt(dx * dx + dy * dy)) < (290);
	}
}