• Advertisement
Sign in to follow this  

theres gotta be a better way

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

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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]

Share this post


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

  • Advertisement