Hey guys,
After helping Piece & Para out by adding Sunpossible to Cultured, I thought I'd share the information in case anyone else felt like they wanted to add it to their game. This tutorial assumes you're using the Yuuutu engine, but the concept is easily extendable once you know what you're doing.
Oh, and for you plebs that don't know what Sunpossible mode is... it's a mode inspired by IWBTChuratch; you get a set amount of lives and that's it - every move you make counts.
Sunpossible Functionality ScriptsI've provided some scripts below; just make some new scripts in Game Maker, name them the bold names, and copy-pasta the code into the script. These make it easy to access the various values associated with Sunpossible mode, so you don't have to worry about the underlying code when you're designing your game.
sunAskForLivesglobal.lifeCount = min(floor(abs(real(string_digits(get_string("How many lives?","50"))))),1000000);
The first thing you might be saying is "WTF why so many parentheses dude" and to that I say... blame Paragus for breaking my code
When you call this function, It will prompt the player with an input box, asking them how many lives they want to play with. The reason there's so many extra functions in there is to make sure you get a nice number out of it, even if the player enters "-3.14159KappaFace" It takes all the digits out of the string the player entered (string_digits), makes it a number (real), makes it positive (abs), drops the fractional part (floor) and makes sure it's less than one million (min) - so if the player entered "-3.14159KappaFace" they would get 314159 lives.
Call this function whenever you want to ask the player how many lives they want - I recommend the warpStart's Player Collision event, but anywhere else that makes logical sense works too.
sunIsSunpossibleModereturn global.lifeCount > 0
This function is just a simple way for you to see if it's sunpossible mode or not - If you never set global.lifeCount, it'll be zero, and we consider that not sunpossible mode.
sunGetRemainingLivesreturn global.lifeCount - global.death[global.savenum]
This one's pretty simple too; call it to get the number of lives remaining.
sunSaveLivesvar tem;
tem = global.lifeCount;
file_bin_write_byte(argument0,floor(tem/10000));
tem -= floor(tem/10000)*10000;
file_bin_write_byte(argument0,floor(tem/100));
tem -= floor(tem/100)*100;
file_bin_write_byte(argument0,tem);
This is a copy of the code from saveGame that saves the player's position. This allows you to save values greater than 255; you can save up to 1,000,000 in fact
sunLoadLivesglobal.lifeCount = file_bin_read_byte(argument0)*10000;
global.lifeCount += file_bin_read_byte(argument0)*100;
global.lifeCount += file_bin_read_byte(argument0);
This is the reverse of the script above - it rebuilds the life count from the file in the opposite way that we encoded it.
Hooking Sunpossible Mode Into the EngineNow that you've got your supporting scripts, let's hook them into the engine:
In the
saveGame script, right before the call to
file_bin_close, add this code:
sunSaveLives(f);
And that's all you have to do to save your life count to your save file!
In the
saveExe script, right before the call to
file_bin_close, add this code:
sunLoadLives(f);
And again, your life count has been loaded from the save file!
MAKE SURE you save & load all the values in the same order - Game Maker doesn't know what each value in the file is, it relies on you to load them in the same order you saved them.
In the
saveExe script, at the
very end, add this code:
if (sunIsSunpossibleMode() && (sunGetRemainingLives() <= 0)) {
with (player) instance_destroy();
room_goto(rSunpossibleEnd);
}
This code checks as soon as you load the game (or when you press R after you die) and if it's sunpossible mode and you're out of lives; it sends you to a room to be used as a "permanent game over" room, which I named "rSunpossibleEnd". You could do anything else here, like deleting the save file or whatever, but this is the condition that cheks to see if the player is out of lives
In the
World's "Press R-key" event, add this code:
if (sunIsSunpossibleMode() && room != rSunpossibleEnd && instance_exists(player)) {
global.death[global.savenum] += 1;
saveDeathTime();
}
This code is optional. It forces the player to lose a life if he's still alive when he presses R - perfect for those m9 traps
And that's all you should have to do to implement Sunpossible mode! Let me know if there are any bugs; I just typed this all directly into the post and so it's possible I typoed something