Next Iteration

Project “Space Invaders”

ConceptsCovered

Control Flow, using loops and branches (sequence, selection, repetition)

Arrays, Custom data types (struct)

String and text processing

Managing multiple values

Custom data types, record/struct and enumeration

Project Description

In this tutorial, you are going to make the most popular arcade game
ever. This game will have some alien ships arranged in a perfect
block with columns and rows on top of the screen. Your ship is at the
bottom of the screen from where you have to shoot at the alien ships
and protect your ship from their bullets. You will have three lives,
if you kill all the aliens before your lives run out you win, if the
alien kills you three times, they win.

See figure 1 for an example

The screen shows three main elements. They are:

Player ship. You need to protect your ship from alien bullets and throw
bullets from your ship to destroy all the aliens.

The aliens. Aliens will be at the top of the screen.

Bullets. Both your ship and the aliens’ ship will throw bullets at each
other. Whatever the bullet hits, it is destroyed.

Implement this game using the “Pascal” version of SwinGame. The following pages outline the process of designing and implementing this.

Getting Started

Create
a new folder on your computer or on the H:\ drive for the lab
machines

Download
a blank “SwinGame template” from the Blackboard web site.

Extract
this into the folder you created, and rename the “Project
Template” to “SpaceInvaders”

Open
NotePad++, and in it open GameMain.pas for the SpaceInvaders
(.../SpaceInvaders/src/GameMain.pas)

Iterations

Iteration 1: Creating your ship

Perform the following steps to build the artefacts needed to be able to
create and move your ship.

First,
you will create your own player
record.
Table 2 contains a data
dictionary that
describes the fields of the player record/structure.

Type

Field Name

Description

Sprite

Fighter

To make the player a sprite

Integer

Life

Number of lifes a player have

Table 1: Fields of the player record

Next part of building this game will be to create your own SpaceInvadersData record. Table 2 contains a data dictionary that describes the fields of the SpaceInvadersData record/structure.

Type

Field Name

Description

Player

playerData

To store all data of the player

Table 2: Fields of the SpaceInvadersData record

In GameMain.pas write the code to declare this record/structure.

Next, you need to create functions and procedures to process all events,
initialize the game data, draw the player, update the player and
move the player. See figure 3 for the structure chart showing these
functions and procedures.