Draw random bubble on launcher

main
Tyler Scott 2022-02-03 13:44:07 +07:00
parent 7d740b893e
commit 942c929c79
1 changed files with 34 additions and 0 deletions

View File

@ -23,6 +23,11 @@ local function load_level(level, bubble_diameter, row_gap)
return slots return slots
end end
-- ex. remaining_bubble_types = {1,4,5,8} -- should only be regular, not special
local function get_next_bubble_type(index, remaining_bubble_types)
return remaining_bubble_types[love.math.random(#remaining_bubble_types)]
end
function love.load(arg) function love.load(arg)
game.window_width, game.window_height = love.graphics.getDimensions() game.window_width, game.window_height = love.graphics.getDimensions()
@ -89,6 +94,21 @@ function love.load(arg)
game.launcher_offset_x = 90 -- rotation point in launcher image game.launcher_offset_x = 90 -- rotation point in launcher image
game.launcher_offset_y = game.launcher_height / 2 game.launcher_offset_y = game.launcher_height / 2
game.launcher_rotation = -tau / 4 -- up game.launcher_rotation = -tau / 4 -- up
game.bubble_type_counts = {}
local bubble_types = {}
for i = 1, #game.bubble_slots do
local bubble_type = game.bubble_slots[i].bubble_type
if game.bubble_type_counts[bubble_type] == nil then
game.bubble_type_counts[bubble_type] = 0
if bubble_type >= 1 and bubble_type <= 8 then
bubble_types[#bubble_types+1] = bubble_type
end
end
game.bubble_type_counts[bubble_type] = game.bubble_type_counts[bubble_type] + 1
end
game.next_bubble_index = 1
game.next_bubble_type = get_next_bubble_type(game.next_bubble_index, bubble_types)
end end
function love.draw() function love.draw()
@ -97,6 +117,7 @@ function love.draw()
love.graphics.draw(game.background_image, 0, 0) love.graphics.draw(game.background_image, 0, 0)
love.graphics.draw(game.background_image, game.background_width, 0) love.graphics.draw(game.background_image, game.background_width, 0)
-- draw stationary bubbles
for i = 1, #game.bubble_slots do for i = 1, #game.bubble_slots do
local slot = game.bubble_slots[i] local slot = game.bubble_slots[i]
if slot.bubble_type >= 1 and slot.bubble_type <= #game.bubble_images then if slot.bubble_type >= 1 and slot.bubble_type <= #game.bubble_images then
@ -142,6 +163,19 @@ function love.draw()
game.launcher_offset_x, game.launcher_offset_x,
game.launcher_offset_y game.launcher_offset_y
) )
-- draw next bubble
love.graphics.setColor(1, 1, 1, 1)
love.graphics.draw(
game.bubble_images[game.next_bubble_type], -- image
game.launcher_x, -- x
game.launcher_y, -- y
0, -- rotation
1, -- x scale
1, -- y scale
game.bubble_radius, -- x offset
game.bubble_radius -- y offset
)
end end
function love.mousemoved(x, y, dx, dy, is_touch) function love.mousemoved(x, y, dx, dy, is_touch)