Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 537115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:53:34+00:00 2026-05-13T09:53:34+00:00

So I write a game once in while. Just for fun, so that I

  • 0

So I write a game once in while. Just for fun, so that I can learn new things.
I have been able to make a working “Breakout” and “SpaceInvaders” game so far. So I know how to handle collision handling etc.

Now I would like to make a “Bubble Shooter” copy.
alt text http://img13.imageshack.us/img13/8361/54611.gif

I hope you guys know the game.

I am having an issue about one aspect of the game.
As you know, if colored ball hits a place where 2 or more same-colored balls are connected – they will all “pop/dissapear”.

Now, how do I detect if there is any same-colored balls connected to the ball I collide with?
Do I keep some sort of seperate list of all clashes of same-collored balls?

I will need to know some sort of hint to which object the different balls are, so that I can delete them all upon impact.

So yeah, how should I go about this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:53:34+00:00Added an answer on May 13, 2026 at 9:53 am

    In my experience with such games, the bubbles that are part of the playfield (ie the ones that have already been fired and have landed) are not positioned arbitrarily, but instead fit in a well-defined grid. Which makes the problem to solve not one of geometry (which would be fiddly), but one of traversing a data structure.

    I suggest you have something, possibly as simple as a two dimensional array, that represents the colours of the bubbles that have already landed. Once you have established where the new bubble lands, you can then just check neighbours in this array. You will need to be careful about the fact that alternate rows are offset, but there’s nothing here a clear diagram won’t solve.

    (it may be that you do in fact want arbitrarily positioned bubbles! In which case you have more work to do…)

    edit OK here is one approach to storing the grid:

    We will use a two-dimensional array, indexed by row and column, except that to handle the fact that our grid as actually hexagonal rather than rectangular, alternate elements will be unused. In each element that is used we will store a simple integer, representing the colour index of the ball that is there, or -1 if the space is free. So a small playfield could look something like this:

        col  012345678901234567
    row 0    2.3.-.5.3.-.3.-.-.
    row 1    .2.1.4.-.3.2.5.-.-
    row 2    4.1.2.3.2.6.-.-.-.
    row 3    .2.1.3.4.4.-.-.-.-
    row 4    -.-.-.-.-.-.-.-.-.
    

    where . is an unused element (the value of which we never examine), and - is an element with value -1, representing an empty hex cell.

    Note that for any hex cell at row r, column c, its neighbours are at

        [r-1, c-1]    [r-1, c+1]
    [r, c-2]                [r, c+2]
        [r+1, c-1]    [r+1, c+1]
    

    with due consideration for the edges of the playfield.

    Now suppose we have established that the just-fired ball, of colour 3, has landed at row 4, column 6. Examining its neighbours, we see that the northwest neighbour is of colour 3, and examining its neighbours we see that its northeast neighbour is also also of colour 3, so we have a chain of three the same, and we can delete them.

    You could either do this check recursively, or keep track within each hex cell of both the colour and additionally the ‘same colour neighbour’ count. Can’t say off the top of my head which one will work out nicer – recursion, I suspect.

    It remains to say how we establish where a fired ball lands; but we can now easily see that we simply make the code that computes the trajectory also determine which hex cell in turn the ball counts as being ‘in’, and stop as soon as soon as one such hex cell has a non-empty neighbour, assuming you want the ball to stick to the first already-landed ball it gets near.

    Stuff that still needs to be thought about:

    • When the player makes a chain and we delete balls, do the other balls collapse up? Or do no-longer-attached balls fall down? How can we determine if a landed ball is connected to the roof?
    • Is this naive collision detection good enough? (I suspect it isn’t – in that if a fired ball puts so much as one pixel into the southwest of a cell, and there is a northeast neighbour, it will leap over and stick to it)

    Hope this gives you some ideas to go on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 373k
  • Answers 373k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You just missed step 5 of the tutorial. The other… May 14, 2026 at 7:30 pm
  • Editorial Team
    Editorial Team added an answer Well, after weeks of waiting, Microsoft finally came through via… May 14, 2026 at 7:30 pm
  • Editorial Team
    Editorial Team added an answer This is pretty much the behavior I would expect. I've… May 14, 2026 at 7:29 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.