From 4481ee45120ecc4ad85cfeca7cf9695c07433294 Mon Sep 17 00:00:00 2001 From: Gonzalo Delgado Date: Wed, 23 Aug 2023 08:13:07 -0300 Subject: [PATCH] Convert turtlePos to pixels. --- main.lua | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/main.lua b/main.lua index 88b0899..18e6b86 100644 --- a/main.lua +++ b/main.lua @@ -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