Add win condition.
This commit is contained in:
parent
65cf8bd968
commit
4f3d417c95
22
main.lua
22
main.lua
|
@ -23,6 +23,9 @@ local game = {
|
|||
},
|
||||
hazards={},
|
||||
drawGrid=false,
|
||||
winState=false,
|
||||
big_font=love.graphics.newFont(48, "mono"),
|
||||
font=love.graphics.newFont(12, "mono"),
|
||||
}
|
||||
|
||||
function t2p(tileDim)
|
||||
|
@ -101,6 +104,13 @@ function love.keyreleased(key)
|
|||
if player.dead or player.turtleHit then
|
||||
return
|
||||
end
|
||||
if game.winState then
|
||||
if key == "space" or key == "return" then
|
||||
game.winState = false
|
||||
resetPlayer()
|
||||
end
|
||||
return
|
||||
end
|
||||
local newPos = screenPixelToTilePos(player.pos)
|
||||
local oldPos = screenPixelToTilePos(player.pos)
|
||||
if key == "up" or key == "w" then
|
||||
|
@ -156,7 +166,10 @@ function love.update(dt)
|
|||
player.deadTimer = 2
|
||||
resetPlayer()
|
||||
end
|
||||
else
|
||||
elseif not game.winState then
|
||||
if screenPixelToTilePos(player.turtlePos).x == game.PLAYFIELD_WIDTH then
|
||||
game.winState = true
|
||||
end
|
||||
local playerRect = tilePos2Rect(screenPixelToTilePos(player.pos))
|
||||
local turtleRect = tilePos2Rect(screenPixelToTilePos(player.turtlePos))
|
||||
if player.float_speed ~= 0 then
|
||||
|
@ -282,6 +295,13 @@ function love.draw()
|
|||
love.graphics.setColor(1, 1, 1)
|
||||
end
|
||||
love.graphics.draw(player.sprites, player.quads.turtle, x, y + 4)
|
||||
if game.winState then
|
||||
love.graphics.setColor(0, 0, 0, 0.8)
|
||||
love.graphics.rectangle("fill", 0, -32, game.SCREEN_WIDTH, game.SCREEN_HEIGHT)
|
||||
love.graphics.setColor(0, 1, 0.2)
|
||||
love.graphics.printf("MADE IT!", game.big_font, 64, 12, 200, "center")
|
||||
love.graphics.printf("press return to play again", game.font, 64, 128, 200, "center")
|
||||
end
|
||||
-- </playfield>
|
||||
love.graphics.pop()
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue