From 571849a9ad07e8a2d800ca13aa6c3146b6598897 Mon Sep 17 00:00:00 2001 From: Gonzalo Delgado Date: Thu, 31 Aug 2023 14:52:37 -0300 Subject: [PATCH] Draw floaters, add more cars, allow different car speeds. --- main.lua | 38 ++- map.lua | 852 +++++++++++++++++++++++++++++++++++----------------- map.tmx | 201 +++++++++---- sprites.png | Bin 1348 -> 1926 bytes 4 files changed, 738 insertions(+), 353 deletions(-) diff --git a/main.lua b/main.lua index 5ef903a..583186c 100644 --- a/main.lua +++ b/main.lua @@ -11,16 +11,18 @@ local game = { PLAYFIELD_OFFSET_TOP=1.5, PLAYFIELD_WIDTH=20, PLAYFIELD_HEIGHT=10, - VEHICLE_SPEED=10, - FLOATDEV_SPEED=8, playFieldTiles={}, map=sti("map.lua"), entities={ vehicles={}, floatdevs={}, }, + default_speeds={ + floatdev=8, + vehicle=10, + }, hazards={}, - drawGrid=true, + drawGrid=false, } function t2p(tileDim) @@ -78,12 +80,10 @@ function love.load() type=mapObj.type, gid=mapObj.gid, } - if mapObj.type == "vehicle" then - local tile = game.map.tiles[mapObj.gid] or game.map:setFlippedGID(mapObj.gid) + if mapObj.type == "vehicle" or mapObj.type == "floatdev" then + local tile = game.map.tiles[mapObj.gid] or game.map.tiles[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 + entity.speed = mapObj.properties.speed or game.default_speeds[mapObj.type] end table.insert(game.entities[typekey], entity) end @@ -173,21 +173,25 @@ function love.update(dt) player.turtleHit = true end - vehicle.y = vehicle.y + game.VEHICLE_SPEED*dt + vehicle.y = vehicle.y + vehicle.speed*dt if vehicle.y > t2p(game.PLAYFIELD_HEIGHT) then vehicle.y = -vehicle.h end + if vehicle.y + vehicle.h < t2p(0) then + vehicle.y = t2p(game.PLAYFIELD_HEIGHT) + end end local was_floating = player.float_speed ~= 0 player.float_speed = 0 for i, floatdev in ipairs(game.entities.floatdevs) do - if player.float_speed == 0 and rectanglesIntersect(playerRect, floatdev) then + local colliderRect = {x=floatdev.x + floatdev.collider.x, y=floatdev.y + floatdev.collider.y, w=floatdev.collider.width, h=floatdev.collider.height} + if player.float_speed == 0 and rectanglesIntersect(playerRect, colliderRect) then if not was_floating then - if math.abs(player.pos.y - floatdev.y) > math.abs(player.pos.y - (floatdev.y + floatdev.h)) then - player.pos.y = floatdev.y + if math.abs(player.pos.y - colliderRect.y) > math.abs(player.pos.y - (colliderRect.y + colliderRect.h)) then + player.pos.y = colliderRect.y player.turtlePos.y = player.pos.y + game.TILE_SIZE*2 else - player.pos.y = floatdev.y + floatdev.h - game.TILE_SIZE + player.pos.y = colliderRect.y + colliderRect.h - game.TILE_SIZE player.turtlePos.y = player.pos.y - game.TILE_SIZE end end @@ -245,9 +249,13 @@ function love.draw() 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 - love.graphics.rectangle("fill", floatdev.x, floatdev.y, floatdev.w, floatdev.h) + local tile = game.map.tiles[floatdev.gid] or game.map:setFlippedGID(floatdev.gid) + local tileset = game.map.tilesets[tile.tileset] + local image = tileset.image + love.graphics.setColor(1, 1, 1) + love.graphics.draw(image, tile.quad, floatdev.x, floatdev.y) + love.graphics.setColor(0.9, 0.1, 0) end if player.dead then love.graphics.setColor(0.8, 0.1, 0) diff --git a/map.lua b/map.lua index 92c4209..60d4c2c 100644 --- a/map.lua +++ b/map.lua @@ -9,7 +9,7 @@ return { tilewidth = 16, tileheight = 16, nextlayerid = 6, - nextobjectid = 35, + nextobjectid = 67, properties = {}, tilesets = { { @@ -49,7 +49,7 @@ return { columns = 10, image = "sprites.png", imagewidth = 160, - imageheight = 32, + imageheight = 128, transparentcolor = "#ff00ff", objectalignment = "unspecified", tileoffset = { @@ -63,7 +63,7 @@ return { }, properties = {}, wangsets = {}, - tilecount = 10, + tilecount = 40, tiles = { { id = 0, @@ -157,6 +157,161 @@ return { } } } + }, + { + id = 3, + 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 = 0, + y = 0, + width = 16, + height = 32, + rotation = 0, + visible = true, + properties = {} + } + } + } + }, + { + id = 4, + 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 = 0, + y = 0, + width = 16, + height = 32, + rotation = 0, + visible = true, + properties = {} + } + } + } + }, + { + id = 5, + 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 = 6, + 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 = 22, + rotation = 0, + visible = true, + properties = {} + } + } + } + }, + { + id = 7, + 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 = 26, + rotation = 0, + visible = true, + properties = {} + } + } + } } } } @@ -245,279 +400,6 @@ return { parallaxy = 1, properties = {}, objects = { - { - id = 8, - name = "", - type = "floatdev", - shape = "rectangle", - x = 82, - y = -8, - width = 12, - height = 32, - rotation = 0, - visible = true, - properties = {} - }, - { - id = 22, - name = "", - type = "floatdev", - shape = "rectangle", - x = 146, - y = -8, - width = 12, - height = 32, - rotation = 0, - visible = true, - properties = {} - }, - { - id = 25, - name = "", - type = "floatdev", - shape = "rectangle", - x = 194, - y = -8, - width = 12, - height = 32, - rotation = 0, - visible = true, - properties = { - ["speed"] = 18 - } - }, - { - id = 11, - name = "", - type = "floatdev", - shape = "rectangle", - x = 98, - y = 16, - width = 12, - height = 32, - rotation = 0, - visible = true, - properties = { - ["speed"] = 12 - } - }, - { - id = 21, - name = "", - type = "floatdev", - shape = "rectangle", - x = 162, - y = 16, - width = 12, - height = 32, - rotation = 0, - visible = true, - properties = { - ["speed"] = -10 - } - }, - { - id = 12, - name = "", - type = "floatdev", - shape = "rectangle", - x = 114, - y = 16, - width = 12, - height = 48, - rotation = 0, - visible = true, - properties = { - ["speed"] = -16 - } - }, - { - id = 20, - name = "", - type = "floatdev", - shape = "rectangle", - x = 178, - y = 16, - width = 12, - height = 48, - rotation = 0, - visible = true, - properties = { - ["speed"] = -18 - } - }, - { - id = 7, - name = "", - type = "floatdev", - shape = "rectangle", - x = 82, - y = 56, - width = 12, - height = 32, - rotation = 0, - visible = true, - properties = {} - }, - { - id = 19, - name = "", - type = "floatdev", - shape = "rectangle", - x = 146, - y = 56, - width = 12, - height = 32, - rotation = 0, - visible = true, - properties = {} - }, - { - id = 24, - name = "", - type = "floatdev", - shape = "rectangle", - x = 194, - y = 56, - width = 12, - height = 32, - rotation = 0, - visible = true, - properties = { - ["speed"] = 18 - } - }, - { - id = 10, - name = "", - type = "floatdev", - shape = "rectangle", - x = 98, - y = 80, - width = 12, - height = 32, - rotation = 0, - visible = true, - properties = { - ["speed"] = 12 - } - }, - { - id = 18, - name = "", - type = "floatdev", - shape = "rectangle", - x = 162, - y = 80, - width = 12, - height = 32, - rotation = 0, - visible = true, - properties = { - ["speed"] = -10 - } - }, - { - id = 13, - name = "", - type = "floatdev", - shape = "rectangle", - x = 114, - y = 128, - width = 12, - height = 48, - rotation = 0, - visible = true, - properties = { - ["speed"] = -16 - } - }, - { - id = 16, - name = "", - type = "floatdev", - shape = "rectangle", - x = 178, - y = 128, - width = 12, - height = 48, - rotation = 0, - visible = true, - properties = { - ["speed"] = -18 - } - }, - { - id = 6, - name = "", - type = "floatdev", - shape = "rectangle", - x = 82, - y = 120, - width = 12, - height = 32, - rotation = 0, - visible = true, - properties = {} - }, - { - id = 17, - name = "", - type = "floatdev", - shape = "rectangle", - x = 146, - y = 120, - width = 12, - height = 32, - rotation = 0, - visible = true, - properties = {} - }, - { - id = 23, - name = "", - type = "floatdev", - shape = "rectangle", - x = 194, - y = 120, - width = 12, - height = 32, - rotation = 0, - visible = true, - properties = { - ["speed"] = 18 - } - }, - { - id = 9, - name = "", - type = "floatdev", - shape = "rectangle", - x = 98, - y = 144, - width = 12, - height = 32, - rotation = 0, - visible = true, - properties = { - ["speed"] = 12 - } - }, - { - id = 15, - name = "", - type = "floatdev", - shape = "rectangle", - x = 162, - y = 144, - width = 12, - height = 32, - rotation = 0, - visible = true, - properties = { - ["speed"] = -10 - } - }, { id = 30, name = "", @@ -530,7 +412,25 @@ return { rotation = 0, gid = 11, visible = true, - properties = {} + properties = { + ["speed"] = 18 + } + }, + { + id = 55, + name = "", + type = "vehicle", + shape = "rectangle", + x = 256, + y = 152, + width = 16, + height = 32, + rotation = 0, + gid = 11, + visible = true, + properties = { + ["speed"] = 12 + } }, { id = 31, @@ -544,7 +444,25 @@ return { rotation = 0, gid = 13, visible = true, - properties = {} + properties = { + ["speed"] = 18 + } + }, + { + id = 57, + name = "", + type = "vehicle", + shape = "rectangle", + x = 256, + y = 64, + width = 16, + height = 32, + rotation = 0, + gid = 13, + visible = true, + properties = { + ["speed"] = 12 + } }, { id = 32, @@ -587,6 +505,384 @@ return { gid = 11, visible = true, properties = {} + }, + { + id = 35, + name = "", + type = "floatdev", + shape = "rectangle", + x = 80.25, + y = 86.25, + width = 16, + height = 32, + rotation = 0, + gid = 14, + visible = true, + properties = {} + }, + { + id = 44, + name = "", + type = "floatdev", + shape = "rectangle", + x = 144, + y = 16, + width = 16, + height = 32, + rotation = 0, + gid = 14, + visible = true, + properties = { + ["speed"] = 10 + } + }, + { + id = 48, + name = "", + type = "floatdev", + shape = "rectangle", + x = 160, + y = 112, + width = 16, + height = 32, + rotation = 0, + gid = 14, + visible = true, + properties = { + ["speed"] = -10 + } + }, + { + id = 36, + name = "", + type = "floatdev", + shape = "rectangle", + x = 112, + y = 48, + width = 16, + height = 32, + rotation = 0, + gid = 14, + visible = true, + properties = { + ["speed"] = -16 + } + }, + { + id = 37, + name = "", + type = "floatdev", + shape = "rectangle", + x = 112, + y = 144, + width = 16, + height = 32, + rotation = 0, + gid = 14, + visible = true, + properties = { + ["speed"] = -16 + } + }, + { + id = 38, + name = "", + type = "floatdev", + shape = "rectangle", + x = 95.75, + y = 48.5, + width = 16, + height = 32, + rotation = 0, + gid = 15, + visible = true, + properties = { + ["speed"] = 12 + } + }, + { + id = 39, + name = "", + type = "floatdev", + shape = "rectangle", + x = 80.75, + y = 24.75, + width = 16, + height = 32, + rotation = 0, + gid = 15, + visible = true, + properties = {} + }, + { + id = 45, + name = "", + type = "floatdev", + shape = "rectangle", + x = 144, + y = 88, + width = 16, + height = 32, + rotation = 0, + gid = 15, + visible = true, + properties = { + ["speed"] = 10 + } + }, + { + id = 47, + name = "", + type = "floatdev", + shape = "rectangle", + x = 160, + y = 48, + width = 16, + height = 32, + rotation = 0, + gid = 15, + visible = true, + properties = { + ["speed"] = -10 + } + }, + { + id = 40, + name = "", + type = "floatdev", + shape = "rectangle", + x = 80, + y = 150.75, + width = 16, + height = 32, + rotation = 0, + gid = 15, + visible = true, + properties = {} + }, + { + id = 43, + name = "", + type = "floatdev", + shape = "rectangle", + x = 144, + y = 152, + width = 16, + height = 32, + rotation = 0, + gid = 15, + visible = true, + properties = { + ["speed"] = 10 + } + }, + { + id = 46, + name = "", + type = "floatdev", + shape = "rectangle", + x = 160, + y = 172, + width = 16, + height = 32, + rotation = 0, + gid = 15, + visible = true, + properties = { + ["speed"] = -10 + } + }, + { + id = 41, + name = "", + type = "floatdev", + shape = "rectangle", + x = 96.75, + y = 176.75, + width = 16, + height = 32, + rotation = 0, + gid = 15, + visible = true, + properties = { + ["speed"] = 12 + } + }, + { + id = 42, + name = "", + type = "floatdev", + shape = "rectangle", + x = 96, + y = 111.25, + width = 16, + height = 32, + rotation = 0, + gid = 14, + visible = true, + properties = { + ["speed"] = 12 + } + }, + { + id = 49, + name = "", + type = "floatdev", + shape = "rectangle", + x = 176, + y = 48, + width = 16, + height = 32, + rotation = 0, + gid = 14, + visible = true, + properties = { + ["speed"] = -18 + } + }, + { + id = 50, + name = "", + type = "floatdev", + shape = "rectangle", + x = 176, + y = 128, + width = 16, + height = 32, + rotation = 0, + gid = 14, + visible = true, + properties = { + ["speed"] = -18 + } + }, + { + id = 51, + name = "", + type = "floatdev", + shape = "rectangle", + x = 192, + y = 24, + width = 16, + height = 32, + rotation = 0, + gid = 15, + visible = true, + properties = { + ["speed"] = 20 + } + }, + { + id = 52, + name = "", + type = "floatdev", + shape = "rectangle", + x = 192, + y = 96, + width = 16, + height = 32, + rotation = 0, + gid = 15, + visible = true, + properties = { + ["speed"] = 20 + } + }, + { + id = 53, + name = "", + type = "floatdev", + shape = "rectangle", + x = 192, + y = 152, + width = 16, + height = 32, + rotation = 0, + gid = 15, + visible = true, + properties = { + ["speed"] = 20 + } + }, + { + id = 62, + name = "", + type = "vehicle", + shape = "rectangle", + x = 284, + y = 32, + width = 16, + height = 32, + rotation = 0, + gid = 18, + visible = true, + properties = { + ["speed"] = -12 + } + }, + { + id = 65, + name = "", + type = "vehicle", + shape = "rectangle", + x = 228, + y = 32.75, + width = 16, + height = 32, + rotation = 0, + gid = 18, + visible = true, + properties = { + ["speed"] = -20 + } + }, + { + id = 63, + name = "", + type = "vehicle", + shape = "rectangle", + x = 284, + y = 120, + width = 16, + height = 32, + rotation = 0, + gid = 17, + visible = true, + properties = { + ["speed"] = -12 + } + }, + { + id = 64, + name = "", + type = "vehicle", + shape = "rectangle", + x = 228, + y = 88, + width = 16, + height = 32, + rotation = 0, + gid = 17, + visible = true, + properties = { + ["speed"] = -20 + } + }, + { + id = 66, + name = "", + type = "vehicle", + shape = "rectangle", + x = 228, + y = 152, + width = 16, + height = 32, + rotation = 0, + gid = 16, + visible = true, + properties = { + ["speed"] = -20 + } } } } diff --git a/map.tmx b/map.tmx index 7543057..9b28605 100644 --- a/map.tmx +++ b/map.tmx @@ -1,13 +1,14 @@ - + - - + + + @@ -23,6 +24,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + @@ -43,81 +69,136 @@ - - - + - + - - - - - - - - - - - - - - - - - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sprites.png b/sprites.png index 6312ea2a9396218b68f91ecf9d0bf0e1c5451ebc..e898730a114a2d74236f5be350903fc3621bca64 100644 GIT binary patch delta 1010 zcmX@Y)y6+ToU4I@nSp^}_ufgG8x<{NUXQOBp_$Gq;=* zco^%~=H{GMbzZnWmg!x4Vfle$#}fH@zsVoIQNH~0O8IvFjKa9K!hL$DjrtD?52L#3h=a;k``1m^y1^=Ewu32d zx|YJ$o%Rpt4S1k#TXxqHjX^v#O#*lTJ;WDc^XP zt%5uD%wv9+4_R-kmZ~K%r8>l{s1R%CnttvPhs~1%=i3jMcsH<5K4N$wuknRvY)?9) zgtygSz7Mmmt$nI_q3VIi=Ze_geeq0rVy{?S#LEoNCA*(iVEq5Yx<0tR>uu?lGiO#V zNj%n-scA^f4e!2nw9SiOCj0)VMeMtVrQ7pUMc3>& z_+;;l#tTOoZ+uvzm~fT10H{oCZh7qOAG}A7{B~sdb$jhB_YS6nyUu+F*YP@NB<@P& zJ#eah!z8Y2Hfoo`a(MPg&(UU4G5)(X_iyqW?}WR}+nnbWv&H|I-=O!V{7TxjTlKN; z>NzSH*YMnW;2>jo{lGC%lYsxHom2%*A9K@M#BO%2`<2H={|9HzG@ zA&{+C(oL@5(v=6w!d=eNamI{V0$H@Y$%Fn-NJ5|=qsH;}I7?`9`uewXgP-CYy%Dys z<-p}1^AM;8O5gV+)SL|Dhyc}4D%d5V9`~Ry#NeIt&U+tL5nz+LepEy8IS6&*5O8ct ze;C5b5d!8J$iQiy=cxkX0*TT z3!MK6FqW-O=tF&0LFo_mz1`~c$UvBc3FsC`+UmT}5PQz?R=4Dc0qO7E4lD)pz5y<> zz=T3zxy?WtV|XCdEI6)E1583%#T==2e`~LhDnp!~Xlz)ynUQH&&-y`X`J)_gP}Ism zGlQR*(kqOkuFfP;u!8$%`fxAiLsJw2cBaD`;sp&c5+`o?d8?CI#l~8if7Y4=gnOEQ zaG!w2?u*zOp$b~nr!%Le3O