diff --git a/main.lua b/main.lua index 01724bf..88b0899 100644 --- a/main.lua +++ b/main.lua @@ -47,6 +47,7 @@ local player = { turtles=3, dead=false, deadTimer=2, + float_speed=0, } function resetPlayer() @@ -66,16 +67,17 @@ function love.load() if game.entities[typekey] == nil then game.entities[typekey] = {} end - table.insert( - game.entities[typekey], - { - x=mapObj.x, - y=mapObj.y, - w=mapObj.width, - h=mapObj.height, - type=mapObj.type, - } - ) + local entity = { + x=mapObj.x, + y=mapObj.y, + w=mapObj.width, + h=mapObj.height, + type=mapObj.type, + } + if entity.type == "floatdev" then + entity.speed = mapObj.properties.speed or game.FLOATDEV_SPEED + end + table.insert(game.entities[typekey], entity) end end end @@ -144,8 +146,8 @@ function love.update(dt) else local playerRect = tilePos2Rect(screenPixelToTilePos(player.pos)) local turtleRect = tilePos2Rect(player.turtlePos) - if player.floating then - player.pos.y = player.pos.y + game.FLOATDEV_SPEED*dt + if player.float_speed ~= 0 then + player.pos.y = player.pos.y + player.float_speed*dt end for i, vehicle in ipairs(game.entities.vehicles) do if rectanglesIntersect(playerRect, vehicle) then @@ -161,17 +163,20 @@ function love.update(dt) vehicle.y = -vehicle.h end end - player.floating = false + player.float_speed = 0 for i, floatdev in ipairs(game.entities.floatdevs) do - if not player.floating and rectanglesIntersect(playerRect, floatdev) then - player.floating = true + if player.float_speed == 0 and rectanglesIntersect(playerRect, floatdev) then + player.float_speed = floatdev.speed end - floatdev.y = floatdev.y + game.FLOATDEV_SPEED*dt + floatdev.y = floatdev.y + floatdev.speed*dt if floatdev.y > t2p(game.PLAYFIELD_HEIGHT) then floatdev.y = -floatdev.h end + if floatdev.y + floatdev.h < t2p(0) then + floatdev.y = t2p(game.PLAYFIELD_HEIGHT) + end end - if not player.floating then + if player.float_speed == 0 then for i, water in ipairs(game.entities.waters) do if not player.dead and rectanglesIntersect(playerRect, water) then player.dead = true diff --git a/map.lua b/map.lua index 96f6139..8d2558b 100644 --- a/map.lua +++ b/map.lua @@ -9,7 +9,7 @@ return { tilewidth = 16, tileheight = 16, nextlayerid = 4, - nextobjectid = 12, + nextobjectid = 15, properties = {}, tilesets = { { @@ -89,11 +89,11 @@ return { type = "water", shape = "rectangle", x = 80, - y = -0.25, + y = 0, width = 48, height = 160, rotation = 0, - visible = false, + visible = true, properties = {} }, { @@ -106,7 +106,7 @@ return { width = 64, height = 160, rotation = 0, - visible = false, + visible = true, properties = {} } } @@ -157,12 +157,27 @@ return { type = "floatdev", shape = "rectangle", x = 98, - y = 32, + y = 16, + width = 12, + height = 32, + rotation = 0, + visible = true, + properties = {} + }, + { + id = 12, + name = "", + type = "floatdev", + shape = "rectangle", + x = 114, + y = 16, width = 12, height = 16, rotation = 0, visible = true, - properties = {} + properties = { + ["speed"] = -10 + } }, { id = 2, @@ -196,12 +211,27 @@ return { type = "floatdev", shape = "rectangle", x = 98, - y = 98, + y = 72, + width = 12, + height = 32, + rotation = 0, + visible = true, + properties = {} + }, + { + id = 13, + name = "", + type = "floatdev", + shape = "rectangle", + x = 114, + y = 80, width = 12, height = 16, rotation = 0, visible = true, - properties = {} + properties = { + ["speed"] = -10 + } }, { id = 3, @@ -235,12 +265,27 @@ return { type = "floatdev", shape = "rectangle", x = 98, - y = 160, + y = 128, + width = 12, + height = 32, + rotation = 0, + visible = true, + properties = {} + }, + { + id = 14, + name = "", + type = "floatdev", + shape = "rectangle", + x = 114, + y = 144, width = 12, height = 16, rotation = 0, visible = true, - properties = {} + properties = { + ["speed"] = -10 + } } } } diff --git a/map.tmx b/map.tmx index c5496ab..d1be4f4 100644 --- a/map.tmx +++ b/map.tmx @@ -1,5 +1,5 @@ - + @@ -21,18 +21,33 @@ - + - + + + + + + - + + + + + + - + + + + + +