xlandersoftware.com

Xlander Software

Void Intruders: Wave Machine Design

For Void Intruders I want the player to do battle with large waves of enemies.
In my previous game Notepad Wars I would randomly spawn in enemies from the edge of the screen. While this approach is quite easy and works it is not the most exciting to play. While playing Geometry Wars I noticed there where some patterns to how the enemies are spawned. Often there would be a swarm of green squares in each corner, or you would become surrounded by a circle of blue squares. These sort of waves are much more fun to encounter.

Time to design a wave machine for Void Intruders.
As a picture speaks a thousand words I have sketched up a rough design of the wave machine in UML.
I will walk you through my design thought process top to bottom.

WaveMachine: This is the class that the main game loop will call upon to spawn a new wave of enemies at the required intensity level. It will take in an array of waves to use. This way if I want a level that only features a subset of all the waves in the game I can do it easily.
The main part of this class is the spawn random wave function, it will pick a wave at random from it’s collection and spawn it with the required intensity.

WaveMachine: This is the interface that the WaveMachine class will use to interact with it’s collection of waves.
The intensity parameter allows me to tweak how intense / hard a wave is. For example a surround wave of intensity 10 would only have a few enemies spawned in a large rough circle around the player. On the opposite end of the scale an intensity 80 surround wave would spawn a larger number of enemies in a tighter circle closer to the player.

Wave Classes: The wave classes are each a specific implementation of a particular wave pattern. For example the corner wave will spawn enemies in the each corner of the screen, while the surround wave will spawn enemies in a circle around the player.

VoidSpriteFactory: Each wave takes an IVoidSpriteFactory parameter. This interface hides the implementation of generating a sprite for use in the wave. So by changing the sprite factory implementation I can vary what enemies are spawned for any wave pattern.

Object pool: Constantly creating sprites in Flash can be a performance hit. One way to optimize this to use the object pool pattern. The object pool is filled with sprites ready to be used. Once you are finished using the object it is recycled back into the pool. Currently it is not know how hectic the spawn rate will be and if object pooling would be need or even if it would help. Since it will interface to the waves by the VoidSpriteFactory I can implement object pooling later then test and measure the performance.

VoidSprite: This is base class for all sprites in Void Intruders.

So that is the overall design for Void Intruders wave machine. I think it will be flexible enough to allow any combination of sprites to any wave attack pattern. It will be interesting to see how to design survives a real world implementation.

Leave a Reply

Your email address will not be published. Required fields are marked *

Proudly powered by WordPress