EndeyshentLabs / Theatre

Easy to use minimalistic state switcher library for LOVE2D where every state is represented by a file.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Theatre

Easy to use minimalistic state switcher library for LOVE2D where every state is represented by a file.

Usage

  1. Get the theatre.lua file
  2. Create a directory for states
-- main.lua
Theatre = require("theatre")
OldPrint = print

function love.load()
    Theatre:setupLogger(OldPrint)

    -- states/   - dir for states
    -- mainmenu  - first state (will be states/mainmenu.lua)
    Theatre:new("states", "mainmenu")
end

function love.update(dt)
    Theatre:update(dt)
end

function love.draw()
    Theatre:draw()
end

-- LOVE2D Callback. See bottom of `theatre.lua` for a list
function love.keypressed(...)
    Theatre:keypressed(...)
end
-- states/mainmenu.lua
local M = {}

function M.draw()
    love.graphics.print("Main Menu", 100, 100)
end

function M.keypressed(k, sc)
    if sc == "space" then
        Theatre:switch("game")
    end
end
-- states/game.lua
local M = {}

function M.draw()
    love.graphics.print("epik gameplay", 100, 100)
end

function M.keypressed(k, sc)
    if sc == "p" then
        Theatre:switch("mainmenu")
    end
end

Documentation

TBD. (you can read the code for now)

About

Easy to use minimalistic state switcher library for LOVE2D where every state is represented by a file.

License:BSD 2-Clause "Simplified" License


Languages

Language:Lua 100.0%