Empty Your Mind Tutorial 8

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.

Enemy Scheduler
We will need a procedure that will create the enemies. In this tutorial, the enemies' data will be hardcoded. The following procedure should be called at the start of the LoadGame procedure. The procedure will create three enemies. You can add more enemies if you wish.

The second parameter for the CreateEnemy function is a time that the enemy enters the screen. This will allow us to schedule the time that the enemies enter. We will need to have a game timer in order to get the enemy scheduler to work. Therefore, we will need to add a new entry to the GameData structure which will be incremented every frame. The new implementation of the GameData will be…

The game timer must be initialised when loading the game.

We have loaded the enemies but we do not have a routine to update the enemy position. The following steps must be taken to update the enemies. These steps must be taken for all enemies. The implementation of the steps:
 * 1) Go to the next step if the enemy is alive
 * 2) Go to the next step if the enemy should be in the screen (compare the game timer and the enemy's time)
 * 3) Move the enemy ship
 * 4) Kill the enemy and skip the rest of the steps if it is not on the screen
 * 5) Draw the enemy
 * 6) Update the sprite animation frame

As you can see from the implementation, the ship can only move horizontally at the moment. This routine should be called after updating the player's ship.

Enemy Bullets
The implementation of the enemy bullet pattern is very easy. We will be reusing the code from the ShootPlayerBullet procedure. The difference between the ShootPlayerBullet routine and the ShootEnemyBullet is the resultant bullet pattern. The implementation of the ShootEnemyBullet routine should produce a simple bullet pattern like this.



The implementation of ShootEnemyBullet with the example bullet pattern:

The image I have created for this example can be found [[Media:EnemyBullet.png|here]]. Do not forget to initialise the image in Game Resources. My example bullet pattern will shoot 19 bullets at a time. The offset value is used to change the angle of the bullets. This will allow us to program the bullet pattern with more flexibility. This routine should be called every time you update an enemy. The new implementation of UpdateEnemies:

Summary
In this tutorial, I have gone through: The current project files can be downloaded from [[Media:EYM_11_05.zip|here]].
 * Enemy data management
 * Enemy scheduling
 * Enemy bullet pattern
 * Simple enemy movement