From 942c929c795a40098aaf635d68f7a92046c1f2b3 Mon Sep 17 00:00:00 2001 From: Tyler Scott Date: Thu, 3 Feb 2022 13:44:07 +0700 Subject: [PATCH] Draw random bubble on launcher --- main.lua | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/main.lua b/main.lua index d8ad146..be8835b 100644 --- a/main.lua +++ b/main.lua @@ -23,6 +23,11 @@ local function load_level(level, bubble_diameter, row_gap) return slots 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) 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_y = game.launcher_height / 2 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 function love.draw() @@ -97,6 +117,7 @@ function love.draw() love.graphics.draw(game.background_image, 0, 0) love.graphics.draw(game.background_image, game.background_width, 0) + -- draw stationary bubbles for i = 1, #game.bubble_slots do local slot = game.bubble_slots[i] 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_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 function love.mousemoved(x, y, dx, dy, is_touch)