Generating shapes?

Started by
1 comment, last by WavyVirus 14 years, 6 months ago
Hi. I'm creating an asteroids clone similar to this one here: http://www.0catch.com/games/asteroids/. I was hoping that someone could point me in the right direction as to how to generate some asteroids with random shapes. I'd rather not use the same shape over and over again, because that would make my game have more of a static feel to it. Btw, how would I do my collision detection for each shape? I'm used to using the bounding box? Should I create a small bounding box for each shot from the ship and test for a collision with each line of the asteroid? Thanks.
Advertisement
One way to generate some shapes would be to create polygons where the radius of each vertex from some center is randomized. Essentially, you are "trying" to create a circle (if you keep the radii the same) with a handful of points. So a three sided circle is an equilateral triangle, four is a square, and so forth. If you randomize the radius you can get some nice looking shapes.

As for collision detection, you could go about it a couple ways. If you want to keep all your asteroids convex (probably not, though) you could do a simple test that checks to see if a vertex from another shape is inside your asteroid and use this to check it against all vertices that fall within the bounding box.

For non-convex shapes, you could either use line intersection tests
A great intersection method

or you could write an algorithm to break each shape into convex regions and use the first method I described. If you use the method I offered for creating your polygons, you will inevitably make non-convex shapes.

Let me know if you would like me to describe something in more detail.
If asteroids aren't massive compared to the player ship you might get away with using distance (i.e. circle) based collision

This topic is closed to new replies.

Advertisement