Arrays and a stupid question...
Let''s say I have a world map for a game represented by characters. Each character is a tile in the game. Here''s an example:
char *world[] =
{
"1111111111111111",
"1000000000000001",
"1011110110111111",
"1010000000000001",
"1010111111111101",
"1000000000000101",
"1010101100110101",
"1010101000010101",
"1010101111110001",
"1010100000000101",
"1010111111111101",
"1010000000000001",
"1011111111011111",
"1000000000000001",
"1111111111111111"
};
How can I modify an individual character in the array (like replacing a 1 with a 0)? I know this is simple C that I should have learned long ago, but I''m still a very inexperienced programmer (I have more knowledge of Windows and DirectX APIs than I do of C/C++). I tried using code like this to modify a character at location (xmap, ymap):
world[ymap][xmap] = ''0'';
When I try to use this in my game, the tile changes when I run this code, but other random tiles on the map change too, so obviously I''m accessing the array incorrectly. What''s wrong?
Al
Alexbigshot@austin.rr.comFoolish man give wife grand piano. Wise man give wife upright organ.
Al,
This takes me back.......
You are already using xmap and ymap coordinates, thats a start, but to address the array anywhere use:
array[(ymap * 16) + xmap] = 0;
Where ymap = 0 is the top line of the declaration, and xmap = 0 is the first character on the left, and 16 is the width of the "map".
Alternatively you could of set up a two dimensional array:
int array[16][16];
then can address it the way you''ve been trying.
Bye
Matt
This takes me back.......
You are already using xmap and ymap coordinates, thats a start, but to address the array anywhere use:
array[(ymap * 16) + xmap] = 0;
Where ymap = 0 is the top line of the declaration, and xmap = 0 is the first character on the left, and 16 is the width of the "map".
Alternatively you could of set up a two dimensional array:
int array[16][16];
then can address it the way you''ve been trying.
Bye
Matt
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement