Jump to content
  • Advertisement

Archived

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

jtecin

Checking for map tile collision

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


Link to 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 position
x = Player.WorldPosX;
int next_x = 0; //Set to 1 if it is in more than one tile
int 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_tile

y = Player.WorldPosY; //Find out the yposition

while (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 tile

tile_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" tile
if (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


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!