Home

Awesome

GameState Library for LÖVE

A simple and flexible state management library for LÖVE. It allows easy switching between game states, such as menus, levels, or screens. Handling input and rendering delegation based on the current state.

Features

Installation

  1. Download GameStateManager.lua and place it in your project directory.

  2. Require the GameStateManager in your main game file:

    local GameStateManager = require("GameStateManager")
    

Usage

Defining States

Each state is a Lua table with functions that correspond to LÖVE's callback functions. Here's an example of a simple state:

local menuState = {
    enter = function()
        print("Entering menu state")
    end,
    update = function(dt)
        -- Update menu items
    end,
    draw = function()
        -- Draw menu UI
    end,
    keypressed = function(key, scancode, isrepeat)
        if key == "return" then
            -- Start the game
        end
    end
}

Switching States

To switch the current state, use the setState method:

GameStateManager:setState(menuState)

Integrating with LÖVE

Delegate LÖVE's callback functions to the GameStateManager in your main.lua:

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

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

-- Delegate other callback functions as needed...

API

The GameStateManager automatically delegates the following LÖVE callbacks to the current state if they are defined:

Contributing

Contributions to the GameState library are welcome! Please feel free to submit pull requests or report issues on the GitHub repository.

License

This library is open-sourced and licensed under the MIT license. See the LICENSE file for details.