Game Programming Fundamentals*

Aug 24, 2009

Programming Basics in Game Context

The goal of this section is certainly not to immediately transform someone with no prior programming experience into a game programmer. That takes time and practice, reading and trying, experimenting and thinking, over a period of weeks (basics), months (intermediate), and years (expert). This is not intended to take the place of a good book on programming, or practice – it’s here for warm up, review, or to complement other resources that are out there by providing a connection to how the most common code structures are used in videogame development.

My hope is that I can plant seeds of familiarity, and establish context of use for the various elements of programming. (Lost already, or a bit unclear on what programming is? Check out What Videogames Are Made Of!)

The following examples are given mostly in C code, taking advantage of a little bit of the flexibility given by a C++ compiler. C++, Objective-C, ActionScript 3, and Java use the same or nearly identical structures for the same functionality, and those are the major programming languages used to develop today’s console, downloadable, mobile, and web videogames.

Finally, the text in this section introduces a lot of material, in a very short space for the amount presented. If you’re new to programming, it will take more than one read, but there’s a good chance that you’ll pick up something new each time. Remember: programming is how every videogame on the market (Wii, online, mobile, 360, PS3, SNES, Atari, Arcade…), every piece of software you use (Office, Windows, FireFox…), and every electronic device works. There’s some patience involved in understanding how all these things work. Stick with it – you’ll be glad you did!


What it is:

Whitespace refers to the gaps between letters within program code, whether represented as tabs, spaces, or new-line breaks (as from the Enter key). Many modern programming languages treat all whitespace the same, meaning that whether you skip lines, indent a certain distance, put two spaces instead of one, or use tabs instead of spaces, the program code will work exactly the same way.

How it looks:

for(int i=0;i<5;i++){showNumber(i);doOtherThingToo();}

…works the same as, but is not as easy on human eyes as…

for(int i = 0; i < 5; i++) {

Example of a use in videogames:

When a program’s source code doesn’t compile correctly, especially for a beginning programmer, it’s frequently due to a mismatch between braces (the { and } symbols). Effective use of indentation to indicate how many pairs of braces are around code helps keep track of where braces should close. All errors in programming code are reported by the compiler using line numbers, which are only useful in leading the programmer to the problem if the code is broken onto new lines after each individual instruction is ended by its semicolon.

The Comment

What it is:

Text visible only to the human reader, that the computer ignores when it’s time to generate (“compile”) a program from the program code.

How it looks:

// Text after 2 slashes on the same line is a comment

/* ...and so is anything typed between the slash-star and the
star slash. This type of comment, unlike the double-slash
style, works on multiple lines. */

Example of a use in videogames:

If you program something at the start of a project, then return to that part of code weeks or months later, you may have trouble figuring out what you were intending when the original code was written. Does the collision detection algorithm assume two objects weren’t already overlapping in the previous frame? Is there a limit to how many badguys the game’s graphics code is intended to render at once? Comments are a perfect way to record this thinking alongside the code it’s relevant to… (continued in ebook)

*This entry is now in the Videogame Developer’s Strategy Guide, available through membership in Gamkedo Club.

Learn and practice team game development with Gamkedo Club.
Membership worldwide. Professional support. Proven process.

Subscribe by e-mail to receive weekly updates with Gamkedo.Community interviews and YouTube training videos for game developers!

All contents Copyright ©2017 Chris DeLeon.

Site production by Ryan Burrell.