I’m playing with code from the AUM 84 where collision is done by checking the color of the pixels near the player. I'm doing some test with some simple graphic. When this line is divided by 2:
Code:
coords1_x = my_player.pos_x + bmap_width(player_tga) / 2;

the half of the player is moving through the corner when half of the players width are outside of the red color’s top. I want all the width of the player sprite to be blocked so I remove the /2 from the line above. That works fine, but just on one corner of the red color's top. At the opposite side, it’s not blocking when some part of the players width are outside the red color’s top (see picture below). How is it possible to avoid this, so that the player is not moving on the inside or through the corners of the red color? It works fine on one side, but not on both.

Here it's the collision fine (the small quadrangle is player)



Here it's moving through and on the inside of the corner



Here is the code:

Code:
function collisions_startup()
{
	wait (3); // wait until the video functions are available
	var coords1_x, coords1_y, coords2_x, coords2_y, coords3_x, coords3_y, coords4_x, coords4_y;
	var format, pixel1, pixel2, pixel3, pixel4;
	COLOR pixel1_color, pixel2_color, pixel3_color, pixel4_color;
 
	while (1)
	{
		
		// check player's feet
      coords1_x = my_player.pos_x + bmap_width(player_tga); // 
		coords1_y = my_player.pos_y + bmap_height(player_tga); // play with 2 or - 20
		format = bmap_lock (level_tga, 0);
		pixel1 = pixel_for_bmap(level_tga, coords1_x, coords1_y);
		pixel_to_vec (pixel1_color, NULL, format, pixel1); // store the color of the pixel1 in pixel1_color 
		if (pixel1_color.red == 255) // detected a red pixel below player's feet?
		{
			my_player.pos_y -= 2;
			}
	
		bmap_unlock (level_tga);
		wait (1);
	}
	
}





Last edited by Gastara; 06/22/10 17:52.