Level switching logic
This commit is contained in:
parent
efe9f386bd
commit
d4c4c7bfd0
3 changed files with 140 additions and 3 deletions
30
levelhandler.lua
Normal file
30
levelhandler.lua
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
require 'makegrid'
|
||||
|
||||
-- Controls switching between levels
|
||||
---@class LevelHandler
|
||||
---@field levels string[]
|
||||
---@field current integer
|
||||
LevelHandler = {
|
||||
levels = {
|
||||
'test2', 'test'
|
||||
},
|
||||
current = 1,
|
||||
}
|
||||
|
||||
-- Switches level to next or cycles if it was the last level
|
||||
---@return Grid
|
||||
function LevelHandler:next()
|
||||
self.current = self.current + 1
|
||||
if self.current > #self.levels then
|
||||
self.current = 1
|
||||
end
|
||||
local levelPath = string.format('levels/%s', self.levels[self.current])
|
||||
return MakeGrid( require( levelPath ) )
|
||||
end
|
||||
|
||||
-- Returns first level
|
||||
---@return Grid
|
||||
function LevelHandler:first()
|
||||
local levelPath = string.format('levels/%s', self.levels[1])
|
||||
return MakeGrid( require( levelPath ) )
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue