Compare commits

..

2 Commits

Author SHA1 Message Date
Tyler Scott cf0ff8a026 Vertically center level 2022-02-13 07:37:50 +07:00
Tyler Scott 214a73c2e0 Allow resetting the level after game over 2022-02-13 07:26:40 +07:00
1 changed files with 77 additions and 59 deletions

136
main.lua
View File

@ -293,7 +293,73 @@ local function find_unattached_bubbles()
return unattached
end
function love.load(arg)
local function start_level()
game.game_over = false
game.paused = false
game.fade_to_grey = {time = 0, duration = 120, progress = 0.0}
game.frame_by_frame = false
game.frame_counter = 0
game.timer = 0
game.score = 0
game.points_display = {}
game.bubbles_launched = 0
game.ceiling_drops_after = 5
game.ceiling_drop_tween = nil
game.ceiling_should_drop = false
game.bubble_slots = load_level(
game.levels[game.current_level], game.bubble_diameter, game.row_gap
)
local max_cols = math.max(
#game.levels[game.current_level][1],
#game.levels[game.current_level][2]
)
local num_rows = #game.levels[game.current_level]
game.level_width = max_cols * game.bubble_diameter
game.level_height = (num_rows - 1) * game.row_gap + game.bubble_diameter
game.level_left = (game.window_width - game.level_width) / 2
game.level_top = (
game.window_height - game.level_height -
game.bubble_diameter - game.bubble_radius
) / 2
game.level_right = game.level_left + game.level_width
game.level_bottom = game.level_top + game.level_height
game.ceiling_bottom = game.level_top
for i = 1, #game.bubble_slots do
game.bubble_slots[i].x = game.bubble_slots[i].x + game.level_left
game.bubble_slots[i].y = game.bubble_slots[i].y + game.ceiling_bottom
end
game.launcher_x = game.window_width / 2
game.launcher_y = game.level_bottom + game.bubble_diameter
game.launcher_rotation = -tau / 4 -- up
local total_bubble_count, counts_by_type = get_bubble_counts()
local bubble_types = {}
for bubble_type, count in pairs(counts_by_type) do
if bubble_type >= 1 and bubble_type <= 8 then
bubble_types[#bubble_types+1] = bubble_type
end
end
game.current_bubble = {
x = game.launcher_x,
y = game.launcher_y,
bubble_type = get_next_bubble_type(1, bubble_types),
velocity_x = 0,
velocity_y = 0
}
game.next_bubble_type = get_next_bubble_type(2, bubble_types)
game.show_aim_guide = true
game.aim_guide = {}
generate_aim_guide(game.window_width / 2, game.window_height / 2)
game.bursting_bubbles = {}
game.falling_bubbles = {}
end
function love.load(arg, unfiltered_arg)
if arg[#arg] == "debug" then require("lldebugger").start() end
game.window_width, game.window_height = love.graphics.getDimensions()
@ -304,14 +370,10 @@ function love.load(arg)
game.points_font = love.graphics.newFont(30)
game.game_over_image = love.graphics.newImage('images/game_over.png')
game.game_over = false
game.fade_to_grey = {time = 0, duration = 120, progress = 0.0}
game.paused = false
game.frame_by_frame = false
game.bubble_diameter = 60
game.bubble_radius = game.bubble_diameter / 2
game.bubble_speed = 960 * delta_time -- 960 px/s
game.bubble_speed = 960 * delta_time -- 960 px/s = 8 px/frame
-- vertical distance between bubble center points
game.row_gap = math.ceil(math.sqrt(
@ -333,9 +395,6 @@ function love.load(arg)
love.graphics.newImage('images/white.png') -- 8
}
game.score = 0
game.points_display = {}
game.levels = {}
game.levels[1] = {
{1,1,1,3,3,2,2,2},
@ -355,61 +414,12 @@ function love.load(arg)
}
game.current_level = 1
game.bubbles_launched = 0
game.ceiling_drops_after = 5
game.ceiling_drop_tween = nil
game.ceiling_should_drop = false
game.bubble_slots = load_level(
game.levels[game.current_level], game.bubble_diameter, game.row_gap
)
local max_cols = math.max(
#game.levels[game.current_level][1],
#game.levels[game.current_level][2]
)
local num_rows = #game.levels[game.current_level]
game.level_width = max_cols * game.bubble_diameter
game.level_height = (num_rows - 1) * game.row_gap + game.bubble_diameter
game.level_left = (game.window_width - game.level_width) / 2
game.level_top = game.bubble_radius
game.level_right = game.level_left + game.level_width
game.level_bottom = game.level_top + game.level_height
game.ceiling_bottom = game.level_top
for i = 1, #game.bubble_slots do
game.bubble_slots[i].x = game.bubble_slots[i].x + game.level_left
game.bubble_slots[i].y = game.bubble_slots[i].y + game.ceiling_bottom
end
game.launcher_image = love.graphics.newImage('images/launcher.png')
game.launcher_height = game.launcher_image:getHeight()
game.launcher_width = game.launcher_image:getWidth()
game.launcher_x = game.window_width / 2
game.launcher_y = game.level_top + game.level_height + game.bubble_diameter
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.show_aim_guide = true
game.aim_guide = {}
local total_bubble_count, counts_by_type = get_bubble_counts()
local bubble_types = {}
for bubble_type, count in pairs(counts_by_type) do
if bubble_type >= 1 and bubble_type <= 8 then
bubble_types[#bubble_types+1] = bubble_type
end
end
game.current_bubble = {
x = game.launcher_x,
y = game.launcher_y,
bubble_type = get_next_bubble_type(1, bubble_types),
velocity_x = 0,
velocity_y = 0
}
game.next_bubble_type = get_next_bubble_type(2, bubble_types)
game.bursting_bubbles = {}
game.falling_bubbles = {}
game.shader = love.graphics.newShader [[
uniform float progress;
@ -423,6 +433,8 @@ function love.load(arg)
return pixel;
}
]]
start_level()
end
function love.update(dt)
@ -891,7 +903,11 @@ function love.draw(alpha)
end
function love.mousepressed(x, y, button, is_touch, presses)
if not game.game_over and button == 1 and game.current_bubble and
if game.game_over then
start_level()
return
end
if button == 1 and game.current_bubble and
game.current_bubble.x == game.launcher_x and
game.current_bubble.y == game.launcher_y and
game.current_bubble.velocity_x == 0 and
@ -931,6 +947,8 @@ end
function love.keypressed(key, scan_code, is_repeat)
if key == 'escape' then
love.event.quit()
elseif game.game_over or key == 'r' then
start_level()
elseif key == 'space' then
game.paused = not game.paused
elseif key == 'n' and game.paused then