modules/world: add basic actor system
This commit is contained in:
parent
936cdc57f3
commit
02b6cbd87d
2 changed files with 49 additions and 0 deletions
24
gamecore/modules/world/actors/actor2D.lua
Normal file
24
gamecore/modules/world/actors/actor2D.lua
Normal 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
|
25
gamecore/modules/world/baseworld.lua
Normal file
25
gamecore/modules/world/baseworld.lua
Normal 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
|
Loading…
Reference in a new issue