I Wanna Community

Tutorial: Adding a Sunpossible Mode to Your Game!

0 Members and 1 Guest are viewing this topic.

Offline klazen108

  • 286
  • your a kid now your a squid now
  • OS:
  • Windows 8.1/Server 2013 Windows 8.1/Server 2013
  • Browser:
  • Firefox 28.0 Firefox 28.0
    • Delicious-Fruit
  • Playstyle: Keyboard
Tutorial: Adding a Sunpossible Mode to Your Game!
« on: April 12, 2014, 11:28:56 AM »
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 Scripts

I'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.

sunAskForLives
Code: [Select]
global.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 :Kappa:
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.

sunIsSunpossibleMode
Code: [Select]
return global.lifeCount > 0This 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.

sunGetRemainingLives
Code: [Select]
return global.lifeCount - global.death[global.savenum]This one's pretty simple too; call it to get the number of lives remaining.

sunSaveLives
Code: [Select]
var 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 ;)

sunLoadLives
Code: [Select]
global.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 Engine

Now 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:
Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
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 :Kappa:



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 :Kappa:

Offline lemonxreaper

  • 226
  • Do you even needle?
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Firefox 28.0 Firefox 28.0
Re: Tutorial: Adding a Sunpossible Mode to Your Game!
« Reply #1 on: April 13, 2014, 01:57:42 PM »
Quote
so if the player entered "-3.14159KappaFace" they would get 314159 lives.

Wouldn't they get 3 since the floor code would drop the rest of the numbers after the decimal point? or am I misinterpreting some of the code, such as real.
Just pretend I have a cool picture like Zero.
Completed Fangames: https://dl.dropboxusercontent.com/u/4678222/Complete%20Fangames.txt

Offline klazen108

  • 286
  • your a kid now your a squid now
  • OS:
  • Windows 8.1/Server 2013 Windows 8.1/Server 2013
  • Browser:
  • Firefox 28.0 Firefox 28.0
    • Delicious-Fruit
  • Playstyle: Keyboard
Re: Tutorial: Adding a Sunpossible Mode to Your Game!
« Reply #2 on: April 13, 2014, 02:22:06 PM »
string_digits() will remove everything that's not 0,1,2,3,4,5,6,7,8 or 9; which means the negative sign and the decimal point won't be included. Technically that would make abs() and floor() unnecessary, but I figured why not include them just in case ;)

Offline lemonxreaper

  • 226
  • Do you even needle?
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Firefox 28.0 Firefox 28.0
Re: Tutorial: Adding a Sunpossible Mode to Your Game!
« Reply #3 on: April 13, 2014, 04:53:14 PM »
haha yeah that stuff threw me off :atkHappy:
Never used string_digits before.
Just pretend I have a cool picture like Zero.
Completed Fangames: https://dl.dropboxusercontent.com/u/4678222/Complete%20Fangames.txt

Offline Starz0r

  • Administrator
  • 342
  • Hall Of Fame
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 34.0.1847.116 Chrome 34.0.1847.116
  • Playstyle: Keyboard
Re: Tutorial: Adding a Sunpossible Mode to Your Game!
« Reply #4 on: April 16, 2014, 01:55:53 PM »
Another Nice Tutorial.  :atkHappy:

Stickied! :BloodTrail: