Add cities

This commit is contained in:
Juhani Krekelä 2023-06-02 16:12:36 +03:00
parent 50f7b00f57
commit a2bbb127c3
1 changed files with 33 additions and 0 deletions

View File

@ -9,6 +9,10 @@ local missiles = {}
local missile_radius = 0.005
local missile_trail_length = 7
local cities = {}
local city_width = 0.07
local city_height = 0.05
local window_width = nil
local window_height = nil
local viewport_x_offset = nil
@ -47,10 +51,26 @@ function love.load()
local width, height = love.graphics.getDimensions()
setScreenDimensions(width, height)
movePaddle(0)
spawnCities()
spawnMissile(0.5, 0.1, -0.1, -0.2)
spawnMissile(0.5, 0.1, 0.1, 0.1)
end
function spawnCities()
local number_of_cities = 7
cities = {}
for i = 1, number_of_cities do
local city_x = ((i - 0.5) / number_of_cities) * (1 - 2*wall_thickness) + wall_thickness
local city_y = 1 - city_height/2
table.insert(cities, {
x = city_x,
y = city_y,
alive = true
})
end
end
function spawnMissile(x, y, dx, dy)
table.insert(missiles, {
x = x,
@ -196,7 +216,20 @@ function drawPaddle()
love.graphics.rectangle('fill', x, y, width, height)
end
function drawCities()
love.graphics.setColor(1, 1, 1)
for _, city in ipairs(cities) do
if city.alive then
local x, y = toScreenCoordinates(city.x - city_width/2, city.y - city_height/2)
local width = toScreenSize(city_width)
local height = toScreenSize(city_height)
love.graphics.rectangle('fill', x, y, width, height)
end
end
end
function love.draw()
drawCities()
drawWalls()
drawMissiles()
drawPaddle()