Name | Author | Game Mode | Rating | |||||
---|---|---|---|---|---|---|---|---|
Weapon Mega | Violet CLM | Mutator | 8.7 |
#pragma name "Weapon Mega: Pathfinder"
#pragma require "weaponMega4.mut"
#include "weaponMega.asc"
bool LoadWeaponMega4() {
if (!SafeToReplaceWeapon(WEAPON::SEEKER))
return false;
jjWeapons[WEAPON::SEEKER].defaultSample = false;
jjWeapons[WEAPON::SEEKER].replacedByBubbles = true;
Preset1.behavior = ApplyPathfinder;
Preset2.behavior = ApplyPathfinder;
Preset1.special = Preset1.determineCurAnim(AnimSet, 0);
Preset2.special = Preset2.determineCurAnim(AnimSet, 1);
Preset1.determineCurFrame(); Preset2.determineCurFrame();
Preset1.isBlastable = false; Preset2.isBlastable = false;
Preset1.playerHandling = Preset2.playerHandling = HANDLING::PARTICLE;
Preset1.counterEnd = 46; Preset2.counterEnd = 32;
return true;
}
const bool WeaponMega4Loaded = LoadWeaponMega4();
void ApplyPathfinder(jjOBJ@ obj) { obj.behavior = Pathfinder(obj); obj.behave(); }
class Pathfinder : WeaponMega {
array<jjOBJ@> nodes;
bool waiting = false;
bool foundAtLeastOneTarget = false;
uint counter = 0;
bool powerup;
Pathfinder(jjOBJ@ objectOfAttachment) {
@obj = @objectOfAttachment;
obj.state = STATE::FLY;
powerup = isPowerup();
jjSample(obj.xPos, obj.yPos, powerup ? SOUND::AMMO_LASER3 : SOUND::AMMO_LASER2);
}
void destroy() {
jjSample(obj.xPos, obj.yPos, SOUND::COMMON_ELECTRIC2);
for (uint i = 0; i < nodes.length; ++i)
nodes[i].delete();
obj.delete();
}
void onBehave(jjOBJ@) override {
if (obj.state == STATE::EXPLODE) {
destroy();
return;
}
obj.frameID = (obj.objectID + jjGameTicks / 3) % 3;
if (++counter >= obj.counterEnd) {
if (waiting = !waiting) { //stop moving
addNode();
counter = obj.counterEnd / 2;
} else { //start moving
if (nodes.length > (uint(powerup ? 6 : 4) / uint(foundAtLeastOneTarget ? 1 : 3)) || obj.state == STATE::DONE) {
destroy();
return;
}
const int nearestEnemyID = getNearestEnemy(200);
if (nearestEnemyID >= 0) {
const jjPLAYER@ target = jjPlayers[nearestEnemyID];
obj.var[7] = 0;
const float standardSpeed = (powerup ? 3.f : 2.5f);
const float dx = target.xPos - obj.xPos, dy = target.yPos - obj.yPos;
foundAtLeastOneTarget = true;
if (abs(dx) > abs(dy)) {
obj.xSpeed = (dx > 0) ? standardSpeed : -standardSpeed;
obj.ySpeed = 0;
} else {
obj.xSpeed = 0;
obj.ySpeed = (dy > 0) ? standardSpeed : -standardSpeed;
}
}
counter = 0;
}
}
if (!waiting) {
obj.xPos += obj.xSpeed + obj.var[7] / 65536.f;
obj.yPos += obj.ySpeed;
if (obj.var[7] > 0x100000)
obj.var[7] = obj.var[7] - 0x80000;
else if (obj.var[7] < -0x100000)
obj.var[7] = obj.var[7] + 0x80000;
if (colliding()) {
counter = obj.counterEnd / 2;
waiting = true;
addNode();
obj.state = STATE::DONE;
}
}
}
bool colliding() const {
return maskedPixelAtBullet() && jjEventAtLastMaskedPixel != AREA::ONEWAY && jjEventAtLastMaskedPixel != AREA::HOOK && jjEventAtLastMaskedPixel != AREA::VINE;
}
void addNode() {
jjOBJ@ node = jjObjects[jjAddObject(OBJECT::BEES, obj.xPos, obj.yPos, obj.creatorID, obj.creatorType)];
node.playerHandling = HANDLING::PLAYERBULLET;
node.var[6] = 2 | (powerup ? 8 : 0) | 16; //fireball
node.animSpeed = powerup ? 2 : 1;
node.curFrame = jjAnimations[obj.curAnim + 2];
node.state = STATE::FLY;
node.lightType = LIGHT::BRIGHT;
node.light = powerup ? 10 : 8;
nodes.insertLast(node);
jjSample(obj.xPos, obj.yPos, SOUND::COMMON_ELECTRIC1);
}
void onDraw(jjOBJ@) override {
jjDrawSpriteFromCurFrame(obj.xPos, obj.yPos, obj.curFrame + obj.frameID);
for (uint i = 0; i < nodes.length; ++i) {
const jjOBJ@ node = nodes[i];
const jjOBJ@ node2 = (i < nodes.length - 1) ? nodes[i + 1] : obj;
jjDrawRectangle(node.xPos, node.yPos, int(node2.xPos - node.xPos) + 1, int(node2.yPos - node.yPos) + 1, 15);
jjDrawSpriteFromCurFrame(node.xPos, node.yPos, node.curFrame + obj.frameID);
}
}
}
Jazz2Online © 1999-INFINITY (Site Credits). We have a Privacy Policy. Jazz Jackrabbit, Jazz Jackrabbit 2, Jazz Jackrabbit Advance and all related trademarks and media are ™ and © Epic Games. Lori Jackrabbit is © Dean Dodrill. J2O development powered by Loops of Fury and Chemical Beats.
Eat your lima beans, Johnny.