Archived

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

Edison Bright

Collision Problem

Recommended Posts

I wanted to test if a 4x4 bullet sprite collides with a 32x24 enemysprite so I write the following code:
collided = true;
				
				if (bullets.y+4 < enemies[j].y) collided = false;
				if (bullets[i].y > enemies[j].y + 24) collided = false;
				if (bullets[i].x+4 < enemies[j].x) collided = false;
				if (bullets[i].x > enemies[j].x + 32) collided = false;

				if (collided == true)
				{
					enemylist[j] = 0;
					bulletlist[i] = 0;
				}
 
This does not seem to work very well (only about 10% of the time) ... I wonder why?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The line:

if (bullets.y+4 < enemies[j].y) collided = false;

should be

if (bullets.y+4 < enemies[j].y) collided = false;

Share this post


Link to post
Share on other sites