Downloads containing Fio_utils.asc

Downloads
Name Author Game Mode Rating
JJ2+ Only: Find It Out (Single Player)Featured Download Superjazz Single player 8.7 Download file

File preview

#include "Fio_drawing.asc"
#include "Fio_entities.asc"
#include "Fio_globals.asc"
#include "sevk.asc"

/* Common utilities for all levels */
namespace fioUtils {
	
	void blockPlayerMovement(jjPLAYER@ play, bool isInBallState = true) {
		play.keyJump = false;
		play.keyRun = false;
		play.keyDown = false;
		play.keyUp = false;
		play.keyLeft = false;
		play.keyRight = false;
		play.keyFire = false;
		play.noFire = true;
		if (isInBallState) {
			play.ballTime = 2; // Set to 2 in case so there is no accidental effects from the game shifting the value to 0
		}
		// Prevent player from skidding on the ground, requires cameraFreeze to otherwise keep the camera in place
		jjCharacters[play.charCurr].canRun = false;
	}
	
	GameSession@ getCurrentGameSessionByPlayerFood(jjPLAYER@ play) {
		for (uint i = 0; i < gameSessions.length(); ++i) {
			if (play.food == gameSessions[i].id) {
				return gameSessions[i];
			}
		}
		// Return a null game record by default, so that a new one can be initialized
		return null;
	}
	
	Checkpoint@ getLatestReachedCheckpoint(array<Checkpoint@> checkpoints) {
		for (int i = checkpoints.length(); i-- > 0;) {
			if (checkpoints[i].isReached()) {
				return checkpoints[i];
			}
		}
		return null;
	}
	
	ANIM::Set getRabbitAnimSetBasedOnCharOrig(jjPLAYER@ play) {
		switch (play.charOrig) {
			case CHAR::LORI:
				return ANIM::LORI;
			case CHAR::SPAZ:
				return ANIM::SPAZ;
			default:
		}
		return ANIM::JAZZ;
	}
	
	bool isKeyTapped(uint8 keyCode) {
		return !keys[keyCode].isPressed && jjKey[keyCode];
	}
	
	bool isKeyTapped(string keyName) {
		return isKeyTapped(getKeyCodeByName(keyName));
	}
	
	bool isMouseLeftClickedInArea(int x, int y, int width, int height) {
		uint8 keyCode = getKeyCodeByName(KEY_MOUSE_LEFT_CLICK);
		return !keys[keyCode].isPressed && jjKey[keyCode]
				&& jjMouseX >= x && jjMouseX < x + width
				&& jjMouseY >= y && jjMouseY < y + height;
	}
	
	string processText(string text, int rowWidth) {
		string processedText = "";
		int rowIterator = 1;
		for (uint char = 0; char < text.length(); char++) {
			processedText += text.substr(char, 1);
			if (jjGetStringWidth(processedText, STRING::SMALL, STRING::NORMAL)
					>= rowIterator * rowWidth
					&& text.substr(char, 1) == " ") {
				processedText += "@";
				rowIterator++;
			}
		}
		return processedText;
	}
	
	void readGameSessionsFromFile() {
		gameSessions = array<GameSession@>(0);
		jjSTREAM file(GAME_SESSIONS_FILENAME);
		
		if (!file.isEmpty()) {
			uint gameSessionsLength;
			file.pop(gameSessionsLength);
			
			for (uint i = 0; i < gameSessionsLength; ++i) {
				GameSession gameSession;
				file.pop(gameSession.difficulty);
				file.pop(gameSession.food);
				file.pop(gameSession.id);
				file.pop(gameSession.score);
				file.pop(gameSession.hasBonusLevelBeenPlayed);
				file.pop(gameSession.hasPlayerDiedPreviously);
				file.pop(gameSession.isFinished);
				file.pop(gameSession.finishedTime);
				file.pop(gameSession.startedTime);
				file.pop(gameSession.totalTime);
				file.pop(gameSession.cutscenesWatched);
				file.pop(gameSession.deathCount);
				file.pop(gameSession.enemiesSlain);
				file.pop(gameSession.purpleGemsCollected);
				file.pop(gameSession.invincibilities);
				file.pop(gameSession.pocketCarrots);
				
				uint8 charOrig;
				file.pop(charOrig);
				gameSession.charOrig = CHAR::Char(charOrig);
				
				gameSessions.insertLast(gameSession);
			}
		}
	}
	
	void releasePlayer() {
		isPlayerUnableToMove = false;
		isPlayerHiddenAndUnableToMove = false;
		play.ballTime = 0;
		play.noFire = false;
		play.invisibility = false;
		jjCharacters[play.charCurr].canRun = true;
	}
	
	bool writeGameSessionsToFile() {
		jjSTREAM file;
		
		file.push(gameSessions.length());
		
		for (uint i = 0; i < gameSessions.length(); ++i) {
			file.push(gameSessions[i].difficulty);
			file.push(gameSessions[i].food);
			file.push(gameSessions[i].id);
			file.push(gameSessions[i].score);
			file.push(gameSessions[i].hasBonusLevelBeenPlayed);
			file.push(gameSessions[i].hasPlayerDiedPreviously);
			file.push(gameSessions[i].isFinished);
			file.push(gameSessions[i].finishedTime);
			file.push(gameSessions[i].startedTime);
			file.push(gameSessions[i].totalTime);
			file.push(gameSessions[i].cutscenesWatched);
			file.push(gameSessions[i].deathCount);
			file.push(gameSessions[i].enemiesSlain);
			file.push(gameSessions[i].purpleGemsCollected);
			file.push(gameSessions[i].invincibilities);
			file.push(gameSessions[i].pocketCarrots);
			file.push(uint8(gameSessions[i].charOrig));
		}
		
		return file.save(GAME_SESSIONS_FILENAME);
	}
}