Downloads containing HH18savegems.asc

Downloads
Name Author Game Mode Rating
TSF with JJ2+ Only: Holiday Hare '18Featured Download SmokeNC Single player 8.9 Download file

File preview

#pragma require "HH18savegems.asc"

namespace gem {
	int gemsCollected, nextHealth, currAmount;
	
	int maxHealth() {
		return ((jjMaxHealth+1) - (jjDifficulty < 3? 5:3));
	}
	
	array<int> gemTotals(4);
	bool restoreGems;
	bool draw = true;

	void upgradeHealth(jjPLAYER@ play) { //onPlayer
		switch (maxHealth()) {
			case 1: currAmount = 100; break;
			case 2: currAmount = 275; break;
			case 3: currAmount = 450; break;
			case 4: currAmount = 625; break;
			case 5: currAmount = 800; break;
		}
	
		if (gemsCollected >= currAmount && nextHealth != maxHealth() && maxHealth() < 6) {
			jjChat("/smhealth " + (jjMaxHealth + 1));
			for (int i = 0; i < 8; ++i) {
				jjAlert("");
			}
			nextHealth = jjMaxHealth;
			if (jjGameTicks > 7) {
				jjSample(play.xPos, play.yPos, SOUND::COMMON_HARP1, 0, 0);
				jjAlert("||||By the power of gems, your maximum health is increased!", false, STRING::MEDIUM);
				if (maxHealth() == 6) jjAlert("|||Congratulations, your health is maximised!", 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 onCheat(string &in cheat) {
	if (cheat == "jjnxt" || cheat == "jjnext") {
		gem::saveGemData();
		jjNxt(true, true);
	} else if (cheat == "jjgems") {
		jjLocalPlayers[0].gems[GEM::RED] = jjLocalPlayers[0].gems[GEM::RED] + 100;
	} else
		return false;
	jjAlert(cheat, false, STRING::MEDIUM);
	return true;
}

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::maxHealth() < 6) {
			canvas.drawString(8, 70, "|" + gem::currAmount + " |||||for upgrade", STRING::SMALL, STRING::NORMAL);
		} else {
			canvas.drawString(8, 70, "||||Max!", STRING::SMALL, STRING::NORMAL);
		}
	}
	return false;
}