Allow resetting the level after game over

main
Tyler Scott 2022-02-13 07:18:00 +07:00
parent 22ce65d003
commit 214a73c2e0
1 changed files with 80 additions and 65 deletions

145
main.lua
View File

@ -293,68 +293,15 @@ local function find_unattached_bubbles()
return unattached
end
function love.load(arg)
if arg[#arg] == "debug" then require("lldebugger").start() end
game.window_width, game.window_height = love.graphics.getDimensions()
game.window_center_x = game.window_width / 2
game.window_center_y = game.window_height / 2
game.score_font = love.graphics.setNewFont(50)
game.points_font = love.graphics.newFont(30)
game.game_over_image = love.graphics.newImage('images/game_over.png')
local function start_level()
game.game_over = false
game.fade_to_grey = {time = 0, duration = 120, progress = 0.0}
game.paused = false
game.fade_to_grey = {time = 0, duration = 120, progress = 0.0}
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
-- vertical distance between bubble center points
game.row_gap = math.ceil(math.sqrt(
(game.bubble_diameter * game.bubble_diameter) -
(game.bubble_radius * game.bubble_radius)
))
game.background_image = love.graphics.newImage('images/background.png')
game.background_width = game.background_image:getWidth()
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.frame_counter = 0
game.timer = 0
game.score = 0
game.points_display = {}
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.bubbles_launched = 0
game.ceiling_drops_after = 5
game.ceiling_drop_tween = nil
@ -381,17 +328,10 @@ function love.load(arg)
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
@ -408,8 +348,75 @@ function love.load(arg)
}
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()
game.window_center_x = game.window_width / 2
game.window_center_y = game.window_height / 2
game.score_font = love.graphics.setNewFont(50)
game.points_font = love.graphics.newFont(30)
game.game_over_image = love.graphics.newImage('images/game_over.png')
game.bubble_diameter = 60
game.bubble_radius = game.bubble_diameter / 2
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(
(game.bubble_diameter * game.bubble_diameter) -
(game.bubble_radius * game.bubble_radius)
))
game.background_image = love.graphics.newImage('images/background.png')
game.background_width = game.background_image:getWidth()
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.launcher_image = love.graphics.newImage('images/launcher.png')
game.launcher_height = game.launcher_image:getHeight()
game.launcher_width = game.launcher_image:getWidth()
game.launcher_offset_x = 90 -- rotation point in launcher image
game.launcher_offset_y = game.launcher_height / 2
game.shader = love.graphics.newShader [[
uniform float progress;
@ -423,6 +430,8 @@ function love.load(arg)
return pixel;
}
]]
start_level()
end
function love.update(dt)
@ -891,7 +900,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 +944,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