Downloads containing ShowgemsV.mut

Downloads
Name Author Game Mode Rating
JJ2+ Only: Show Player Gems VFeatured Download Violet CLM Mutator 8.5 Download file

File preview

#pragma name "Show Player Gems V"
#pragma require "ShowgemsV.png"
#pragma description "Shows how many gems all opponents have, even when they are offscreen, so you know whom to target. Intended for Treasure Hunt and Head Hunters. Play with Anti-Radar disabled."

uint labelFrameID;
void onLevelLoad() {
	if (jjAnimSets[ANIM::PLUS_BETA] == 0)
		jjAnimSets[ANIM::PLUS_BETA].load();
	
	uint setID;
	jjANIMFRAME@ frame;
	for (uint customAnimSetID = 0; customAnimSetID < 256; ++customAnimSetID)
		if (jjAnimSets[setID = ANIM::CUSTOM[customAnimSetID]] == 0) {
			@frame = jjAnimFrames[labelFrameID = jjAnimations[jjAnimSets[setID].load(jjPIXELMAP("ShowgemsV.png"), 85,42)]];
			break;
		}
	frame.hotSpotX = -22;
	frame.hotSpotY = -22;
	@frame = jjAnimFrames[labelFrameID + 1];
	frame.hotSpotX = -20;
	frame.hotSpotY = -20;
}

uint8 getAlphaMapColor(const jjPLAYER& play, const int gems) {
	if (jjGameMode == GAME::CTF) {
		switch (play.team) {
			case TEAM::BLUE:
				return 35;
			case TEAM::RED:
				return 52;
			case TEAM::GREEN: //forward-compatible in case head hunters ever supports extra teams
				return 18;
			case TEAM::YELLOW:
				return 59;
		}
	}
	if (jjGameMode == GAME::TREASURE && gems >= jjMaxScore)
		return 41; //gold
	return 67; //brown
}

jjTEXTAPPEARANCE app;
bool onDrawGameModeHUD(jjPLAYER@ play, jjCANVAS@ canvas) {
	if (play is null)
		return false;
	const auto rightBorder = jjSubscreenWidth + 50, bottomBorder = jjSubscreenHeight + 50;
	for (uint i = 0; i < 32; ++i) {
		const jjPLAYER@ other = jjPlayers[i];
		if (!other.isInGame)
			continue;
		if (play is other)
			continue;
		
		const int gems = other.gems[GEM::RED] + other.gems[GEM::PURPLE] + other.gems[GEM::GREEN] * 5 + other.gems[GEM::BLUE] * 10;
		if (gems <= 0)
			continue; //don't show anything for players with no gems
		app.spacing = gems < 100 ? 3 : -1;
		
		const int gemX = int(other.xPos - 18 - play.cameraX) + jjBorderWidth, gemY = int(other.yPos - 47 - play.cameraY) + jjBorderHeight;
		int textX, textY;
		if (gemX >= -50 && gemY >= -50 && gemX < rightBorder && gemY < bottomBorder) { //onscreen
			canvas.drawSprite(gemX,gemY, ANIM::PLUS_BETA, 1, jjGameTicks >> 3, 1, SPRITE::GEM, jjGameMode != GAME::CTF? 0:(other.team == TEAM::BLUE? 2:0));
			canvas.drawSpriteFromCurFrame(gemX,gemY, labelFrameID, 1, SPRITE::ALPHAMAP, getAlphaMapColor(other, gems));
			app.align = STRING::RIGHT;
			textX = gemX + 49;
			textY = gemY - 6;
		} else {
			if (jjGameMode == GAME::CTF && other.team == play.team)
				continue;
			//https://stackoverflow.com/questions/32030488/get-the-coordinates-at-the-edge-of-the-screen-from-a-given-angle
			const int centerX = jjSubscreenWidth / 2, centerY = jjSubscreenHeight / 2;
			const int reducedWidth = centerX - 40, reducedHeight = centerY - 40;
			const auto xDiff = other.xPos - (centerX + jjBorderWidth + play.cameraX), yDiff = other.yPos - (centerY + jjBorderHeight + play.cameraY);
			const auto angle = atan2(yDiff, xDiff);
			float xEnd = cos(angle) * 1000, yEnd = sin(angle) * 1000; //as measured from 0,0
			float xFactor = reducedWidth / xEnd;
			if (xEnd < -reducedWidth)
				xFactor = -xFactor;
			else if (xEnd <= reducedWidth)
				xFactor = 1;
			xEnd *= xFactor;
			yEnd *= xFactor;
			float yFactor = reducedHeight / yEnd;
			if (yEnd < -reducedHeight)
				yFactor = -yFactor;
			else if (yEnd <= reducedHeight)
				yFactor = 1;
			xEnd *= yFactor;
			yEnd *= yFactor;
			xEnd += centerX;
			yEnd += centerY;
			canvas.drawRotatedSpriteFromCurFrame(int(xEnd),int(yEnd), labelFrameID + 1, int(angle * -512.0 * 0.318309886142228), 1,1, SPRITE::ALPHAMAP, getAlphaMapColor(other, gems));
			app.align = STRING::CENTER;
			textX = int(xEnd);
			textY = int(yEnd - 2);
		}
		canvas.drawString(textX,textY, "" + gems, STRING::MEDIUM, app, spriteMode:SPRITE::BLEND_LIGHTEN, param2:255);
	}
	return false;
}