Compare commits
2 Commits
fd6c7fafa0
...
2439711358
Author | SHA1 | Date |
---|---|---|
Juhani Krekelä | 2439711358 | |
Juhani Krekelä | 7b3ef24b7a |
|
@ -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
|
||||
|
|
130
bundle/main.lua
130
bundle/main.lua
|
@ -16,7 +16,7 @@ local missile_speed_max = 0.25
|
|||
local unreflected_missiles = nil
|
||||
local unreflected_missiles_allowed = nil
|
||||
local unreflected_missiles_allowed_ramp_up = 10
|
||||
local unreflected_missiles_max = 7
|
||||
local unreflected_missiles_max = nil
|
||||
|
||||
local cities = nil
|
||||
local city_radius = 0.05
|
||||
|
@ -31,6 +31,11 @@ local enemy_min_shoot = 2
|
|||
local enemy_max_shoot = 10
|
||||
local enemy_inaccuracy = 0.05
|
||||
|
||||
local intro_duration = 1
|
||||
local outro_duration = 0.5
|
||||
|
||||
local stage = 1
|
||||
|
||||
local window_width = nil
|
||||
local window_height = nil
|
||||
local viewport_x_offset = nil
|
||||
|
@ -39,12 +44,9 @@ local scale = nil
|
|||
|
||||
local time = nil
|
||||
|
||||
local states = {title = 0, gameplay = 1}
|
||||
local states = {title = 0, intro = 1, outro = 2, gameplay = 3}
|
||||
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,43 +77,83 @@ function fromScreenCoordinate(x, y)
|
|||
end
|
||||
|
||||
function startStage()
|
||||
movePaddle(0)
|
||||
|
||||
missiles = {}
|
||||
unreflected_missiles = 0
|
||||
unreflected_missiles_allowed = 0
|
||||
cities = {}
|
||||
explosions = {}
|
||||
enemies = {}
|
||||
time = 0
|
||||
|
||||
spawnCities()
|
||||
spawnEnemy(0.1, 0.1)
|
||||
spawnEnemy(0.2, 0.1)
|
||||
spawnEnemy(0.3, 0.1)
|
||||
-- First row
|
||||
if stage >= 3 then
|
||||
spawnEnemy(0.1, 0.1)
|
||||
end
|
||||
if stage >= 2 then
|
||||
spawnEnemy(0.2, 0.1)
|
||||
spawnEnemy(0.3, 0.1)
|
||||
end
|
||||
spawnEnemy(0.4, 0.1)
|
||||
spawnEnemy(0.5, 0.1)
|
||||
spawnEnemy(0.6, 0.1)
|
||||
spawnEnemy(0.7, 0.1)
|
||||
spawnEnemy(0.8, 0.1)
|
||||
spawnEnemy(0.9, 0.1)
|
||||
spawnEnemy(0.15, 0.2)
|
||||
spawnEnemy(0.25, 0.2)
|
||||
if stage >= 2 then
|
||||
spawnEnemy(0.7, 0.1)
|
||||
spawnEnemy(0.8, 0.1)
|
||||
end
|
||||
if stage >= 3 then
|
||||
spawnEnemy(0.9, 0.1)
|
||||
end
|
||||
|
||||
-- Second row
|
||||
if stage >= 3 then
|
||||
spawnEnemy(0.15, 0.2)
|
||||
end
|
||||
if stage >= 2 then
|
||||
spawnEnemy(0.25, 0.2)
|
||||
end
|
||||
spawnEnemy(0.35, 0.2)
|
||||
spawnEnemy(0.45, 0.2)
|
||||
spawnEnemy(0.55, 0.2)
|
||||
spawnEnemy(0.65, 0.2)
|
||||
spawnEnemy(0.75, 0.2)
|
||||
spawnEnemy(0.85, 0.2)
|
||||
if stage >= 2 then
|
||||
spawnEnemy(0.75, 0.2)
|
||||
end
|
||||
if stage >= 3 then
|
||||
spawnEnemy(0.85, 0.2)
|
||||
end
|
||||
|
||||
state = states.gameplay
|
||||
-- Third row
|
||||
if stage >= 4 then
|
||||
spawnEnemy(0.1, 0.3)
|
||||
spawnEnemy(0.2, 0.3)
|
||||
spawnEnemy(0.3, 0.3)
|
||||
spawnEnemy(0.4, 0.3)
|
||||
spawnEnemy(0.5, 0.3)
|
||||
spawnEnemy(0.6, 0.3)
|
||||
spawnEnemy(0.7, 0.3)
|
||||
spawnEnemy(0.8, 0.3)
|
||||
spawnEnemy(0.9, 0.3)
|
||||
end
|
||||
|
||||
if stage == 3 or stage >= 5 then
|
||||
unreflected_missiles_max = unreflected_missiles_max + 1
|
||||
end
|
||||
|
||||
state = states.intro
|
||||
end
|
||||
|
||||
function love.load()
|
||||
math.randomseed(os.time())
|
||||
|
||||
local width, height = love.graphics.getDimensions()
|
||||
setScreenDimensions(width, height)
|
||||
|
||||
movePaddle(window_width / 2)
|
||||
|
||||
unreflected_missiles_max = 1
|
||||
|
||||
cities = {}
|
||||
spawnCities()
|
||||
|
||||
state = states.title
|
||||
end
|
||||
|
||||
|
@ -294,7 +336,7 @@ function updateExplosions(dt)
|
|||
|
||||
explosion.remaining = explosion.remaining - dt
|
||||
|
||||
if explosion.remaining < explosion_duration * 0.2 then
|
||||
if explosion.remaining < explosion_duration * 0.2 and state == states.gameplay then
|
||||
-- Destroy cities within range
|
||||
for _, city in ipairs(cities) do
|
||||
local dx = city.x - explosion.x
|
||||
|
@ -352,9 +394,37 @@ function love.update(dt)
|
|||
unreflected_missiles_allowed = unreflected_missiles_allowed + 1
|
||||
end
|
||||
|
||||
if #explosions == 0 and #missiles == 0 and #enemies == 0 then
|
||||
love.event.quit()
|
||||
if #enemies == 0 then
|
||||
state = states.outro
|
||||
time = 0
|
||||
explodeAllMissiles()
|
||||
end
|
||||
elseif state == states.outro then
|
||||
updateMissiles(dt)
|
||||
updateExplosions(dt)
|
||||
|
||||
if #explosions == 0 then
|
||||
time = time + dt
|
||||
if time >= outro_duration then
|
||||
stage = stage + 1
|
||||
startStage()
|
||||
end
|
||||
end
|
||||
elseif state == states.intro then
|
||||
time = time + dt
|
||||
if time >= intro_duration then
|
||||
time = 0
|
||||
state = states.gameplay
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function explodeAllMissiles()
|
||||
for _, missile in ipairs(missiles) do
|
||||
spawnExplosion(missile.x, missile.y)
|
||||
-- Freeze the missile
|
||||
missile.dx = 0
|
||||
missile.dy = 0
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -505,7 +575,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 +599,20 @@ function drawTextCentered(y, text_scale, text)
|
|||
end
|
||||
|
||||
function love.draw()
|
||||
if state == states.gameplay then
|
||||
if state == states.gameplay or state == states.outro 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
|
||||
|
|
Loading…
Reference in New Issue