Downloads containing LFgems.asc

Downloads
Name Author Game Mode Rating
TSF with JJ2+ Only: Lori FortressFeatured Download Primpy Single player 8.7 Download file

File preview

#pragma require "LFgems.asc"

namespace gem {
	int gemsCollected, currAmount;
	bool foundAll = false;
	
	array<int> gemTotals(4);
	bool restoreGems;
	bool draw = true;

	void upgradeHealth(jjPLAYER@ play) { //onPlayer
	currAmount = 100; 
		if (gemsCollected >= currAmount && foundAll == false) {
			foundAll = true;
			jjChat("/smhealth " + (jjMaxHealth + 1));
			play.powerup[WEAPON::BLASTER] = true;
			for (int i = 0; i < 8; ++i) {
				jjAlert("");
			}
			if (jjGameTicks > 7) {
				jjSample(play.xPos, play.yPos, SOUND::INTRO_IFEEL, 0, 0);
				jjAlert("|||You feel your strength increase through the power of the gems.", false, STRING::MEDIUM);
				jjAlert("");
				jjAlert("||||Your health and blaster power have increased!", false, STRING::MEDIUM);
			}
		}
	}
	
	void trackPlayerGems(jjPLAYER@ play) { //onPlayer
		if (!restoreGems) {
			gemTotals[0] = play.gems[GEM::RED];
			gemTotals[1] = play.gems[GEM::GREEN] * 5;
			gemTotals[2] = play.gems[GEM::BLUE] * 10;
			gemTotals[3] = play.gems[GEM::PURPLE] * 20;
			gemsCollected = gemTotals[0] + gemTotals[1] + gemTotals[2] + gemTotals[3];
		} else {
			play.gems[GEM::RED] = jjGameTicks > 1? gemTotals[0] : play.lives;
			play.gems[GEM::GREEN] = gemTotals[1] / 5;
			play.gems[GEM::BLUE] = gemTotals[2] / 10;
			play.gems[GEM::PURPLE] = gemTotals[3] / 20;
			restoreGems = false;
		}
	}
	
	void restorePlayerGems() { //onLevelLoad and onLevelReload
		restoreGems = true;
	}
	
	void saveGemData() { //this needs to go in an AS function that also acts as the level exit
		jjLocalPlayers[0].lives = gemsCollected;
	}
	
	void deleteCollectedGems() {
		for (int i = 1; i < jjObjectCount; i++) {
			jjOBJ@ obj = jjObjects[i];
			int playerID = obj.findNearestPlayer(200000);
			jjPLAYER@ play = jjPlayers[playerID];
			
			if (playerID > -1 && 
			(obj.eventID == OBJECT::REDGEM ||
			obj.eventID == OBJECT::GREENGEM ||
			obj.eventID == OBJECT::BLUEGEM ||
			obj.eventID == OBJECT::PURPLEGEM ||
			obj.eventID == OBJECT::RECTREDGEM ||
			obj.eventID == OBJECT::RECTGREENGEM ||
			obj.eventID == OBJECT::RECTBLUEGEM)) {
				if (obj.creatorType == CREATOR::LEVEL) {
					if (play.doesCollide(obj, true)) {
						jjEventSet(uint(obj.xOrg) >> 5, uint(obj.yOrg) >> 5, 0);
					}
				} else {
					if (obj.creatorID == 0 && obj.state != STATE::FLOATFALL) {
						obj.playerHandling = HANDLING::PARTICLE;
						obj.delete();
					}
					
				}
			}
			
			if (obj.eventID == OBJECT::GEMBARREL || obj.eventID == OBJECT::GEMCRATE) {
				if (obj.state == STATE::EXPLODE) jjEventSet(uint(obj.xOrg) >> 5, uint(obj.yOrg) >> 5, 0);
			}
			
			if (obj.eventID == OBJECT::GEMRING) {
				if (obj.state == STATE::HIT) jjEventSet(uint(obj.xOrg) >> 5, uint(obj.yOrg) >> 5, 0);
			}
			
			if (obj.eventID == OBJECT::SUPERGEM) {
				if (obj.state == STATE::ACTION) jjEventSet(uint(obj.xOrg) >> 5, uint(obj.yOrg) >> 5, 0);
			}
			
			if (obj.eventID == OBJECT::BOMBCRATE || obj.eventID == OBJECT::ONEUPCRATE) {
				if (obj.state == STATE::FALL && (obj.var[0] == OBJECT::REDGEM ||
				obj.var[0] == OBJECT::GREENGEM ||
				obj.var[0] == OBJECT::BLUEGEM ||
				obj.var[0] == OBJECT::PURPLEGEM ||
				obj.var[0] == OBJECT::RECTREDGEM ||
				obj.var[0] == OBJECT::RECTGREENGEM ||
				obj.var[0] == OBJECT::RECTBLUEGEM)) {
					jjEventSet(uint(obj.xOrg) >> 5, uint(obj.yOrg) >> 5, 0);
				}
			}
		}
	}
}

bool onDrawScore(jjPLAYER@ play, jjCANVAS@ canvas) {
	if (gem::draw) {
		canvas.drawSprite(20, 42, ANIM::PICKUPS, 22, jjGameTicks>>2, 0, SPRITE::GEM, 0);
		canvas.drawString(36, 42, "x " + gem::gemsCollected, STRING::MEDIUM, STRING::NORMAL);
		if (gem::gemsCollected < gem::currAmount) {
			canvas.drawString(8, 70, "|||Get " + (gem::currAmount - gem::gemsCollected) + " more gems", STRING::SMALL, STRING::NORMAL);
			canvas.drawString(32, 90, "|||to power up.", STRING::SMALL, STRING::NORMAL);
		} else {
			canvas.drawString(8, 70, "||||Max!", STRING::SMALL, STRING::NORMAL);
		}
	}
	return false;
}