If bubbles drop too far, fade to grey and game over
parent
efab0a941e
commit
8578bb8877
106
main.lua
106
main.lua
|
|
@ -301,6 +301,8 @@ function love.load(arg)
|
|||
game.score_font = love.graphics.setNewFont(50)
|
||||
game.points_font = love.graphics.newFont(30)
|
||||
|
||||
game.game_over = false
|
||||
game.fade_to_grey_tween = {p = 1.0}
|
||||
game.paused = false
|
||||
game.frame_by_frame = false
|
||||
|
||||
|
|
@ -404,10 +406,34 @@ function love.load(arg)
|
|||
|
||||
game.bursting_bubbles = {}
|
||||
game.falling_bubbles = {}
|
||||
|
||||
game.shader = love.graphics.newShader [[
|
||||
uniform float progress;
|
||||
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords)
|
||||
{
|
||||
vec4 pixel = Texel(texture, texture_coords);
|
||||
number average = (pixel.r + pixel.b + pixel.g) / 3.0;
|
||||
pixel.r = pixel.r + (average-pixel.r) * progress;
|
||||
pixel.g = pixel.g + (average-pixel.g) * progress;
|
||||
pixel.b = pixel.b + (average-pixel.b) * progress;
|
||||
return pixel;
|
||||
}
|
||||
]]
|
||||
end
|
||||
|
||||
function love.update(dt)
|
||||
if game.paused then
|
||||
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)
|
||||
end
|
||||
|
||||
if game.paused or game.game_over then
|
||||
return
|
||||
end
|
||||
|
||||
|
|
@ -439,8 +465,17 @@ function love.update(dt)
|
|||
game.ceiling_drop_tween.c,
|
||||
game.ceiling_drop_tween.d
|
||||
)
|
||||
local diff_y = game.ceiling_bottom - old_y
|
||||
for i = 1, #game.bubble_slots do
|
||||
game.bubble_slots[i].y = game.bubble_slots[i].y + (game.ceiling_bottom - old_y)
|
||||
game.bubble_slots[i].y = game.bubble_slots[i].y + diff_y
|
||||
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}
|
||||
end
|
||||
end
|
||||
if game.game_over then
|
||||
return
|
||||
end
|
||||
if game.ceiling_drop_tween.t == game.ceiling_drop_tween.d then
|
||||
game.ceiling_drop_tween = nil
|
||||
|
|
@ -472,11 +507,18 @@ function love.update(dt)
|
|||
t = 0,
|
||||
d = 30,
|
||||
b = game.ceiling_bottom,
|
||||
c = game.bubble_diameter
|
||||
c = game.row_gap
|
||||
}
|
||||
end
|
||||
|
||||
local matches = find_matches(movement_info.nearest_slot_index)
|
||||
|
||||
if #matches < 3 and game.next_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}
|
||||
return
|
||||
end
|
||||
|
||||
if #matches >= 3 then
|
||||
game.next_bubble = nil
|
||||
|
||||
|
|
@ -718,6 +760,19 @@ function love.draw(alpha)
|
|||
end
|
||||
end
|
||||
|
||||
-- draw aim guide
|
||||
if game.show_aim_guide then
|
||||
love.graphics.setColor(0, 0, 0, 1)
|
||||
for i = 1, #game.aim_guide - 1 do
|
||||
love.graphics.circle(
|
||||
'line',
|
||||
game.aim_guide[i].x,
|
||||
game.aim_guide[i].y,
|
||||
game.aim_guide[i].radius
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
-- draw next bubble
|
||||
-- if moving, extrapolate position based on alpha value from love.run
|
||||
if game.next_bubble then
|
||||
|
|
@ -734,6 +789,10 @@ function love.draw(alpha)
|
|||
)
|
||||
end
|
||||
|
||||
if game.game_over then
|
||||
love.graphics.setShader()
|
||||
end
|
||||
|
||||
-- draw score
|
||||
love.graphics.setFont(game.score_font)
|
||||
love.graphics.setColor(0, 0, 0, 1)
|
||||
|
|
@ -754,22 +813,32 @@ function love.draw(alpha)
|
|||
)
|
||||
end
|
||||
|
||||
-- draw aim guide
|
||||
if game.show_aim_guide then
|
||||
love.graphics.setColor(0, 0, 0, 1)
|
||||
for i = 1, #game.aim_guide - 1 do
|
||||
love.graphics.circle(
|
||||
'line',
|
||||
game.aim_guide[i].x,
|
||||
game.aim_guide[i].y,
|
||||
game.aim_guide[i].radius
|
||||
-- draw game over
|
||||
if game.game_over and game.fade_to_grey_tween.p == 1.0 then
|
||||
love.graphics.setColor(0, 0, 0, 0.8)
|
||||
love.graphics.rectangle(
|
||||
'fill',
|
||||
game.level_left + game.bubble_diameter,
|
||||
game.window_height / 2 - 80,
|
||||
game.level_width - game.bubble_diameter * 2,
|
||||
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'
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function love.mousepressed(x, y, button, is_touch, presses)
|
||||
if button == 1 and game.next_bubble and
|
||||
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
|
||||
|
|
@ -777,6 +846,8 @@ function love.mousepressed(x, y, button, is_touch, presses)
|
|||
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
|
||||
|
||||
|
|
@ -790,13 +861,18 @@ function love.mousepressed(x, y, button, is_touch, presses)
|
|||
end
|
||||
|
||||
function love.mousemoved(x, y, dx, dy, is_touch)
|
||||
if not game.game_over then
|
||||
local diff_x = x - game.launcher_x
|
||||
local diff_y = y - game.launcher_y
|
||||
game.launcher_rotation = math.atan2(diff_y, diff_x)
|
||||
local rotation = math.atan2(diff_y, diff_x)
|
||||
if rotation >= -tau * 7 / 16 and rotation <= -tau / 16 then
|
||||
game.launcher_rotation = rotation
|
||||
end
|
||||
|
||||
if game.show_aim_guide then
|
||||
generate_aim_guide(x, y)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function love.keypressed(key, scan_code, is_repeat)
|
||||
|
|
|
|||
Loading…
Reference in New Issue