Add title screen
This commit is contained in:
parent
d7146a1d52
commit
29f1b1f344
2 changed files with 153 additions and 21 deletions
82
bundle/font.lua
Normal file
82
bundle/font.lua
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
local font = {}
|
||||||
|
font[" "] = {}
|
||||||
|
font["a"] = {
|
||||||
|
{0, 1, 0, 0.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, 1},
|
||||||
|
{0, 0.6, 0.7, 0.6},
|
||||||
|
}
|
||||||
|
font["c"] = {
|
||||||
|
{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},
|
||||||
|
}
|
||||||
|
font["e"] = {
|
||||||
|
{0, 0, 0, 1},
|
||||||
|
{0, 0, 0.7, 0},
|
||||||
|
{0, 0.5, 0.5, 0.5},
|
||||||
|
{0, 1, 0.7, 1},
|
||||||
|
}
|
||||||
|
font["f"] = {
|
||||||
|
{0, 0, 0, 1},
|
||||||
|
{0, 0, 0.7, 0},
|
||||||
|
{0, 0.5, 0.5, 0.5},
|
||||||
|
}
|
||||||
|
font["i"] = {
|
||||||
|
{0.1, 0, 0.6, 0},
|
||||||
|
{0.35, 0, 0.35, 1},
|
||||||
|
{0.1, 1, 0.6, 1},
|
||||||
|
}
|
||||||
|
font["k"] = {
|
||||||
|
{0, 0, 0, 1},
|
||||||
|
{0, 0.5, 0.3, 0.5},
|
||||||
|
{0.3, 0.5, 0.7, 0},
|
||||||
|
{0.3, 0.5, 0.7, 1},
|
||||||
|
}
|
||||||
|
font["l"] = {
|
||||||
|
{0, 0, 0, 1},
|
||||||
|
{0, 1, 0.7, 1},
|
||||||
|
}
|
||||||
|
font["o"] = {
|
||||||
|
{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},
|
||||||
|
}
|
||||||
|
font["r"] = {
|
||||||
|
{0, 0, 0, 1},
|
||||||
|
{0, 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, 0.5},
|
||||||
|
{0, 0.5, 0.7, 1}
|
||||||
|
}
|
||||||
|
font["s"] = {
|
||||||
|
{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},
|
||||||
|
}
|
||||||
|
font["t"] = {
|
||||||
|
{0, 0, 0.7, 0},
|
||||||
|
{0.35, 0, 0.35, 1},
|
||||||
|
}
|
||||||
|
return font
|
|
@ -39,6 +39,14 @@ local scale = nil
|
||||||
|
|
||||||
local time = nil
|
local time = nil
|
||||||
|
|
||||||
|
local states = {title = 0, gameplay = 1}
|
||||||
|
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)
|
function setScreenDimensions(width, height)
|
||||||
window_width = width
|
window_width = width
|
||||||
window_height = height
|
window_height = height
|
||||||
|
@ -66,7 +74,10 @@ function fromScreenCoordinate(x, y)
|
||||||
return logical_x, logical_y
|
return logical_x, logical_y
|
||||||
end
|
end
|
||||||
|
|
||||||
function initialize()
|
function startStage()
|
||||||
|
love.mouse.setVisible(false)
|
||||||
|
movePaddle(0)
|
||||||
|
|
||||||
missiles = {}
|
missiles = {}
|
||||||
unreflected_missiles = 0
|
unreflected_missiles = 0
|
||||||
unreflected_missiles_allowed = 0
|
unreflected_missiles_allowed = 0
|
||||||
|
@ -93,15 +104,16 @@ function initialize()
|
||||||
spawnEnemy(0.65, 0.2)
|
spawnEnemy(0.65, 0.2)
|
||||||
spawnEnemy(0.75, 0.2)
|
spawnEnemy(0.75, 0.2)
|
||||||
spawnEnemy(0.85, 0.2)
|
spawnEnemy(0.85, 0.2)
|
||||||
|
|
||||||
|
state = states.gameplay
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.load()
|
function love.load()
|
||||||
math.randomseed(os.time())
|
math.randomseed(os.time())
|
||||||
love.mouse.setVisible(false)
|
|
||||||
local width, height = love.graphics.getDimensions()
|
local width, height = love.graphics.getDimensions()
|
||||||
setScreenDimensions(width, height)
|
setScreenDimensions(width, height)
|
||||||
movePaddle(0)
|
|
||||||
initialize()
|
state = states.title
|
||||||
end
|
end
|
||||||
|
|
||||||
function spawnCities()
|
function spawnCities()
|
||||||
|
@ -331,17 +343,19 @@ function updateEnemies(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.update(dt)
|
function love.update(dt)
|
||||||
updateMissiles(dt)
|
if state == states.gameplay then
|
||||||
updateExplosions(dt)
|
updateMissiles(dt)
|
||||||
updateEnemies(dt)
|
updateExplosions(dt)
|
||||||
|
updateEnemies(dt)
|
||||||
|
|
||||||
time = time + dt
|
time = time + dt
|
||||||
if unreflected_missiles_allowed < unreflected_missiles_max and time >= unreflected_missiles_allowed * unreflected_missiles_allowed_ramp_up then
|
if unreflected_missiles_allowed < unreflected_missiles_max and time >= unreflected_missiles_allowed * unreflected_missiles_allowed_ramp_up then
|
||||||
unreflected_missiles_allowed = unreflected_missiles_allowed + 1
|
unreflected_missiles_allowed = unreflected_missiles_allowed + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
if #explosions == 0 and #missiles == 0 and #enemies == 0 then
|
if #explosions == 0 and #missiles == 0 and #enemies == 0 then
|
||||||
love.event.quit()
|
love.event.quit()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -365,7 +379,13 @@ end
|
||||||
|
|
||||||
love.mousemoved = movePaddle
|
love.mousemoved = movePaddle
|
||||||
|
|
||||||
love.mousepressed = explodeAllReflected
|
function love.mousepressed(x, y, button, istouch, presses)
|
||||||
|
if state == states.gameplay then
|
||||||
|
explodeAllReflected()
|
||||||
|
elseif state == states.title then
|
||||||
|
startStage()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
love.resize = setScreenDimensions
|
love.resize = setScreenDimensions
|
||||||
|
|
||||||
|
@ -471,11 +491,41 @@ function drawEnemies()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.draw()
|
function drawText(x, y, text_scale, text)
|
||||||
drawCities()
|
love.graphics.setLineWidth(2 / 700 * scale)
|
||||||
drawWalls()
|
love.graphics.setColor(1, 1, 1)
|
||||||
drawMissiles()
|
for i, char in ipairs(text) do
|
||||||
drawPaddle()
|
local glyph = font[char]
|
||||||
drawEnemies()
|
for _, line in ipairs(glyph) do
|
||||||
drawExplosions()
|
local x0, y0 = toScreenCoordinates(x + (i - 1) * text_scale + line[1] * text_scale, y + line[2] * text_scale)
|
||||||
|
local x1, y1 = toScreenCoordinates(x + (i - 1) * text_scale + line[3] * text_scale, y + line[4] * text_scale)
|
||||||
|
love.graphics.line(x0, y0, x1, y1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function textWidth(text_scale, text)
|
||||||
|
-- Each character is 0.7 wide with 0.3 character spacing before scaling
|
||||||
|
-- Width of a text is therefore math.max(#text - 0.3, 0) before scaling
|
||||||
|
-- and math.max(#text - 0.3, 0) * text_scale after
|
||||||
|
return math.max(#text - 0.3, 0) * text_scale
|
||||||
|
end
|
||||||
|
|
||||||
|
function drawTextCentered(y, text_scale, text)
|
||||||
|
local x = (1 - textWidth(text_scale, text)) / 2
|
||||||
|
drawText(x, y, text_scale, text)
|
||||||
|
end
|
||||||
|
|
||||||
|
function love.draw()
|
||||||
|
if state == states.gameplay then
|
||||||
|
drawCities()
|
||||||
|
drawWalls()
|
||||||
|
drawMissiles()
|
||||||
|
drawPaddle()
|
||||||
|
drawEnemies()
|
||||||
|
drawExplosions()
|
||||||
|
elseif state == states.title then
|
||||||
|
drawTextCentered(0.3, 0.1, title)
|
||||||
|
drawTextCentered(0.45, 0.03, start_instructions)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue