Hi,
I’m having trouble with some theory. It’s going to be coded in AS3 OOP. I’m making a game like Puzzle Bobble, I can get the ball to register a position, and collide, but the problem is identifying:
When a colour has 4 or more touching bubbles?
When to explode them.
Currently I have the ball in a container clip, I fire it at the bubbles. When it’s fired and collides with another bubble, it’s X/Y position is saved in an array, the array is then looped through to update the bubbles shown on screen.
Active Bubble (bubbleContainer_mc) -> Fired At Bubbles (bubbleLayout_mc) -> Collides, bubbleContainer_mc removed and reset. X/Y of the collision saved in bubbleArray[x][y] along with the colour -> Loop goes through X and Y of BubbleArray, and attaches the appropiate coloured bubbles into the bubbleLayout_mc.
var grid:Array = [];
var width:int = 10;
var heigt:int = 20;
for( int x = 0; x < width; ++x ) {
grid[ x ] = [];
for( int y = 0; y < height; ++y )
grid[ x ][ y ] = null; // initialize
}
// store something in grid
grid[ 4 ][ 2 ] = something;
How about if there are multiple directions to search. I’ve made a function that checks up, down, left and right and tells you the colours of each of them. But say this happens.
Now I need a function that destroys these, as there are more than four touching, however, how does the function/loop, destroy the red ones first, and then the blue ones (or vice versa)?
Also, see how the directions of these bubbles can vary? How would that be accounted for?
Sorry if I seem like I’m just dumping a whole load of the coding theory to you, but I have honestly thought about it for weeks now. >_<
This is something I would do with a recursive function. You start the recursion with the bubble you just added, and it checks each bubble touching it whether it is the same colour.
In puzzle bobble, the scenario you gave where you’d have a group of red and a group of blue would never occur. Are you doing something different that means this could happen?