2.0
13 Apr 2015 12:10
/*********************************Potion/Effect Script********************************************/
array<bool> effectID(4, false);
array<int> fakeTimeSeconds(4, 0);
array<int> timeSeconds(4, 0);
array<int> timeMinutes(4, 0);
int activePotions;
array<int> effectQueue(4, 0);
array<int> effectLevel(4, 0);
void onLevelLoad() {
jjObjectPresets[OBJECT::CHERRY].determineCurAnim(ANIM::PICKUPS, 78);
jjObjectPresets[OBJECT::CHERRY].special = jjObjectPresets[OBJECT::CHERRY].determineCurAnim(ANIM::PICKUPS,78,false);
jjObjectPresets[OBJECT::CHERRY].determineCurFrame();
jjObjectPresets[OBJECT::CHERRY].scriptedCollisions = true;
jjObjectPresets[OBJECT::LETTUCE].determineCurAnim(ANIM::PICKUPS, 78);
jjObjectPresets[OBJECT::LETTUCE].special = jjObjectPresets[OBJECT::LETTUCE].determineCurAnim(ANIM::PICKUPS,78,false);
jjObjectPresets[OBJECT::LETTUCE].determineCurFrame();
jjObjectPresets[OBJECT::LETTUCE].scriptedCollisions = true;
jjObjectPresets[OBJECT::EGGPLANT].determineCurAnim(ANIM::PICKUPS, 78);
jjObjectPresets[OBJECT::EGGPLANT].special = jjObjectPresets[OBJECT::EGGPLANT].determineCurAnim(ANIM::PICKUPS,78,false);
jjObjectPresets[OBJECT::EGGPLANT].determineCurFrame();
jjObjectPresets[OBJECT::EGGPLANT].scriptedCollisions = true;
jjObjectPresets[OBJECT::DONUT].determineCurAnim(ANIM::PICKUPS, 78);
jjObjectPresets[OBJECT::DONUT].special = jjObjectPresets[OBJECT::DONUT].determineCurAnim(ANIM::PICKUPS,78,false);
jjObjectPresets[OBJECT::DONUT].determineCurFrame();
jjObjectPresets[OBJECT::DONUT].scriptedCollisions = true;
}
void onPlayer() {
if (effectID[0]) {
--fakeTimeSeconds[0];
timeSeconds[0] = fakeTimeSeconds[0] / 70;
if (timeMinutes[0] > 0 && timeSeconds[0] == 0) {
--timeMinutes[0];
fakeTimeSeconds[0] = 70 * 60;
}
else if (timeMinutes[0] <= 0 && timeSeconds[0] == 0) {
effectID[0] = false;
--activePotions;
removeEffect(0);
effectLevel[0] = 0;
}
}
if (effectID[1]) {
--fakeTimeSeconds[1];
timeSeconds[1] = fakeTimeSeconds[1] / 70;
if (timeMinutes[1] > 0 && timeSeconds[1] == 0) {
--timeMinutes[1];
fakeTimeSeconds[1] = 70 * 60;
}
else if (timeMinutes[1] <= 0 && timeSeconds[1] == 0) {
effectID[1] = false;
--activePotions;
removeEffect(1);
}
}
if (effectID[2]) {
--fakeTimeSeconds[2];
timeSeconds[2] = fakeTimeSeconds[2] / 70;
if (timeMinutes[2] > 0 && timeSeconds[2] == 0) {
--timeMinutes[2];
fakeTimeSeconds[2] = 70 * 60;
}
else if (timeMinutes[2] <= 0 && timeSeconds[2] == 0) {
effectID[2] = false;
--activePotions;
removeEffect(2);
}
}
if (effectID[3]) {
--fakeTimeSeconds[3];
timeSeconds[3] = fakeTimeSeconds[3] / 70;
if (timeMinutes[3] > 0 && timeSeconds[3] == 0) {
--timeMinutes[3];
fakeTimeSeconds[3] = 70 * 60;
}
else if (timeMinutes[3] <= 0 && timeSeconds[3] == 0) {
effectID[3] = false;
--activePotions;
removeEffect(3);
}
}
potionEffects();
}
bool onDrawLives(jjPLAYER@ p, jjCANVAS@ canvas) {
if (effectID[0]) {
canvas.drawSprite(jjSubscreenWidth - 630, jjSubscreenHeight-340+(20 * effectQueue[0]), ANIM::AMMO, 12, 0, 0, SPRITE::NORMAL, 0);
if (effectLevel == 1) canvas.drawString(jjSubscreenWidth - 620, jjSubscreenHeight-340+(20 * effectQueue[0]), "Poison: " + timeMinutes[0] + "/" + timeSeconds[0], STRING::SMALL, STRING::NORMAL);
else if (effectLevel == 2) canvas.drawString(jjSubscreenWidth - 620, jjSubscreenHeight-340+(20 * effectQueue[0]), "Poison II: " + timeMinutes[0] + "/" + timeSeconds[0], STRING::SMALL, STRING::NORMAL);
}
if (effectID[1]) {
canvas.drawSprite(jjSubscreenWidth - 630, jjSubscreenHeight-340+(20 * effectQueue[1]), ANIM::AMMO, 4, 4, 0, SPRITE::NORMAL, 0);
canvas.drawString(jjSubscreenWidth - 620, jjSubscreenHeight-340+(20 * effectQueue[1]), "Blindness: " + timeMinutes[1] + "/" + timeSeconds[1], STRING::SMALL, STRING::NORMAL);
}
if (effectID[2]) {
canvas.drawSprite(jjSubscreenWidth - 630, jjSubscreenHeight-340+(20 * effectQueue[2]), ANIM::PICKUPS, 41, 0, 0, SPRITE::NORMAL, 0);
canvas.drawString(jjSubscreenWidth - 620, jjSubscreenHeight-340+(20 * effectQueue[2]), "Regeneration: " + timeMinutes[2] + "/" + timeSeconds[2], STRING::SMALL, STRING::NORMAL);
}
if (effectID[3]) {
canvas.drawSprite(jjSubscreenWidth - 630, jjSubscreenHeight-340+(20 * effectQueue[3]), /*Sprite Group*/, /*Sprite Group Animation*/, /*Sprite Group Animation Frame*/, /*Direction*/, /*SPRITE::Sprite Mode*/, /*param*/);
canvas.drawString(jjSubscreenWidth - 620, jjSubscreenHeight-340+(20 * effectQueue[3]), "Your Potion Effect: " + timeMinutes[3] + "/" + timeSeconds[3], STRING::SMALL, STRING::NORMAL);
}
return false;
}
void onObjectHit(jjOBJ@ obj, jjOBJ@ bullet, jjPLAYER@ p, int force) {
switch(obj.eventID) {
case OBJECT::CHERRY:
fakeTimeSeconds[0] = 70 * 45;
timeMinutes[0] = 0;
effectID[0] = true;
effectLevel = 1;
if (effectLevel == 0) {
++activePotions;
effectQueue[0] = activePotions;
}
obj.scriptedCollisions = false;
obj.behavior = BEHAVIOR::EXPLOSION2;
obj.frameID = 0;
jjSample(p.xPos, p.yPos, SOUND::COMMON_DRINKSPAZZ1, 30);
jjSample(p.xPos, p.yPos, SOUND::COMMON_DRINKSPAZZ2, 30);
jjSample(p.xPos, p.yPos, SOUND::COMMON_DRINKSPAZZ3, 30);
jjSample(p.xPos, p.yPos, SOUND::COMMON_DRINKSPAZZ4, 30);
break;
case OBJECT::LETTUCE:
fakeTimeSeconds[1] = 70 * 5;
timeMinutes[1] = 0;
effectID[1] = true;
++activePotions;
effectQueue[1] = activePotions;
obj.scriptedCollisions = false;
obj.behavior = BEHAVIOR::EXPLOSION2;
obj.frameID = 0;
jjSample(p.xPos, p.yPos, SOUND::COMMON_DRINKSPAZZ1, 30);
jjSample(p.xPos, p.yPos, SOUND::COMMON_DRINKSPAZZ2, 30);
jjSample(p.xPos, p.yPos, SOUND::COMMON_DRINKSPAZZ3, 30);
jjSample(p.xPos, p.yPos, SOUND::COMMON_DRINKSPAZZ4, 30);
break;
case OBJECT::EGGPLANT:
fakeTimeSeconds[2] = 70 * 45;
timeMinutes[2] = 1;
effectID[2] = true;
++activePotions;
effectQueue[2] = activePotions;
obj.scriptedCollisions = false;
obj.behavior = BEHAVIOR::EXPLOSION2;
obj.frameID = 0;
jjSample(p.xPos, p.yPos, SOUND::COMMON_DRINKSPAZZ1, 30);
jjSample(p.xPos, p.yPos, SOUND::COMMON_DRINKSPAZZ2, 30);
jjSample(p.xPos, p.yPos, SOUND::COMMON_DRINKSPAZZ3, 30);
jjSample(p.xPos, p.yPos, SOUND::COMMON_DRINKSPAZZ4, 30);
break;
case OBJECT::DONUT:
fakeTimeSeconds[3] = 70 * 45;
timeMinutes[3] = 0;
effectID[3] = true;
++activePotions;
effectQueue[3] = activePotions;
obj.scriptedCollisions = false;
obj.behavior = BEHAVIOR::EXPLOSION2;
obj.frameID = 0;
jjSample(p.xPos, p.yPos, SOUND::COMMON_DRINKSPAZZ1, 30);
jjSample(p.xPos, p.yPos, SOUND::COMMON_DRINKSPAZZ2, 30);
jjSample(p.xPos, p.yPos, SOUND::COMMON_DRINKSPAZZ3, 30);
jjSample(p.xPos, p.yPos, SOUND::COMMON_DRINKSPAZZ4, 30);
break;
}
void removeEffect(int id) {
for(int i = 0; i < 9; i++) {
if(effectQueue[i] == 0)
continue;
else if(effectQueue[i] > effectQueue[id])
effectQueue[i]--;
}
effectQueue[id]=0;
}
void potionEffects() {
if (effectID[0]) {
if (effectLevel == 1) {
if (p.health > 1 && jjGameTicks % 280 == 0) {
p.health = p.health - 1;
}
} else if (effectLevel == 2) {
if (jjGameTicks % 140 == 0) {
p.health = p.health - 1;
}
}
if (p.health == 0) {
effectID[0] = false;
--activePotions;
removeEffect(0);
effectLevel = 0;
}
}
if (effectID[1]) {
if (jjGameTicks % 140 == 0) {
p.lighting = 0;
if (p.health == 0) {
effectID[1] = false;
--activePotions;
removeEffect(1);
}
}
} else p.lighting = 100;
if (effectID[2]) {
if (p.health <= jjMaxHealth && jjGameTicks % 560 == 0) {
p.health = p.health + 1;
}
if (p.health == 0) {
effectID[2] = false;
--activePotions;
removeEffect(2);
}
}
if (effectID[3]) {
/*Put here what the effect does*/
if (p.health == 0) {
effectID[3] = false;
--activePotions;
removeEffect(3);
}
}
}
/***********************************************************************************************************/
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.