You can use SaveData, onTickEnd and onStart for this:
Every time you beat an area for the first time, remember it in SaveData (in onTickEnd of episode-wide luna.lua):
Code: Select all
-- Initialize if nil
SaveData.beatenLevel = SaveData.beatenLevel or {}
SaveData.numberOfLevelsBeaten = SaveData.numberOfLevelsBeaten or 0
function onTickEnd()
-- Check if the current level is beaten
if Level.winState() > 0 and not SaveData.beatenLevel[Level.filename()] then
SaveData.beatenLevel[Level.filename()] = true
SaveData.numberOfLevelsBeaten = SaveData.numberOfLevelsBeaten + 1
end
end
The level containing the entrance to the new area must then just trigger an event in the level if the conditions are met (level-wide luna.lua):
Code: Select all
function onStart()
if SaveData.numberOfLevelsBeaten == 9 then
triggerEvent("unlockLastArea")
end
end
This will cause the unlockLastArea-Event to be called, where you can show/hide relevant layers.