Empty Your Mind Tutorial 7

This tutorial will teach you how to use the SwinGameSDK to develop a simple danmaku game which looks cool. At the end of this tutorial you should be able to use pascal to implement your own space invaders or scrolling shooter style game which makes use of Vectors, animated Sprites, SoundEffects, and Music.

Implementing The Enemies
We are going to start implementing the enemies. I will not cover a complex algorithm for enemies in this tutorial. The following things need to be implemented in order to get the enemies to work.
 * Enemy data structure
 * Enemy scheduler
 * Simple enemy bullet pattern

Enemy Data Structure
The enemies' data structure will need the following data in addition to the player ship's data.
 * Time (used for the enemy scheduler)
 * Offset (used for the bullet pattern that will be implementing later)
 * Direction (left to right or right to left)
 * Health
 * Alive (true if the enemy is alive)

As you can see from the list of things needed to implement, the enemy data structure is not very big. Therefore, we will be extending the ShipData which will be used for both player's ship and an enemy's ship. The new implementation of the ShipData:

If you read the new implementation of the ShipData record, you will see the new enumeration called the EnemyMovement. This enumeration defines how a enemy enters the screen and exits from the screen. The implementation of the EnemyMovement enumeration:

We have finished structuring the enemies' data structure but we have not used it in the GameData structure. We will have to add a new entry into the GameData. The new implementation of the GameData:

As you can see, I have added the array of ShipData which will contain all enemies. This must be initialised in the LoadGame procedure. The initialisation part will be explained in the next section.

Creating An Enemy
We will be creating the enemies using the new data structure we have defined. We will be writing a function that will create an enemy and return the new enemy. The implementation is of the CreateEnemy function is…

The example image I have created can be found [[Media:Enemy.png|here]]. Details of the offset and the time will be explained later. Most of the enemy details are static for now. You may extend the game by adding more flexibility.

Continue to the next tutorial…