Original Post
Hi ya i need help with my asteroids game.
I''ve been trying for a while now but with now luck. Im trying to test my bullets against my asteroids. I have an array of 5 bullets and an array of asteroids. The bullsts have a x and y position and my asteroids also have an x and y pos. My asteroid are very round so that i could use it radius as a way of testing collsion. What i tried to do was to get the length of the line between the asteroid and the bullet and if the length of the line was smaller or equal to the radius, then there was collsion. Is this correct. Does anyone out there have any other ideas how to get collsion. PLease help
Thanks
below is the code for collsion ive been trying to implement.
int cIdleThreatApp::CollisionDetection()
{
int i, j;
int radius = 41;
float length_of_line;
float astx, asty, bulletx,bullety;
float astx_center = astx + radius;
float asty_center = asty + radius;
float testx, testy;
for (i = 0; i < MAX_ASTEROIDS; i++)
{
astx = Asteroid.Asteroid.XPos;
asty = Asteroid.Asteroid[i].YPos;
for (j = 0; j < MAX_BULLETS; j++)
{
bulletx = Ship.Bullets[j].xcenter;
bullety = Ship.Bullets[j].ycenter;
testx = bulletx - astx_center;
testy = bullety - asty_center;
length_of_line = sqrt((testx * testx) (testy * testy));
if(length_of_line < radius)
{
return 1;
Asteroid.Asteroid[i].alive = false;
Ship.Bullets[j].alive = false;
}
}
}
}