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. . .