levels, score and other saves

Talk about making games.

levels, score and other saves

Postby Nykos » Tue Jan 04, 2011 10:01 pm

Hi everyone and happy new year, I'm making a block breaker game, I have a lot of work done thanks to some of you.
Almost all graphics are done, and a big part of the code too.But there still are few things that I have problems with.

First, I made a menu, which (whem play button is pressed) opens another .ged where you have all the levels in the form of icons that when pressed open levels .geds. Every level has a different .ged.
What I want is that when you first play the game, only the first level is available, and when you finish that first level, it makes the second one available. Just like many games on Iphone (angry birds, cut the rope, etc...) I know that I have to use savevars and loadvars but I can't figure out how.

Then I'd like to save score from a level and then load and add it in the main level selection .ged

And finaly, another thing I can't figure out, when my ball gets out of vision, it's brought in the middle of the screen and one live is lost, but I'd like it to get just up of the paddle and follow it, just like at the beggining of the level.


If someone could help me, it would be realy nice.

Thanks in advance, Nykos
Nykos
 
Posts: 110
Joined: Sun Dec 19, 2010 11:11 pm
Score: 6 Give a positive score

Re: levels, score and other saves

Postby sonicfire » Fri Jan 07, 2011 6:35 pm

mhh you should globally save a variable for e.g. "levelsDone" and put a 0 for level, 1 for level 2 and so on it.
in your level selection GED you can use loadvars (load levelsDone) and compare the value. From there make it so that only the levels that are done / played are selectable.

is this what you mean?

For example a very simple method to do so(Level selection GED):

Create a global variable called "levelsDone" (integer) and put it into a "levelgroup" savegroup.
Initialize it with value "1".

Then in your level2icon -> create actor:
(I assume level1 is always "playable")
Code: Select all
EventDisable("Event Actor", EVENTMOUSEBUTTONDOWN); // make level 2 unclickable by default
loadVars("level.dat", "levelgroup"); // load value from levelsDone back into the variable
if (levelsDone > 1) // e.g. if it is 2 that means at least level 1 has been completed
{
    EventEnable("Event Actor", EVENTMOUSEBUTTONDOWN); // make level 2 clickable
}


level3icon -> createactor:
Code: Select all
EventDisable("Event Actor", EVENTMOUSEBUTTONDOWN); // make level 3 unclickable by default
loadVars("level.dat", "levelgroup"); // load value from levelsDone back into the variable
if (levelsDone > 2) // e.g. if it is 3 that means level 2 has been completed also
{
    EventEnable("Event Actor", EVENTMOUSEBUTTONDOWN); // make level 3 clickable
}


level4icon -> createactor:
Code: Select all
EventDisable("Event Actor", EVENTMOUSEBUTTONDOWN); // make level 4 unclickable by default
loadVars("level.dat", "levelgroup"); // load value from levelsDone back into the variable
if (levelsDone > 3) // e.g. if it is 4 that means level 3 has been completed also
{
    EventEnable("Event Actor", EVENTMOUSEBUTTONDOWN); // make level 4 clickable
}


...and so on. Of course you could put all this code into one single actor and change the levelicon-actors accordingly.
This here is just for the ease of understanding.

Of course when you play / FINISH! your levels, e.g. when you finish level 2 you have to create the globals levelsDone variable again and store a "2" into it, e.g.:
Code: Select all
levelsDone = 2;
saveVars("level.dat", "levelgroup"); // save var levelsDone with value of 2 into level.dat


Not sure if i made mistakes but it should work this way somehow :-)
Hope it helps.
sonicfire
 
Posts: 425
Joined: Wed Nov 01, 2006 9:34 pm
Location: berlin germany
Score: 16 Give a positive score

Re: levels, score and other saves

Postby sonicfire » Fri Jan 07, 2011 6:42 pm

Nykos wrote:Then I'd like to save score from a level and then load and add it in the main level selection .ged


That´s fairly easy.

In your level selection GED, do this:

Create a global integer variable called "playerscore" or "score", i use just "score" now.
Variables -> Add -> Name: score. Integer, Global and use "scoregroup" for the Save Group.

Then i would put an score actor in the view. In its properties, go to "Text" and type in "00000" for example.
In it´s Create Actor event put:
Code: Select all
loadVars("score.dat", "scoregroup"); // loads value from score from disk back into score itself
textNumber = score;


When launching the level selection this actor should display the last score you´ve made.

For saving the score use (where you want / need it):
Code: Select all
saveVars("score.dat", "scoregroup"); //saves value of score variable into score.dat

You might also need to load that score in some of your levels and / or create the global variable again in there, since you´re using seperate GED files.

I hope i didn´t made any mistakes :)
sonicfire
 
Posts: 425
Joined: Wed Nov 01, 2006 9:34 pm
Location: berlin germany
Score: 16 Give a positive score

Re: levels, score and other saves

Postby Nykos » Fri Jan 07, 2011 9:01 pm

Thanks a lot sonicfire.

I appreciate the help, but I managed to do it already. More or less the way you did.
I made a variable called "levelopen" and coded it that way in my level:
view/draw actor/ script:

levelopen = 2;
saveVars("levelopen", "level");

and in the level selection .ged/

loadVars("levelopen", "level");

if (levelopen==2)
(VisibilityState("lebbutton.1", ENABLE));

Is it good? For the moment it works for me.
Nykos
 
Posts: 110
Joined: Sun Dec 19, 2010 11:11 pm
Score: 6 Give a positive score

Re: levels, score and other saves

Postby sonicfire » Fri Jan 07, 2011 9:11 pm

Sounds good and if it works for you - perfect :)
sonicfire
 
Posts: 425
Joined: Wed Nov 01, 2006 9:34 pm
Location: berlin germany
Score: 16 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest