Pikachumanson 0 Light Poster

I am working on a 2-d scrolling map RPG ala final fantasy. Anyway the question I wanted to ask you is how do you go about tile based collision? Let's say I got my scroll map made up and I don't want my player to walk over tiles assigned to ten and twelve. How would I go about doing something like that?

I asked my professor about this and he told me this:

You could create a two dimensional array of RECTs that map to the tiles. Then you could check for collision between the player and the RECT by looping through the two dimensional array.


I'm not understanding what he means by this. Could someone show me an example what he means by mapping the Rects to the tiles and looping through the dimensional array? I don't any experience with working with scrolling tile maps so any help would be appreciated. Oh yeah, and before anyone says anything I already asked him this question he hasn't gotten back to me yet.

//my tile array
int TOWN[TOWN_MAPWIDTH*TOWN_MAPHEIGHT] = {
	0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2, 
    8,156,157,157,156,157,157,156,157,157,156,157,157,156,157,157,156,157,157,156,157,157,156,157,7, 
    8,157,3,3,3,3,3,3,3,3,3,156,157,157,9,9,9,9,9,3,3,3,3,156,7, 
	8,156,3,3,3,3,3,3,3,3,3,157,157,156,9,10,11,12,9,3,3,3,3,157,7, 
    8,157,3,3,3,3,3,3,3,3,3,156,157,157,9,26,27,28,9,3,3,3,3,156,7,
    8,156,3,3,3,3,3,3,3,3,3,157,157,156,9,42,43,44,9,3,3,3,3,157,7, 
    8,157,3,3,3,3,3,3,3,3,3,156,157,157,9,9,9,9,9,3,3,3,3,156,7, 
    8,156,157,157,156,157,157,156,157,157,156,157,157,156,157,157,156,157,157,156,157,157,156,157,7, 
    8,157,156,157,157,156,157,157,156,157,157,156,157,157,156,157,157,156,157,157,156,157,157,156,7, 
    8,156,157,157,156,157,157,156,157,157,156,157,157,156,157,157,156,157,157,156,157,157,156,157,7, 
    8,157,3,3,3,3,3,3,3,3,3,156,157,156,3,3,3,3,3,3,3,3,3,156,7,
    8,156,3,3,3,3,3,3,3,3,3,157,157,156,3,3,3,3,3,3,3,3,3,157,7,
    8,157,3,3,3,3,3,3,3,3,3,156,157,157,3,3,3,3,3,3,3,3,3,156,7, 
    8,156,3,3,3,3,3,3,3,3,3,157,157,156,3,3,3,3,3,3,3,3,3,157,7, 
    8,157,3,3,3,3,3,3,3,3,3,156,157,157,3,3,3,3,3,3,3,3,3,156,7, 
    8,156,157,156,156,157,157,156,157,157,156,157,157,156,157,157,156,157,157,156,157,157,156,157,7,
    8,157,156,157,157,156,157,157,156,157,157,156,157,157,156,157,156,156,157,156,156,157,157,156,7,
    4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6 
};



//my collision function

int Collision(SPRITE *sprite1, SPRITE *sprite2)
{
       RECT rect1;
    rect1.left   = sprite1->getX() + 1;
    rect1.top    = sprite1->getY() + 1;
    rect1.right  = sprite1->getX() + sprite1->getWidth()  -1;
    rect1.bottom = sprite1->getY() + sprite1->getHeight() -1;

    RECT rect2;
    rect2.left   = sprite2->getX() + 1;
    rect2.top    = sprite2->getY() + 1;
    rect2.right  = sprite2->getX() + sprite2->getWidth()  -1;
    rect2.bottom = sprite2->getY() + sprite2->getHeight() -1;

    RECT dest;
    return IntersectRect(&dest, &rect1, &rect2);
}