Find matches after launched bubble collision
parent
7ace7cca72
commit
4410d32776
27
main.lua
27
main.lua
|
|
@ -91,6 +91,31 @@ local function find_nearest_slot(x, y)
|
|||
return nearest_slot_index
|
||||
end
|
||||
|
||||
local function find_matches(start_index)
|
||||
local bubble_type = game.bubble_slots[start_index].bubble_type
|
||||
local to_check = {start_index}
|
||||
local matches = {start_index}
|
||||
local visited = {}
|
||||
visited[start_index] = true
|
||||
|
||||
while #to_check > 0 do
|
||||
local current_index = table.remove(to_check)
|
||||
local slot = game.bubble_slots[current_index]
|
||||
|
||||
for i = 1, #slot.neighbours do
|
||||
local neighbour_index = slot.neighbours[i]
|
||||
local neighbour = game.bubble_slots[neighbour_index]
|
||||
if not visited[neighbour_index] and neighbour.bubble_type == bubble_type then
|
||||
matches[#matches+1] = neighbour_index
|
||||
to_check[#to_check+1] = neighbour_index
|
||||
end
|
||||
visited[neighbour_index] = true
|
||||
end
|
||||
end
|
||||
|
||||
return matches
|
||||
end
|
||||
|
||||
function love.load(arg)
|
||||
if arg[#arg] == "debug" then require("lldebugger").start() end
|
||||
|
||||
|
|
@ -255,6 +280,8 @@ function love.update(dt)
|
|||
game.next_bubble.y = game.bubble_slots[nearest_slot_index].y
|
||||
game.next_bubble.velocity_x = 0
|
||||
game.next_bubble.velocity_y = 0
|
||||
|
||||
local matches = find_matches(nearest_slot_index)
|
||||
else
|
||||
game.next_bubble.x = next_x
|
||||
game.next_bubble.y = next_y
|
||||
|
|
|
|||
Loading…
Reference in New Issue