# Simple tile based colision problem:

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

## Recommended Posts

Hi, im currently trying to write a tile based colision system, yet I always seem to get messed up when trying colision. Whats going on is I have a map that consists of an array of tiles and an array of event numbers. What my colision is trying to check is if certain parts of my sprite would be on a tile that is marked as non walkable. Yet for som reason my colision is all messed up and it blocks some things, and allows others. Can you look at this and see if you can understand whats wrong?
{
// Check top left
int blah1 = ((player.m_PosX)/32);
int blah2 = ((player.m_PosY)/32);
if(event[blah1][blah2] == Tile) return SDL_TRUE;

// Check top right
blah1= ((player.m_PosX)/32);
blah2= ((player.m_PosY+player.m_BlockWidth)/32);
if(event[blah1][blah2] == Tile) return SDL_TRUE;

// Check bottom left
blah1 = ((player.m_PosX+player.m_BlockHeight)/32);
blah2 = ((player.m_PosY)/32);
if(event[blah1][blah2] == Tile) return SDL_TRUE;

// Check bottom right
blah1 = ((player.m_PosX+player.m_BlockHeight)/32);
blah2 = ((player.m_PosY+player.m_BlockWidth)/32);
if(event[blah1][blah2] == Tile) return SDL_TRUE;

return SDL_FALSE;
}



##### Share on other sites
It's probably because you add player.m_BlockWidth to player.m_PosY and player.m_BlockHeight to player.m_PosX. It should be the other way round.

1. 1
Rutin
38
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633350
• Total Posts
3011469
• ### Who's Online (See full list)

There are no registered users currently online

×