# Generating shapes?

This topic is 3346 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

##### Share on other sites
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.

##### Share on other sites
If asteroids aren't massive compared to the player ship you might get away with using distance (i.e. circle) based collision

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5
khawk
11

• 9
• 9
• 11
• 11
• 23
• ### Forum Statistics

• Total Topics
633677
• Total Posts
3013281
×