Game programming

Game programming is the branch of software engineering related to creating video games. It is not widely taught as a distinct career itself. Many programmers learn it themselves as a hobby, through trial-and-error, through modding existing games, books or via online resources. A few universities are starting to offer game development courses, however, such as Massachusetts Institute of Technology, University of Utah and University of Southern California. Some even specialize in game development, such as DigiPen and Full Sail University.

This course will cover basic to advanced topics using the C language and SDL. If the reader of this course completes all the samples, they will be able to create a simple 2D game in the vein of Tetris, Arkanoid or a game of their own design. Game programming is a specific type of software engineering and can only be learned by doing. We chose SDL as a game API because it is an easy library to work with: it is very powerful and offers almost all the features needed in a game. Other game APIs, like DirectX and OpenGL, require a higher learning curve.

Knowledge and experience in a programming language is expected. It is recommended that the reader understands C in an intermediate level since most articles and sample code will focus on that language. Also, it is recommended—but not required—to know something about event driven programming, such as with SDL or the Windows API. It is helpful if the reader is comfortable with some intermediate math, such as algebra, and some basic knowledge of physics. We will proceed from there and get to the programming topics related to our task: learning game programming.

The art of game programming is not like playing video games; it is more exciting, said the founder of DigiPen. To become a good developer of games, first of all you should be a regular player. If you do not know the main types of games that exist you may not be able to develop a game that meets the minimum standards of quality and does not meet player's expectations. Therefore, the first step is to know which kinds of games are available to get an idea of what kind of game you are going to develop.

2D Games
Games have become much more complex and exciting than they were in their infancy. Now most new games are some kind of three-dimensional adventure, whether they are sports games, strategy, racing, wrestling, role-playing, or puzzle. However, the knowledge that this tutorial series will give you will be useful to develop games in two dimensions (2D). To make the jump to the world of 3D games, you need to learn the techniques of 2D games first. Then you master the math knowledge required (linear algebra) and other advanced topics, not covered on this topic.

However, 2D games are not entirely outdated. There will always be public for a Tetris-style game or one like Mario Brothers (maybe for a handheld console, even for the PC). The manner in which the reader can compete with the new 3D video games is by taking advantage of what people like: playability. It is incredible that relatively simple games like Space Invaders and Pacman have had people entertained for decades. By learning this series of tutorials, you may develop games like Space Invaders, Centipede, Asteroids, Pacman or, if you practiced hard enough, a game like Contra or Mario Brothers. But not without tons of work. A game programmer does not build himself from night to day, or in 21 days, like some books claim.

Although most commercial top selling games are developed by a full team of designers, programmers, artists and writers, it is still possible for one person to develop a game of good quality. If you look at the credits screen of some successful games in the past, the main logic of the game was programmed by one or three people. Therefore, and based upon my personal experience (11 full games made by myself), I know that this is possible. Also, there is a big community of self-taught game programmers who make the coding just by themselves (no team).

Game libraries
And the most important thing is that nowadays it is easier to program games (relatively speaking, because any kind of software is somewhat complex). In the past, to program games for the PC you needed to be an experienced Assembler programmer (Assembler guru) to access the video card, sound and joystick through interrupts and BIOS functions. Today, there are different libraries with specialized functions that ease the development of video games; those are DirectX and SDL, mainly. You use them as you do with any other library... and Assembler knowledge is not needed. Windows operating system is sufficiently sophisticated to avoid having to use difficult functions from the past. In Windows 3.1, for example, memory management was 16-bit and, hence, in order to access the dynamic memory you could not use the classical functions called malloc and free. You had to request the memory, lock it, use it and unlock it. It was a very tedious task compared with the straight use of malloc that you can make in Win32. Even if you use the Windows API functions it is a straight task.

What you need to do now is to master one of these development libraries. If you plan to use DirectX, you must also have basic to advanced knowledge of Windows programming, depending on the task. If you use SDL, (what we do in these tutorials, for simplicity) you only need to learn how to handle this library. SDL encapsulates everything related to Windows (or Linux XWindows, if used in this system) so you never have to make a WinMain or WinProc function. Besides, obviously, the need to know a programming language (C in this case) thoroughly and know how to compile and run programs. It is recommended to have made several programs in other areas of software development.

In these tutorials, words such as double buffering, flipping page, blitting, sprites and finite state machines will be used often. So check the corresponding articles when you need to know more about each topic.

André Lamothe suggestions
What is most exciting about learning how to program video games is that after this, any kind of software (except operating system software) will be much easier to program. The developers of video games do things that other programmers would consider impossible (as the great master André Lamothe said). André recommends people to program as if nothing were impossible. That way you can get very far. In his words (the bold is mine):

... You'd better forget everything you learned about the PC and what's supposed impossible. Think of programming as a game. It's the greatest game in the world. The object of the game is to do the impossible. Most of the programming that a video-game programmer does would seem impossible to a programmer of ordinary applications. —André Lamothe, game programmer, author of many books on the subject and CEO of Xtreme Games LLC.

Therefore, we must defeat the impossible in programming video games. The games Banjo-Kazooie, Quake, and Need For Speed boast features that had been thought impossible a few decades ago (except for writers of science fiction).

Game stages
First of all, it comes the idea for the game. That idea is improved and written in a game design document. That document is useful for tracking the changes done to the software. Here, the game designer writes and plans everything about the future software: the plot, the characters, the music, the playability, the controls and so on.

Second, it comes the harder stage, the game programming itself and the creation of the media needed for the software. The programmers, who usually work in teams, are divided according their mission: gameplay programmers, 3D engine programmers, system programmers (they make the tools needed for the game: linkers, compilers, art converters among other) and map designer. This is not an exhaustive list, these division may vary.

The creation of media is done here. Several 2D and/or 3D artists begin making their models and they later send it to the programmers, for these people to incorporate them into the game. Musicians also work on this phase.

The third stage is the beta-testing and modification of the game software. It is done by a special team of beta-testers who try to test every possible action in the game, searching for bugs (programming errors) and informing the programmers. The programmers then modify the software to correct the problems found.

The fourth stage is selling the game. It includes marketing strategies, advertising and so on. Sometimes the company that created the game sells the rights to another for it to commercialize the game. That is the case of Rare, who sold its game licenses to Nintendo.

The fifth stage is optional, and it may include some improvements made to the game to be sold as expansion packs. Also some corrections can be done if the release version still has bugs. Usually, the modifications can be downloaded freely through a website.

On this topic we will cover step 2, game programming.

C

 * Abstract Data Types
 * Collision detection
 * Basic SDL
 * Blitter and sprites
 * Dynamic Link Libraries
 * Function pointers
 * Options menus
 * Physics
 * Finite State Machines
 * Sound

BASIC

 * BlitzBasic
 * DarkBasic
 * GLBasic

C++
Go to main article

Java, Python


 * Add your own

Related topics

 * Game Design