From 7b3ef24b7a157586ecc719ebd15a12c9ebd4fb2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Sun, 4 Jun 2023 20:22:53 +0300 Subject: [PATCH] Add pre-stage screen --- bundle/font.lua | 97 +++++++++++++++++++++++++++++++++++++++++++++++++ bundle/main.lua | 33 ++++++++++++----- 2 files changed, 120 insertions(+), 10 deletions(-) diff --git a/bundle/font.lua b/bundle/font.lua index e018e52..7a0b36c 100644 --- a/bundle/font.lua +++ b/bundle/font.lua @@ -79,4 +79,101 @@ font["t"] = { {0, 0, 0.7, 0}, {0.35, 0, 0.35, 1}, } +font["v"] = { + {0, 0, 0.35, 1}, + {0.35, 1, 0.7, 0}, +} +font["w"] = { + {0, 0, 0.175, 1}, + {0.175, 1, 0.35, 0.5}, + {0.35, 0.5, 0.525, 1}, + {0.525, 1, 0.7, 0}, +} + +font["0"] = font["o"] +font["1"] = { + {0.15, 0.2, 0.35, 0}, + {0.35, 0, 0.35, 1}, + {0.1, 1, 0.6, 1}, +} +font["2"] = { + {0, 0.2, 0.2, 0}, + {0.2, 0, 0.5, 0}, + {0.5, 0, 0.7, 0.2}, + {0.7, 0.2, 0.7, 0.4}, + {0.7, 0.4, 0, 1}, + {0, 1, 0.7, 1}, +} +font["3"] = { + {0, 0.2, 0.2, 0}, + {0.2, 0, 0.5, 0}, + {0.5, 0, 0.7, 0.2}, + {0.7, 0.2, 0.7, 0.3}, + {0.7, 0.3, 0.5, 0.5}, + {0.5, 0.5, 0.2, 0.5}, + {0.5, 0.5, 0.7, 0.7}, + {0.7, 0.7, 0.7, 0.8}, + {0.7, 0.8, 0.5, 1}, + {0.5, 1, 0.2, 1}, + {0.2, 1, 0, 0.8}, +} +font["4"] = { + {0.2, 0, 0, 0.5}, + {0, 0.5, 0.7, 0.5}, + {0.6, 0, 0.6, 1}, +} +font["5"] = { + {0, 0, 0.7, 0}, + {0, 0, 0, 0.4}, + {0, 0.4, 0.5, 0.4}, + {0.5, 0.4, 0.7, 0.6}, + {0.7, 0.6, 0.7, 0.8}, + {0.7, 0.8, 0.5, 1}, + {0.5, 1, 0, 1}, +} +font["6"] = { + {0.2, 0.3, 0.6, 0}, + {0.2, 0.3, 0, 0.5}, + {0, 0.5, 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.5}, + {0.7, 0.5, 0.5, 0.3}, + {0.5, 0.3, 0.2, 0.3}, +} +font["7"] = { + {0, 0, 0.7, 0}, + {0.7, 0, 0, 1}, + {0.15, 0.5, 0.55, 0.5}, +} +font["8"] = { + {0.5, 0.5, 0.7, 0.3}, + {0.7, 0.3, 0.7, 0.2}, + {0.7, 0.2, 0.5, 0}, + {0.5, 0, 0.2, 0}, + {0.2, 0, 0, 0.2}, + {0, 0.2, 0, 0.3}, + {0, 0.3, 0.2, 0.5}, + {0.2, 0.5, 0.5, 0.5}, + {0.5, 0.5, 0.7, 0.7}, + {0.7, 0.7, 0.7, 0.8}, + {0.7, 0.8, 0.5, 1}, + {0.5, 1, 0.2, 1}, + {0.2, 1, 0, 0.8}, + {0, 0.8, 0, 0.7}, + {0, 0.7, 0.2, 0.5}, +} +font["9"] = { + {0.2, 0.0, 0, 0.2}, + {0, 0.2, 0, 0.5}, + {0, 0.5, 0.2, 0.7}, + {0.2, 0.7, 0.5, 0.7}, + {0.5, 0.7, 0.7, 0.5}, + {0.7, 0.5, 0.7, 0.2}, + {0.7, 0.2, 0.5, 0}, + {0.5, 0, 0.2, 0}, + {0.1, 1, 0.5, 0.7}, +} + return font diff --git a/bundle/main.lua b/bundle/main.lua index 98c7f54..f881682 100644 --- a/bundle/main.lua +++ b/bundle/main.lua @@ -31,6 +31,10 @@ local enemy_min_shoot = 2 local enemy_max_shoot = 10 local enemy_inaccuracy = 0.05 +local intro_duration = 1 + +local stage = 1 + local window_width = nil local window_height = nil local viewport_x_offset = nil @@ -39,12 +43,9 @@ local scale = nil local time = nil -local states = {title = 0, gameplay = 1} +local states = {title = 0, intro = 1, gameplay = 2} local state = nil -local title = {"r", "e", "f", "l", "e", "c", "t"} -local start_instructions = {"c", "l", "i", "c", "k", " ", "t", "o", " ", "s", "t", "a", "r", "t"} - font = require("font") function setScreenDimensions(width, height) @@ -75,7 +76,7 @@ function fromScreenCoordinate(x, y) end function startStage() - movePaddle(0) + movePaddle(window_width / 2) missiles = {} unreflected_missiles = 0 @@ -104,7 +105,7 @@ function startStage() spawnEnemy(0.75, 0.2) spawnEnemy(0.85, 0.2) - state = states.gameplay + state = states.intro end function love.load() @@ -355,6 +356,12 @@ function love.update(dt) if #explosions == 0 and #missiles == 0 and #enemies == 0 then love.event.quit() end + elseif state == states.intro then + time = time + dt + if time >= intro_duration then + time = 0 + state = states.gameplay + end end end @@ -505,7 +512,8 @@ end function drawText(x, y, text_scale, text) love.graphics.setLineWidth(2 / 700 * scale) love.graphics.setColor(1, 1, 1) - for i, char in ipairs(text) do + for i = 1, #text do + local char = string.sub(text, i, i) local glyph = font[char] for _, line in ipairs(glyph) do local x0, y0 = toScreenCoordinates(x + (i - 1) * text_scale + line[1] * text_scale, y + line[2] * text_scale) @@ -528,15 +536,20 @@ function drawTextCentered(y, text_scale, text) end function love.draw() - if state == states.gameplay then + if state == states.gameplay or state == states.intro then drawCities() drawWalls() drawMissiles() drawPaddle() drawEnemies() drawExplosions() + if state == states.intro then + drawTextCentered(0.4, 0.1, "wave") + local number = tostring(stage) + drawTextCentered(0.55, 0.1, number) + end elseif state == states.title then - drawTextCentered(0.3, 0.1, title) - drawTextCentered(0.45, 0.03, start_instructions) + drawTextCentered(0.3, 0.1, "reflect") + drawTextCentered(0.45, 0.03, "click to start") end end