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 false otherwise.

It's the same concept we used to check for collisions between enemy and player spaceships in the making ...

Get Flash Game Development by Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.