That doesn't implement all stateful, but it's more than enough for Game state management, I think. Well done!vrld wrote:(Good stuff)
Well, the idea is that you initially create a (possibly global) variable called game inside love.load:Jack5500 wrote:I don't really get how my game structure (update,load,draw) fits into the game.lua. Those are just functions.
Code: Select all
require 'middleclass'
Stateful = require 'Stateful'
require 'game'
function love.load()
game = Game:new()
game:gotoState("MainMenu")
end
Code: Select all
function love.draw()
game:draw()
end
functino love.update(dt)
game:update(dt)
end
Code: Select all
function MainMenu:startButtonPressed()
self:gotoState('Play')
end
Notice also that the way I pictured here is not the only possible one. You might, for example, need to add more "updates" inside love.update. Or maybe you might not want to use the game inside love.draw. Or maybe you will also want to use it inside love.keypress. It all depends on how you want to structure your game.