From 65b0c74a068a83f2d2d7b43ed701633d85cccd7d Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 15 Jun 2019 11:50:53 +0200 Subject: [PATCH] feat(world): add a batchActor function activated by a bool in tiled This way, you can add multiple actors with just one tiled object. It also bring better feature parity with Imperium Porcorum. Fixes #10 --- CHANGELOG.md | 2 + .../gameplay/plateform/assets/platformer.lua | 173 ++++-------------- .../gameplay/plateform/assets/platformer.tmx | 41 +++-- gamecore/modules/world/baseworld.lua | 24 ++- 4 files changed, 87 insertions(+), 153 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9fb98b..3ef90df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **world/camera:** Add support for Head-Up-Display +- **world:** Support batching actor loading + ### Changed - **world:** automatize world integration in a scene diff --git a/examples/gameplay/plateform/assets/platformer.lua b/examples/gameplay/plateform/assets/platformer.lua index d15938d..76dd8cc 100644 --- a/examples/gameplay/plateform/assets/platformer.lua +++ b/examples/gameplay/plateform/assets/platformer.lua @@ -1,7 +1,7 @@ return { version = "1.2", luaversion = "5.1", - tiledversion = "1.2.2", + tiledversion = "1.2.4", orientation = "orthogonal", renderorder = "right-down", width = 150, @@ -9,7 +9,7 @@ return { tilewidth = 16, tileheight = 16, nextlayerid = 6, - nextobjectid = 24, + nextobjectid = 25, backgroundcolor = { 0, 170, 255 }, properties = {}, tilesets = { @@ -271,83 +271,20 @@ return { draworder = "topdown", properties = {}, objects = { - { - id = 9, - name = "", - type = "", - shape = "rectangle", - x = 512, - y = 2160, - width = 16, - height = 16, - rotation = 0, - visible = true, - properties = {} - }, { id = 11, name = "", type = "", shape = "rectangle", - x = 480, + x = 464, y = 2160, - width = 16, + width = 128, height = 16, rotation = 0, visible = true, - properties = {} - }, - { - id = 12, - name = "", - type = "", - shape = "rectangle", - x = 544, - y = 2160, - width = 16, - height = 16, - rotation = 0, - visible = true, - properties = {} - }, - { - id = 13, - name = "", - type = "", - shape = "rectangle", - x = 576, - y = 2160, - width = 16, - height = 16, - rotation = 0, - visible = true, - properties = {} - }, - { - id = 14, - name = "", - type = "", - shape = "rectangle", - x = 368, - y = 2208, - width = 16, - height = 16, - rotation = 0, - visible = true, - properties = {} - }, - { - id = 15, - name = "", - type = "", - shape = "rectangle", - x = 400, - y = 2208, - width = 16, - height = 16, - rotation = 0, - visible = true, - properties = {} + properties = { + ["batchActor"] = true + } }, { id = 16, @@ -356,76 +293,15 @@ return { shape = "rectangle", x = 336, y = 2208, - width = 16, + width = 80, height = 16, rotation = 0, visible = true, - properties = {} - }, - { - id = 17, - name = "", - type = "", - shape = "rectangle", - x = 112, - y = 2224, - width = 16, - height = 16, - rotation = 0, - visible = true, - properties = {} - }, - { - id = 18, - name = "", - type = "", - shape = "rectangle", - x = 144, - y = 2224, - width = 16, - height = 16, - rotation = 0, - visible = true, - properties = {} - }, - { - id = 19, - name = "", - type = "", - shape = "rectangle", - x = 176, - y = 2224, - width = 16, - height = 16, - rotation = 0, - visible = true, - properties = {} - }, - { - id = 20, - name = "", - type = "", - shape = "rectangle", - x = 256, - y = 2272, - width = 16, - height = 16, - rotation = 0, - visible = true, - properties = {} - }, - { - id = 21, - name = "", - type = "", - shape = "rectangle", - x = 256, - y = 2240, - width = 16, - height = 16, - rotation = 0, - visible = true, - properties = {} + properties = { + ["batchActor"] = true, + ["gheight"] = 32, + ["gwidth"] = 32 + } }, { id = 22, @@ -435,10 +311,31 @@ return { x = 256, y = 2208, width = 16, + height = 80, + rotation = 0, + visible = true, + properties = { + ["batchActor"] = true, + ["gheight"] = 32, + ["gwidth"] = 32 + } + }, + { + id = 24, + name = "", + type = "", + shape = "rectangle", + x = 112, + y = 2224, + width = 80, height = 16, rotation = 0, visible = true, - properties = {} + properties = { + ["batchActor"] = true, + ["gheight"] = 32, + ["gwidth"] = 32 + } } } }, diff --git a/examples/gameplay/plateform/assets/platformer.tmx b/examples/gameplay/plateform/assets/platformer.tmx index dd38a86..34cd43a 100644 --- a/examples/gameplay/plateform/assets/platformer.tmx +++ b/examples/gameplay/plateform/assets/platformer.tmx @@ -1,5 +1,5 @@ - + @@ -161,19 +161,32 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/gamecore/modules/world/baseworld.lua b/gamecore/modules/world/baseworld.lua index 274f6d1..c9fc6b1 100644 --- a/gamecore/modules/world/baseworld.lua +++ b/gamecore/modules/world/baseworld.lua @@ -231,13 +231,35 @@ function BaseWorld:loadMapActors() if self:isActorIndexed(objectlayer.name) then print("DEBUG: loading actors in " .. objectlayer.name .. " actor layer") for k, object in pairs(objectlayer.objects) do - self:newActor(objectlayer.name, object.x, object.y) + if (object.properties.batchActor) then + self:batchActor(objectlayer.name, object) + else + self:newActor(objectlayer.name, object.x, object.y) + end end self.map:removeLayer(objectlayer.name) end end end +function BaseWorld:batchActor(name, object) + local gwidth = object.properties.gwidth or self.map.tilewidth + local gheight = object.properties.gheight or self.map.tileheight + local x = object.x + local y = object.y + local w = object.width + local h = object.height + + local cellHor = math.ceil(w / gwidth) + local cellVert = math.ceil(h / gheight) + + for i=1, cellHor do + for j=1, cellVert do + self:newActor(name, x + (i-1)*gwidth, y + (j-1)*gheight) + end + end +end + function BaseWorld:loadMapPlayers() for k, objectlayer in pairs(self.map.layers) do if (objectlayer.name == "player") then