The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Page 1 of 2 12 LastLast
Results 1 to 15 of 25

Thread: AS3 - Puzzle Bobble, Destroying the bubbles.

  1. #1

    AS3 - Puzzle Bobble, Destroying the bubbles.

    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:

    1. When a colour has 4 or more touching bubbles?
    2. 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.

    Any help?
    - CrimsonHEART

  2. #2
    Well, what kind of layout is used? Are the balls positioned to a fixed grid (quadratic, hexagonal, diamond shaped...) or can they be placed arbitrarily? In the latter case you should build up a graph representing adjacent bubbles. You then could use some kind of graph traversal (breadth-first or depth-first, both should suffice your needs) to find out whether there is a path of several same-colored bubbles, but that depends on when you want the bubbles to be exploded. I think a simple graphic would help tracking down the best methods for your game.

  3. #3
    Its a normal 12 high, 6 wide grid. Bubbles should explode when 4 or more of the same colour are touching.

  4. #4
    Well, then just use a 12 by 6 array where you save a reference to the bubble at the respective grid. Then for every position in the grid, search the nearby area for same colored bubbles; probably with a recursion like
    (Pseudo-AS)
    Code:
    function getSameColoredBubbles( currentBubble:Bubble, visited:Array ):Array {
    	var res:Array = [ currentBubble ];
    	for each( bubble in neighbourhood of currentBubble ) {
    		if ( bubble.color == currentBubble.color && !visited.contains(bubble) ) {
    			visited.push( bubble );
    			res.concat( getSameColoredBubbles( bubble, visited );
    		}
    	}
    
    	return res;
    }
    (Warning: it's late here, there may be stupid mistakes contained in this post)

  5. #5
    Thanks, I'll give that a shot, I'll let you know how it goes.

  6. #6
    How can I store the X and Y values together? Every time I try to push a value into an array position at array[x][y] it doesn't let me.

  7. #7
    1. Don't push().
    2. Use multi-dimensional arrays.

    If you don't know about the latter:


    Code:
    	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;

  8. #8
    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.


    [0][2][0][0][0][0]
    [0][2][0][0][0][0]
    [0][2][0][0][0][0]
    [0][2][2][2][2][2]
    [0][0][0][0][0][0]
    [0][0][0][0][0][0]
    [0][0][0][0][0][0]
    [0][0][0][0][0][0]
    [0][1][1][1][1][0]
    [0][1][1][0][1][0]
    [0][1][0][0][1][0]
    [1][1][0][0][1][0]

    1 - Is a red bubble.
    2 - Is a blue bubble.

    ---

    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. >_<

  9. #9
    207
    posts
    Registered User
    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?

  10. #10
    Yea, it isn't just a straight puzzle bubble thing.

  11. #11
    Quote Originally Posted by CrimsonHEART
    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?
    If you want the red ones to be destroyed first, you'll have to have it search the red ones first and remove them.

    To handle the bubbles going in different directions, you'll want something set up similar to a pathfinding script, like A*. The best link I can give you is this one:

    Basic Pathfinding.

    Basically, you have all grid slots, with (x, y) coordinates (not their x & y position on screen), and when you want to begin checking for touching neighbours, your algorithm actually starts on a grid slot, looks up, down, left, & right, and reacts accordingly. In your case, when it would look to its neighbours and find a matching colour, it would then analyze that slot too, all the while, the connecting neighbour tiles/grid slots get dumped into a temporary array until the algorithm is done. From there, you just loop through that temporary array, and process your grid slots accordingly. Easy

    Let me know if you have any questions, but if you go through that tutorial I sent and get the hang of it, it should become quite clear
    you = function(){
    setEnabled( true );
    live();
    setEnabled( false );
    }

  12. #12
    Errm... have you bothered looking at the function I wrote above? It does exactly what you need: it traverses the grid in a recursive fashion. Path finding is a different thing that has little to do with this.

  13. #13
    Your function is good, but say there are two seperate groups of the same colour, one with 3 touching, the other with four. Your function would burst them all.

    From looking at the pathfinding, I think it's the right direction. Thanks to both of you. I'll let you know how it goes.

  14. #14
    Quote Originally Posted by Favardin View Post
    Errm... have you bothered looking at the function I wrote above? It does exactly what you need: it traverses the grid in a recursive fashion. Path finding is a different thing that has little to do with this.
    I know it may not seem like pathfinding has anything to do with this, but it does kind of
    Every time a new bubble is added, you use that as the starting node and check it's neighbors, and branch outward until you reach a dead end. It'd be a dead-end finder, that stores touching, same colored bubbles in an array as it goes through its routine. Plus, I offered the pathfinding thing to give CrimsonHeart more of a background on multi-dimensional arrays, which is practically essential for something like this.
    you = function(){
    setEnabled( true );
    live();
    setEnabled( false );
    }

  15. #15
    Quote Originally Posted by therobot View Post
    I know it may not seem like pathfinding has anything to do with this, but it does kind of
    Every time a new bubble is added, you use that as the starting node and check it's neighbors, and branch outward until you reach a dead end. It'd be a dead-end finder, that stores touching, same colored bubbles in an array as it goes through its routine. Plus, I offered the pathfinding thing to give CrimsonHeart more of a background on multi-dimensional arrays, which is practically essential for something like this.
    You are right in the sense that path-finding is a special case of traversing.

    Your function is good, but say there are two seperate groups of the same colour, one with 3 touching, the other with four. Your function would burst them all.
    That is not true, I think you misunderstood something in the code. The method only checks all adjacent bubbles and only adds them to the resulting group if it has the same color. Therefore the result will be a set of bubbles which are all connected to the starting bubble and have the same color.

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012