modules/world: add basic actor system

This commit is contained in:
Kazhnuz 2019-04-01 08:08:54 +02:00
parent 936cdc57f3
commit 02b6cbd87d
2 changed files with 49 additions and 0 deletions

View file

@ -0,0 +1,24 @@
local Actor2D = Object:extend()
function Actor2D:new(world, type, x, h, w, h)
self.world = world
self.x = x or 0
self.y = y or 0
self.w = w or 0
self.h = h or 0
self.type = type or ""
end
function Actor2D:register()
self.world:registerActor(self)
end
function Actor2D:update(dt)
-- here will be update actions
end
function Actor2D:draw()
-- here will be update actions
end
return Actor2D

View file

@ -0,0 +1,25 @@
local BaseWorld = Object:extend()
function BaseWorld:new(scene)
self.scene = scene
self.entities = {}
end
function BaseWorld:registerEntity(entity)
table.insert(self.entities, entity)
end
function BaseWorld:update(dt)
for i,v in ipairs(self.entities) do
v:update(dt)
end
end
function BaseWorld:draw(dt)
for i,v in ipairs(self.entities) do
v:draw(dt)
end
end
return BaseWorld