From bac76b95dc0c4fe23707d21fe2149bd5d44fec6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Sun, 4 Jun 2023 21:38:58 +0300 Subject: [PATCH] Implement game over --- bundle/font.lua | 35 +++++++++++++++++++++++++++++++++++ bundle/main.lua | 43 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 71 insertions(+), 7 deletions(-) diff --git a/bundle/font.lua b/bundle/font.lua index 7a0b36c..2a79691 100644 --- a/bundle/font.lua +++ b/bundle/font.lua @@ -28,6 +28,17 @@ font["f"] = { {0, 0, 0.7, 0}, {0, 0.5, 0.5, 0.5}, } +font["g"] = { + {0, 0.2, 0.2, 0}, + {0.2, 0, 0.5, 0}, + {0.5, 0, 0.7, 0.2}, + {0, 0.2, 0, 0.8}, + {0, 0.8, 0.2, 1}, + {0.2, 1, 0.5, 1}, + {0.5, 1, 0.7, 0.8}, + {0.7, 0.8, 0.7, 0.6}, + {0.7, 0.6, 0.5, 0.6}, +} font["i"] = { {0.1, 0, 0.6, 0}, {0.35, 0, 0.35, 1}, @@ -43,6 +54,12 @@ font["l"] = { {0, 0, 0, 1}, {0, 1, 0.7, 1}, } +font["m"] = { + {0, 1, 0.175, 0}, + {0.175, 0, 0.35, 1}, + {0.35, 1, 0.525, 0}, + {0.525, 0, 0.7, 1}, +} font["o"] = { {0, 0.2, 0.2, 0}, {0.2, 0, 0.5, 0}, @@ -53,6 +70,17 @@ font["o"] = { {0.5, 1, 0.7, 0.8}, {0.7, 0.2, 0.7, 0.8}, } +font["q"] = { + {0, 0.2, 0.2, 0}, + {0.2, 0, 0.5, 0}, + {0.5, 0, 0.7, 0.2}, + {0, 0.2, 0, 0.8}, + {0, 0.8, 0.2, 1}, + {0.2, 1, 0.5, 1}, + {0.5, 1, 0.7, 0.8}, + {0.7, 0.2, 0.7, 0.8}, + {0.5, 0.7, 0.7, 1}, +} font["r"] = { {0, 0, 0, 1}, {0, 0, 0.5, 0}, @@ -79,6 +107,13 @@ font["t"] = { {0, 0, 0.7, 0}, {0.35, 0, 0.35, 1}, } +font["u"] = { + {0, 0, 0, 0.8}, + {0, 0.8, 0.2, 1}, + {0.2, 1, 0.5, 1}, + {0.5, 1, 0.7, 0.8}, + {0.7, 0.8, 0.7, 0}, +} font["v"] = { {0, 0, 0.35, 1}, {0.35, 1, 0.7, 0}, diff --git a/bundle/main.lua b/bundle/main.lua index 619dbf3..d304838 100644 --- a/bundle/main.lua +++ b/bundle/main.lua @@ -34,7 +34,7 @@ local enemy_inaccuracy = 0.05 local intro_duration = 1 local outro_duration = 0.5 -local stage = 1 +local stage = nil local window_width = nil local window_height = nil @@ -44,7 +44,7 @@ local scale = nil local time = nil -local states = {title = 0, intro = 1, outro = 2, gameplay = 3} +local states = {title = 0, intro = 1, outro = 2, gameplay = 3, game_over = 4} local state = nil font = require("font") @@ -154,6 +154,8 @@ function love.load() cities = {} spawnCities() + stage = 1 + state = states.title end @@ -394,7 +396,13 @@ function love.update(dt) unreflected_missiles_allowed = unreflected_missiles_allowed + 1 end - if #enemies == 0 then + local cities_remaining = 0 + for _, city in ipairs(cities) do + if city.alive then + cities_remaining = cities_remaining + 1 + end + end + if cities_remaining == 0 or #enemies == 0 then state = states.outro time = 0 explodeAllMissiles() @@ -406,8 +414,21 @@ function love.update(dt) if #explosions == 0 then time = time + dt if time >= outro_duration then - stage = stage + 1 - startStage() + local cities_remaining = 0 + for _, city in ipairs(cities) do + if city.alive then + cities_remaining = cities_remaining + 1 + end + end + if cities_remaining == 0 then + love.mouse.setVisible(true) + love.mouse.setGrabbed(false) + state = states.game_over + else + time = 0 + stage = stage + 1 + startStage() + end end end elseif state == states.intro then @@ -456,6 +477,8 @@ function love.mousepressed(x, y, button, istouch, presses) explodeAllReflected() elseif state == states.title then startStage() + elseif state == states.game_over then + love.event.quit() end end @@ -599,7 +622,7 @@ function drawTextCentered(y, text_scale, text) end function love.draw() - if state == states.gameplay or state == states.outro or state == states.intro then + if state == states.gameplay or state == states.outro or state == states.intro or state == states.game_over then drawCities() drawWalls() drawMissiles() @@ -609,7 +632,13 @@ function love.draw() if state == states.intro then drawTextCentered(0.4, 0.1, "wave") local number = tostring(stage) - drawTextCentered(0.55, 0.1, number) + drawTextCentered(0.55, 0.07, number) + end + if state == states.game_over then + drawTextCentered(0.4, 0.1, "game over") + local number = tostring(stage) + drawTextCentered(0.55, 0.07, number) + drawTextCentered(0.7, 0.03, "click to quit") end elseif state == states.title then drawTextCentered(0.3, 0.1, "reflect")