Downloads containing LaserBlaster.asc

Downloads
Name Author Game Mode Rating
JJ2+ Only: Threed RealmsFeatured Download Violet CLM Single player 9.7 Download file
TSF with JJ2+ Only: The DARKEST Diamonds Killer NC Capture the flag 7.5 Download file
Custom Weapons...Featured Download Violet CLM Other 10 Download file

File preview

#pragma require "LaserBlaster.asc"
#include "MLLE-Weapons.asc"
#pragma require "LaserBlaster.j2a"
#pragma offer "xlmpolaris_sounds/f_laser1.wav"
#pragma offer "xlmpolaris_sounds/f_laser2.wav"
#pragma offer "xlmpolaris_sounds/f_laser3.wav"
#pragma offer "xlmpolaris_sounds/f_laser4.wav"

namespace LaserBlaster {
	class Weapon : MLLEWeapons::WeaponInterface {
		Weapon() {
			super(
				regularObjectTemplate: MLLEWeapons::ObjectTemplate(
					xSpeed: 1.5,
					xAcc: 0.125,
					animSpeed: 1,
					killAnim: jjAnimSets[ANIM::AMMO].firstAnim + 7,
					curAnim: 1,
					lightType: LIGHT::POINT2,
					counterEnd: 125
				),
				powerupObjectTemplate: MLLEWeapons::ObjectTemplate(
					xSpeed: 2,
					xAcc: 0.1875,
					animSpeed: 2,
					killAnim: jjAnimSets[ANIM::AMMO].firstAnim + 7,
					curAnim: 0,
					lightType: LIGHT::POINT2,
					counterEnd: 95
				),
				sampleFilenames: array<string> = {"xlmpolaris_sounds/f_laser1.wav", "xlmpolaris_sounds/f_laser2.wav", "xlmpolaris_sounds/f_laser3.wav", "xlmpolaris_sounds/f_laser4.wav"},
				animSetFilename: "LaserBlaster.j2a",
				pickupAnimation: 2,
				poweredUpPickupAnimation: 3,
				//powerupAnimation: 4,
				apply: MLLEWeapons::applyFunction(LightKillAnim),
				behavior: MLLEWeapons::behaviorFunction(PlayStartupSound)
			);
		}
		void PlayStartupSound(jjOBJ@ obj, bool powerup) const {
			if (obj.creatorType == CREATOR::PLAYER)
				jjSample(obj.xPos, obj.yPos, Samples[(powerup ? 2 : 0) + (jjRandom() & 1)]);
			if (obj.eventID == OBJECT::ICEBULLET) obj.eventID = OBJECT::BLASTERBULLET;
			obj.behavior = Behavior;
		}
		bool LightKillAnim(uint, se::WeaponHook@, jjSTREAM@ parameter) {
			if (parameter !is null && !parameter.isEmpty()) {
				bool enlighten;
				parameter.pop(enlighten);
				if (enlighten) {
					RegularObjectTemplate.KillAnim = PowerupObjectTemplate.KillAnim = jjAnimSets[ANIM::AMMO].firstAnim + 82;
					jjANIMATION@ anim = jjAnimations[jjAnimSets[ANIM::AMMO] + 82];
					for (uint i = 0; i < anim.frameCount; ++i) {
						jjANIMFRAME@ frame = jjAnimFrames[anim + i];
						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] += 33; //only modify the 32-39 range, in case this code is run more than once for whatever reason
						sprite.save(frame);
					}
					return true;
				}
			}
			return true;
		}
	}
	
	void Behavior(jjOBJ@ obj) {
		if (obj.state == STATE::START) {
			if (obj.creatorType == CREATOR::PLAYER)
				obj.direction = jjPlayers[obj.creatorID].direction;
			else
				obj.direction = jjObjects[obj.creatorID].direction;
			obj.special = 1; //use JJ2+ code to rotate sprites
		}
		const float reboundSpeed = MLLEWeapons::HelpfulBulletFunctions::IsPowerup(obj) ? 3.f : 1.5f;
		if (jjMaskedPixel(int(obj.xPos + obj.xSpeed + obj.var[7] / 65536.f), int(obj.yPos))) {
			obj.xSpeed = -obj.xSpeed;
			obj.var[7] = -obj.var[7];
			obj.xAcc = -obj.xAcc;
			obj.ySpeed -= reboundSpeed;
			obj.counter -= 5;
			if (obj.state == STATE::FLY) randomSample(obj);
		}
		else if (jjMaskedPixel(int(obj.xPos), int(obj.yPos + obj.ySpeed))) {
			obj.ySpeed = -obj.ySpeed;
			obj.yAcc = -obj.yAcc;
			obj.xSpeed -= obj.direction == 1 ? -reboundSpeed : reboundSpeed;
			obj.counter -= 5;
			if (obj.state == STATE::FLY) randomSample(obj);
		}
		
		obj.behave(BEHAVIOR::BULLET);
	}
	void randomSample(jjOBJ@ obj) {
		jjSample(obj.xPos, obj.yPos, SOUND::Sample(SOUND::AMMO_BUL1 + (jjRandom() & 3)));
	}
}