Convert turtlePos to pixels.
This commit is contained in:
parent
680a0c2790
commit
4481ee4512
11
main.lua
11
main.lua
|
@ -41,7 +41,7 @@ end
|
||||||
|
|
||||||
local player = {
|
local player = {
|
||||||
pos={x=t2p(0), y=t2p(0)},
|
pos={x=t2p(0), y=t2p(0)},
|
||||||
turtlePos={x=1, y=2},
|
turtlePos={x=t2p(0), y=t2p(1)},
|
||||||
turtleHit=false,
|
turtleHit=false,
|
||||||
lives=3,
|
lives=3,
|
||||||
turtles=3,
|
turtles=3,
|
||||||
|
@ -53,6 +53,7 @@ local player = {
|
||||||
function resetPlayer()
|
function resetPlayer()
|
||||||
player.pos = {x=t2p(0), y=t2p(0)}
|
player.pos = {x=t2p(0), y=t2p(0)}
|
||||||
player.dead = false
|
player.dead = false
|
||||||
|
player.turtlePos = {x=t2p(0), y=t2p(1)}
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.load()
|
function love.load()
|
||||||
|
@ -102,7 +103,8 @@ function love.keyreleased(key)
|
||||||
if key == "left" or key == "a" then
|
if key == "left" or key == "a" then
|
||||||
newPos.x = newPos.x - 1
|
newPos.x = newPos.x - 1
|
||||||
end
|
end
|
||||||
player.turtlePos = oldPos
|
player.turtlePos.x = t2p(oldPos.x - 1)
|
||||||
|
player.turtlePos.y = t2p(oldPos.y - 1)
|
||||||
if newPos.x < 1 then
|
if newPos.x < 1 then
|
||||||
newPos.x = 1
|
newPos.x = 1
|
||||||
end
|
end
|
||||||
|
@ -145,7 +147,7 @@ function love.update(dt)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local playerRect = tilePos2Rect(screenPixelToTilePos(player.pos))
|
local playerRect = tilePos2Rect(screenPixelToTilePos(player.pos))
|
||||||
local turtleRect = tilePos2Rect(player.turtlePos)
|
local turtleRect = tilePos2Rect(screenPixelToTilePos(player.turtlePos))
|
||||||
if player.float_speed ~= 0 then
|
if player.float_speed ~= 0 then
|
||||||
player.pos.y = player.pos.y + player.float_speed*dt
|
player.pos.y = player.pos.y + player.float_speed*dt
|
||||||
end
|
end
|
||||||
|
@ -216,12 +218,11 @@ function love.draw()
|
||||||
else
|
else
|
||||||
love.graphics.setColor(0.9, 0.6, 0.1)
|
love.graphics.setColor(0.9, 0.6, 0.1)
|
||||||
end
|
end
|
||||||
-- TODO: change this to use player's stored pixel pos
|
|
||||||
local x, y = player.pos.x, player.pos.y
|
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.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.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)
|
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.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)
|
love.graphics.circle("line", x + game.TILE_SIZE/2, y + game.TILE_SIZE/2, game.TILE_SIZE/2)
|
||||||
if player.turtleHit then
|
if player.turtleHit then
|
||||||
|
|
Loading…
Reference in New Issue
Block a user