Draw upcoming bubble next to launcher

main
Tyler Scott 2022-02-12 16:00:56 +07:00
parent 9c86ebb464
commit 29df1c149c
1 changed files with 44 additions and 29 deletions

View File

@ -396,13 +396,14 @@ function love.load(arg)
bubble_types[#bubble_types+1] = bubble_type bubble_types[#bubble_types+1] = bubble_type
end end
end end
game.next_bubble = { game.current_bubble = {
x = game.launcher_x, x = game.launcher_x,
y = game.launcher_y, y = game.launcher_y,
bubble_type = get_next_bubble_type(game.bubbles_launched+1, bubble_types), bubble_type = get_next_bubble_type(1, bubble_types),
velocity_x = 0, velocity_x = 0,
velocity_y = 0 velocity_y = 0
} }
game.next_bubble_type = get_next_bubble_type(2, bubble_types)
game.bursting_bubbles = {} game.bursting_bubbles = {}
game.falling_bubbles = {} game.falling_bubbles = {}
@ -485,25 +486,25 @@ function love.update(dt)
end end
end end
if game.next_bubble and if game.current_bubble and
(game.next_bubble.velocity_x ~= 0 or game.next_bubble.velocity_y ~= 0) then (game.current_bubble.velocity_x ~= 0 or game.current_bubble.velocity_y ~= 0) then
local movement_info local movement_info
movement_info = move_bubble( movement_info = move_bubble(
game.next_bubble.x, game.current_bubble.x,
game.next_bubble.y, game.current_bubble.y,
game.next_bubble.velocity_x, game.current_bubble.velocity_x,
game.next_bubble.velocity_y game.current_bubble.velocity_y
) )
game.next_bubble.x = movement_info.x game.current_bubble.x = movement_info.x
game.next_bubble.y = movement_info.y game.current_bubble.y = movement_info.y
game.next_bubble.velocity_x = movement_info.velocity_x game.current_bubble.velocity_x = movement_info.velocity_x
game.next_bubble.velocity_y = movement_info.velocity_y game.current_bubble.velocity_y = movement_info.velocity_y
if movement_info.should_stop then if movement_info.should_stop then
game.bubble_slots[movement_info.nearest_slot_index].bubble_type = game.bubble_slots[movement_info.nearest_slot_index].bubble_type =
game.next_bubble.bubble_type game.current_bubble.bubble_type
if game.ceiling_should_drop then if game.ceiling_should_drop then
game.ceiling_drop_tween = { game.ceiling_drop_tween = {
@ -517,14 +518,14 @@ function love.update(dt)
local matches = find_matches(movement_info.nearest_slot_index) local matches = find_matches(movement_info.nearest_slot_index)
if #matches < 3 and game.next_bubble.y > game.level_bottom then if #matches < 3 and game.current_bubble.y > game.level_bottom then
game.game_over = true game.game_over = true
game.fade_to_grey_tween = {t = 0, d = 120, b = 0, c = 1, p = 0.0} game.fade_to_grey_tween = {t = 0, d = 120, b = 0, c = 1, p = 0.0}
return return
end end
if #matches >= 3 then if #matches >= 3 then
game.next_bubble = nil game.current_bubble = nil
-- remove matches -- remove matches
for i = 1, #matches do for i = 1, #matches do
@ -600,13 +601,14 @@ function love.update(dt)
end end
end end
-- get next bubble -- get next bubble
game.next_bubble = { game.current_bubble = {
x = game.launcher_x, x = game.launcher_x,
y = game.launcher_y, y = game.launcher_y,
bubble_type = get_next_bubble_type(game.bubbles_launched+1, bubble_types), bubble_type = game.next_bubble_type,
velocity_x = 0, velocity_x = 0,
velocity_y = 0 velocity_y = 0
} }
game.next_bubble_type = get_next_bubble_type(game.bubbles_launched+2, bubble_types)
end end
end end
end end
@ -805,14 +807,14 @@ function love.draw(alpha)
end end
end end
-- draw next bubble -- draw current bubble
-- if moving, extrapolate position based on alpha value from love.run -- if moving, extrapolate position based on alpha value from love.run
if game.next_bubble then if game.current_bubble then
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.bubble_type], game.bubble_images[game.current_bubble.bubble_type],
game.next_bubble.x + game.next_bubble.velocity_x * alpha, game.current_bubble.x + game.current_bubble.velocity_x * alpha,
game.next_bubble.y + game.next_bubble.velocity_y * alpha, game.current_bubble.y + game.current_bubble.velocity_y * alpha,
0, 0,
1, 1,
1, 1,
@ -821,6 +823,19 @@ function love.draw(alpha)
) )
end end
-- draw upcoming bubble
love.graphics.setColor(1, 1, 1, 1)
love.graphics.draw(
game.bubble_images[game.next_bubble_type],
game.launcher_x + game.bubble_diameter * 2,
game.launcher_y,
0,
1,
1,
game.bubble_radius,
game.bubble_radius
)
if game.game_over then if game.game_over then
love.graphics.setShader() love.graphics.setShader()
end end
@ -870,18 +885,18 @@ function love.draw(alpha)
end end
function love.mousepressed(x, y, button, is_touch, presses) function love.mousepressed(x, y, button, is_touch, presses)
if not game.game_over and button == 1 and game.next_bubble and if not game.game_over and button == 1 and game.current_bubble and
game.next_bubble.x == game.launcher_x and game.current_bubble.x == game.launcher_x and
game.next_bubble.y == game.launcher_y and game.current_bubble.y == game.launcher_y and
game.next_bubble.velocity_x == 0 and game.current_bubble.velocity_x == 0 and
game.next_bubble.velocity_y == 0 then game.current_bubble.velocity_y == 0 then
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
local dist = math.sqrt(diff_x * diff_x + diff_y * diff_y) local dist = math.sqrt(diff_x * diff_x + diff_y * diff_y)
-- TODO: don't allow shooting backwards -- TODO: don't allow shooting backwards
game.next_bubble.velocity_x = diff_x / dist * game.bubble_speed game.current_bubble.velocity_x = diff_x / dist * game.bubble_speed
game.next_bubble.velocity_y = diff_y / dist * game.bubble_speed game.current_bubble.velocity_y = diff_y / dist * game.bubble_speed
game.bubbles_launched = game.bubbles_launched + 1 game.bubbles_launched = game.bubbles_launched + 1