Skip to content

JosephShering/adorbs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 

Repository files navigation

(Totes) Adorbs

Adorbs is a functional entity framework for LÖVE. The goal was to provide a minimal entity framework sdk with a centralized game state.

Getting Started

Below is an example of a minimal ECS setup in adorbs.

local engine, system, entity, component = require 'adorbs' ()

function love.load()
    entity.create('player', {
        'characterController', -- components are defined inline, and can be empty, as long as they are a string
        transform = { x = 15, y = 0 }
    })

    system.create(
        'systemName',
        {'characterController', 'transform'},
        function(delta, characterController, transform) -- called on each entity that matches components
            print(transform.x) -- should print out 15
        end
    )
end

function love.draw()
    engine.process()
end

If you're looking to move past the pare minimum I generally lay my projects out like so:

folders
 -> components
 -> entities
 -> systems

I populate those folders with my a respective ECS lua module that return a function, here is an example.

Component
-- newTransform.lua
return function(x, y, scale, rotation)
    return { x = x, y = y, scale = scale, rotation = rotation}
end
Entity
return function(spriteSheetLoc, x, y, speed)
    entity.create('player', {
        characterController = newCharacterController(speed),
        transform = newTransform(x, y)
    })
end
System
return function()
    system.create(
        'animator',
        {'animation', 'transform'},
        function(dt, animation, transform)
            local currentAnimation = animation.animations[animation.current]

            if currentAnimation == nil then
                error('You called an animation (' .. animation.current .. ') that does\'nt exist!')
                return
            end

            currentAnimation:update(dt)
            currentAnimation:draw(animation.image, transform.x, transform.y)
        end
    )
end

Then in your main.lua or scene file you just require what you need and they get added to the state automatically.

-- overworld.lua

local scene = {}
require 'systems/map' ()
require 'systems/inputController' ()
require 'systems/animator' ()

function scene:enter()
    require 'entities/map' ('maps/test') --you can make the functions accept arguments
    require 'entities/player' ('assets/animplayers.png', 20, 20, 40) 
end

function scene:draw(dt)
    engine.process()
end

return scene

About

LÖVE (love2d) entity framework

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages