Downloads containing PickupTracker.asc

Downloads
Name Author Game Mode Rating
TSF with JJ2+ Only: Jingle JumbleFeatured Download Primpy Single player 9.3 Download file

File preview

#pragma require "PickupTracker.asc"

namespace PickupTracker {

	enum FoundAllReward {
		Upgrade, Unlock
	};
	
	uint pickupsCollected, pickupUIcolorChange;
	const uint minAmount = 15;
	const uint maxAmount = 20;
	bool foundAllMin = false;
	bool foundAllMax = false;
	
	uint pickupTotal;
	bool restorePickups;
	bool draw = true;
	
	void deleteGemDrops() {
		for (int i = 1; i < jjObjectCount; i++) {
			jjOBJ@ obj = jjObjects[i];
			int playerID = obj.findNearestPlayer(200000);
			jjPLAYER@ player = 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 (obj.creatorID == 0 && obj.state != STATE::FLOATFALL) {
						obj.playerHandling = HANDLING::PARTICLE;
						obj.delete();
					}
				}
			}
		}
	}

	void onFoundAllPickups(jjPLAYER@ player, FoundAllReward foundAllReward) { //onPlayer
		if (pickupsCollected >= minAmount && !foundAllMin) {
			foundAllMin = true;
			switch (foundAllReward)
			{
				case FoundAllReward::Upgrade:
					jjChat("/smhealth " + (jjMaxHealth + 1));
					player.powerup[WEAPON::BLASTER] = true;
					
					if (jjGameTicks > 7) {
						jjSample(player.xPos, player.yPos, SOUND::COMMON_HARP1, 0, 20000);
						jjAlert("||||Your health and weapon power have increased!", false, STRING::MEDIUM);
					}
					break;
				case FoundAllReward::Unlock:
					jjSwitchTrigger(11);
					
					if (jjGameTicks > 7) {
						jjSample(player.xPos, player.yPos, SOUND::COMMON_HARP1, 0, 20000);
						jjAlert("||||You have collected enough gifts to return to Santa!", false, STRING::MEDIUM);
					}
					break;
			}
		}
		if (pickupsCollected >= maxAmount && !foundAllMax)
		{
			foundAllMax = true;
			player.powerup[WEAPON::BLASTER] = true;
			
			if (jjGameTicks > 7) {
				jjSample(player.xPos, player.yPos, SOUND::COMMON_HARP1, 0, 20000);
				jjAlert("|||You found all the gifts!", false, STRING::MEDIUM);
				jjAlert("|||Your blaster has been powered up.", false, STRING::MEDIUM);
				jjAlert("|||Congratulations!", false, STRING::MEDIUM);
			}
		}
	}
	
	void trackPlayerPickups(jjPLAYER@ player) { //onPlayer
		if (pickupUIcolorChange > 0)
			pickupUIcolorChange--;
		if (!restorePickups) {
			pickupTotal = player.gems[GEM::RED];
			if (pickupsCollected != pickupTotal) {
				pickupsCollected = pickupTotal;
				pickupUIcolorChange = 200;
			}
		} else {
			player.gems[GEM::RED] = pickupTotal;
			restorePickups = false;
		}
	}
	
	void restorePlayerPickups() { //onLevelLoad and onLevelReload
		restorePickups = true;
	}
	
	void drawCounter(jjPLAYER@ player, jjCANVAS@ canvas, const string msg) { // onDrawScore
		if (PickupTracker::draw) {
			const uint iconXpos = 25;
			const uint iconYpos = 47;
			string pickupsCollectedString = formatUInt(PickupTracker::pickupsCollected);
			uint slashOffset = 26 + jjGetStringWidth(pickupsCollectedString, STRING::MEDIUM, jjTEXTAPPEARANCE());

			canvas.drawSprite(iconXpos + 2, iconYpos + 2, ANIM::CUSTOM[1], 0, jjGameTicks>>2, 0, SPRITE::SHADOW, 5);
			canvas.drawSprite(iconXpos, iconYpos, ANIM::CUSTOM[1], 0, jjGameTicks>>2, 0, SPRITE::NORMAL, 0);		
			canvas.drawString(iconXpos + 22, iconYpos - 3, ( (PickupTracker::pickupsCollected < PickupTracker::maxAmount) ? (((pickupUIcolorChange / 25) % 2 == 1) ? "||" : "") : "||||") + PickupTracker::pickupsCollected, STRING::MEDIUM, STRING::NORMAL);
			canvas.drawString(iconXpos + slashOffset, iconYpos + 4, ( (PickupTracker::pickupsCollected < PickupTracker::maxAmount) ? "|||/" : "||||/") + PickupTracker::maxAmount, STRING::SMALL, STRING::NORMAL);
		}
	}
}