Downloads containing ArtificialArrow.asc

Downloads
Name Author Game Mode Rating
JJ2+ Only: Threed RealmsFeatured Download Violet CLM Single player 9.7 Download file
JJ2+ Only: Gold Rush Violet CLM Mutator N/A Download file
JJ2+ Only: MultiflagFeatured Download Violet CLM Mutator 9.5 Download file
TSF with JJ2+ Only: Jazz of the JungleFeatured Download Violet CLM Single player 8.9 Download file

File preview

#pragma require "ArtificialArrow.asc"

namespace ArtificialArrow {
	class SortableDistance {
		float distance;
		uint index;
		SortableDistance(){}
		SortableDistance(float d, uint i) { distance = d; index = i; }
		int opCmp(const SortableDistance &in other) const {
			return int(distance - other.distance);
		}
	}

	int ArrowTimer = 0;
	const uint ArrowSprite = jjAnimations[jjAnimSets[ANIM::FLAG]];
	
	void DrawArrow(const array<int> &in targets, const jjPLAYER@ player, SPRITE::Mode spriteMode, uint8 spriteParam, int maxDistance = -1) {
		if (targets.length != 0 && (targets.length & 1) == 0 && player !is null) {
			if (ArrowTimer > jjGameTicks + 70*4)
				ArrowTimer = jjGameTicks;
			else if (ArrowTimer < jjGameTicks) {
				if (ArrowTimer + 64 >= jjGameTicks) {
					const int px = int(player.xPos), py = int(player.yPos);
					array<SortableDistance> distances;
					for (uint i = 0; i < targets.length; i += 2) {
						const float deltaX = abs(px - targets[i]);
						const float deltaY = abs(py - targets[i+1]);
						distances.insertLast(SortableDistance(deltaX * deltaX + deltaY * deltaY, i));
					}
					int target = -1;
					distances.sortAsc();
					if (maxDistance < 0 || distances[0].distance > maxDistance)
						target = distances[0].index;
					if (target >= 0) {
						const int angle = int(atan2(
							py - targets[target+1],
							targets[target] - px
						) * -512.0 * 0.318309886142228);
						const float scale = (112 - (jjSin((jjGameTicks - ArrowTimer) << 3) * -64)) / 128.f;
						jjDrawRotatedSpriteFromCurFrame(
							player.xPos + jjCos(angle) * 32, player.yPos + jjSin(angle) * 32,
							ArrowSprite, 970 - angle, scale, scale, spriteMode,spriteParam, 4, 4, player.playerID
						);
					}
				} else {
					ArrowTimer = jjGameTicks + 70*3;
				}
			}
		}
	}
}