Downloads containing SleighRide.j2as

Downloads
Name Author Game Mode Rating
JJ2 1.23 vanilla: Miscellaneous stuff Violet CLM Multiple N/A Download file

File preview

array<string> LevelData = {
	"        P      D      P                                         P                                               ",
	"      P        D   P     D          P  P  P                                                                     ",
	"      D   P       P                                  P          P                                               "
};

enum AnimSets { Demon, House, Present, Sleigh, _LAST };

void onLevelLoad() {
	for (uint i = 0; i < AnimSets::_LAST; ++i)
		jjAnimSets[ANIM::CUSTOM[i]].load(i, "SleighRide.j2a");
	SleighFrameID = jjAnimations[jjObjects[0].determineCurAnim(ANIM::BIGROCK, 0, false)];
}
void onLevelBegin() {
	for (int i = 0; i < jjLocalPlayerCount; ++i)
		jjLocalPlayers[i].spriteMode = SPRITE::INVISIBLE;
}
void onPlayerInput(jjPLAYER@ play) {
	play.keyLeft = play.keyRight = play.keyUp = play.keyDown = play.keyJump = play.keyFire = play.keyRun = play.keySelect = false;
}
bool onCheat(string &in cheat) { return cheat != "jjnxt" && cheat != "jjnext"; }

bool onDrawAmmo(jjPLAYER@, jjCANVAS@) { return true; }
bool onDrawScore(jjPLAYER@, jjCANVAS@) { return true; }
bool onDrawLives(jjPLAYER@, jjCANVAS@) { return true; }
bool onDrawHealth(jjPLAYER@, jjCANVAS@ canvas) { return true; }

const float PlayerXPos = 100;
const float PlayerYPos = 240;
const float RowHeight = 160;
const int BeatYPos = PlayerYPos + 35;

uint SleighFrameID;

bool PresentDroppingMode = false;
const uint LevelDataIndexOffset = 3;
uint LevelDataIndex = LevelDataIndexOffset;
int Presents = 0;
uint Combo = 0;

uint BungledInput = 0;
uint TimeToStopCheckingForInputs = 70;
uint TimeToCheckSuccess = TimeToStopCheckingForInputs / 2;
uint InputWiggleRoom = 10;
uint Counter = 0;
bool KeyUpWasPressed = false, KeyDownWasPressed = false;
bool MoveUp = false, MoveDown = false, MoveUpNext = false, MoveDownNext = false;

const float FlyingObjectSpeedMultiplier = 3;
float FlyingObjectSpeed = TimeToStopCheckingForInputs * FlyingObjectSpeedMultiplier;

