In this section, Bot will show you some Windows programs that he
wrote (using C# and Visual Studios).

Free programs will be provided for you to download.

Also, Bot will show you how these programs work. Bot has recently
started work on an 'arcade' style shoot-'em-up! This makes use of
animated sprites, like those on the left. Bot will show you how to
make animated sprites and how to move them around a computer
window and shoot other sprites! (This involves detecting sprite

Bot will also introduce you to features of GDI+, the MS Windows
Graphical Device Interface (improved + version for the .NET

If you want to join Bot in learning how to write your own computer
games, then you have come to the right place!

Click on the screenshot on the left to see where Bot has got to
(after a few days work). So far the player ship (a sprite controlled
by the player) can shoot missiles (more sprites) at the aliens. One
can also destroy the aliens by ramming into them, but this
damages the hull of your ship! The aliens don't shoot back yet -
that's the next task on the list! The graphics were created using
Pov-Ray (the backdrop made use of

Want to know how this works? Want to test the finished product? If
so, then stay tuned for updates!
The full source code for the game engine (which will be
periodically updated) can be seen
Bot also writes science programs, like OrbPlotter which plots some 2D mathematical functions like the hydrogen atomic
orbitals and diffraction waves, which was used to generate the plots for This program is fun to play with
and has served a useful purpose, but until more functions are added, it still serves a useful instructional purpose, as it
makes necessary use of a technique called 'threading' and some other useful techniques.

Link to download
OrbPlotter installer! This application was written in .NET 1.1 and is also not exactly optimised for speed,
but it does what it is meant to do.

Bibliography / Suggested Reading

  • SAMS Teach yourself Game Programming in 24 Hours, Michael morrison; SAMS 2002. [An old book that uses
    traditional C++ and COM Windows programming, but gives an excellent insight into the design of 2D games
    engines. A newer ed may be available.]

  • Accelerated C# 2010, Trey Nash; Apress, 2010. [Not very suitable for beginners, but written by an expert this book
    gives a good insight into c# up to version 4 and takes some of the mystery out of the 'black boxes' by explaining
    what goes on under the hood. Complete with interesting and useful code examples and a good introduction to
    some of the more frequently used design patterns.]

  • The Open University: offer excellent courses on Java programming. If you are unable to study with them (for
    example if you are outside their geographical area) then their course texts are frequently for sale and are
    extremely well written. They also offer thorough assessment, including programming assignments and written texts
    that require the writing of code by hand (a favourite approach with employers!).

  • Oracle provide free and outstandingly well-written Java tutorials online.

  • Microsoft Development Network (MSDN) offer an improved set of tutorials and code samples for C# and C++/CLI
    [though I would take the claims that C# is 'simple and easy to learn' with a pinch of salt, as no computing language
    is easy, especially not if you include the standard class libraries in your definition of 'programming language'!].

Software Development Tools Used

Microsoft Visual studio 2012 Express (the free version, can be downloaded online). Download here: http://www.

Inno Setup Compiler 5.5.1. VS 20120 Express does not give full support for preparing setup files with only a rather
crude one click deployment facility. (This is one key reason why I put C# aside for a long while). However, the freely
available third-party Inno setup Compiler makes it relatively easy to prepare setup files - so maybe I will write some more
C# apps and distribute them online. Download here:
//Moving the player ship

private void OnKeyPress(object sender, System.Windows.Forms.KeyEventArgs e)
Player PlayerShip = new Player();
PlayerShip = playerShips[0];
//When the Spacebar has been pressed = fire!
if(e.KeyCode == Keys.Space)
// When the Left-Cursor has been pressed
if(e.KeyCode == Keys.NumPad4 || e.KeyValue == 37)
     PlayerShip.XCoord = PlayerShip.XCoord - PlayerShip.Speed;
     if(PlayerShip.XCoord <= 40)
     { PlayerShip.XCoord = 40; }
// When the Right-Cursor has been pressed
if(e.KeyCode == Keys.NumPad6 || e.KeyValue == 39)
     PlayerShip.XCoord = PlayerShip.XCoord + PlayerShip.Speed;
     if(PlayerShip.XCoord >= 720)
     { PlayerShip.XCoord = 720; }
// When the Up-Cursor has been pressed
if(e.KeyCode == Keys.NumPad8 || e.KeyValue == 38)
     PlayerShip.YCoord = PlayerShip.YCoord - PlayerShip.Speed;
     if(PlayerShip.YCoord <= 40)
     { PlayerShip.YCoord = 40; }
// When the Down-Cursor has been pressed
if(e.KeyCode == Keys.NumPad2 || e.KeyValue == 40)
     PlayerShip.YCoord = PlayerShip.YCoord + PlayerShip.Speed;
     if(PlayerShip.YCoord >= 500)
     { PlayerShip.YCoord = 500; }
1. Moving the player ship

Below is the code that I have used to move the player ship whenever the player presses the appropriate cursor
key (or firing a missile if the spacebar is pressed).
In double buffering, rather than drawing directly to the screen (the first buffer) it draws to a virtual space in
memory (the second buffer) and only when the drawing is ready is the whole image updated to the screen in one
smooth draw event.

The playerShips array

Notice that I have created the playerShip as the first element of an array:

PlayerShip = playerShips[0];

In this game all the objects are stored as an array of objects, so the alien class of instantiated objects will be
stored in an aliens array, and the missiles in another array. Now, at the moment there is only one player ship so
using an array might seem redundant, however, it will enable the use of multiple ships as a future option, for
example if a power bonus doubles-up the player ship, or if several ships with different characteristics are
created, even if only one is displayed at a time. Thus, all the objects are in arrays for future flexibility and for
code consistency.

The PlayerShip class can be viewed

2. Creating Animated Sprites

The PlayerShip, aliens and missiles and other interactive game objects are all sprites. A sprite is a 2D graphic, a
smaller bitmap, which is independent of the larger background image. Sprites are the main method of animation
used in most 2D games. Sprite animation is
cast-based animation. An alternative approach, which only works in
certain circumstances, is
frame-based animation. In frame-based animation, the whole image simply changes
through a series of pre-generated static images, like a cartoon. This is not very useful for interactive games, but
could be used for introduction animations and is used a lot in non-gaming animations. In cast-based animation,
graphical objects can move independently of the background. Thus, a player-ship can be made to move as a
sprite against a backdrop graphic. Sprites can also interact with one-another via collision detection.

An animated sprite is made-up of several different frames. Below are the three frames which make-up the
PlayerShip sprite (the exhaust flame is animated):
frame 1
frame 2
frame 3
What we can do in the program code is to load each bitmap frame at runtime, join them all together in a chain to
make a single long bitmap (concatenate them) and them simply display only part of the bitmap at anyone time.
Thus, we can display only the left third of the image (frame 1) and then periodically cycle through the frames,
creating animation which is independent of the movement of the sprite around the screen by the player.

The code that does this is in the CreatePlayer() function shown below:
private void CreatePlayer()
//Create player spritemap
Image MyImage_1a = Image.FromFile("PlayerShip_1a.bmp");
Image MyImage_1b = Image.FromFile("PlayerShip_1b.bmp");
Image MyImage_1c = Image.FromFile("PlayerShip_1c.bmp");
Bitmap PlayerShip_AS_1 = new Bitmap(480,120);
using (Graphics gfx = Graphics.FromImage(PlayerShip_AS_1))
      gfx.DrawImage(MyImage_1a, new Point(0,0));
      gfx.DrawImage(MyImage_1b, new Point(160,0));
      gfx.DrawImage(MyImage_1c, new Point(320,0));
// Get the color of a background pixel.
Color backColor = PlayerShip_AS_1.GetPixel(1,1);
// Make backColor transparent for myBitmap.

for(int i = 0; i <=0; i++)
      Player PlayerShip = new Player();
      PlayerShip.SpriteMap = PlayerShip_AS_1;
      PlayerShip.Speed = 40;
      PlayerShip.XCoord = 20;
      PlayerShip.YCoord = 500;
      PlayerShip.XVelocity = 0;
      PlayerShip.YVelocity = 0;
      PlayerShip.FrameCounter = 1;
      PlayerShip.FrameInterval = 10;
      PlayerShip.FrameTimer = 1;
      PlayerShip.NumFrames = 3;
      PlayerShip.HullPoints = 10;
      PlayerShip.ShotCount = 0;
      playerShips[i] = PlayerShip;
Other Sprite Arrays

As with the player ship(s) arrays are used for the other sprite classes as follows:

//Sprite arrays
private const int numberAliens = 20;
private Sprite[] alienSprites = new Sprite[numberAliens+1];
private Missile[] playerShots = new Missile[20];
private Missile[] alienShots = new Missile[20];
private Sprite[] explosions = new Sprite[20];

Each sprite has a number of hull points (HP), if the HP = 0 then the sprite is not drawn and does not participate in sprite
collisions - it does not exist. If a missile is fired, then the first missile sprite in the array with HP = 0 is assigned a positive HP
value and its coordinates set, it then becomes active and visible. Setting an upper limit for the max number of alien missiles
(20)  means that no more than 20n alien missiles can be displayed at a time, which prevents the game screen becoming too
cluttered (and places a finite time required for collision detection and movement algorithms). As soon as a missile hits a
target or goes off the screen its HP are set equal to zero.

The CreatePlayer() Function

This creates the PlayerShip at runtime, when the game is initialising. The code first loads the separate sprite frames, then
adds them together into a single bitmap called PlayerShip_AS_1 (can't remember why I called it that!). It then proceeds to
sample the background colour of the sprite (black in this case) and makes it transparent. Finally, the function creates an
instance of the Player class, called PlayerShip and then sets several of its properties. [See the
player class description for

3. Game Engine Functions and the Game Clock

  • private void DoSplash()
  Opens the 'splash screen' or introductory screen with game instructions.
  • private void TimerOnTick(object sender, System.EventArgs e)
  Coordinates the game, initiating a 'round' of play every time the timer advances by a set amount.
  E.g. calls MoveAliens(), MoveMissiles() and CollisionDetection() functions etc.
  • protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  Draws and redraws the game display.
  • private void PrepareMissiles()
  Prepares the missile array prior to game play, setting up missile sprite graphics and parameters for each missile.
  • private void MoveAliens()
  • private void MoveMissiles()
  • private void CollisionDetection()
  Checks to see if an alien sprite has collided with the player sprite. This is achieved by optimised bounding rectangles
(collision hulls) and an algorithm that tests whether the collision hulls of different sprites overlap with one-another.
  • private void HitDetection()
  Checks to see if any sprite has been hit by an enemy missile using the rectangular collision hull of each sprite.
  • private void AlienAttack()
   Determines which aliens will fire and then activates a missile sprite with the correct screen coordinates.
  • private void OnKeyPress(object sender, System.Windows.Forms.KeyEventArgs e)
  • private void PrepareAliens()
  • private void CreateAliens()
  • private void CreatePlayer()
  • private void CreatePlayerMissile()
  • private void DestroyAliens()
   Removes aliens from the display (e.g. prior to restarting the game).
  • private void GameOver()

The Game Clock, which results in the TimerOnTick event being triggered every time its set interval elapses is initialised in
the Form constructor as follows:
Computer Game Programming

To download a (Windows) demo of the program illustrating sprite animation, click here (updated 24/8/2011). This is the
source code project which can be run in Visual Studio 2010 (the express version of which can be downloaded free from
microsoft). The code has not been cleaned up at all and so there are lots of commented out sections where I have
experimented with different things! The program is not exactly finished, and I may return to it in between juggling my
many other projects! I ought to get round to building a proper installer and placing all the required image and sound files
into a resource file. Unfortunately, I am using the free 'Expresss' version of Visual studio which as far as I am aware does
not provide ready support for resource files, since MS prefer us to purchase the full application if we wish to distribute
complete applications with easy installation.
Note: C# Versioning and Multithreading

The original game engine was written in C# using VS 2003 (C# v 1.1). Recently Bot imported it into VS 2010 (Express
edition) and C# v 4.0. This caused some interesting issues.

1. The original program used multithreading and a number of threads had access to the controls on the form. For example,
one thread (say the thread animating aliens) would update controls on the form, such as the player score (when an alien
was destroyed). C# 1.1 allowed this cross-threaded access of Winform controls. However, such cross-threaded controls
can cause problems of synchronization in Winform controls, since these controls are not thread safe. This means that
several threads may access a control concurrently, which can cause errors, for example in the numeric value of the control,
such as the player score text control, if several threads read and write concurrently. For example one thread may be
part-way through writing a value whilst another thread reads the value, leading to an incorrect value being read. In this
particular program this was never an issue and no errors ever resulted (synchronization is not always a problem, it depends
what the threads are doing with their shared resource). However, as awkward problems may arise, such cross-threaded
calls to Winform controls is widely considered to be bad programming practise. Thus, in later versions of C#, such as v 4.0,
MS have forced programmers by default not to make such calls and code containing such calls will not compile. (This block
can, however, be turned off using:

Control.CheckForIllegalCrossThreadCalls = false;

in the Winform constructor, which may be useful for backwards compatibility or for demonstrations of synchronization
problems. However, it is better to avoid cross-threaded calls to unsynchronized resources altogether, which means only
altering the value of a form's control on the thread which created the control.

2. Multithreading proved necessary in the original C# 1.1 game version, as redrawing the sprites and some other
operations were too slow to perform on a single thread. However, in C# 4.0, this is no longer necessary, the whole program
runs smoothly on the main thread, so the solution to problem 1 was to remove multithreading altogether 9except possibly
for sound playback). In fact, keeping in the multithreading made the program run very slow! This must be due to the
extensive changes MS have made to multithreading, for optimisation purposes and in preparation for parallel processors
(multi-core processors). Rather than creating threads ad lib, it is now recommended that simple multithreaded tasks be
carried out using the threadpool provided in the C# class library. Other classes exist to optimise threads for more complex
tasks. I also suspect that this is not the end of the story and that multithreading will be overhauled again in the
not-too-distant future.

6. Artificial Intelligence

Purists might say that artificial intelligence (AI) refers only to machines that have human-like intelligence or above and
which mimic the way humans think and react. Such AI will often use programming techniques quite different to the
procedural programming we are considering here, that is programs in which the computer executes one instruction after
another in an orderly sequence. However, we are using the more general definition (or games programming definition) of AI
as simulated intelligent behaviour and in particular the intelligent behaviour of the alien sprites.  The book: teach Yourself
Game Programming in 24 hours, by Michael Morrison (SAMS pub.) gives a good account of the basic kinds of AI we are
interested in here.

In particular,
roaming AI, refers to the movement of game objects, the alien sprites in this instance. Chasing is a type of
roaming AI that has been implemented for the large Blinking Eye type of alien in our game. This involves the alien homing
in on the player and chasing them. The basic algorithm is:

if (Alien.X > Player.X)
  { Alien.X = Alien.X - 1; }
else if (Alien.X < Player.X)
  { Alien.X = Alien.X + 1; }
if (Alien.Y > Player.Y)
  { Alien.Y = Alien.Y - 1; }
else if (Alien.Y < Player.Y)
  { Alien.Y = Alien.Y + 1; }

In this case, the change in X-position can be implemented thus (and the change in Y-position similarly if desired):
if (Alien.XCoord < playerShips[0].XCoord)
           Alien.XCoord = Alien.XCoord + Alien.XVelocity;
else if (Alien.XCoord > playerShips[0].XCoord)
           Alien.XCoord = Alien.XCoord - Alien.XVelocity;
else // Alien.XCoord = playerShips[0].XCoord
           //Move alien
           Alien.XCoord = Alien.XCoord + Alien.XVelocity;
In this case, this works fine. However, in some games, depending on game play style, this might make the alien too
precise and a random element can be incorporated, in which the alien sometimes corrects its position but sometimes fails
to do so.

Similarly aliens can be programmed to evade the player.

Patterned roaming is a type of AI employed by the other aliens in our game - they simply follow a preset movement
pattern.  This can create intelligent behaviour if those patterns are well-chosen, for example the combination of Spinners
moving down the screen diagonally in a row and Twisters coming in from the side in columns, creates an 'intelligent'
strategy that can be tricky to defeat. This can be used effectively if the aliens switch from one pattern to another, like
when the last alien in the classic Space invaders game speeds up and moves sideways once it lands.
Blinking Eye
Blinking Eye - easier to hit, but harder to destroy and more intelligent than
Spinners or Twisters.
5. Collision Detection Algorithm

We need to tell when the player ship collides with an alien or when a missile hits a target sprite. The easiest way to do this is
to define imaginary boxes or bounding rectangles around each sprite, a collision hull, and then determine whether or not
collision hulls overlap. This is illustrated below:
Collision detection
Top left: collision hulls around the player ship, two alien missiles
and an alien are shown as white boxes.

Bottom left: the alien has undoubted collided with the player
ship - both the collision hulls and the sprites themselves
overlap. However, one of the missiles has also collided, even
though it has not yet touched the player ship. This is not
desirable. A solution is to use minimised collision hulls, shown
Collision detection
Now the missile on the left may
strike the engine, but will simply
pass over the top of it - not
unrealistic, whilst the missile on
the right has already hit the target
(or near enough). This method is
a compromise, but is much faster
and more efficient than comparing
actual pixels on the sprite. Well
tweaked collision hulls usually do
a sufficiently accurate job in a
fast-moving game.

A suitable algorithm is given
bool overlap = false;
Rectangle playerBox = new Rectangle(PlayerShip.XCoord, PlayerShip.YCoord, 160, 120);
Rectangle alienBox = new Rectangle(Alien.XCoord, Alien.YCoord, 80, 60);
bool overlapX = ( (playerBox.X + 95) > (alienBox.X+12) && (playerBox.X+55) < (alienBox.X + 68));
bool overlapY = ( (playerBox.Y + 75) > (alienBox.Y+3) && playerBox.Y < (alienBox.Y + 57));
overlap = (overlapX && overlapY);
This code constructs the collision hulls and then checks separately to see if the rectangles overlap in the x-direction
(horizontally) and then if they overlap in the y-direction (vertically). If they overlap both horizontally and vertically then a
collision has been detected and the bool overlap is set to true. (Suitable steps can then be taken, like setting the missile's
hull points to zero so that it is destroyed). [It is possible to do this in a more streamlined fashion without created instances of
the Rectangle class, however, this algorithm executes very rapidly in practise.]
// Activate DoubleBuffering etc. for flicker-free printing
        SetStyle(ControlStyles.DoubleBuffer, true);
        SetStyle(ControlStyles.UserPaint, true);
        SetStyle(ControlStyles.AllPaintingInWmPaint, true);
It is important to switch-on the Winforms double buffering, for flicker-free animation and drawing, with the following
commands in the Form's constructor.
GameClock = new System.Windows.Forms.Timer();
        GameClock.Interval = 40;
        GameClock.Tick += new
        GameClock.Enabled = true;
4. Game Engine Classes

Apart from the main game engine class itself, I have added a Player class, a Sprite class and a Missile class. I could have
derived the Missile class (and perhaps even the Player class) from the Sprite class, but that didn't seem necessary at this
stage. The Sprite class is used to create aliens and other graphics (such as obstacles, pick-ups etc.).
The Game Clock ensures that game activities are coordinated and keeps track of time for any special timed events that
may be added and also ensures that drawing of the display only occurs at set intervals and sets the speed of animation.
(An alternative strategy is to pause the main thread for a few milliseconds whilst the image draws).

[DllImport("winmm.dll", SetLastError = true)]
static extern bool PlaySound(byte[] pszSound, IntPtr hmod, SoundFlags fdwSound);


PlaySound(Sbuffer, IntPtr.Zero, SoundFlags.SND_MEMORY |
We prefer to use buffered sound in computer games. This speeds things up by loading the sound into memory long
before we need to play it, for example during game initialisation (in the Form constructor). This can be done by loading
the .wav sound file into a byte array, byte[]. Note the use of an enumeration (enum) to set bit (binary digit) flags. A byte
comprises b bits, a standard integer 32 bits. With an enum that is labelled with the [Flags] attribute, it is possible to easily
set the individual bits in a byte and to read the value of each bit as a flag or switch, so that each bit contains potentially
useful information. Notice the use of the bitwise inclusive OR operator, |, to set the required bits (turn the required
switches on). Here we want to use a sound in memory (in our buffer) and we want to play the sound asynchronously.

Synchronous sound generally means that the sound is in time with other events, such as animation. In this context it
means that other actions can not be performed until the sound has finished playing. This could get annoying if another
sound has fired or some other event is taking place, so we use asynchronous sound.

Notice also the use of hexadecimal (base 16) notation as indicated by the 0x before every flag position. Four binary
digits correspond to one hexadecimal digit, so we need only 8 hex digits to represent a 32 bit integer, which is a lot
easier to write!

Fortunately, newer versions of .NET (and hence of C#) provide the SoundPlayer class for sound playback. To use this
feature we add an instance of the SoundPlayer class to the list of variables in our main class:
System.Media.SoundPlayer aSoundPlayer = new System.Media.SoundPlayer();
Then in our Form constructor, or wherever we initialise the game, we load the sound (zap1 in this case) into a buffer:
//Load sound
aSoundPlayer.SoundLocation = "zap1.wav";
Then, whenever the player presses fire we can call a function like PlayFireSound():
private void PlayFireSound()
Note the commented out line of code, this was for the alternative strategy of reading the sound from a resource file.
Resources are non-executable data embedded in an application, for example a set of images (such as sprites). The
resource file is written in XML format.

8. Choice of Programming Language

At the end of the day it often isn't the choice of language that matters but what you do with it. Bot used to program the
BBC Micro and Commodore C64 and Vic 20 computers in Basic some years ago, and also machine code (via Assembly
language) for the C64. He then moved on to program Console Apps with C and C++ before moving onto programming
Winforms with C#. More recently he was programmed in the use of Java and for server-side scripting he uses PHP as
that is what the Yahoo Servers that host support.

I do not wish to get involved in the traditional and somewhat egotistical 'my language is better than your language' style
battles that rage incessantly on the Internet these days. Not that they are all a bad thing, this competition keeps
programming languages improving - when one implements a popular feature the others tend to follow suite. For most
purposes I actually use Java since I like the syntax. (As a mathematician I appreciate the maxim: 'Simplify! Simplify!
Simplify!') However, I also use C++ and C# and each language has its pros and cons. I suspect that what each
developer prefers depends on their experiences and the type of applications they write. For example, I do not use
ASP.NET simply because I had problems installing it and running it on my PC as a local host. However, within a day I
was able to develop JSP pages in Java using Netbeans. (However, has to use PHP for server-side
scripts.) I also have no problem with Java's event handling system which is conceptually very clear and the type of
applications I write would not have benefited from the use of delegates, even though when I first used Java I complained
at the lack of delegates and their obvious flexibility, I no longer miss them since their syntax can be awkward (and I do
not think that anonymous methods and 'hidden delegates' entirely alleviate these syntactical issues). However, C# has
good facilities for communicating with databases (i.e. Linq which looks like an improvement on the rather awkward
ADO.NET). I have also had issues, as described above, with the early C# class library (like its lack of sound support)
and some of the early .NET class libraries were also notoriously buggy. The introduction of C++/CLI has attracted me
back to C++ programming, though VS 2010 does not provide intellisense support for this! The moral of the tale is:
releasing incomplete software development tools can put some of us off using certain languages.

If speed is essential, then most people would vouch for C++ since this compiles straight into machine code (native code)
which can then be interpreted directly by the computer. Java instead compiles the code into an intermediate language
called Bytecode, which is then recompiled and interpreted into native code by the JVM (Java Virtual Machine) while the
program actually executes. Similarly C# compiles into Intermediate Language which is recompiled/interpreted at runtime
by the CLR (Common Language Runtime) into native code. Java and C# use JIT (Just in Time) compilers to accomplish
this runtime compilation. This of course slows down program execution initially - each section of code is compiled when
first needed, so each time the program is run there is less compiling to do and execution speeds up. This use of an
intermediate language and JIT compilers has the advantage of facilitating portability or use on different platforms or
operating systems. Java is especially portable. For most purposes, this loss of speed is negligible, especially on modern
systems. However, for very complex processing tasks (though not iterative tasks as these reuse the same code) or real
time applications it may become significant. However, critics forget to mention that a real time Java is being developed.

Another factor to consider is the ease of use of a language. A good computer language is easy to use without suffering
a loss of power and flexibility. This was one of the major considerations when Java was designed. The truth of the matter
is that no programming language is easy. One of the easiest was the early BASIC (though Visual Basic is much more
like C# in complexity and I wont join the usual band of people who knock Visual Basic, which I have only used sparingly
myself). Scripting languages are, by design, easier to learn, though they are not necessarily easier to use (this depends
a lot on what compiler and IDE (Integrated development environment) one uses). Traditionally C++ is considered the
hardest mainstream language to learn, though I personally think it depends on the person. C++ is lower level than Java
or C#, though it is encapsulates high-level programming. C# is probably the highest-level of the three languages, which
for some may make it the easiest to understand, for others the hardest. Personally I find C# the hardest of the three to
understand, precisely because it abstracts away from the mathematical workings with 'black-box' high-level style
constructs. I found delegates and events in C# tricky to grasp at first, though others find them straightforward. Clearly it
depends on a person's past experience and mindset. C++ is perhaps harder for some people because it can take time
to get the hang of pointers (though they reminded me of the peek and poke statements of Commodore BASIC and so I
had relatively few problems with them) and programming Windows forms in the old COM days was a bit strange and
awkward. Now, however, with C++/CLI in .NET, C++ is not so difficult for these purposes. C and C++ are the only
languages that can be commonly used for OS kernels and device drivers, since they can execute at start-up before the
full processing powers of the computer are online, whereas Java and C# require more layers operating beneath them
and more services to boot and so can not currently be executed at start-up. Java and .NET are the prime choices for
complex Web applications, especially with the IDEs to support them and the use of various models, including MVC
architecture coupled with ASP and JSP. C and C++ remain prime choices for lower level OS programming and
high-speed programming. Most high-end games programming, which places maximum demands on a PC, currently uses
C++. However, complex games are being increasingly developed in other languages too.

Personally, I intend to continue using and developing primarily C++/CLI (and C?), C# and Java for Console applications
and Winforms, along with PHP and Javascript for Web applications (and of course HTML and CSS). I don't think I can
cope with more than this at the moment!
7. Adding Sounds

Sound support was not provided by .NEt 1.1 as this early version had no library class for this purpose. Instead you had
to import the native dynamic link library API (Application Programming Interface) package (or COM (component object
model) object) for the Windows native operating system: winmm.dll, which handles the multimedia device drivers, such as
sound cards. These native COM APIs (or the API if you refer to the whole set of these .dll files) provide an interface
between an application or program and the core components of the Windows OS (operating system) in the pre .NET
days. Problems with this system, called DLL hell (conflicts caused by installing an old version of a currently used dll) led
to their replacement with the newer .NET components. However, .NET and COM can operate together, with each being
able to draw upon components of the other - they are interoperable. The .NET components comprise so-called managed
or safe code, with safe automatic memory management, whilst COM objects lack automatic memory management and
require the programmer to dispose of them in code (deterministically). The .NET Framework minimises versioning issues
by including a manifest with each project or program file (assembly in .NET language) which describes the various
components required to run the application and enables the CLR (Common Language Runtime) to ensure that these are

I tried the SimplePlaySound class kindly provided
here. Notice that to import a native COM DLL object in C# you use the
Dllimport attribute (attributes are instructions to the compiler and are enclosed in square brackets) as shown in the
example from the SimplePlaySound class below:
Download a working demo of the game so far (single Win32 setup file).
Alien Invaders - a Java game screenshot
Games Programming with Java

The screenshot below is for a computer game developed, on a PC using the NetBeans IDE, for a university assignment
on animation (and which scored 100% for the coding). I have not added sound yet (it was not a requirement of the
project) and I have not included the source code as the university course still runs and I do not want to give people an
answer to an assignment question! (Also part of the code is subject to the university's copyright).

The JAR file (Java archive file) can be downloaded here:
Simply double-click on this file to run the application, and grant any security privileges requested by your computer, but
be sure that jar files are associated with a Java runtime and so should be represented by a Java icon (to troubleshoot
see, 'trouble-shooting JAR file associations'.
The graphics are not very sophisticated (!) as this does not use sprites as such, but uses Java's built-in graphics
facilities to construct simple shapes, for example the aliens are drawn as follows:

import java.awt.Graphics;

//Part of Picture class
for(Alien a : aliens)
        //Draw alien
        int alienX = a.getAlienXPos();
        int alienY = a.getAlienYPos();
        g.fillOval(alienX, alienY, 16*scale,10*scale);
        //Draw eye
        g.fillOval(alienX+(4*scale), alienY+(2*scale), 8*scale,6*scale);
        //Draw antennae
        g.drawArc(alienX-(2*scale), alienY-(4*scale), 8*scale, 7*scale, -20, 100);
        g.drawArc(alienX+(10*scale), alienY-(3*scale), 8*scale, 7*scale, 200, -100);
        aliensAlive = true;

The game consists of the following class:

Game class - manages game events and timing, etc.
Picture class - draws the screen display each round of the game
Alien class - describes an alien and its properties
Player class
Missile class

and finally the main class that is simply an entry point that runs the Game class to start the program.

Apart from the graphics the core code is very similar to our C# game - collision detection, for example uses the same
overlapping rectangle technique. Rather than a timer, the game runs in a loop with a pause to the main thread after
each screen redrawing event. The game speeds up with each wave. There is no splash screen, all instructions (not
many needed!) are included on the main screen. The whole runs in one thread. Once one has written a game
engine in one language, it is quite straightforward to write one in any language you are familiar with, which perhaps
demonstrates that algorithms and code structure are more important to learn and understand than coding language.

JavaScript/Html Space Invaders for the Web!

The new HTML 5 specification with its canvas class and the newfound support for JavaScript, makes it much easier
to develop games for the Web. I spent the best part of a day developing a template (which you can modify) though I
have not yet added sounds.
Play JavaScript Space Invaders!

I have to say, I thoroughly enjoyed these coding exercises!