Implement multiple stages
This commit is contained in:
parent
7b3ef24b7a
commit
2439711358
103
bundle/main.lua
103
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
|
||||
|
@ -32,6 +32,7 @@ local enemy_max_shoot = 10
|
|||
local enemy_inaccuracy = 0.05
|
||||
|
||||
local intro_duration = 1
|
||||
local outro_duration = 0.5
|
||||
|
||||
local stage = 1
|
||||
|
||||
|
@ -43,7 +44,7 @@ local scale = nil
|
|||
|
||||
local time = nil
|
||||
|
||||
local states = {title = 0, intro = 1, gameplay = 2}
|
||||
local states = {title = 0, intro = 1, outro = 2, gameplay = 3}
|
||||
local state = nil
|
||||
|
||||
font = require("font")
|
||||
|
@ -76,43 +77,83 @@ function fromScreenCoordinate(x, y)
|
|||
end
|
||||
|
||||
function startStage()
|
||||
movePaddle(window_width / 2)
|
||||
|
||||
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
|
||||
|
||||
-- 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
|
||||
|
||||
|
@ -295,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
|
||||
|
@ -353,8 +394,21 @@ 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
|
||||
|
@ -365,6 +419,15 @@ function love.update(dt)
|
|||
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
|
||||
|
||||
function explodeAllReflected()
|
||||
for _, missile in ipairs(missiles) do
|
||||
if missile.reflected then
|
||||
|
@ -536,7 +599,7 @@ function drawTextCentered(y, text_scale, text)
|
|||
end
|
||||
|
||||
function love.draw()
|
||||
if state == states.gameplay or state == states.intro then
|
||||
if state == states.gameplay or state == states.outro or state == states.intro then
|
||||
drawCities()
|
||||
drawWalls()
|
||||
drawMissiles()
|
||||
|
|
Loading…
Reference in New Issue