Allowing bubbles to stack
It's time to let the bubbles stack, which means we have to make them solid, so they can't overlay anymore.
The idea: When the bubble is moving, check if it collides with the bubbles already placed in the game field. In this case, find the closest available cell at once, without waiting for the bubble to leave the game field to the top.
The development: We are working with collisions between circles, so we'll use Pythagorean Theorem to see if the two bubbles collide.
Let's create a new function called
collide that wants a bubble as argument and will return
true if it collides with the fired bubble, and
It's the same concept we used to check for collisions between enemy and player spaceships in the making ...