Compare commits

...

6 Commits

1 changed files with 103 additions and 50 deletions

153
main.lua
View File

@ -297,12 +297,15 @@ 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')
game.game_over = false
game.fade_to_grey_tween = {p = 1.0}
game.fade_to_grey = {time = 0, duration = 120, progress = 0.0}
game.paused = false
game.frame_by_frame = false
@ -396,13 +399,14 @@ function love.load(arg)
bubble_types[#bubble_types+1] = bubble_type
end
end
game.next_bubble = {
game.current_bubble = {
x = game.launcher_x,
y = game.launcher_y,
bubble_type = get_next_bubble_type(game.bubbles_launched+1, bubble_types),
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 = {}
@ -422,15 +426,13 @@ function love.load(arg)
end
function love.update(dt)
if game.game_over and game.fade_to_grey_tween.p < 1.0 then
game.fade_to_grey_tween.t = game.fade_to_grey_tween.t + 1
game.fade_to_grey_tween.p = easing.linear(
game.fade_to_grey_tween.t,
game.fade_to_grey_tween.b,
game.fade_to_grey_tween.c,
game.fade_to_grey_tween.d
)
game.shader:send("progress", game.fade_to_grey_tween.p)
if game.game_over then
if game.fade_to_grey.time < game.fade_to_grey.duration then
game.fade_to_grey.time = game.fade_to_grey.time + 1
game.fade_to_grey.progress =
game.fade_to_grey.time / game.fade_to_grey.duration
game.shader:send("progress", game.fade_to_grey.progress)
end
end
if game.paused or game.game_over then
@ -471,7 +473,8 @@ function love.update(dt)
if game.bubble_slots[i].bubble_type ~= 0 and
game.bubble_slots[i].y > game.level_bottom then
game.game_over = true
game.fade_to_grey_tween = {t = 0, d = 120, b = 0, c = 1, p = 0.0}
game.fade_to_grey.time = 0
game.fade_to_grey.progress = 0.0
end
end
if game.game_over then
@ -480,27 +483,30 @@ function love.update(dt)
if game.ceiling_drop_tween.t == game.ceiling_drop_tween.d then
game.ceiling_drop_tween = nil
end
if game.show_aim_guide then
generate_aim_guide(love.mouse:getX(), love.mouse:getY())
end
end
if game.next_bubble and
(game.next_bubble.velocity_x ~= 0 or game.next_bubble.velocity_y ~= 0) then
if game.current_bubble and
(game.current_bubble.velocity_x ~= 0 or game.current_bubble.velocity_y ~= 0) then
local movement_info
movement_info = move_bubble(
game.next_bubble.x,
game.next_bubble.y,
game.next_bubble.velocity_x,
game.next_bubble.velocity_y
game.current_bubble.x,
game.current_bubble.y,
game.current_bubble.velocity_x,
game.current_bubble.velocity_y
)
game.next_bubble.x = movement_info.x
game.next_bubble.y = movement_info.y
game.next_bubble.velocity_x = movement_info.velocity_x
game.next_bubble.velocity_y = movement_info.velocity_y
game.current_bubble.x = movement_info.x
game.current_bubble.y = movement_info.y
game.current_bubble.velocity_x = movement_info.velocity_x
game.current_bubble.velocity_y = movement_info.velocity_y
if movement_info.should_stop then
game.bubble_slots[movement_info.nearest_slot_index].bubble_type =
game.next_bubble.bubble_type
game.current_bubble.bubble_type
if game.ceiling_should_drop then
game.ceiling_drop_tween = {
@ -510,17 +516,19 @@ function love.update(dt)
c = game.row_gap
}
end
game.ceiling_should_drop = false
local matches = find_matches(movement_info.nearest_slot_index)
if #matches < 3 and game.next_bubble.y > game.level_bottom then
if #matches < 3 and game.current_bubble.y > game.level_bottom then
game.game_over = true
game.fade_to_grey_tween = {t = 0, d = 120, b = 0, c = 1, p = 0.0}
game.fade_to_grey.time = 0
game.fade_to_grey.progress = 0.0
return
end
if #matches >= 3 then
game.next_bubble = nil
game.current_bubble = nil
-- remove matches
for i = 1, #matches do
@ -596,13 +604,14 @@ function love.update(dt)
end
end
-- get next bubble
game.next_bubble = {
game.current_bubble = {
x = game.launcher_x,
y = game.launcher_y,
bubble_type = get_next_bubble_type(game.bubbles_launched+1, bubble_types),
bubble_type = game.next_bubble_type,
velocity_x = 0,
velocity_y = 0
}
game.next_bubble_type = get_next_bubble_type(game.bubbles_launched+2, bubble_types)
end
end
end
@ -691,11 +700,38 @@ function love.draw(alpha)
)
end
-- draw ceiling drop indicator
love.graphics.setColor(0, 0, 0, 1)
for i = 1, game.ceiling_drops_after do
love.graphics.circle(
'line',
game.level_left + (i - 1) * 15 + 15,
game.level_bottom + 15,
6
)
end
love.graphics.setColor(1, 1, 1, 1)
local ceiling_progress = game.bubbles_launched % game.ceiling_drops_after
for i = 1, ceiling_progress do
love.graphics.circle(
'fill',
game.level_left + (i - 1) * 15 + 15,
game.level_bottom + 15,
5
)
end
if game.game_over then
love.graphics.setShader(game.shader)
end
-- draw stationary bubbles
local ceiling_drops_in = game.ceiling_drops_after - ceiling_progress
if not game.game_over and (ceiling_drops_in == 1 or game.ceiling_should_drop) then
local dx = love.math.random(-2, 2)
local dy = love.math.random(-2, 2)
love.graphics.translate(dx, dy)
end
love.graphics.setColor(1, 1, 1, 1)
for i = 1, #game.bubble_slots do
local slot = game.bubble_slots[i]
@ -710,6 +746,7 @@ function love.draw(alpha)
)
end
end
love.graphics.origin()
-- draw launcher
love.graphics.setColor(1, 1, 1, 1)
@ -773,14 +810,14 @@ function love.draw(alpha)
end
end
-- draw next bubble
-- draw current bubble
-- if moving, extrapolate position based on alpha value from love.run
if game.next_bubble then
if game.current_bubble then
love.graphics.setColor(1, 1, 1, 1)
love.graphics.draw(
game.bubble_images[game.next_bubble.bubble_type],
game.next_bubble.x + game.next_bubble.velocity_x * alpha,
game.next_bubble.y + game.next_bubble.velocity_y * alpha,
game.bubble_images[game.current_bubble.bubble_type],
game.current_bubble.x + game.current_bubble.velocity_x * alpha,
game.current_bubble.y + game.current_bubble.velocity_y * alpha,
0,
1,
1,
@ -789,6 +826,19 @@ function love.draw(alpha)
)
end
-- draw upcoming bubble
love.graphics.setColor(1, 1, 1, 1)
love.graphics.draw(
game.bubble_images[game.next_bubble_type],
game.launcher_x + game.bubble_diameter * 2,
game.launcher_y,
0,
1,
1,
game.bubble_radius,
game.bubble_radius
)
if game.game_over then
love.graphics.setShader()
end
@ -814,42 +864,45 @@ function love.draw(alpha)
end
-- draw game over
if game.game_over and game.fade_to_grey_tween.p == 1.0 then
if game.game_over and game.fade_to_grey.progress == 1.0 then
love.graphics.setColor(0, 0, 0, 0.8)
love.graphics.rectangle(
'fill',
game.level_left + game.bubble_diameter,
game.level_left + 10,
game.window_height / 2 - 80,
game.level_width - game.bubble_diameter * 2,
game.level_width - 20,
160,
20,
20
)
love.graphics.setColor(1, 1, 1, 1)
love.graphics.printf(
'YOU LOSE',
game.level_left,
game.window_height / 2 - 30,
game.level_width,
'center'
love.graphics.draw(
game.game_over_image,
game.window_center_x,
game.window_center_y,
0,
1,
1,
game.game_over_image:getWidth() / 2,
game.game_over_image:getHeight() / 2
)
end
end
function love.mousepressed(x, y, button, is_touch, presses)
if not game.game_over and button == 1 and game.next_bubble and
game.next_bubble.x == game.launcher_x and
game.next_bubble.y == game.launcher_y and
game.next_bubble.velocity_x == 0 and
game.next_bubble.velocity_y == 0 then
if not game.game_over and 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
game.current_bubble.velocity_y == 0 then
local diff_x = x - game.launcher_x
local diff_y = y - game.launcher_y
local dist = math.sqrt(diff_x * diff_x + diff_y * diff_y)
-- TODO: don't allow shooting backwards
game.next_bubble.velocity_x = diff_x / dist * game.bubble_speed
game.next_bubble.velocity_y = diff_y / dist * game.bubble_speed
game.current_bubble.velocity_x = diff_x / dist * game.bubble_speed
game.current_bubble.velocity_y = diff_y / dist * game.bubble_speed
game.bubbles_launched = game.bubbles_launched + 1