Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm implementing a bubble-witch-like game (http://www.king.com/games/puzzle-games/bubble-witch/), and I was thinking on what's the better way to store the "bubbles" and to work with. I thought of using graphs, but that might be too complex for a trivial thing. Thought of a matrix, just like a tile map, but that might get too 'workaroundy'. I don't know.

I'll be doing in Flash/AS3, though.

Thanks. :)

share|improve this question
add comment

1 Answer 1

up vote 5 down vote accepted

You may not want to use a graph, but ultimately the problem is one of planar 6-connectedness. I challenge you to find a simpler and better-suited structure than a graph for this :) I wouldn't be intimidated by the data structure for this -- when you consider how trivial the implementation will be, it's not like you'd be writing Boost Graph Library all over again.

class Bubble
{
   private static const NEIGHBOUR_TOP_LEFT:int = 0;
   private static const NEIGHBOUR_TOP_RIGHT:int = 1;
   private static const NEIGHBOUR_RIGHT:int = 2;
   //etc.

   var neighbours:Array = [];
}

...That's your graph data structure.

As for algorithms, in your main class, run through a loop that arrays them according to their connectivity. And when a player shot collides with the rest, join it at the closest grid position, and then walk all neighbours in the connected graph that match the player shot colour, adding these to a list to "pop", and disallowing walks over neighbours that are already in that list (prevents infinite loops from walking cycles of nodes).

share|improve this answer
    
Hmm, nice! Simple and easy. It's already working. Thanks. :) –  CrociDB Nov 14 '11 at 19:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.