C1 refers to the player sprite, and C2 is the enemy sprite. Getcx is essentially collecting the X location of the edge of what is essentially a collision detection circle, and gety does the same, but collects the Y location. GetR returns the radius of the collision detection circle.

\$\begingroup\$Was it running too slowly? How fast you detect a collision between two objects is not as important as being able to deal with thousands of them. In your case you do not have too many of the asteroids. By the way, there are some UI usability improvements that you can look into - the menu for selecting difficulty and a spaceship was not very intuitive (hard to find) and clunky. In professional games the implementation may be harder but the menus are slicker - you get all the info you want on screen, and you can often cycle through options with <=, => or other keys. Difficulty can be a combo box\$\endgroup\$
– LeonidMay 21 '13 at 19:38

\$\begingroup\$Thank you for you help, but that didn't really improve the accuracy. I updated the original post with context. The full JS file is also available here: asteroidfield.eu5.org/_js/main.js\$\endgroup\$
– user2350334May 21 '13 at 18:26

\$\begingroup\$@user2350334, what is wrong with the accuracy? This site is mainly for improving something that already works. Your problem might be with a timer or with modeling the bounding box of a spacecraft.\$\endgroup\$
– LeonidMay 21 '13 at 19:40

\$\begingroup\$@Leonid I am trying to improve the collision detect function-it works fine currently, but as I previously mentioned, it basically uses two collision detect circles. The problem is that since the asteroids have different sizes, it is hard to create an accurate collision detect function for all of them. Try taking a look at the JS file for more details.\$\endgroup\$
– user2350334May 21 '13 at 20:28

1

\$\begingroup\$@user2350334, Take a look at the accepted answer for stackoverflow.com/questions/8968591/… Basically you need to hard-coded a polygon that outlines the shape of each spaceship well. You can then test whether each of the line segments intersects with a given circle. Alternatively, you may cheat and pick n equally-spaced and tightly packed points on the outside of the spaceship. Hard-code that list for each spaceship. Then check whether any of the points lies inside of a circle. That test will run quickly because you are just comparing R w distance to the center\$\endgroup\$
– LeonidMay 21 '13 at 22:36

1

\$\begingroup\$@user2350334, for speed purposes you may take a shortcut - come up with a big bounding sphere that fully encompasses all of your space ships. Then quickly check whether that bounding sphere intersects with any of the asteroids. If it does not, then the space ship is 100% safe. If the bounding sphere intersects with some asteroids, then only finely inspect the intersection with asteroids that are "suspects", e.g. their bounding spheres intersected. These are standard approaches to collision detection in gaming. So, your question did not belong at this codereview site to begin with.\$\endgroup\$
– LeonidMay 21 '13 at 22:41