Object-spawning in a top-down shooter

My name is Guy Dimor, I’m the sole programmer (and therefore lead coder) for Team Wendigo, currently working on the game Umibozu.

The biggest challenge for me was finding the right way to spawn enemies. I needed them to come into the screen from all sides. My initial idea was for them to spawn randomly on an ellipse just outside of the game screen and then move in a straight line across the screen. A quick google search landed me an algorithm that produces a random point on a circle.
While I wanted an ellipse, I nontheless implamented the algorithm (and adapted it to C#, as it was originally in Java).
I’m somewhat ashamed to admit that it took me too long to figure out how to turn the circle into an ellipse. After a while of struggling with it, I finally realized all I had to do was divide the Y value of the dot by any number larger than 1 to get an ellipse. I made a function out of said algorithm and set the spawn-manager to instantiate enemies using the resulting points as positions. The ellipse can be seen in the featured image.

Once the spawn pattern was created, I need to make the enemies move across the screen. The enemies’ only “AI” is moving forward, so I needed I way to make them point towards the screen when instantiated. I initially had them point towards another random point on the same ellipse. However, too many either did not enter the screen or just barely grazed it. I then decided to have that point towards the player’s position at the time of their creation, which indeed caused all of them to enter the screen. However, this meant that the player had to constantly change position to avoid them, as staying static for long guaranteed taking damage. While that is not a bad feature in and of itself, it does go against the goal of having the player not feel stressed.

My final idea proved more accurate: Have the enemies move towards a random point inside a rectangle slightly smaller than the screen. This meant all enemies entered the screen, but were more evenly spread-out and did not overwhelm the player.

About Guy Dimor

2017 Programming