From 02b6cbd87d829bb35978dc98e5fc7d04fe64e7da Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Mon, 1 Apr 2019 08:08:54 +0200 Subject: [PATCH] modules/world: add basic actor system --- gamecore/modules/world/actors/actor2D.lua | 24 ++++++++++++++++++++++ gamecore/modules/world/baseworld.lua | 25 +++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 gamecore/modules/world/actors/actor2D.lua create mode 100644 gamecore/modules/world/baseworld.lua diff --git a/gamecore/modules/world/actors/actor2D.lua b/gamecore/modules/world/actors/actor2D.lua new file mode 100644 index 0000000..2cc8002 --- /dev/null +++ b/gamecore/modules/world/actors/actor2D.lua @@ -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 diff --git a/gamecore/modules/world/baseworld.lua b/gamecore/modules/world/baseworld.lua new file mode 100644 index 0000000..fb02132 --- /dev/null +++ b/gamecore/modules/world/baseworld.lua @@ -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