-2

Could someone please give me some direction on how to spawn enemies in a circle (XNA Programming)?

I want the enemies to randomly spawn along the circumference of a circle that is just outside the bounds of the window. I want them to move in straight lines through the center of the window and out to the opposite side of where they started (or as close to that as possible).

Ideally this would create an environment where enemies are randomly coming across from seemingly all directions. Any help would be appreciated.

jdewitte
  • 131
  • 3
  • 13

1 Answers1

3

Just generate a random number between 0 and 360 (or 0 and 2π if it uses radians), and use trigonometry based on the radius of the circle you want.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • I need more of a code-related answer. I'll repost with some of my code showing what I've got so far. – jdewitte Dec 10 '12 at 20:05
  • 1
    @382heresy ok, do the trigonometry *in code* ;p Seriously, that is very basic: if you can't convert from Cartesian to/from polar co-ordinates, you're going to find writing a game pretty challenging... or have I misunderstood? – Marc Gravell Dec 10 '12 at 20:39
  • Basically what I'm seeing here is you're asking for someone to essentially write this section of your code for you. That's not a good way to do things. This in particular is a fundamentally trivial thing to do for anyone with even the slightest knowledge of how to program a game engine. It's just basic trigonometry. You just need to generate a random number between -π and π, and then use trigonometry to calculate the x and y offsets from your centre point. Adding the centre point to this offset will give you your spawn position. – Hoeloe Dec 11 '12 at 20:10