diff --git a/images/launcher.png b/images/launcher.png new file mode 100644 index 0000000..4a6447f Binary files /dev/null and b/images/launcher.png differ diff --git a/main.lua b/main.lua index 6da5de9..6442bfc 100644 --- a/main.lua +++ b/main.lua @@ -1,15 +1,72 @@ +local tau = math.pi * 2 local game = {} function love.load(arg) - game.images = {} + game.window_width, game.window_height = love.graphics.getDimensions() - game.images.background = love.graphics.newImage('images/background.png') - game.images.background_width = game.images.background:getWidth() + game.bubble_diameter = 60 + game.bubble_radius = game.bubble_diameter / 2 + + -- vertical distance between bubble center points + game.row_gap = math.ceil(math.sqrt( + (game.bubble_diameter * game.bubble_diameter) - + (game.bubble_radius * game.bubble_radius) + )) + + game.background_image = love.graphics.newImage('images/background.png') + game.background_width = game.background_image:getWidth() + + local bubbles_wide = 8 + local bubbles_high = 14 + game.level_width = bubbles_wide * game.bubble_diameter + game.level_height = (bubbles_high - 1) * game.row_gap + game.bubble_diameter + game.level_x = (game.window_width - game.level_width) / 2 + game.level_y = game.bubble_radius + + game.launcher_image = love.graphics.newImage('images/launcher.png') + game.launcher_height = game.launcher_image:getHeight() + game.launcher_width = game.launcher_image:getWidth() + game.launcher_x = game.window_width / 2 + game.launcher_y = game.level_y + game.level_height + game.bubble_diameter + game.launcher_offset_x = 90 -- rotation point in launcher image + game.launcher_offset_y = game.launcher_height / 2 + game.launcher_rotation = -tau / 4 -- up end function love.draw() - love.graphics.draw(game.images.background, 0, 0) - love.graphics.draw(game.images.background, game.images.background_width, 0) + -- draw background + love.graphics.setColor(1, 1, 1, 1) + love.graphics.draw(game.background_image, 0, 0) + love.graphics.draw(game.background_image, game.background_width, 0) + + -- draw level border + love.graphics.setColor(0, 0, 0, 1) + love.graphics.rectangle( + 'line', + game.level_x, + game.level_y, + game.level_width, + game.level_height + ) + + -- draw launcher + love.graphics.setColor(1, 1, 1, 1) + love.graphics.draw( + game.launcher_image, + game.launcher_x, + game.launcher_y, + game.launcher_rotation, + 1, + 1, + game.launcher_offset_x, + game.launcher_offset_y + ) +end + +function love.mousemoved(x, y, dx, dy, is_touch) + local diff_x = x - game.launcher_x + local diff_y = y - game.launcher_y + game.launcher_rotation = math.atan2(diff_y, diff_x) end function love.keypressed(key, scan_code, is_repeat)