90 lines
1.7 KiB
Lua
90 lines
1.7 KiB
Lua
-- STATE HANDLER
|
|
local gamePath = love.filesystem.getSourceBaseDirectory() -- Assuming it's always in fused mode.
|
|
-- love TaggedEngine.love --fused
|
|
|
|
local mounted = love.filesystem.mount(gamePath, "") -- Mounting the game directory, should be accessible like if normal.
|
|
|
|
require("modules.loveanimate")
|
|
print("y")
|
|
require("modules.types")
|
|
require("modules.math")
|
|
|
|
---@class StateClass
|
|
local StateClass = {}
|
|
|
|
function StateClass.load()
|
|
end
|
|
function StateClass.draw()
|
|
end
|
|
---@param key love.KeyConstant
|
|
function StateClass.keypressed(key)
|
|
end
|
|
---@param delta number
|
|
function StateClass.update(delta)
|
|
end
|
|
|
|
curChar = "bf"
|
|
|
|
|
|
assert(mounted, "Couldn't mount the game directory.")
|
|
|
|
local curState
|
|
local stateLoaded = false
|
|
|
|
local setState
|
|
|
|
function setState(name, ...)
|
|
if curState then
|
|
curState.quit()
|
|
end
|
|
|
|
curState = require(string.format("states.%s", name))(...)
|
|
|
|
curState.quit = function(accuracy, score)
|
|
curState = nil
|
|
stateLoaded = false
|
|
render.destroyAllSprites()
|
|
setState("freeplaystate")
|
|
end
|
|
|
|
curState.restart = function(...)
|
|
local lastStateName = curState.name
|
|
curState = nil
|
|
stateLoaded = false
|
|
render.destroyAllSprites()
|
|
|
|
setState(lastStateName, ...)
|
|
end
|
|
|
|
curState.changeState = function(...)
|
|
curState = nil
|
|
stateLoaded = false
|
|
render.destroyAllSprites()
|
|
setState(...)
|
|
end
|
|
|
|
curState.load()
|
|
end
|
|
|
|
function love.draw()
|
|
if curState then
|
|
curState.draw()
|
|
end
|
|
end
|
|
|
|
function love.update(dt)
|
|
if curState then
|
|
curState.update(dt)
|
|
end
|
|
end
|
|
|
|
function love.keypressed(...)
|
|
if curState then
|
|
curState.keypressed(...)
|
|
end
|
|
end
|
|
|
|
function love.load()
|
|
setState("menustate")
|
|
end
|