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 = nil
|
||||||
local unreflected_missiles_allowed = nil
|
local unreflected_missiles_allowed = nil
|
||||||
local unreflected_missiles_allowed_ramp_up = 10
|
local unreflected_missiles_allowed_ramp_up = 10
|
||||||
local unreflected_missiles_max = 7
|
local unreflected_missiles_max = nil
|
||||||
|
|
||||||
local cities = nil
|
local cities = nil
|
||||||
local city_radius = 0.05
|
local city_radius = 0.05
|
||||||
|
@ -32,6 +32,7 @@ local enemy_max_shoot = 10
|
||||||
local enemy_inaccuracy = 0.05
|
local enemy_inaccuracy = 0.05
|
||||||
|
|
||||||
local intro_duration = 1
|
local intro_duration = 1
|
||||||
|
local outro_duration = 0.5
|
||||||
|
|
||||||
local stage = 1
|
local stage = 1
|
||||||
|
|
||||||
|
@ -43,7 +44,7 @@ local scale = nil
|
||||||
|
|
||||||
local time = 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
|
local state = nil
|
||||||
|
|
||||||
font = require("font")
|
font = require("font")
|
||||||
|
@ -76,43 +77,83 @@ function fromScreenCoordinate(x, y)
|
||||||
end
|
end
|
||||||
|
|
||||||
function startStage()
|
function startStage()
|
||||||
movePaddle(window_width / 2)
|
|
||||||
|
|
||||||
missiles = {}
|
missiles = {}
|
||||||
unreflected_missiles = 0
|
unreflected_missiles = 0
|
||||||
unreflected_missiles_allowed = 0
|
unreflected_missiles_allowed = 0
|
||||||
cities = {}
|
|
||||||
explosions = {}
|
explosions = {}
|
||||||
enemies = {}
|
enemies = {}
|
||||||
time = 0
|
time = 0
|
||||||
|
|
||||||
spawnCities()
|
-- First row
|
||||||
spawnEnemy(0.1, 0.1)
|
if stage >= 3 then
|
||||||
spawnEnemy(0.2, 0.1)
|
spawnEnemy(0.1, 0.1)
|
||||||
spawnEnemy(0.3, 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.4, 0.1)
|
||||||
spawnEnemy(0.5, 0.1)
|
spawnEnemy(0.5, 0.1)
|
||||||
spawnEnemy(0.6, 0.1)
|
spawnEnemy(0.6, 0.1)
|
||||||
spawnEnemy(0.7, 0.1)
|
if stage >= 2 then
|
||||||
spawnEnemy(0.8, 0.1)
|
spawnEnemy(0.7, 0.1)
|
||||||
spawnEnemy(0.9, 0.1)
|
spawnEnemy(0.8, 0.1)
|
||||||
spawnEnemy(0.15, 0.2)
|
end
|
||||||
spawnEnemy(0.25, 0.2)
|
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.35, 0.2)
|
||||||
spawnEnemy(0.45, 0.2)
|
spawnEnemy(0.45, 0.2)
|
||||||
spawnEnemy(0.55, 0.2)
|
spawnEnemy(0.55, 0.2)
|
||||||
spawnEnemy(0.65, 0.2)
|
spawnEnemy(0.65, 0.2)
|
||||||
spawnEnemy(0.75, 0.2)
|
if stage >= 2 then
|
||||||
spawnEnemy(0.85, 0.2)
|
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
|
state = states.intro
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.load()
|
function love.load()
|
||||||
math.randomseed(os.time())
|
math.randomseed(os.time())
|
||||||
|
|
||||||
local width, height = love.graphics.getDimensions()
|
local width, height = love.graphics.getDimensions()
|
||||||
setScreenDimensions(width, height)
|
setScreenDimensions(width, height)
|
||||||
|
|
||||||
|
movePaddle(window_width / 2)
|
||||||
|
|
||||||
|
unreflected_missiles_max = 1
|
||||||
|
|
||||||
|
cities = {}
|
||||||
|
spawnCities()
|
||||||
|
|
||||||
state = states.title
|
state = states.title
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -295,7 +336,7 @@ function updateExplosions(dt)
|
||||||
|
|
||||||
explosion.remaining = explosion.remaining - 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
|
-- Destroy cities within range
|
||||||
for _, city in ipairs(cities) do
|
for _, city in ipairs(cities) do
|
||||||
local dx = city.x - explosion.x
|
local dx = city.x - explosion.x
|
||||||
|
@ -353,8 +394,21 @@ function love.update(dt)
|
||||||
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 #enemies == 0 then
|
||||||
love.event.quit()
|
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
|
end
|
||||||
elseif state == states.intro then
|
elseif state == states.intro then
|
||||||
time = time + dt
|
time = time + dt
|
||||||
|
@ -365,6 +419,15 @@ function love.update(dt)
|
||||||
end
|
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
|
||||||
|
|
||||||
function explodeAllReflected()
|
function explodeAllReflected()
|
||||||
for _, missile in ipairs(missiles) do
|
for _, missile in ipairs(missiles) do
|
||||||
if missile.reflected then
|
if missile.reflected then
|
||||||
|
@ -536,7 +599,7 @@ function drawTextCentered(y, text_scale, text)
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.draw()
|
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()
|
drawCities()
|
||||||
drawWalls()
|
drawWalls()
|
||||||
drawMissiles()
|
drawMissiles()
|
||||||
|
|
Loading…
Reference in New Issue