Public Group

# theres gotta be a better way

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

## Recommended Posts

ok i have 479 tiles i want to use in a draw() function and i have to interpret the int maps as tiles using case statement. normally this wouldnt be a problem except for the fact that i have 479 TILES!!! theres got to be a better way to do this thanks for your help [grin] oh and by the way heres what i have so far
void Map::DrawMap(Tile *tilelist[479],int MapOver[100][100], SDL_Surface *screen)
{
int x , y;
y=1;
x=1;
for (int i = 0; i < 100; i+= 32)
{
for(int j = 0; j < 100; j +=24)
{
switch(MapOver[j])
{
x=j;
y=i;
case 0:
{
SDL_Rect dest;
dest.x = x;
dest.y = y;
SDL_BlitSurface(tilelist[0]->GetImage(), NULL, screen, &dest);
};

};
};
};

};


BTW i already tried a for loop (you need a const int for case statements)

##### Share on other sites
I hope this is what you mean:

for...   for...   ...   int index = MapOver[j];   SDL_BlitSurface(tilelist[index]->GetImage(), ...   ...   }}

[Edited by - OrenGL on October 3, 2004 7:23:58 PM]

##### Share on other sites
Try

void Map::DrawMap(Tile *tilelist[479],int MapOver[100][100], SDL_Surface *screen) {    int x , y;    y=1;    x=1;    for (int i = 0; i < 100; i+= 32) {      for(int j = 0; j < 100; j +=24) {         SDL_Rect dest;           dest.x = j;         dest.y = i;         SDL_BlitSurface(tilelist[MapOver[j]]->GetImage(),                                   NULL, screen, &dest);      };    };       };

You should be able to use the mapover value as the index directly, saving you the switch statement. Also, the x and y variables were unneeded, you can just use the loop indexes directly.

Of course, all this is off the top of my head, so I might be wrong :)

##### Share on other sites
Or you can even be smart like OrenGL and use a second variable to improve readability.

##### Share on other sites
thanks for the help guys and BTW i used diffrent variables because i wrote the loops as psudo code and then pluged it in so instead of changing all the x and y variables (there were 15 case statements) i just made them = the increments

[grin]

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 15
• 22
• 13
• 14
• 45