Downloads containing HH24_Intro.j2as

Downloads
Name Author Game Mode Rating
TSF with JJ2+ Only: Holiday Hare 24Featured Download PurpleJazz Single player 10 Download file

File preview

const bool MLLESetupSuccessful = MLLE::Setup(); ///@MLLE-Generated
#include "MLLE-Include-1.7.asc" ///@MLLE-Generated
#pragma require "xmasfeawloonedit.j2t" ///@MLLE-Generated
#pragma require "HH24_Intro.j2l" ///@MLLE-Generated
#include "HH24.asc"

auto defaultTextAppearance = jjTEXTAPPEARANCE();
auto selectedAppearance = jjTEXTAPPEARANCE();
int hhTextColorOffset = 0;

array<bool> keyStates = array<bool>(256);

// [[ 0 = START, 1 = GEM UPGRADES TOGGLE ]]
int selection = 0;
int maxSelection = 1;

// key states
bool prevKeyDown   = false;
bool prevKeyUp     = false;
bool prevKeyFire   = false;
bool prevKeySelect = false;
bool pressEnterOnce = false;

void onLevelBegin() {
	selectedAppearance.pipe    = STRING::SPECIALSIGN;
    // thanks jjTEXTAPPEARANCE::newline for not working
    selectedAppearance.newline = STRING::SPECIALSIGN;
    selectedAppearance.xAmp = 0;
    selectedAppearance.yAmp = 1;
    
    HH24::gem::draw = false;
	HH24::gem::loadSettings();
}

bool saveSettings() {
    jjSTREAM settings;
    settings.push(HH24::gem::SETTINGS_VERSION);
    settings.push(HH24::gem::healthUpgradesEnabled);
    if(!settings.save("HH24settings.asdat")) {
        jjConsole("Failed to save settings!");
        return false;
    }

    return true;
}

void toggleGemHealthUpgrades() {
    HH24::gem::healthUpgradesEnabled = !HH24::gem::healthUpgradesEnabled;
    playRandomMenuSound();
}

void playRandomMenuSound() {
    // WARNING: bad code ahead (dictionary.get for SOUND::Sample doesn't work, how sad)
    SOUND::Sample randomMenuSound = SOUND::MENUSOUNDS_SELECT0;
    int soundVariation = jjRandom() & 6;
    if (soundVariation == 1)
        randomMenuSound = SOUND::MENUSOUNDS_SELECT1;
    else if (soundVariation == 2)
        randomMenuSound = SOUND::MENUSOUNDS_SELECT2;
    else if (soundVariation == 3)
        randomMenuSound = SOUND::MENUSOUNDS_SELECT3;
    else if (soundVariation == 4)
        randomMenuSound = SOUND::MENUSOUNDS_SELECT4;
    else if (soundVariation == 5)
        randomMenuSound = SOUND::MENUSOUNDS_SELECT5;
    else if (soundVariation == 6)
        randomMenuSound = SOUND::MENUSOUNDS_SELECT6;
    
    jjSamplePriority(randomMenuSound);
}

void onMain() {
    if (jjGameTicks % 35 == 0)
        // We have to increment by 7 to make the text not twitch
        hhTextColorOffset += 7;
}

void onPlayer(jjPLAYER@ player) {
    player.cameraUnfreeze(true);
    player.cameraFreeze(0, 0, false, true);
	player.ballTime = 1;
	player.keyJump = player.keyRun = false;

    array<bool> currentKeyStates(256);
    const array<uint> selectKeys = { 13 };    // Enter key
    const array<uint> moveUpKeys = { 38 };    // Up arrow
    const array<uint> moveDownKeys = { 40 };  // Down arrow
    
    bool select = false;
    bool move = false;
    bool moveDir = false; // false = up, true = down
    
    for (uint i = 0; i < 256; i++) {
        currentKeyStates[i] = jjKey[i];
    
        if (!keyStates[i] && currentKeyStates[i]) {
            if (selectKeys.find(i) >= 0) {
                select = true;
            } else if (moveUpKeys.find(i) >= 0) {
                move = true;
                moveDir = false;
            } else if (moveDownKeys.find(i) >= 0) {
                move = true;
                moveDir = true;
            }
    
            if (select || move) {
                keyStates[i] = jjKey[i];
                break;
            }
        }
    
        keyStates[i] = jjKey[i];
    }    

    // select
    if ((player.keyFire && !prevKeyFire) || (player.keySelect && !prevKeySelect) || (select)) {
        if (player.keyFire && !prevKeyFire)
            prevKeyFire = true;
        else
            prevKeySelect = true;

        if (selection == 0) {
            if (saveSettings()) {
                jjNxt(false, true);
            }
        } else if (selection == 1) {
            toggleGemHealthUpgrades();
        }
    }

    // navigation up and down
    if (player.keyUp && !prevKeyUp || (move && !moveDir)) {
        prevKeyUp = true;
        selection -= 1;
        playRandomMenuSound();
        if (selection < 0)
            selection = maxSelection;
    }
    if (player.keyDown && !prevKeyDown || (move && moveDir)) {
        prevKeyDown = true;
        selection += 1;
        playRandomMenuSound();
        if (selection > maxSelection)
            selection = 0;
    }

    // check if prev state is true and new state is false
    if (!player.keyFire && prevKeyFire)
        prevKeyFire = false;
    if (!player.keySelect && prevKeySelect)
        prevKeySelect = false;
    if (!player.keyUp && prevKeyUp)
        prevKeyUp = false;
    if (!player.keyDown && prevKeyDown)
        prevKeyDown = false;
}

/*
Colors text using | chars, offset adds x amount of pipes to the start of the text
*/
string color(string text, uint offset = 0) {
    string output = "";

    for (uint i = 0; i < offset; i++)
        output += "|";
    for (uint i = 0; i < text.length(); i++)
        output += "|" + (text.substr(i, 1));

    return output;
}

bool onDrawHealth(jjPLAYER@ player, jjCANVAS@ canvas) {
    // level title
    string text = "Holiday Hare";
    
    canvas.drawString(
        int(jjSubscreenWidth * 0.5) - (jjGetStringWidth(text, STRING::LARGE, selectedAppearance)/2),
        int(jjSubscreenHeight * 0.08),
        color(text, hhTextColorOffset),
        STRING::LARGE,
        selectedAppearance
    );

    text = "24";

    canvas.drawString(
        int(jjSubscreenWidth * 0.5) - (jjGetStringWidth(text, STRING::LARGE, selectedAppearance)/2),
        int(jjSubscreenHeight * 0.15),
        color(text, hhTextColorOffset+text.length()),
        STRING::LARGE,
        selectedAppearance
    );

    text = "Start";

    canvas.drawString(
        int(jjSubscreenWidth * 0.5) - (jjGetStringWidth(text, STRING::MEDIUM, selectedAppearance)/2),
        int(jjSubscreenHeight * 0.3),
        selection == 0 ? color(text) : text,
        STRING::MEDIUM,
        selectedAppearance
    );

    // section title
    /*text = "Optional Settings";
    
    canvas.drawString(
        int(jjSubscreenWidth * 0.5) - (jjGetStringWidth(text, STRING::MEDIUM, defaultTextAppearance)/2),
        int(jjSubscreenHeight * 0.4),
        text,
        STRING::MEDIUM
    );*/

    // option title
    text = "Gems upgrade health";

    canvas.drawString(
        int(int(jjSubscreenWidth * 0.5) - float(jjGetStringWidth(text, STRING::MEDIUM, selectedAppearance))/1.5),
        int(jjSubscreenHeight * 0.48),
        selection == 1 ? color(text) : text,
        STRING::MEDIUM,
        selectedAppearance
    );

    // state
    text = HH24::gem::healthUpgradesEnabled ? "On" : "Off";

    canvas.drawString(
        int(jjSubscreenWidth * (jjResolutionWidth <= 640 ? 0.72 : 0.7)) - (jjGetStringWidth(text, STRING::SMALL, selectedAppearance)/2),
        int(jjSubscreenHeight * 0.5),
        text,
        STRING::SMALL,
        selectedAppearance,
		0,
		SPRITE::PALSHIFT,
		HH24::gem::healthUpgradesEnabled? -48 : -40
    );

    // description
    text = "Collecting a specific number of gems" + (jjResolutionWidth <= 640 ? "" : " will increase your max health.");

    canvas.drawString(
        int(jjSubscreenWidth * 0.5) - (jjGetStringWidth(text, STRING::SMALL, defaultTextAppearance)/2),
        int(jjSubscreenHeight * 0.55),
        text,
        STRING::SMALL
    );

    if (jjResolutionWidth <= 640) {
        text = "will increase your max health.";

        canvas.drawString(
            int(jjSubscreenWidth * 0.5) - (jjGetStringWidth(text, STRING::SMALL, defaultTextAppearance)/2),
            int(jjSubscreenHeight * 0.58),
            text,
            STRING::SMALL
        );
    }

    text = "Disable if you're looking for a more challenging experience.";

    canvas.drawString(
        int(jjSubscreenWidth * 0.5) - (jjGetStringWidth(text, STRING::SMALL, defaultTextAppearance)/2),
        int(jjSubscreenHeight * (jjResolutionWidth <= 640 ? 0.61 : 0.58)),
        text,
        STRING::SMALL
    );
	
	text = "We recommend playing on Easy difficulty if you are new to JJ2.";

    canvas.drawString(
        int(jjSubscreenWidth * 0.5) - (jjGetStringWidth(text, STRING::SMALL, defaultTextAppearance)/2),
        int(jjSubscreenHeight * 0.68),
        text,
        STRING::SMALL
    );
	
	text = "Use the cheat codes jjeasy, jjmedium, jjhard and jjnightmare";
    canvas.drawString(
        int(jjSubscreenWidth * 0.5) - (jjGetStringWidth(text, STRING::SMALL, defaultTextAppearance)/2),
        int(jjSubscreenHeight * 0.78),
        text,
        STRING::SMALL,
		defaultTextAppearance,
		0,
		SPRITE::PALSHIFT,
		232
    );
	
	text = "to change difficulty settings mid-game.";
    canvas.drawString(
        int(jjSubscreenWidth * 0.5) - (jjGetStringWidth(text, STRING::SMALL, defaultTextAppearance)/2),
        int(jjSubscreenHeight * 0.81),
        text,
        STRING::SMALL,
		defaultTextAppearance,
		0,
		SPRITE::PALSHIFT,
		232
    );
	
	text = "(Doing so will restart the current level)";
    canvas.drawString(
        int(jjSubscreenWidth * 0.5) - (jjGetStringWidth(text, STRING::SMALL, defaultTextAppearance)/2),
        int(jjSubscreenHeight * 0.86),
        text,
        STRING::SMALL,
		defaultTextAppearance,
		0,
		SPRITE::PALSHIFT,
		232
    );
	
	text = "Have fun!";
	   canvas.drawString(
        int(jjSubscreenWidth * 0.5) - (jjGetStringWidth(text, STRING::SMALL, defaultTextAppearance)/2),
        int(jjSubscreenHeight * 0.92),
        text,
        STRING::SMALL
    );


    return true;
}

bool onDrawAmmo(jjPLAYER@ player, jjCANVAS@ canvas) { return true; }
bool onDrawPlayerTimer(jjPLAYER@ player, jjCANVAS@ canvas) { return true; }
bool onDrawGameModeHUD(jjPLAYER@ player, jjCANVAS@ canvas) { return true; }
// HH24savegems.asc already overrides onDrawScore and suppresses it!
bool onDrawScore(jjPLAYER@ player, jjCANVAS@ canvas) { return true; }

// why would they name this "onPlayerDraw" and not "onDrawPlayer"
// this angers me >:(
void onPlayerDraw(jjPLAYERDRAW& pd) {
    pd.gunFlash = false;
    pd.invincibility = false;
    pd.name = false;
    pd.sprite = false;
    pd.trail = false;
}

void onLevelReload() {
	MLLE::ReapplyPalette();
}