1)

Programming games in 'C'

By J.C.Spooner 2001

Introduction
One of the most commonly asked questions here is "how do you write a computer game ?" - a short question, but one where the answer requires a very long explanation. Of course there are always the 'cop out' answers, like "with a lot of hard work and patience", but a reply like this, whilst being true, is only a partial answer. I'm no expert programmer, far from it, but hopefully the following pages will provide a more detailed answer to the question.

The task though is immense and it's difficult knowing where to start. There are two approaches : start with something simple, like small Visual Basic games that are easy to write, or delve right in at the deep end and use 'C'. I believe the latter is the better option because C and C++ are the languages of choice for the vast majority of game programmers. Another advantage with learning C is that once it is mastered, it will make learning other programming languages like Perl ( for CGI scripting ) a lot easier, as they share a lot of similarities.

There are no special skills required to write computer games apart from determination and a willingness to adapt and learn. It is true that a basic mathematical knowledge is needed though, but the more you program the better your maths becomes over time, so being a mathematical genius is not a requirement.

The pages in this series will grow all the time, with more being added continuously on an ad-hoc random basis. The tutorials will initially start with some pretty boring simple text based C programs, and will require no prior knowledge whatsoever of programming. Although the first part will be boring and the programs will seem pointless, it is probably the most important of all to understand. Evenutally the tutorials will move away from text based programs to graphical 3D programs running under Microsoft Direct X 8 ( the latest Direct X version at the time of writing ) and c++.

If you are interested in learning about programming then please continue on, and stick with it, no matter what, it will give you a great amount of pleasure as well as pain at times....

 

A 'C' compiler
A compiler is a program that turns C "source code" into "machine code". Source code is sometimes referred to as program code, and is the name given to the code programmers type in. Computers don't understand this code, they only understand machine code, so it is the compilers job to turn our C programs into a form that the computer will understand.

A compiler is really just a program itself, and there are various C compilers around to choose from. The two most common are Microsoft Visual C and Borland C. For the purposes of the first few programs a simpler free *compiler will do the job. There is an excellent one ( Miracle C ) available at www.c-compiler.com. It's only a 300 K download as well and is perfectly suited for the purposes of the early programs. Later other compiles, like Microsoft Visual C and Bloodshed's Dev C++ will be needed as they will require more advanced features like Direct X and projects.

The description above is a very brief description of the compilation process, it is a lot more detailed, but it's of no interest yet. There is detailed information about the compilation process on the Miracle C site if you want to delve a bit deeper into it. Note that to install Miracle C on any other operating systems than ME, 2000 and XP you will need the Microsoft installer, there is a link to the download on the Miracle C site above and instructions on installing it.

* Miracle-C can be registered, upon registration you recieve the source code ( program ) for the compiler itself

 

Onwards and upwards
After the compiler is installed, ( it's probably best to install it to the default folder c:\program files\miracle c\ ), everything is set up and ready to start programming. Each of the programs that will be followed will introduce a new C language feature and should be followed in order. The first few programs are not really that useful, but help in the learning of the C language. Only the new parts of each program are explained, which is why it is important to follow them through in order. Each program has it's own page containing a description of the program, the program code ( both displayed and downloadable ) and a detailed line by line description of the features. They do get progressively more detailed as they go on, and it is advised that each should be fully understood before moving onto the next program.

Initially the programs will be all DOS like text programs, don't let this put you off, the only difference between text programs and graphical programs is in the way information is presented, everything else is the same for both.

Continue

(c) J.C.Spooner 2001