Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Tile Matching Grid

Hi There,

I want to make a game utilizing a grid of squares in which you can slide one row/column at a time, with any one square going offscreen coming back on the other side . What is the best way to program this? A 2D List? I've been using 2D rays for detection between squares also but that seems inefficient.

(I would like it to be like the grid in "You Must Build a Boat" if you've ever played that)


  • Sl0thSl0th Member

    Hey there. I'd probably use a 2D array.

    In terms of updating the grid data, moving a row/column will require a linear amount of operations (that is, you need to do something as many times as there are tiles to be moved). So if the grid is 8x8, you need to do 8 operations. That is absolutely fine. You could try to come up with a smart way to get this to be more efficient, but it is probably not worth the effort and more complicated code. Even if you could do it with a single operation, it's not going to matter much, because the grid will be relatively small and updating graphics will be much tougher on the computer anyway.

    When it comes to the graphics, I'd approach it so that the graphics are controlled by the data and not the other way around. You should do checks on the underlying 2D array of data, not on the game objects. There are many ways to animate the rows moving, I'm sure you can figure out something nice.

    For detection, it depends a lot on what you want to detect. I'll need some more elaboration here.

    Hope it helps.

Sign In or Register to comment.