summaryrefslogtreecommitdiff
path: root/world.lua
diff options
context:
space:
mode:
authorcursed22bc <admin@pixeldawn.org>2026-03-01 12:58:57 +0200
committercursed22bc <admin@pixeldawn.org>2026-03-01 12:58:57 +0200
commit937de6cf0402535def99bdd8056ac706afee2c82 (patch)
tree9e7694bdd3a90cc1c9862abd609f9dad612704e5 /world.lua
parentde94226e1b302cee2a006f78f0153aa5fa081f47 (diff)
flexible multisized tiles in tilemap loading
Diffstat (limited to 'world.lua')
-rw-r--r--world.lua36
1 files changed, 18 insertions, 18 deletions
diff --git a/world.lua b/world.lua
index b9ba01f..1c49fd4 100644
--- a/world.lua
+++ b/world.lua
@@ -26,7 +26,7 @@ function World:new()
return self
end
-function World:load(mapPath, tilesetPath)
+function World:load(mapPath, tilesets)
if self.physicsWorld then
self.groundEntities = {}
end
@@ -43,14 +43,15 @@ function World:load(mapPath, tilesetPath)
end
)
- self.tilemap = Tilemap:new(mapPath, tilesetPath)
+ self.tilemap = Tilemap:new(mapPath, tilesets)
self.mapData = self.tilemap:getMapData()
if not self.mapData then
error("World:load - no map data from " .. tostring(mapPath))
end
- local tileWidth = self.tilemap:getTileWidth()
- local tileHeight = self.tilemap:getTileHeight()
+ local groundDims = self.tilemap:getLayerTileDimensions("ground")
+ local tileWidth = groundDims.tilewidth
+ local tileHeight = groundDims.tileheight
local groundLayer = self.tilemap:getGroundLayer()
if groundLayer and groundLayer.data then
@@ -205,7 +206,7 @@ function World:getMapData()
return self.mapData
end
-local function drawTileLayer(layer, tileWidth, tileHeight, tilesetImage, tileQuads)
+local function drawTileLayer(layer, mapTileW, mapTileH, tileGidInfo)
if not layer or not layer.visible or not layer.data then return end
local w = layer.width or 0
local data = layer.data
@@ -214,16 +215,17 @@ local function drawTileLayer(layer, tileWidth, tileHeight, tilesetImage, tileQua
local idx = i - 1
local tx = idx % w
local ty = math.floor(idx / w)
- local x = tx * tileWidth
- local y = ty * tileHeight
- if tilesetImage and tileQuads and tileQuads[gid] then
- love.graphics.draw(tilesetImage, tileQuads[gid], x, y)
+ local x = tx * mapTileW
+ local y = ty * mapTileH
+ local info = tileGidInfo and tileGidInfo[gid]
+ if info then
+ love.graphics.draw(info.image, info.quad, x, y)
else
local r = ((gid * 17) % 256) / 255
local g = ((gid * 31 + 50) % 256) / 255
local b = ((gid * 47 + 100) % 256) / 255
love.graphics.setColor(r, g, b, 1)
- love.graphics.rectangle("fill", x, y, tileWidth, tileHeight)
+ love.graphics.rectangle("fill", x, y, mapTileW, mapTileH)
love.graphics.setColor(1, 1, 1, 1)
end
end
@@ -231,14 +233,12 @@ local function drawTileLayer(layer, tileWidth, tileHeight, tilesetImage, tileQua
end
function World:draw()
- local tw = self.tilemap:getTileWidth()
- local th = self.tilemap:getTileHeight()
- local tilesetImage = self.tilemap:getTilesetImage()
- local tileQuads = self.tilemap:getTileQuads()
-
- drawTileLayer(self.tilemap:getBackgroundLayer(), tw, th, tilesetImage, tileQuads)
+ local mapTileW = self.tilemap:getTileWidth()
+ local mapTileH = self.tilemap:getTileHeight()
+ local tileGidInfo = self.tilemap:getTileGidInfo()
- drawTileLayer(self.tilemap:getGroundLayer(), tw, th, tilesetImage, tileQuads)
+ drawTileLayer(self.tilemap:getBackgroundLayer(), mapTileW, mapTileH, tileGidInfo)
+ drawTileLayer(self.tilemap:getGroundLayer(), mapTileW, mapTileH, tileGidInfo)
for _, e in ipairs(self.entities) do
if e.draw then e:draw() else World.drawEntityDefault(e) end
@@ -249,7 +249,7 @@ function World:draw()
World.drawPhysicsBodyOutlines(self.groundEntities)
end
- drawTileLayer(self.tilemap:getForegroundLayer(), tw, th, tilesetImage, tileQuads)
+ drawTileLayer(self.tilemap:getForegroundLayer(), mapTileW, mapTileH, tileGidInfo)
end
function World.drawPhysicsBodyOutlines(entityList)