1
0
Fork 0

Convert turtlePos to pixels.

This commit is contained in:
Gonzalo Delgado 2023-08-23 08:13:07 -03:00
parent 680a0c2790
commit 4481ee4512
1 changed files with 6 additions and 5 deletions

View File

@ -41,7 +41,7 @@ end
local player = {
pos={x=t2p(0), y=t2p(0)},
turtlePos={x=1, y=2},
turtlePos={x=t2p(0), y=t2p(1)},
turtleHit=false,
lives=3,
turtles=3,
@ -53,6 +53,7 @@ local player = {
function resetPlayer()
player.pos = {x=t2p(0), y=t2p(0)}
player.dead = false
player.turtlePos = {x=t2p(0), y=t2p(1)}
end
function love.load()
@ -102,7 +103,8 @@ function love.keyreleased(key)
if key == "left" or key == "a" then
newPos.x = newPos.x - 1
end
player.turtlePos = oldPos
player.turtlePos.x = t2p(oldPos.x - 1)
player.turtlePos.y = t2p(oldPos.y - 1)
if newPos.x < 1 then
newPos.x = 1
end
@ -145,7 +147,7 @@ function love.update(dt)
end
else
local playerRect = tilePos2Rect(screenPixelToTilePos(player.pos))
local turtleRect = tilePos2Rect(player.turtlePos)
local turtleRect = tilePos2Rect(screenPixelToTilePos(player.turtlePos))
if player.float_speed ~= 0 then
player.pos.y = player.pos.y + player.float_speed*dt
end
@ -216,12 +218,11 @@ function love.draw()
else
love.graphics.setColor(0.9, 0.6, 0.1)
end
-- TODO: change this to use player's stored pixel pos
local x, y = player.pos.x, player.pos.y
love.graphics.circle("fill", x + game.TILE_SIZE/2, y + game.TILE_SIZE/2, game.TILE_SIZE/2)
love.graphics.setColor(0.2, 0.1, 0.1)
love.graphics.circle("line", x + game.TILE_SIZE/2, y + game.TILE_SIZE/2, game.TILE_SIZE/2)
x, y = tilePos2Pixels(player.turtlePos)
x, y = player.turtlePos.x, player.turtlePos.y
love.graphics.setColor(0.2, 0.1, 0.1)
love.graphics.circle("line", x + game.TILE_SIZE/2, y + game.TILE_SIZE/2, game.TILE_SIZE/2)
if player.turtleHit then