diff --git a/main.lua b/main.lua index 8fbb8c3..a13dfaa 100644 --- a/main.lua +++ b/main.lua @@ -63,6 +63,7 @@ function love.load() game.scaleH = desktop_height / game.SCREEN_HEIGHT for i, layer in ipairs(game.map.layers) do if layer.objects then + layer.visible = false for j, mapObj in ipairs(layer.objects) do mapObj.visible = false local typekey = mapObj.type.."s" @@ -75,7 +76,12 @@ function love.load() w=mapObj.width, h=mapObj.height, type=mapObj.type, + gid=mapObj.gid, } + if mapObj.type == "vehicle" then + local tile = game.map.tiles[mapObj.gid] or game.map:setFlippedGID(mapObj.gid) + entity.collider = tile.objectGroup.objects[1] + end if entity.type == "floatdev" then entity.speed = mapObj.properties.speed or game.FLOATDEV_SPEED end @@ -153,11 +159,12 @@ function love.update(dt) player.turtlePos.y = player.turtlePos.y + player.float_speed*dt end for i, vehicle in ipairs(game.entities.vehicles) do - if rectanglesIntersect(playerRect, vehicle) then + local colliderRect = {x=vehicle.x + vehicle.collider.x, y=vehicle.y + vehicle.collider.y, w=vehicle.collider.width, h=vehicle.collider.height} + if rectanglesIntersect(playerRect, colliderRect) then player.dead = true player.lives = player.lives - 1 end - if rectanglesIntersect(turtleRect, vehicle) then + if rectanglesIntersect(turtleRect, colliderRect) then player.turtleHit = true end @@ -224,9 +231,14 @@ function love.draw() love.graphics.line(0, t2p(i), t2p(game.PLAYFIELD_WIDTH), t2p(i)) end end - love.graphics.setColor(0.9, 0.2, 0) for i, vehicle in ipairs(game.entities.vehicles) do - love.graphics.rectangle("fill", vehicle.x, vehicle.y, vehicle.w, vehicle.h) + local tile = game.map.tiles[vehicle.gid] or game.map:setFlippedGID(vehicle.gid) + local tileset = game.map.tilesets[tile.tileset] + local image = tileset.image + love.graphics.setColor(1, 1, 1) + love.graphics.draw(image, tile.quad, vehicle.x, vehicle.y) + love.graphics.setColor(0.9, 0.1, 0) + -- love.graphics.rectangle("line", vehicle.x + vehicle.collider.x, vehicle.y + vehicle.collider.y, vehicle.collider.width, vehicle.collider.height) end love.graphics.setColor(0.8, 0.7, 0) for i, floatdev in ipairs(game.entities.floatdevs) do diff --git a/map.lua b/map.lua index cdfb51f..92c4209 100644 --- a/map.lua +++ b/map.lua @@ -8,8 +8,8 @@ return { height = 10, tilewidth = 16, tileheight = 16, - nextlayerid = 4, - nextobjectid = 26, + nextlayerid = 6, + nextobjectid = 35, properties = {}, tilesets = { { @@ -38,6 +38,127 @@ return { wangsets = {}, tilecount = 10, tiles = {} + }, + { + name = "sprites", + firstgid = 11, + tilewidth = 16, + tileheight = 32, + spacing = 0, + margin = 0, + columns = 10, + image = "sprites.png", + imagewidth = 160, + imageheight = 32, + transparentcolor = "#ff00ff", + objectalignment = "unspecified", + tileoffset = { + x = 0, + y = 0 + }, + grid = { + orientation = "orthogonal", + width = 16, + height = 32 + }, + properties = {}, + wangsets = {}, + tilecount = 10, + tiles = { + { + id = 0, + objectGroup = { + type = "objectgroup", + draworder = "index", + id = 2, + name = "", + visible = true, + opacity = 1, + offsetx = 0, + offsety = 0, + parallaxx = 1, + parallaxy = 1, + properties = {}, + objects = { + { + id = 1, + name = "", + type = "", + shape = "rectangle", + x = 1, + y = 1, + width = 14, + height = 24, + rotation = 0, + visible = true, + properties = {} + } + } + } + }, + { + id = 1, + objectGroup = { + type = "objectgroup", + draworder = "index", + id = 2, + name = "", + visible = true, + opacity = 1, + offsetx = 0, + offsety = 0, + parallaxx = 1, + parallaxy = 1, + properties = {}, + objects = { + { + id = 1, + name = "", + type = "", + shape = "rectangle", + x = 1, + y = 2, + width = 14, + height = 24, + rotation = 0, + visible = true, + properties = {} + } + } + } + }, + { + id = 2, + objectGroup = { + type = "objectgroup", + draworder = "index", + id = 2, + name = "", + visible = true, + opacity = 1, + offsetx = 0, + offsety = 0, + parallaxx = 1, + parallaxy = 1, + properties = {}, + objects = { + { + id = 1, + name = "", + type = "", + shape = "rectangle", + x = 1, + y = 1, + width = 14, + height = 24, + rotation = 0, + visible = true, + properties = {} + } + } + } + } + } } }, layers = { @@ -122,22 +243,8 @@ return { offsety = 0, parallaxx = 1, parallaxy = 1, - tintcolor = { 170, 0, 0 }, properties = {}, objects = { - { - id = 1, - name = "", - type = "vehicle", - shape = "rectangle", - x = 18, - y = 0, - width = 12, - height = 16, - rotation = 0, - visible = true, - properties = {} - }, { id = 8, name = "", @@ -239,19 +346,6 @@ return { ["speed"] = -18 } }, - { - id = 2, - name = "", - type = "vehicle", - shape = "rectangle", - x = 18, - y = 64, - width = 12, - height = 16, - rotation = 0, - visible = true, - properties = {} - }, { id = 7, name = "", @@ -353,19 +447,6 @@ return { ["speed"] = -18 } }, - { - id = 3, - name = "", - type = "vehicle", - shape = "rectangle", - x = 18, - y = 128, - width = 12, - height = 16, - rotation = 0, - visible = true, - properties = {} - }, { id = 6, name = "", @@ -436,6 +517,76 @@ return { properties = { ["speed"] = -10 } + }, + { + id = 30, + name = "", + type = "vehicle", + shape = "rectangle", + x = 44, + y = 152, + width = 16, + height = 32, + rotation = 0, + gid = 11, + visible = true, + properties = {} + }, + { + id = 31, + name = "", + type = "vehicle", + shape = "rectangle", + x = 44, + y = 64, + width = 16, + height = 32, + rotation = 0, + gid = 13, + visible = true, + properties = {} + }, + { + id = 32, + name = "", + type = "vehicle", + shape = "rectangle", + x = 16, + y = 32, + width = 16, + height = 32, + rotation = 0, + gid = 13, + visible = true, + properties = {} + }, + { + id = 33, + name = "", + type = "vehicle", + shape = "rectangle", + x = 16, + y = 88, + width = 16, + height = 32, + rotation = 0, + gid = 12, + visible = true, + properties = {} + }, + { + id = 34, + name = "", + type = "vehicle", + shape = "rectangle", + x = 16, + y = 152, + width = 16, + height = 32, + rotation = 0, + gid = 11, + visible = true, + properties = {} } } } diff --git a/map.tmx b/map.tmx index cb72e6b..7543057 100644 --- a/map.tmx +++ b/map.tmx @@ -1,11 +1,29 @@ - + + + + + + + + + + + + + + + + + + + 1,2,3,4,1,5,5,5,1,5,5,5,5,1,2,3,7,3,4,6, @@ -24,8 +42,7 @@ - - + @@ -53,7 +70,6 @@ - @@ -81,7 +97,6 @@ - @@ -99,5 +114,10 @@ + + + + +