Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/JosephShering/adorbs
LÖVE (love2d) entity framework
https://github.com/JosephShering/adorbs
Last synced: about 1 month ago
JSON representation
LÖVE (love2d) entity framework
- Host: GitHub
- URL: https://github.com/JosephShering/adorbs
- Owner: JosephShering
- Created: 2016-11-23T19:48:36.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2020-02-25T23:06:14.000Z (almost 5 years ago)
- Last Synced: 2024-08-02T06:17:11.590Z (4 months ago)
- Language: Lua
- Size: 18.6 KB
- Stars: 30
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
- awesome-love2d - adorbs - Minimal, Functional Entity Component System. (Entity)
README
# (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.
```lua
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
)
endfunction 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
```lua
-- newTransform.lua
return function(x, y, scale, rotation)
return { x = x, y = y, scale = scale, rotation = rotation}
end
```##### Entity
```lua
return function(spriteSheetLoc, x, y, speed)
entity.create('player', {
characterController = newCharacterController(speed),
transform = newTransform(x, y)
})
end
```##### System
```lua
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
endcurrentAnimation: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.
```lua
-- overworld.lualocal 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)
endfunction scene:draw(dt)
engine.process()
endreturn scene
```