diff --git a/images/blue.png b/images/blue.png new file mode 100644 index 0000000..f4fc718 Binary files /dev/null and b/images/blue.png differ diff --git a/images/green.png b/images/green.png new file mode 100644 index 0000000..476819d Binary files /dev/null and b/images/green.png differ diff --git a/images/orange.png b/images/orange.png new file mode 100644 index 0000000..545c009 Binary files /dev/null and b/images/orange.png differ diff --git a/images/pink.png b/images/pink.png new file mode 100644 index 0000000..a562be0 Binary files /dev/null and b/images/pink.png differ diff --git a/images/purple.png b/images/purple.png new file mode 100644 index 0000000..9c8af6d Binary files /dev/null and b/images/purple.png differ diff --git a/images/red.png b/images/red.png new file mode 100644 index 0000000..aba6fcc Binary files /dev/null and b/images/red.png differ diff --git a/images/white.png b/images/white.png new file mode 100644 index 0000000..0379b24 Binary files /dev/null and b/images/white.png differ diff --git a/images/yellow.png b/images/yellow.png new file mode 100644 index 0000000..1bfb3a1 Binary files /dev/null and b/images/yellow.png differ diff --git a/main.lua b/main.lua index 6442bfc..d8ad146 100644 --- a/main.lua +++ b/main.lua @@ -1,6 +1,28 @@ local tau = math.pi * 2 local game = {} +local function load_level(level, bubble_diameter, row_gap) + local slots = {} + local bubble_radius = bubble_diameter / 2 + + -- set prev_num_cols to size of 2nd row so x_offset is correct when row == 1 + local prev_num_cols = #level[2] + for row = 1, #level do + local num_cols = #level[row] + local x_offset = num_cols < prev_num_cols and bubble_radius or 0 + for col = 1, num_cols do + slots[#slots+1] = { + x = x_offset + bubble_radius + (col - 1) * bubble_diameter, + y = bubble_radius + (row - 1) * row_gap, + bubble_type = level[row][col] + } + end + prev_num_cols = num_cols + end + + return slots +end + function love.load(arg) game.window_width, game.window_height = love.graphics.getDimensions() @@ -16,8 +38,44 @@ function love.load(arg) 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.bubble_images = { + love.graphics.newImage('images/red.png'), -- 1 + love.graphics.newImage('images/orange.png'), -- 2 + love.graphics.newImage('images/yellow.png'), -- 3 + love.graphics.newImage('images/green.png'), -- 4 + love.graphics.newImage('images/blue.png'), -- 5 + love.graphics.newImage('images/purple.png'), -- 6 + love.graphics.newImage('images/pink.png'), -- 7 + love.graphics.newImage('images/white.png') -- 8 + } + + game.levels = {} + game.levels[1] = { + {1,1,1,3,3,2,2,2}, + { 1,1,3,3,3,2,2 }, + {4,4,7,8,8,6,5,5}, + { 4,7,7,8,6,6,5 }, + {0,0,0,0,0,0,0,0}, + { 0,0,0,0,0,0,0 }, + {0,0,0,0,0,0,0,0}, + { 0,0,0,0,0,0,0 }, + {0,0,0,0,0,0,0,0}, + { 0,0,0,0,0,0,0 }, + {0,0,0,0,0,0,0,0}, + { 0,0,0,0,0,0,0 }, + {0,0,0,0,0,0,0,0}, + { 0,0,0,0,0,0,0 } + } + game.current_level = 1 + + game.bubble_slots = load_level( + game.levels[game.current_level], game.bubble_diameter, game.row_gap + ) + local bubbles_wide = math.max( + #game.levels[game.current_level][1], + #game.levels[game.current_level][2] + ) + local bubbles_high = #game.levels[game.current_level] 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 @@ -39,6 +97,29 @@ function love.draw() love.graphics.draw(game.background_image, 0, 0) love.graphics.draw(game.background_image, game.background_width, 0) + 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 + love.graphics.draw( + game.bubble_images[slot.bubble_type], -- image + game.level_x + slot.x, -- x + game.level_y + slot.y, -- y + 0, -- rotation + 1, -- x scale + 1, -- y scale + game.bubble_radius, -- x offset + game.bubble_radius -- y offset + ) + else + love.graphics.circle( + 'line', + game.level_x + slot.x, + game.level_y + slot.y, + game.bubble_radius + ) + end + end + -- draw level border love.graphics.setColor(0, 0, 0, 1) love.graphics.rectangle(