Jump to content
  • Advertisement
Sign in to follow this  
ballack

Brick game question

This topic is 4052 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I am doing a game similar to brick game.But i am having problem as to how do i match similar tiles. I have stored the map in a one-dimension array GameWorld .game map is 6x12. each tile will have data as to wat is stored in the tile. if it has a red tile,or blue tile or is empty. Can anyone give me a idea on how can i best check for matching tile horizontally,vertically and both. thank you very much. Glen

Share this post


Link to post
Share on other sites
Advertisement
So basically, you're storing a 2D grid in a 1D array, right? If so, why a 1D array and not a 2D?

If, for some reason, you want to stick to the 1D array, then I would write an accessor function for it that takes a x and y coordinate and returns the value located at that point:

int GetTile(int x, int y)
{
return array[x + y * width];
}

So, when working with a 2D array, you'd access items with array[x][y], and if you use the above function, the 1D approach isn't much different: GetTile(x, y).

From there, you'd simply call every element in a row or in a collumn and compare them to each other. Just compare each element to the next one: if one differs, then you know for sure not all elements in that row or collumn are the same, and you stop testing already.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!