Jump to content
• Advertisement

#### Archived

This topic is now archived and is closed to further replies.

# Checking for map tile collision

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

Dude, ever heard of physics? I think sin and cos comes into play. Try storing a vector varible for the direction the object is facing.

#### Share this post

##### Share on other sites
Advertisement
Okay, I have a two-layered map. The first layer is for all of the tiles, the second layer is for NPC's and items. Now, I want to be able to check if one of the tiles they are in is a brick tile and have the ship bounce if it is. Here is my function so far:

code:
void Check_For_Bounce(){int x, y;int x_tile, y_tile, tile_num;//Find out the x positionx = Player.WorldPosX;int next_x = 0; //Set to 1 if it is in more than one tileint next_y = 0;while (x % 32 != 0) //Find the left-most tile it is in{	x--;	next_x = 1;  //Set more-than-one-tile to 1}x_tile = x/32;	 //Get the x_tiley = Player.WorldPosY;  //Find out the ypositionwhile (y % 32 != 0)  //Find the top-most tile it is in{	y--;	next_y = 1;   //Set more-than-one tile to one}y_tile = y/32;	 //Get the x tiletile_num = x_tile + (y_tile*XNUMBEROFTILES);  //Find the actual tile number in the array//If one of the tiles they are in is a "brick" tileif (Map[tile_num] == 1 | | Map[tile_num + 1] == 1 | | Map[tile_num+XNUMBEROFTILES] == 1 | | Map[tile_num+XNUMBEROFTILES+1] == 1){  Player.x_vol = -Player.x_vol;  Player.y_vol = -Player.y_vol;} }

However, you will see on the bottom part what is wrong with this. If one of the tiles is a brick tile, then they "bounce". However, if they go at it at an angle it will defy the laws of physics. Anyone know a quick algo to fix the bottom part? I have previous x and previous y stored. . .

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5
• Advertisement

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633701
• Total Posts
3013450
×

## Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!