Sign in to follow this  
raptorstrike

theres gotta be a better way

Recommended Posts

raptorstrike    181
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[i][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
OrenGL    228
I hope this is what you mean:


for...
for...
...
int index = MapOver[i][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
Idhrendur    122
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[i][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
raptorstrike    181
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this