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, free with Gamkedo Weekly Check-In.

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!


  1. […] code aspects could make sense in videogame making, there’s a section to address that in Text Lessons Vol. 5. If you’re needing some help getting a C++ project started with Allegro in order to track the […]

  2. […] the explanatory comments in the source itself, anyone with conceptual and structural familiarity with programming should be able to make sense of it, or at least well enough to make […]

  3. […] Vol 5 Beg – Videogame Development Usage of Common Programming Structures […]

  4. […] Once comfortable with the basics of programming, check out this decoder showing how programmings basics fit into game programming. […]

  5. […] Classes can be used to better organize the data above. X/Y pairs are often contained in a Point or Vector class. Both vectors are often grouped into a larger class, along with the image used (goblin, in this case), plus the functions used to handle the character’s movement and updates on the screen. […]

  6. […] Once you have the program compiling – on whichever operating system you prefer – for next steps, read through the comments in the project’s main.cpp file. See if you can figure out how to modify the text to perform some of the remaining tasks. For a conceptual explanation of programming, check out Text Lessons Vol. 1. For a detailed introduction to different programming structures as they relate to videogame programming, check out Text Lessons Vol. 5. […]

  7. […] to start from in the weeks ahead specifically in Processing. They’ll actually be based on the old Volume 5 entry, in which I discuss ideas like white space, for loops, imports, if conditionals, while loops, and […]

  8. […] typing a loop, function, or conditional (confused? see this entry about common programming terms), most programmers close braces pairs and quickly handle format indenting before the filling what […]

All contents Copyright ©2017 Chris DeLeon.

Site production by Ryan Burrell.