1
0
Fork 0

Improve player and turtle positions when floating.

This commit is contained in:
Gonzalo Delgado 2023-08-23 08:34:56 -03:00
parent 36975cf72f
commit 621a7aaddf
1 changed files with 19 additions and 0 deletions

View File

@ -150,6 +150,7 @@ function love.update(dt)
local turtleRect = tilePos2Rect(screenPixelToTilePos(player.turtlePos))
if player.float_speed ~= 0 then
player.pos.y = player.pos.y + player.float_speed*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
@ -165,9 +166,20 @@ function love.update(dt)
vehicle.y = -vehicle.h
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
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
player.turtlePos.y = player.pos.y + game.TILE_SIZE*2
else
player.pos.y = floatdev.y + floatdev.h - game.TILE_SIZE
player.turtlePos.y = player.pos.y - game.TILE_SIZE
end
end
player.turtlePos.x = player.pos.x
player.float_speed = floatdev.speed
end
floatdev.y = floatdev.y + floatdev.speed*dt
@ -185,6 +197,13 @@ function love.update(dt)
player.lives = player.lives - 1
end
end
if not player.dead and was_floating then
player.turtlePos.x = player.pos.x
player.turtlePos.y = player.pos.y - game.TILE_SIZE
if player.turtlePos.y < t2p(0) then
player.turtlePos.y = player.pos.y + game.TILE_SIZE
end
end
end
end
end