diff options
| author | cursed22bc <admin@pixeldawn.org> | 2026-03-01 11:17:23 +0200 |
|---|---|---|
| committer | cursed22bc <admin@pixeldawn.org> | 2026-03-01 11:17:23 +0200 |
| commit | 8f9182baff36d33c07c5eb8df795e3cfcd5307a5 (patch) | |
| tree | 97d66e64e36f447b950609d5e849e24f2c438731 | |
| parent | 6eacf393b370a7586276108705b805e222a069a5 (diff) | |
improved tileset and load
| -rw-r--r-- | main.lua | 7 | ||||
| -rw-r--r-- | tilemap.lua | 12 | ||||
| -rw-r--r-- | world.lua | 6 |
3 files changed, 11 insertions, 14 deletions
@@ -16,7 +16,8 @@ local camera = nil local fonts = require("fonts") local currentState = "game" -local currentLevel = "assets/maps/tilemap1.lua" +local currentMapPath = "assets/maps/tilemap.lua" +local currentTilesetPath = "assets/maps/tileset.png" local world = nil local states = { @@ -36,9 +37,9 @@ end function states.game.load() local World = require("world") world = World:new() - world:load(currentLevel) + world:load(currentMapPath, currentTilesetPath) local target = world:getPlayer() or { x = 0, y = 0, width = 16, height = 16 } - camera = cameraModule:new(target, VIRTUAL_WIDTH/3, VIRTUAL_HEIGHT/3, true, WORLD_TO_CANVAS) + camera = cameraModule:new(target, VIRTUAL_WIDTH/2, VIRTUAL_HEIGHT/2, true, WORLD_TO_CANVAS) world:setCamera(camera) end diff --git a/tilemap.lua b/tilemap.lua index 64ca520..4780cfe 100644 --- a/tilemap.lua +++ b/tilemap.lua @@ -39,7 +39,7 @@ local function objectToEntity(obj) return entity end -function Tilemap:new(map) +function Tilemap:new(mapPath, tilesetPath) local self = setmetatable({}, Tilemap) self.entitiesTiles = {} @@ -55,7 +55,7 @@ function Tilemap:new(map) self.tilesetImage = nil self.tileQuads = {} - local mapData = loadMapData(map) + local mapData = loadMapData(mapPath) self.mapData = mapData self.tileWidth = mapData and (mapData.tilewidth or 16) or 16 @@ -63,10 +63,8 @@ function Tilemap:new(map) self.mapWidth = (mapData and mapData.width or 0) * self.tileWidth self.mapHeight = (mapData and mapData.height or 0) * self.tileHeight - if type(map) == "string" then - local basePath = map:gsub("%.lua$", ""):gsub("%.tmx$", "") - local imagePath = basePath .. ".png" - local ok, img = pcall(love.graphics.newImage, imagePath) + if type(tilesetPath) == "string" and tilesetPath ~= "" then + local ok, img = pcall(love.graphics.newImage, tilesetPath) if ok and img then self.tilesetImage = img local firstGid = (mapData.tilesets and mapData.tilesets[1] and mapData.tilesets[1].firstgid) or 1 @@ -121,8 +119,6 @@ function Tilemap:getEntitiesCameraBorders() return self.entitiesCameraBorders end --- Returns minX, maxX, minY, maxY from camera_border entities for use with Camera:setLimits. --- Returns nil, nil, nil, nil if there are no camera border entities. function Tilemap:getCameraLimits() local borders = self.entitiesCameraBorders if not borders or #borders == 0 then @@ -21,17 +21,17 @@ function World:new() return self end -function World:load(levelPath) +function World:load(mapPath, tilesetPath) if self.physicsWorld then self.groundEntities = {} end self.physicsWorld = love.physics.newWorld(0, GRAVITY) self.physicsWorld:setCallbacks(nil, nil, nil, nil) - self.tilemap = Tilemap:new(levelPath) + self.tilemap = Tilemap:new(mapPath, tilesetPath) self.mapData = self.tilemap:getMapData() if not self.mapData then - error("World:load - no map data from " .. tostring(levelPath)) + error("World:load - no map data from " .. tostring(mapPath)) end local tileWidth = self.tilemap:getTileWidth() |