void onMain() {
	const bool keyUp = jjKey[0x26], keyDown = jjKey[0x28];
	const bool keyUpNewlyPressed = keyUp && !KeyUpWasPressed;
	const bool keyDownNewlyPressed = keyDown && !KeyDownWasPressed;
	KeyUpWasPressed = keyUp;
	KeyDownWasPressed = keyDown;
	
	++Counter;
	if (Counter == TimeToStopCheckingForInputs - 5)
		jjSamplePriority(SOUND::COMMON_BELL_FIRE2);
	if (Counter == TimeToStopCheckingForInputs) {
		Counter = 0;
		MoveUp = MoveUpNext;
		MoveDown = MoveDownNext;
		MoveUpNext = MoveDownNext = false;
		if (BungledInput != 0)
			--BungledInput;
		LevelDataIndex += 1;
	} else if (BungledInput < 2 && Counter >= TimeToStopCheckingForInputs - InputWiggleRoom) {
		if (keyUpNewlyPressed)
			MoveUpNext = true;
		if (keyDownNewlyPressed)
			MoveDownNext = true;
	} else {
		if (BungledInput < 1 && Counter < InputWiggleRoom) {
			if (keyUpNewlyPressed)
				MoveUp = true;
			if (keyDownNewlyPressed)
				MoveDown = true;
		} else if (Counter == InputWiggleRoom) {
			if (BungledInput != 0)
				--BungledInput;
		} else {
			if (BungledInput == 0 && (keyUpNewlyPressed || keyDownNewlyPressed)) {
				BungledInput = 2;
				jjSamplePriority(SOUND::COMMON_HORN1);
			}
			if (Counter == TimeToCheckSuccess)
				for (uint y = 0; y < LevelData.length; ++y)
					switch (LevelData[y][LevelDataIndex]) {
						case 0x50: //P
							if (
								(MoveUp && y == 0) ||
								(MoveDown && y == 2) ||
								(!MoveDown && y == 1)
							) {
								jjSamplePriority(SOUND::COMMON_PICKUP1);
								Presents += 1;
								Combo += 1;
								LevelData[y][LevelDataIndex] = "E"[0];
							} else {
								jjSamplePriority(SOUND::COMMON_HORN1);
								Combo = 0;
							}
							break;
						case 0x44: //D
							if (
								(MoveUp && y == 0) ||
								(MoveDown && y == 2) ||
								(!MoveDown && y == 1)
							) {
								jjSamplePriority(SOUND::JAZZSOUNDS_HEY1);
								if ((Presents -= 5) < 0) Presents = 0;
								Combo = 0;
							}
							break;
					}
		}
	}
	
	const float beatXPos = PlayerXPos + int(TimeToCheckSuccess * FlyingObjectSpeedMultiplier);
	const uint8 markerColor = (BungledInput == 0) ?
		(
			(
				((MoveUp||MoveDown) && Counter < InputWiggleRoom) ||
				((MoveUpNext || MoveDownNext) && Counter >= TimeToStopCheckingForInputs - InputWiggleRoom)
			) ?
				17 :
				40
		) :
		24;
	jjDrawRectangle(beatXPos, 0, 8, jjResolutionHeight,markerColor);
	//jjDrawRectangle(beatXPos + FlyingObjectSpeed, 0, 6, jjResolutionHeight, markerColor,SPRITE::TRANSLUCENT);
	const int FarRight = jjResolutionWidth;
	for (int beatX = int(beatXPos) - int(TimeToStopCheckingForInputs) * 5 - int(Counter); beatX <= FarRight; beatX += int(TimeToStopCheckingForInputs))
		jjDrawRectangle(beatX, BeatYPos, 6, 20, 34, SPRITE::TRANSLUCENT);
	
	const int yAdjust = int(jjSin(uint(Counter / float(TimeToStopCheckingForInputs) * 512)) * RowHeight);
	int playerPlayerY = PlayerYPos;
	int playerSleighY = PlayerYPos + 57;
	if (MoveUp)
		playerPlayerY -= yAdjust;
	if (MoveDown) {
		if (!MoveUp)
			playerPlayerY += yAdjust;
		playerSleighY += yAdjust;
	}
	jjDrawSpriteFromCurFrame(PlayerXPos, playerSleighY, SleighFrameID);
	jjDrawSprite(PlayerXPos, playerPlayerY, jjLocalPlayers[0].setID, !MoveUp ? RABBIT::STAND : Counter <= TimeToCheckSuccess ? RABBIT::JUMPING3 : RABBIT::FALL, jjGameTicks>>3, 1, SPRITE::PLAYER, jjLocalPlayers[0].playerID);
	
	for (uint y = 0; y < LevelData.length; ++y) {
		const int objectY = int(PlayerYPos + (int(y) - 1) * RowHeight);
		int index = LevelDataIndex - LevelDataIndexOffset;
		for (float objectX = PlayerXPos + (TimeToCheckSuccess - int(Counter)) * FlyingObjectSpeedMultiplier - LevelDataIndexOffset * FlyingObjectSpeed; objectX <= FarRight; objectX += FlyingObjectSpeed, ++index) {
			switch (LevelData[y][index]) {
				case 0x50: //P
					jjDrawSprite(objectX, objectY, ANIM::CUSTOM[AnimSets::Present],0,0);
					break;
				case 0x44: //D
					jjDrawSprite(objectX, objectY, ANIM::CUSTOM[AnimSets::Demon],0,jjGameTicks>>3);
					break;
				case 0x45: //E
					jjDrawSpriteFromCurFrame(objectX, objectY, jjAnimations[jjObjectPresets[OBJECT::GENERATOR].curAnim] + int(PlayerXPos - objectX) / 16);
					break;
			}
		}
	}
}