Sign in to follow this  

Simple tile based colision problem:

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

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


Link to post
Share on other sites

This topic is 4355 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.

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