Add score and draw points on individual bubbles
parent
d35b9a08e4
commit
6fe70e7b57
71
main.lua
71
main.lua
|
|
@ -298,6 +298,9 @@ function love.load(arg)
|
|||
|
||||
game.window_width, game.window_height = love.graphics.getDimensions()
|
||||
|
||||
game.score_font = love.graphics.setNewFont(50)
|
||||
game.points_font = love.graphics.newFont(30)
|
||||
|
||||
game.paused = false
|
||||
game.frame_by_frame = false
|
||||
|
||||
|
|
@ -325,6 +328,9 @@ 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},
|
||||
|
|
@ -455,6 +461,20 @@ function love.update(dt)
|
|||
alpha = 1.0
|
||||
}
|
||||
game.bubble_slots[index].bubble_type = 0
|
||||
local points = i * 5
|
||||
game.score = game.score + points
|
||||
game.points_display[#game.points_display+1] = {
|
||||
points = points,
|
||||
x = game.bubble_slots[index].x,
|
||||
y = game.bubble_slots[index].y,
|
||||
tween = {
|
||||
delay = 0,
|
||||
t = 0,
|
||||
d = 50,
|
||||
b = game.bubble_slots[index].y - 10,
|
||||
c = -game.bubble_radius
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
-- remove unattached bubbles
|
||||
|
|
@ -469,6 +489,21 @@ function love.update(dt)
|
|||
bubble_type = game.bubble_slots[index].bubble_type
|
||||
}
|
||||
game.bubble_slots[index].bubble_type = 0
|
||||
local points = (i + 1) ^ 3
|
||||
game.score = game.score + points
|
||||
print(points, "points")
|
||||
game.points_display[#game.points_display+1] = {
|
||||
points = points,
|
||||
x = game.bubble_slots[index].x,
|
||||
y = game.bubble_slots[index].y,
|
||||
tween = {
|
||||
delay = 0,
|
||||
t = 0,
|
||||
d = 50,
|
||||
b = game.bubble_slots[index].y - 10,
|
||||
c = -game.bubble_radius
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -532,6 +567,22 @@ function love.update(dt)
|
|||
end
|
||||
end
|
||||
|
||||
for i = #game.points_display, 1, -1 do
|
||||
local p = game.points_display[i]
|
||||
if p.tween then
|
||||
if p.tween.delay == 0 then
|
||||
p.tween.t = p.tween.t + 1
|
||||
if p.tween.t == p.tween.d then
|
||||
table.remove(game.points_display, i)
|
||||
else
|
||||
p.y = easing.outBack(p.tween.t, p.tween.b, p.tween.c, p.tween.d)
|
||||
end
|
||||
else
|
||||
p.tween.delay = p.tween.delay - 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if game.frame_by_frame then
|
||||
game.paused = true
|
||||
game.frame_by_frame = false
|
||||
|
|
@ -646,6 +697,26 @@ function love.draw(alpha)
|
|||
)
|
||||
end
|
||||
|
||||
-- draw score
|
||||
love.graphics.setFont(game.score_font)
|
||||
love.graphics.setColor(0, 0, 0, 1)
|
||||
love.graphics.print(
|
||||
string.format("%08d", game.score),
|
||||
game.bubble_radius,
|
||||
game.bubble_radius
|
||||
)
|
||||
love.graphics.setFont(game.points_font)
|
||||
for i = 1, #game.points_display do
|
||||
local p = game.points_display[i]
|
||||
love.graphics.printf(
|
||||
p.points,
|
||||
p.x - game.bubble_radius,
|
||||
p.y,
|
||||
game.bubble_diameter, -- TODO: fix this, wraps sometimes
|
||||
'center'
|
||||
)
|
||||
end
|
||||
|
||||
-- draw aim guide
|
||||
if game.show_aim_guide then
|
||||
love.graphics.setColor(0, 0, 0, 1)
|
||||
|
|
|
|||
Loading…
Reference in New Issue