# Find adjecent balls in grid (arrays) for bubble game

**URL:** <https://forum.kirupa.com/t/find-adjecent-balls-in-grid-arrays-for-bubble-game/286913>\
**Category:** Uncategorized\
**Created:** [April 22, 2009, 7:29pm UTC](https://forum.kirupa.com/t/find-adjecent-balls-in-grid-arrays-for-bubble-game/286913 "2009-04-22T19:29:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wocker](https://avatars.discourse-cdn.com/v4/letter/w/4da419/32.png) [@Wocker](https://forum.kirupa.com/u/Wocker)\
**Post date:** [April 22, 2009, 7:29pm UTC](https://forum.kirupa.com/t/find-adjecent-balls-in-grid-arrays-for-bubble-game/286913/1 "2009-04-22T19:29:44Z")

</div>

Hi everyone,  
I am creating a bubble shooter game in AS3, and now I am at the phase where I want to detect the bubbles arround the bubble I hit.

I have an array called levelBalls  
it contains 10 arrays, and each of those 10 arrays can contain balls.

levelBalls[0][0] for example returns a reference to a ball object( BallClip class -this is basically a movieClip with extra properties for storing color info etc.)

The first 5 rows are filled with a ball object.  
The remaining 5 rows are filled with 0 (zero), to indicate nothing is there.

Every other row onscreen has a offset on x. This is to create a brick layer effect, instead of just having straight rows of balls.

QUESTION:  
Taking into account limits on the array length, how do I return the six positions surrounding the ball that got hit.

```auto

//h = horizontal pos
//v = vertical pos of ball
//the balls are distributed bij 32px
//registration point of balls is in the center, not top left
function getSix(h,v){
var ballRadius = 32;
var centerBall = levelBalls[v][h];
var indentVal = ballRadius/2;

var hasIndent:Boolean = false;
if (h == 0){
//this is the left most ball in this row.
if (centerBall.x >indentVal ) {
//this row has an indent
hasIndent = true;
}
} else {

if (centerBall.x > (h*spacingX)+indentVal){
hasIndent = true;
}
}
//.....and then???? I know if the row has an indent or not
// but how do I get the surrounding balls?

}

```
