Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

randomDecay

Flipping a 10x10 grid horizontally

This topic is 6091 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

I have a 2D array , as such: cell[columns][rows] which is a 10x10 grid. I have characters on individual cells. I wish to flip the maze horizontally so that each character is flipped horizontally on the maze. I have tried without luck to do this. I can't seem to do it. Any help is appreciated! Edit(using C++ in a console prog) Edited by - randomDecay on November 18, 2001 1:06:15 AM

Share this post


Link to post
Share on other sites
Advertisement
In-game, you can do something like this:

for (int y = 0; y < 5; y++)
{
for (int x = 0; x < 10; x++)
{
SwapStruct(cell[x][y], cell[x][9-y]);
}
}

SwapStruct could be just a basic swaping function. It could be modelled like a SwapInt, which goes like this:

void SwapInt(int& a, int& b)
{
int temp = a;
a = b;
b = temp;
}

Hope this helps

Share this post


Link to post
Share on other sites
What about

  
int x,y;
for( x = 0; x < columns/2; ++x )
for( y = 0; y < rows; ++y )
{
cell_t tmp; // assuming cell_t is the type of your cell;

tmp = cell[x][y];
cell[x][y] = cell[columns - x - 1][y]
cell[columns - x - 1][y] = tmp;
};

Share this post


Link to post
Share on other sites
this is what I have, but it doesn''t work:

  
Cell temp2;

for ( int x = 0; x < 10; x++ )
{
for ( int y = 0; y < 10; y++ )
{
temp2 = cell[ y ][ x ];
cell[ y ][ x ] = cell[ 10 - y - 1 ][ x ];
cell[ 10 - y - 1][ x ] = temp2;
}
}


Should this work?

Share this post


Link to post
Share on other sites
No, you are flipping your cells twice : when y goes from 0 to 4 then when y goes from 5 to 10.

basically you are doing

swap( 0, 10 );
.
.
.
swap( 10, 0 );

You must stop in the middle.

Share this post


Link to post
Share on other sites
One more q...when I use the cell tmp2 variable do I also have to pass the members of the cell struct, like this:

temp2 = cell[ x ][ y ];
and then...

temp2.symbol = cell[ x ][ y ].symbol;

or does the first line pass all the members anyway?

Share this post


Link to post
Share on other sites
No, that''s the advantage of using a struct (or a *SIMPLE* class (i.e. one for which you don''t have to write your own assignment operator...)).

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!