Add launcher, level borders
parent
f8bff917f1
commit
3e06a6d970
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
67
main.lua
67
main.lua
|
|
@ -1,15 +1,72 @@
|
||||||
|
local tau = math.pi * 2
|
||||||
local game = {}
|
local game = {}
|
||||||
|
|
||||||
function love.load(arg)
|
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.bubble_diameter = 60
|
||||||
game.images.background_width = game.images.background:getWidth()
|
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
|
end
|
||||||
|
|
||||||
function love.draw()
|
function love.draw()
|
||||||
love.graphics.draw(game.images.background, 0, 0)
|
-- draw background
|
||||||
love.graphics.draw(game.images.background, game.images.background_width, 0)
|
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
|
end
|
||||||
|
|
||||||
function love.keypressed(key, scan_code, is_repeat)
|
function love.keypressed(key, scan_code, is_repeat)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue