Hey, I'm working on an asteroids game.
I am storing the location of an asteroid as a single point: x and y. And the asteroid is drawn centered on that point. So when I check for collision I can just add the size of the asteroid to the the specific point to get something like a box shape.
This worked when checking collision between shots fired and asteroids, but proved more difficult to do between the ship and the asteroids. Here is my statement:
xShip = the x coordinate of the ship
yShip = the y coordinate of the ship
asteroidX = the x coordinate of the asteroid
asteroidY = the y coordinate of the asteroid
collisionFactor = The the size the asteroid extends from the actual point
The 0.6f is the size the ship extends from its point
edit: fixed some the of greater then less then signs to what I intended, but still does not workCode:if (((xShip + 0.6f < asteroidX + collisionFactor || xShip + 0.6f < asteroidX - collisionFactor) &&
(xShip - 0.6f > asteroidX + collisionFactor || xShip - 0.6f > asteroidX - collisionFactor)) &&
((yShip + 0.6f < asteroidY + collisionFactor || yShip + 0.6f < asteroidY - collisionFactor) &&
(yShip - 0.6f > asteroidY + collisionFactor || yShip - 0.6f > asteroidY - collisionFactor)))
So this isn't working.
Should I even be using a statement this long? Should it be broken into several statements?
Also it isn't working properly, because you will just die at random times, even when you are not hitting an asteroid.
Thanks,
David