Add pre-stage screen

This commit is contained in:
Juhani Krekelä 2023-06-04 20:22:53 +03:00
parent fd6c7fafa0
commit 7b3ef24b7a
2 changed files with 120 additions and 10 deletions

View File

@ -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

View File

@ -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