Skip to content

Instantly share code, notes, and snippets.

@krzkrzkrz
Created October 7, 2017 18:17
Show Gist options
  • Save krzkrzkrz/6b6a609dfa801188cd4251def0910710 to your computer and use it in GitHub Desktop.
Save krzkrzkrz/6b6a609dfa801188cd4251def0910710 to your computer and use it in GitHub Desktop.
local World = require('world')
local Component = require('component')
local System = require('system')
local coms = require('components/common_components')
local health = require('components/health')
function new_renderer_system()
local renderer = System.new {'body', 'rect'}
function renderer:load(entity)
print 'found one!'
end
function renderer:draw(entity)
local body = entity:get 'body'
love.graphics.rectangle('fill', body.x, body.y, 32, 32)
end
return renderer
end
function new_functional_system()
local system = System.new {'function'}
function system:load(entity)
end
function system:update(dt, entity)
local fn = entity:get('function').fn
fn(entity)
end
return system
end
function love.load()
World:register(new_renderer_system())
World:register(new_functional_system())
World:create()
:madd(coms.new_body(100, 100))
:madd(coms.new_rectangle_component())
World:assemble({
{ coms.new_body, 300, 100 },
{ coms.new_rectangle_component },
})
end
function love.update(dt)
World:update(dt)
end
function love.draw()
World:draw()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment