From a2bbb127c3c04a2d1136b411264c19ac4a7695c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Fri, 2 Jun 2023 16:12:36 +0300 Subject: [PATCH] Add cities --- bundle/main.lua | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/bundle/main.lua b/bundle/main.lua index 56ee9a4..82b4950 100644 --- a/bundle/main.lua +++ b/bundle/main.lua @@ -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()