Archived

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

Checking for map tile collision

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 on other sites
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. . .

• Forum Statistics

• Total Topics
628356
• Total Posts
2982251

• 10
• 9
• 13
• 24
• 11