Space Invaders

Description: User avoids invaders and shoots them
Programmer: Josh Blake
Compiler: Smart Mobile Studio 2.2

Introduction

The code is packed with advanced features and has many constants that you can experiment with to suit your game-playing ability. Play the game full screen and view the code on subsequent pages. If SpaceInvaders does not run in your current browser, please try another (such as Chrome).

Technical Features

The code has suitably named identifiers and should be straightforward for a professional programmer to follow, but we think that the following paragraph might help the majority of you to understand how Josh handles key presses. (His handling of key-up events is similar).

Tracing the code for a key press, the asm block in procedure ApplicationStarting calls procedure KeyDownEvent (which is in the Input unit). If DEBUG (in the Settings unit) is True, procedure KeyDownEvent logs the press and also outputs to the console the position of each callback procedure (of type procedure(mCode: Integer)) that have been added to the array of procedures. Whether or not in debug mode, procedure KeyDownEvent calls each procedure in the array of key-down procedures. Procedures are added to the array of key-down procedures by AddKeyDown procedure in the Input unit. This is called in procedure ApplicationStarting, which adds KeyDown from the SpaceInvaders unit to handle the space bar. The constructor for the Player adds its own KeyDown procedure to the array to handle the arrow keys.

The code benefits from: