Launch bubble on mouse press
parent
942c929c79
commit
1603242321
42
main.lua
42
main.lua
|
|
@ -33,6 +33,7 @@ function love.load(arg)
|
||||||
|
|
||||||
game.bubble_diameter = 60
|
game.bubble_diameter = 60
|
||||||
game.bubble_radius = game.bubble_diameter / 2
|
game.bubble_radius = game.bubble_diameter / 2
|
||||||
|
game.bubble_speed = 900 -- px/s
|
||||||
|
|
||||||
-- vertical distance between bubble center points
|
-- vertical distance between bubble center points
|
||||||
game.row_gap = math.ceil(math.sqrt(
|
game.row_gap = math.ceil(math.sqrt(
|
||||||
|
|
@ -108,7 +109,20 @@ function love.load(arg)
|
||||||
game.bubble_type_counts[bubble_type] = game.bubble_type_counts[bubble_type] + 1
|
game.bubble_type_counts[bubble_type] = game.bubble_type_counts[bubble_type] + 1
|
||||||
end
|
end
|
||||||
game.next_bubble_index = 1
|
game.next_bubble_index = 1
|
||||||
game.next_bubble_type = get_next_bubble_type(game.next_bubble_index, bubble_types)
|
game.next_bubble = {
|
||||||
|
x = game.launcher_x,
|
||||||
|
y = game.launcher_y,
|
||||||
|
bubble_type = get_next_bubble_type(game.next_bubble_index, bubble_types),
|
||||||
|
velocity_x = 0,
|
||||||
|
velocity_y = 0
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
function love.update(dt)
|
||||||
|
if game.next_bubble.velocity_x ~= 0 or game.next_bubble.velocity_y ~= 0 then
|
||||||
|
game.next_bubble.x = game.next_bubble.x + game.next_bubble.velocity_x * dt
|
||||||
|
game.next_bubble.y = game.next_bubble.y + game.next_bubble.velocity_y * dt
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.draw()
|
function love.draw()
|
||||||
|
|
@ -167,17 +181,27 @@ function love.draw()
|
||||||
-- draw next bubble
|
-- draw next bubble
|
||||||
love.graphics.setColor(1, 1, 1, 1)
|
love.graphics.setColor(1, 1, 1, 1)
|
||||||
love.graphics.draw(
|
love.graphics.draw(
|
||||||
game.bubble_images[game.next_bubble_type], -- image
|
game.bubble_images[game.next_bubble.bubble_type],
|
||||||
game.launcher_x, -- x
|
game.next_bubble.x,
|
||||||
game.launcher_y, -- y
|
game.next_bubble.y,
|
||||||
0, -- rotation
|
0,
|
||||||
1, -- x scale
|
1,
|
||||||
1, -- y scale
|
1,
|
||||||
game.bubble_radius, -- x offset
|
game.bubble_radius,
|
||||||
game.bubble_radius -- y offset
|
game.bubble_radius
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function love.mousepressed(x, y, button, is_touch, presses)
|
||||||
|
if button == 1 then
|
||||||
|
local diff_x = x - game.launcher_x
|
||||||
|
local diff_y = y - game.launcher_y
|
||||||
|
local dist = math.sqrt(diff_x * diff_x + diff_y * diff_y)
|
||||||
|
game.next_bubble.velocity_x = diff_x / dist * game.bubble_speed
|
||||||
|
game.next_bubble.velocity_y = diff_y / dist * game.bubble_speed
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function love.mousemoved(x, y, dx, dy, is_touch)
|
function love.mousemoved(x, y, dx, dy, is_touch)
|
||||||
local diff_x = x - game.launcher_x
|
local diff_x = x - game.launcher_x
|
||||||
local diff_y = y - game.launcher_y
|
local diff_y = y - game.launcher_y
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue