Best Way To Structure Multi-Level Game?

Hi,

I’m working on a multi-level game. I’ve got the general ideas sketched out in comments in my main.lua, and I’d like to get some ideas on the best ways to implement things.

Is it best to have every level in a function and simply call the next function when conditions of a while loop prove false? Something like:

function Level1(event)
 while something
 do something
 end
 Level2()
end

function Level2(event)
 while something
 do something
 end
 Level3()
end

or is there a better way to do it?

I’m new to Lua, and am reading the Programming in Lua book (http://www.lua.org/pil/) but I’d also like to be working on the game at the same time.

Any and all suggestions are much appreciated!

Thanks. [import]uid: 20731 topic_id: 5356 reply_id: 305356[/import]

In Corona you don’t want to have a continuous while loop like that, because the screen will freeze until the loop is complete. Instead, use an event listener to listen for enterFrame and call a function every frame.

Then you can have the listener function check the current level in a variable somewhere, and respond appropriately depending on what level you’re on.

That’s still a pretty unwieldy way of organizing multiple levels though; I would suggest check out this framework for how it’s organized:
http://developer.anscamobile.com/code/object-oriented-sample-game-framework [import]uid: 12108 topic_id: 5356 reply_id: 17858[/import]

Thanks! I’m really glad I asked - that example is priceless!

Much appreciated! [import]uid: 20731 topic_id: 5356 reply_id: 17882[/import]

Thanks! I’m really glad I asked - that example is priceless!

Much appreciated! [import]uid: 20731 topic_id: 5356 reply_id: 17883[/import]