View Single Post
Love & Thunder

JCF Member

Joined: Sep 2011

Posts: 1,101

Love & Thunder has disabled reputation

Jan 11, 2015, 01:02 AM
Love & Thunder is offline
Reply With Quote
Code:
uint elapsed = 0;
bool surge = false;
int slain = 0;
bool surgeover = false;

void onMain() {
    if (surge == false) {
        elapsed = 0;
    } else {
        elapsed ++;
    }
    if ((jjTriggers[5] == true) && (surgeover == false) == true) {
        if (surge == false) {
            jjLocalPlayers[0].showText("@@@@@SURGE INCOMING!", STRING::LARGE);
        }
        doEnemySurge();
    }
}

void doEnemySurge() {
    if (surge == false) {
        surge = true;
    }
    if (slain < 10) {
        if (elapsed % 70 == 0) { //Once per second
            uint16 randomTarget = (237 + (jjRandom()&8)) * 32;
            jjOBJ@ obj = jjObjects[jjAddObject(OBJECT::FLOATLIZARD, randomTarget, 1024)];
            obj.state = STATE::FALL;
            obj.var[5] = 0;
            obj.scriptedCollisions = true;
        }
    } else { //slain >= 10: surge is over
        surgeover = true;
        jjMusicLoad("carrotus.j2b");
        jjLocalPlayers[0].showText("@@@@@SURGE COMPLETE!", STRING::LARGE);
        for (int i = 0; i < jjLocalPlayerCount; i++) {
            jjLocalPlayers[i].limitXScroll(43, 0);
        }
        elapsed = 0;
    }
}

void onLevelReload() {
    slain = 0;
    elapsed = 0;
}

void onObjectHit(jjOBJ@ object, jjOBJ@ bullet, jjPLAYER@ player, int force) {
    if ((object.eventID == OBJECT::FLOATLIZARD || object.eventID == OBJECT::XMASFLOATLIZARD) && object.state != STATE::KILL) {
        if (player !is null) {//no TNT or turtle shells in this level, so shouldn't be necessary, but can't hurt
            if (force == 0) //normal collision, not using any buttstomps or whatever
                player.hurt();
            else {
                //Here JJ2 would check to see if the object is frozen, and if so,
                //unfreeze it and (possibly; some objects do this and others don't)
                //alter the amount of damage it receives from the bullet. There's no
                //ice ammo in this level, so that's not required.
                if (force > 0) //probably a bullet
                    object.energy -= force;
                else //special attack
                    object.energy -= 4;
                if (object.energy <= 0) {
                    if (bullet !is null) {
                        if ((bullet.var[6] & 2) == 2) { //toaster and its ilk
                            object.particlePixelExplosion(1); //burny explosion
                            jjSample(object.xPos, object.yPos, SOUND::COMMON_BURN);
                        } else {
                            object.particlePixelExplosion(0);
                        }
                        object.grantPickup(player, (bullet.eventID == OBJECT::BLASTERBULLET) ? 5 : 10);
                            //JJ2 only ever calls grantPickup for enemies/crates destroyed
                            //by bullets, but you can branch out a bit if you like
                    } else {
                        object.particlePixelExplosion(2); //killed by physical contact
                        jjSample(object.xPos, object.yPos, SOUND::COMMON_SPLAT1);
                    }
                    object.state = STATE::KILL; //let the object's behavior function take care of deleting it
                    player.score += object.points;
                    jjPARTICLE@ score = jjAddParticle(PARTICLE::STRING);     //JJ2 checks that jjGameMode is SP or COOP before doing this,
                    if (score !is null) {                    //and also makes sure that object.points is non-zero. We know both
                        score.xPos = object.xPos;            //are true here, so there's no need to bother.
                        score.yPos = object.yPos;
                        score.xSpeed = -0.5 - (jjRandom() & 0x3FFF) / 65536.;
                        score.ySpeed = -1   - (jjRandom() & 0x7FFF) / 65536.;
                        score.string.text = formatInt(object.points, "1");
                    }
                    ++slain; //the only reason we're going to all this effort
                } else //not yet dead
                    object.justHit = 5; //flash white for five ticks
            }
        }
        if (bullet !is null && (bullet.var[6] & 16) == 0) { //JJ2 also checks for var[6] & 4, aka the laser shield blast, but eh whatever
            bullet.state = STATE::EXPLODE;    //EXPLODE, like START, means the bullet won't be checked for collisions with other objects/players
                            //also, all normal bullet behaviors have code to dispose of themselves during EXPLODE, so that's nice
        }
    }
}
__________________