Jump to content
  • Advertisement
Sign in to follow this  
Thrust

Simple tile based colision problem:

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

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!