I have been learning Corona for over a month now and was thingking of creating a level based game, somewhat like “Angry Birds”. Where user is showed all levels but can play 2nd level only when he/she clears the first. Just wanted to how like where do I start from and what should be the approach. [import]uid: 183447 topic_id: 32965 reply_id: 332965[/import]
There are a few tutorials on level unlocking in corona that provides some code(google it), but this is pretty easy and using libraries like Ice or some other persistans storage libs this can be done in no time.
Using ice the logic would be sort of like this:
Fetch the last level the player succeded completing.
If this is the first time the user plays you game, you have nothing to fetch, so instead save the value.
This is not working code, just an example! You will need to look up how to save and update values with ice or whatever lib you use.
local lastLevel = ice:getValue("lastLevel")
if lastLevel == nil then
ice:store("lastLevel", 1)
end if
So lets say you have a total of 20 levels, you have a loop that prints out 20 buttons representing each level. Now you can check if the level number is higher then your attribute lastLevel, if so: do not enable the button.
Thats all you need for the level select scene.
Last thing to do is:
When a user finishes a level, save the level number if it is higher then the value already saved:
local lastLevel = ice:getValue("lastLevel")
if lastLevel \< currentLevel then
ice:store("lastLevel", currentLevel)
end
Thats all you really need. Same logic would be used for number of stars etc.
[import]uid: 40356 topic_id: 32965 reply_id: 130916[/import]
It’s really a simple solution. You need a table that represents each level. For my example, I’ll have a 5 level game:
local levelLocked = { false, true, true, true, true }
I now have an array of values, one for each level that can be indexed by level number
local function isLevelLocked(level)
return levelLocked[level]
end
local currentLevel = 3
if isLevelLocked(currentLevel) then
print("Locked!")
else
print("Lets play")
end
Of course you would want to be able to save that lock information between sessions which is where the “ice” package comes in or my super simple table saver: http://omnigeek.robmiracle.com/2012/02/23/need-to-save-your-game-data-in-corona-sdk-check-out-this-little-bit-of-code/
[import]uid: 19626 topic_id: 32965 reply_id: 130922[/import]
There are a few tutorials on level unlocking in corona that provides some code(google it), but this is pretty easy and using libraries like Ice or some other persistans storage libs this can be done in no time.
Using ice the logic would be sort of like this:
Fetch the last level the player succeded completing.
If this is the first time the user plays you game, you have nothing to fetch, so instead save the value.
This is not working code, just an example! You will need to look up how to save and update values with ice or whatever lib you use.
local lastLevel = ice:getValue("lastLevel")
if lastLevel == nil then
ice:store("lastLevel", 1)
end if
So lets say you have a total of 20 levels, you have a loop that prints out 20 buttons representing each level. Now you can check if the level number is higher then your attribute lastLevel, if so: do not enable the button.
Thats all you need for the level select scene.
Last thing to do is:
When a user finishes a level, save the level number if it is higher then the value already saved:
local lastLevel = ice:getValue("lastLevel")
if lastLevel \< currentLevel then
ice:store("lastLevel", currentLevel)
end
Thats all you really need. Same logic would be used for number of stars etc.
[import]uid: 40356 topic_id: 32965 reply_id: 130916[/import]
It’s really a simple solution. You need a table that represents each level. For my example, I’ll have a 5 level game:
local levelLocked = { false, true, true, true, true }
I now have an array of values, one for each level that can be indexed by level number
local function isLevelLocked(level)
return levelLocked[level]
end
local currentLevel = 3
if isLevelLocked(currentLevel) then
print("Locked!")
else
print("Lets play")
end
Of course you would want to be able to save that lock information between sessions which is where the “ice” package comes in or my super simple table saver: http://omnigeek.robmiracle.com/2012/02/23/need-to-save-your-game-data-in-corona-sdk-check-out-this-little-bit-of-code/
[import]uid: 19626 topic_id: 32965 reply_id: 130922[/import]
Just to throw one more out there, shows full sample; http://corona.techority.com/2012/01/22/easy-level-unlocking-with-ego/
Peach
[import]uid: 52491 topic_id: 32965 reply_id: 130985[/import]
Just to throw one more out there, shows full sample; http://corona.techority.com/2012/01/22/easy-level-unlocking-with-ego/
Peach
[import]uid: 52491 topic_id: 32965 reply_id: 130985[/import]
Thank You Soooooooooo much :))))) [import]uid: 183447 topic_id: 32965 reply_id: 131051[/import]
Thank You Soooooooooo much :))))) [import]uid: 183447 topic_id: 32965 reply_id: 131051[/import]