Compare commits
No commits in common. "891e37fa4f57fdb465a7269c3322600748dd9775" and "ad5d60bfa0562c43db8f4660280b779f4221ea82" have entirely different histories.
891e37fa4f
...
ad5d60bfa0
1 changed files with 8 additions and 100 deletions
108
bundle/main.lua
108
bundle/main.lua
|
@ -7,20 +7,15 @@ local wall_thickness = 0.01
|
|||
|
||||
local missiles = {}
|
||||
local missile_radius = 0.005
|
||||
local missile_trail_length = 15
|
||||
local missile_trail_length = 7
|
||||
|
||||
local cities = {}
|
||||
local city_radius = 0.05
|
||||
|
||||
local explosions = {}
|
||||
local explosion_radius = 0.08
|
||||
local explosion_radius = 0.05
|
||||
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
|
||||
|
@ -60,16 +55,9 @@ function love.load()
|
|||
setScreenDimensions(width, height)
|
||||
movePaddle(0)
|
||||
spawnCities()
|
||||
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)
|
||||
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)
|
||||
end
|
||||
|
||||
function spawnCities()
|
||||
|
@ -115,16 +103,6 @@ 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
|
||||
|
@ -174,20 +152,6 @@ 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,
|
||||
|
@ -222,30 +186,20 @@ function updateExplosions(dt)
|
|||
-- Destroy missiles within range
|
||||
for _, missile in ipairs(missiles) do
|
||||
local dx = missile.x - explosion.x
|
||||
local dy = missile.y - explosion.y
|
||||
local dy = missile.x - explosion.x
|
||||
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.y - explosion.y
|
||||
local dy = city.x - explosion.x
|
||||
local distance = math.sqrt(dx * dx + dy * dy)
|
||||
if distance < explosion.radius + city_radius then
|
||||
city.alive = false
|
||||
|
@ -261,49 +215,15 @@ 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 and #enemies == 0 then
|
||||
if #explosions == 0 and #missiles == 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)
|
||||
|
@ -313,8 +233,6 @@ end
|
|||
|
||||
love.mousemoved = movePaddle
|
||||
|
||||
love.mousepressed = explodeAllReflected
|
||||
|
||||
love.resize = setScreenDimensions
|
||||
|
||||
function drawWalls()
|
||||
|
@ -394,20 +312,10 @@ 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