Jan 222012
 

How to easily created a level lock system using the CoronaSDK and Ego.

This tutorial/sample shows you how to unlock levels, save and load little bits of information and reset this information when necessary.

I’m using Director and a number of different scenes to properly demonstrate how Ego can be used for this purpose so this tutorial is only available as a download, which I apologize for as I know you guys like it when I can post the code on the site as well so you can browse it on your various mobile devices.

Although basic I hope this can help those of you struggling with level locking/unlocking to get past that particular hurdle – I know it is something I struggled with a lot as a new user.

Enjoy!

Download Ego Level Locking Template

Peach Pellen :)

Like this post? Subscribe to the monthly newsletter!

*If you haven’t already checked out the tutorial for saving highscores in your Corona app with Ego, you can find it here.

  25 Responses to “Easy Level Unlocking With Ego”

    • Hey Mark – sorry, no – I didn’t write Ice, Graham Ranson did. You’d want to ask him about available docs to assist :)

  1. Hi Peach, do you have this tutorial using ICE? I’ve just implemented ICE in my game, and now would like to implement your level lock / unlock but with ICE.

    The thread I saw regarding something similar to this is here:

  2. Just add the ego lines to main and then take out the saving/loading/setup bits from level files, is what I would suggest.

    Although really this was (unfortunately?) written with only Director in mind.

  3. Hi, lets say I have written a game with 6 levels and now I wanted to add your level locking. Should I combine the 2 main.lua files as well as all the level files? Also I wrote mine in storyboard which may prove a bit more confusing if I try to combine director and storyboard on the same game.
    tnx

  4. Have a file that you save the current level into – as in at the start of a level do;

    saveFile(“currentLevel”, nameOfLevelFile)

    Then on main menu load it;

    currentLevel = loadFile(“currentLevel”)

    Then on continue button, have function with;

    director:changeScene(currentLevel)

    That should do it :)

  5. Ok peach here it is

    I have retry working (just delay 500, reloads level# again)
    I have main menu working (same thing)
    I have level selection working (a button)

    However, if I exit game and I don’t want to go to level selection, pick a level etc I want to have a button on the main menu (using director 1.4)

    Basically the flow is right now

    loadmainmenu > mainmenu> (Hit play button)>level selection

    vs

    loadmainmenu> mainmenu > (hit continue)

    so basically, if I exit out and come back later, I just hit continue and loads the level vs selecting it. Ya, that was more wordier than I wanted, but I think you get it now :)

    ng

  6. I’ll get to it one of these days, honestly. (I’m setting up another site so it will be my next project after that, all being well.)

    RE the continue, is this at the end of a level, going to next level, or on the home screen going to the high level they’ve unlocked?

  7. Ok, I understand this completely and using it in my game. All my levels unlock, I have last level going to an end game screen with credits (which you are in there btw) etc.

    What I am trying to figure out is how to put a continue function in my main menu, so a player can just hit continue and skip the level selection process.

    I’ve tried a few things, but it seems to elude me :)

    +1 on coins unlock thing

    ng

  8. Certainly it is – in the code you pasted above you say;

    1
    for i = 1, 20

    So if you wanted to do 5, you’d do;

    1
    for i = 1, 5

    Then you could do it again for other rows, either within the same loop or using;

    1
    for i = 6, 10

    Etc. :)

  9. Hi Peach,

    thank you very much for your help :) I have one last question I hope you can help me with :) If I in the code write, I want 20 levels, all the images is in one long row, but is it possible to do something so after 5 (Level) images, I want it to shift line, then 5 Images again – shift line and so on? :) I hope you understand what I try to explain :)

  10. Hi Peach,
    thank you very much for the tutorial, this really helped! But I have a quick question, I hope you can help me with. In my game I have 20 levels and 20 Images with numbers 1-20 and I want these 20 images to be shown like the circles, but if use the following code: I get 20 images of the same, I want the images to be from 1-20 and not 20 level 1 “images/buttons”, how can I accomplish this? :) I hope you understand what I mean. Thank you :=)

    local function setupLevels()
    for i = 1, 20 do
    if tonumber(currentLevel) >= i then
    level[i] = display.newImage(“Level1Image.png”, startX*i, 50, 20 )
    — level[i]:setFillColor(220, 220, 120)
    localGroup:insert( level[i] )
    level[i].scene = “level”..i..”"
    level[i]:addEventListener(“tap”, goLevel)
    elseif tonumber(currentLevel) < i then
    level[i] = display.newImage("LevelLock.png", startX*i, 50, 20 )
    — level[i]:setFillColor(255, 255, 255)
    localGroup:insert( level[i] )
    end
    end
    end
    setupLevels()

    • If all called level1image, level2image, etc then do this -

      level[i] = display.newImage(“Level”..i..”Image.png”, startX*i, 50, 20 )

      That should do it :)

  11. Basic code will remain the same :)

  12. ack. I use storyboard, but I am going to check it out.

  13. Hey, firstly, sorry Philip – I misread that. Yes, you could have different spritesheets for different characters. (To change the color or whatnot.)

    RE coins, yes, maybe that would be a good tutorial – I have actually made an app like this before, so perhaps I could write that tutorial soon :)

    Thanks for the kind words Peter – I do my best ;)

  14. Peach the great! That’s what we should know you as! You’ve helped me so much that without you my quest to make something happen would have been long abandoned. I second Philip’s request. It would be killer to have a similar unlocking setup that would allow you unlock a level on a number of collected “coins”. I’m trying to work on it myself, but as usual… i don’t mind a “push” or in my case a “shove” in the right direction. I tend to confuse myself at times with all the greatness :P

  15. Hi peach, i really love your tutorials and they have helpt me alot. But are there any ways for adding “ingame coins”. So the player will have to collect money to unlock cool features.
    Are there anyways to to that?

    I also want a option to change the color of the character (change spiritesheet) with a single button klick. Is it possible?

    Best regards Philip

    PS sorry for my bad English :P

    • Philip, hello! I have seen your Skype messages just now but haven’t yet had a chance to reply. You could do that with a sprite sheet for different colored coins, yes. Can you make a detailed post in the Corona forum about what you want and let me know the link? I can advise you better there :)

  16. Sorry for any hassles, I haven’t had any here but if you still can’t download it let me know, I’ll email it to you. (I did just check the button and it was working here, though.) :)

  17. I had to do it twice for some reason… but if you do it “fast enough” you won’t tweet the same thing again, and then you’ll be presented with a download button for the files.

  18. For some reason, I could not download mine and now when I click on Tweet and Get it, I get an error. Any idea?

  19. Thank you; jstrahan gave me the idea of using Tweet & Get It, I love it so far :)

  20. Great tutorial Peach! The new Tweet & Get It is the way to go! Thanks!

  21. [...] to learn how to lock/unlock levels using Ego? See here. Tweet  Posted by Peach Pellen at 3:11 pm  Tagged with: Highscores, Loading, [...]

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.