Question

I'm coding a GameBoy Advance game in C and I'm trying to come up with the most efficient way of spawning enemies. The game is going to be similar to SpyHunter (http://en.wikipedia.org/wiki/Spy_Hunter).

The problem is that I don't know what would be the most efficient way to have randomly appearing enemies at the top of the screen and never have more than 3 or 4 at the same time on screen.

I thought about creating 4 structures at random places at top of the screen and as soon as one reaches the bottom initialize it again at the top and so forth using random positions but I don't know if this would be the most efficient algorithm.

How should I spawn the enemies?

Était-ce utile?

La solution

The algorithm you outline does seem quite efficient.

You are only allocating memory for the actual sprites you wish to have on screen. You'll need to track their position down the screen anyhow to properly render them. Once they are off screen, you are re-using existing structures. Doesn't get much better than that.

One thought would be to randomly delay some period of time after a sprite goes off screen before re-initializing it at a random position at the top of the screen again. This would lead to some variability.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top