

Code: Select all
return{
states={},
focus={},
action={switch=false, push=false, pop=false, newid=0},
init=function(self, start_state)
--gets all the game states from the game states directory
for i,v in ipairs(love.filesystem.getDirectoryItems("scenes")) do
if string.find(v, ".lua") then
self.states[string.gsub(v, ".lua", "")]=require("scenes." .. string.gsub(v, ".lua", ""))
end
end
if start_state then
self:push(start_state)
end
end,
push=function(self, state)
self.states[state]:init()
self.focus[#self.focus+1]=state
end,
pop=function(self)
local cfocus=self:currentFocus()
if #self.focus>1 then
if(self.states[cfocus].close~=nil) then
self.states[cfocus]:close()
end
self.focus[#self.focus]=nil
end
end,
switch=function(self, state)
for i,v in ipairs(self.focus) do
self.focus[i]=nil
end
self.focus={}
self:push(state)
end,
currentFocus=function(self)
return self.focus[#self.focus]
end,
update=function(self, dt)
self.states[self:currentFocus()]:update(dt)
end,
draw=function(self)
for i,v in pairs(self.focus) do
self.states[v]:draw()
end
end,
}
Code: Select all
Scenes=require "scenes"
function love.load(args)
Scenes:init("start") --or whatever your first state is called. This is the same name as the .lua file.
end
function love.update(dt)
Scenes:update(dt)
end
function love.draw()
Scenes:draw()
end
Code: Select all
return {
init=function()
end,
update=function(dt)
end,
draw=function()
end,
}
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 5 guests