Check objects around another object

I’m making a Bejeweled style game and I need some help. I can’t seem to grasp what I need to do to detect game objects around another game object without using ray casting or collision detection.

R G B G O
B O G R O
R R B B O

If I’m the middle O on far right how can I tell that there is a O above and O below me.

I have all my random blocks and colors done also the moving of the blocks is complete. I just can’t figure this final part out and need some input.

I have the block coordinates in an array but I don’t actually store the game objects in an array like some other people have suggested. I’m just not getting it for some reason… :frowning:

well you may try to figure out how to handle that using a grid ( that will be the way to do if that was pure 2D game tho ).

then array may represent your grid (row and column ) where you put ref to your gameobjects ( up to you the way you reference them ) when you initialize your level.

then you just need to do grid case check.

I am sure you can find some tutorial of similar game made in flash, and maybe be able to look at some source it may help.

try to work on just the grid things on the side of your project , starting with a simple 22 or 33 and figure out the way to check from a given case what the other contain.

Once you get that to work that will be easy to re-apply in the context of your game.

If I store a game object in an array do all of its attributes go along with it? position…tag…etc?

For this kind of game you are probably best off to separate your presentation (what you have now) from your game state.

For example you might have something like (rough psuedo code to convey the idea):

enum JewelColor {RED, GREEN, BLUE, YELLOW};

class Jewel {
  var go:GameObject;
  var colour:JewelColour;
}

// In the game engine/main controller
var gameState:Jewel[X_SIZE][Y_SIZE];

function isThreeInARow(j:Jewel, x:int, y:int) {
  var match:int = 0;
  if (x > 0)
    if (gameState[x - 1][y]).colour == j.colour)
      match++;

  if (x < X_SIZE - 1)
    if (gameState[x + 1][y]).colour == j.colour)
      match++;

  if (y > 0)
    if (gameState[x][y - 1]).colour == j.colour)
      match++;

  if (y < Y_SIZE - 1)
    if (gameState[x][y + 1]).colour == j.colour)
      match++;

  if (match > 2)
     return true;

  return false;
}

Then you need something that coverts from 3D state to gameState… maybe a function on each block that checks if it has collided with something and if it has velocity zero it converts the 3D position into a location within the gameObject array.

The key is that the logic works on a much simplified view of the world, no need to do any kind of raycasting etc.