Compare commits
5 commits
ad5d60bfa0
...
891e37fa4f
Author | SHA1 | Date | |
---|---|---|---|
|
891e37fa4f | ||
|
cc73f371a5 | ||
|
c12d3f7bf0 | ||
|
c0b0012701 | ||
|
9a9e57dbd2 |
1 changed files with 100 additions and 8 deletions
108
bundle/main.lua
108
bundle/main.lua
|
@ -7,15 +7,20 @@ local wall_thickness = 0.01
|
|||
|
||||
local missiles = {}
|
||||
local missile_radius = 0.005
|
||||
local missile_trail_length = 7
|
||||
local missile_trail_length = 15
|
||||
|
||||
local cities = {}
|
||||
local city_radius = 0.05
|
||||
|
||||
local explosions = {}
|
||||
local explosion_radius = 0.05
|
||||
local explosion_radius = 0.08
|
||||
local explosion_duration = 0.4
|
||||
|
||||
local enemies = {}
|
||||
local enemy_radius = 0.025
|
||||
local enemy_min_shoot = 5
|
||||
local enemy_max_shoot = 10
|
||||
|
||||
local window_width = nil
|
||||
local window_height = nil
|
||||
local viewport_x_offset = nil
|
||||
|
@ -55,9 +60,16 @@ function love.load()
|
|||
setScreenDimensions(width, height)
|
||||
movePaddle(0)
|
||||
spawnCities()
|
||||
spawnMissile(0.5, 0.1, cities[3].x, cities[3].y, 0.2)
|
||||
spawnMissile(0.1, 0.3, cities[7].x, cities[7].y, 0.2)
|
||||
spawnMissile(0.1, 0.3, cities[3].x, cities[3].y, 0.1)
|
||||
spawnEnemy(0.1, 0.1, false)
|
||||
spawnEnemy(0.2, 0.1, true)
|
||||
spawnEnemy(0.3, 0.1, false)
|
||||
spawnEnemy(0.4, 0.1, true)
|
||||
spawnEnemy(0.5, 0.1, false)
|
||||
spawnEnemy(0.6, 0.1, true)
|
||||
spawnEnemy(0.7, 0.1, false)
|
||||
spawnEnemy(0.8, 0.1, true)
|
||||
spawnEnemy(0.9, 0.1, false)
|
||||
spawnEnemy(0.1, 0.3, true)
|
||||
end
|
||||
|
||||
function spawnCities()
|
||||
|
@ -103,6 +115,16 @@ function spawnExplosion(x, y)
|
|||
})
|
||||
end
|
||||
|
||||
function spawnEnemy(x, y, active)
|
||||
table.insert(enemies, {
|
||||
x = x,
|
||||
y = y,
|
||||
active = active,
|
||||
until_shoot = math.random() * (enemy_max_shoot - enemy_min_shoot),
|
||||
alive = true
|
||||
})
|
||||
end
|
||||
|
||||
function updateMissiles(dt)
|
||||
for _, missile in ipairs(missiles) do
|
||||
missile.x = missile.x + missile.dx * dt
|
||||
|
@ -152,6 +174,20 @@ function updateMissiles(dt)
|
|||
end
|
||||
end
|
||||
|
||||
if missile.reflected then
|
||||
for _, enemy in ipairs(enemies) do
|
||||
local dx = enemy.x - missile.x
|
||||
local dy = enemy.y - missile.y
|
||||
local distance = math.sqrt(dx * dx + dy * dy)
|
||||
if distance < enemy_radius then
|
||||
spawnExplosion(missile.x, missile.y)
|
||||
-- Freeze the missile in-place
|
||||
missile.dx = 0
|
||||
missile.dy = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if collided then
|
||||
table.insert(missile.history, 1, {
|
||||
x = missile.x,
|
||||
|
@ -186,20 +222,30 @@ function updateExplosions(dt)
|
|||
-- Destroy missiles within range
|
||||
for _, missile in ipairs(missiles) do
|
||||
local dx = missile.x - explosion.x
|
||||
local dy = missile.x - explosion.x
|
||||
local dy = missile.y - explosion.y
|
||||
local distance = math.sqrt(dx * dx + dy * dy)
|
||||
if distance < explosion.radius then
|
||||
missile.alive = false
|
||||
end
|
||||
end
|
||||
|
||||
-- Destroy enemies within range
|
||||
for _, enemy in ipairs(enemies) do
|
||||
local dx = enemy.x - explosion.x
|
||||
local dy = enemy.y - explosion.y
|
||||
local distance = math.sqrt(dx * dx + dy * dy)
|
||||
if distance < explosion.radius + enemy_radius then
|
||||
enemy.alive = false
|
||||
end
|
||||
end
|
||||
|
||||
explosion.remaining = explosion.remaining - dt
|
||||
|
||||
if explosion.remaining < explosion_duration * 0.2 then
|
||||
-- Destroy cities within range
|
||||
for _, city in ipairs(cities) do
|
||||
local dx = city.x - explosion.x
|
||||
local dy = city.x - explosion.x
|
||||
local dy = city.y - explosion.y
|
||||
local distance = math.sqrt(dx * dx + dy * dy)
|
||||
if distance < explosion.radius + city_radius then
|
||||
city.alive = false
|
||||
|
@ -215,15 +261,49 @@ function updateExplosions(dt)
|
|||
end
|
||||
end
|
||||
|
||||
function updateEnemies(dt)
|
||||
local i = 1
|
||||
while i <= #enemies do
|
||||
local enemy = enemies[i]
|
||||
|
||||
if enemy.active then
|
||||
enemy.until_shoot = enemy.until_shoot - dt
|
||||
if enemy.until_shoot < 0 then
|
||||
enemy.until_shoot = enemy_min_shoot + math.random() * (enemy_max_shoot - enemy_min_shoot)
|
||||
local target = cities[math.random(1, #cities)]
|
||||
spawnMissile(enemy.x, enemy.y, target.x, target.y, 0.2)
|
||||
end
|
||||
end
|
||||
|
||||
if not enemy.alive then
|
||||
table.remove(enemies, i)
|
||||
else
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function love.update(dt)
|
||||
updateMissiles(dt)
|
||||
updateExplosions(dt)
|
||||
updateEnemies(dt)
|
||||
|
||||
if #explosions == 0 and #missiles == 0 then
|
||||
if #explosions == 0 and #missiles == 0 and #enemies == 0 then
|
||||
love.event.quit()
|
||||
end
|
||||
end
|
||||
|
||||
function explodeAllReflected()
|
||||
for _, missile in ipairs(missiles) do
|
||||
if missile.reflected then
|
||||
spawnExplosion(missile.x, missile.y)
|
||||
-- Freeze the missile
|
||||
missile.dx = 0
|
||||
missile.dy = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function movePaddle(screen_x)
|
||||
paddle_x = fromScreenCoordinate(screen_x, 0)
|
||||
paddle_x = math.max(paddle_x, paddle_width/2 + wall_thickness)
|
||||
|
@ -233,6 +313,8 @@ end
|
|||
|
||||
love.mousemoved = movePaddle
|
||||
|
||||
love.mousepressed = explodeAllReflected
|
||||
|
||||
love.resize = setScreenDimensions
|
||||
|
||||
function drawWalls()
|
||||
|
@ -312,10 +394,20 @@ function drawExplosions()
|
|||
end
|
||||
end
|
||||
|
||||
function drawEnemies()
|
||||
for _, enemy in ipairs(enemies) do
|
||||
love.graphics.setColor(0.7, 0.5, 1)
|
||||
local x, y = toScreenCoordinates(enemy.x, enemy.y)
|
||||
local radius = toScreenSize(enemy_radius)
|
||||
love.graphics.circle('fill', x, y, radius)
|
||||
end
|
||||
end
|
||||
|
||||
function love.draw()
|
||||
drawCities()
|
||||
drawWalls()
|
||||
drawMissiles()
|
||||
drawPaddle()
|
||||
drawEnemies()
|
||||
drawExplosions()
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue