Now that we have a ship for the player to control, it's time to add some enemies.
Adding enemies covers more than you might initially think. First of all we need to work out how we are going to define our enemies. Any good shoot'em'up has a decent selection of foes, and we need a way to create this range of enemies that doesn't involve a whole lot of needless coding.
BaseEnemy.cpp / BaseEnemy.h
First we define a base class, called BaseEnemy, which will hold all of the common attributes that an enemy can have. Right now, because our enemies are dumb, and because we have no collision detection implemented yet, there are only two common aspects that need to be implemented by the BaseEnemy class. The first is that they will draw an image onto the screen, so we extend the VisualGameObject class. The second is that when they leave the screen they need to be removed from the system, which is done in the EnterFrame by calling the Shutdown function once the enemies moves off the edge of the screen.
In future the BaseEnemy will get more properties like shield strength and score value, but for now those properties are not needed.
BasicEnemy.cpp / BasicEnemy.h
The BaseEnemy class is designed to be extended – it does not implement the functionality needed to define an enemy by itself. The BasicEnemy class is the most simple exmaple of a functioning enemy. It extends the BaseEnemy class and overrides that EnterFrame function to move the enemy across the screen. This is a very dumb enemy, but it will allow us to get some enemies on the screen.
Now that we have created our enemies, we need to create a way to add them to the game. The sequence of enemies added to the screen basically defines the level structure. Traditionally this is done by saving a sequence of enemies to be created at certain points or times. Creating a level in this manner gives you complete control over how each level plays out. The downside is that each level is exactly the same every time you play it. Another option is to create randomly generated levels. This way each level is unique, and it also frees the developer from having to think up 50 different enemies placements to make up the game levels. Because of the flexibility that random levels gives you, this is how we will define our levels.