From 4f3d417c953a80aca41681dce148e163f48c1f3b Mon Sep 17 00:00:00 2001 From: Gonzalo Delgado Date: Fri, 1 Sep 2023 08:55:40 -0300 Subject: [PATCH] Add win condition. --- main.lua | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/main.lua b/main.lua index 9db81dc..d9f5a18 100644 --- a/main.lua +++ b/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 -- love.graphics.pop() end