Empty Your Mind Tutorial 4

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.

Bullet Data Structure
It is possible for you to implement the bullet data using a parallels arrays, but it can get unnecessarily complex. I will be defining a bullet data structure and an enumerations. We will need few things to represent a bullet data structure. As you can see, we need to define enumerations for Kind of a bullet and Side. The implementation of the structure is shown bellow.
 * Bullet sprite
 * Damage it can cause (Integer)
 * Kind of a bullet
 * Alive (True if this bullet is alive)
 * Side (Enemy bullet or the player's bullet)

Creating A Bullet
We will have to create a bullet to fire a bullet. This is a simple initialisation process to set the bullet information. We need the following information to create a bullet. The following function will implement the initialisation of a bullet and return a new bullet.
 * 1) The name of a bullet image
 * 2) The ship data to know where the bullet was fired from
 * 3) The amount of damage the bullet can cause
 * 4) Kind of a bullet
 * 5) Side of a bullet
 * 6) Movement vector of a bullet

Managing Bullets
There will be hundreds of bullets flying on the screen at the same time. Therefore we must have an efficient bullet management system. To implement this, I'm going to have an array of BulletData which contains every bullet in the game. The new GameData record is… You will also need to modify the LoadGame routine to initialise the game structure. This will kill all bullets at the start of the game and sets the maximum numbers of bullets to 500.

Shooting A Bullet pt.1
Shooting a bullet can be done very easily by going through the bullets array. The steps to shoot a bullet is…
 * 1) Find a dead bullet
 * 2) Copy the new bullet into the dead bullet
 * 3) Exit

The implementation:

Calling the DeployBullet routine by passing the appropriate parameters will shoot the bullet. However, we need to draw the bullets and update the positions. The following steps must be taken to implement this.
 * 1) Find a bullet which is alive
 * 2) Kill the bullet if the bullet is offscreen
 * 3) Draw the bullet
 * 4) Move the bullet
 * 5) Repeat the step 1 to 4 until all bullets are processed

The implementation of the steps:

Continue to the next tutorial…