The Game Developer's Guidepost

The Game Developer's Guidepost

Your guide to learning game development

Programming Simple 2D Games in D

Introduction

If you were to put the question "How do I program video games?" to the search engine of your choice you would receive a staggering number of results. Many of these are excellent sources of information, some of them are less so. But almost every source only discusses a particular topic in isolation. Sure, you may find good advice on scalable input handling, but how does that relate to the other systems that make up a game? How do you go about programming a complete game project? That’s where this tutorial series comes in. Welcome to Programming Simple 2D Games in D! These tutorials explore various techniques and algorithms applicable in solving real-world game programming challenges by guiding you through the process of coding several complete (though decidedly simple) 2-dimensional arcade-style video games.

The code throughout this series of tutorials will be written in the D programming language and, unless specifically stated otherwise, is distributed under the BSD Zero Clause (0BSD) license. You may wonder why D instead of, say, C++ or Python. The answer is the choice simply boils down to my preferences. I learned to program in C++ and D is quite similar except without many of the annoying rough edges and with powerful introspection and metaprogramming features included. Also, I find D is rarely featured in tutorials of this kind, so perhaps this series will help people discover how suited the language is to writing performance-critical applications such as video games.

This series is intended to be read in order as each chapter builds on the material from the previous one. Most of these chapters will discuss code snippets that will incrementally add features onto the game project until it's completed. The end of each chapter will link to the source code for the project up to that point, though I would recommend only using this as a reference. I encourage you to type all the code discussed into the text editor or IDE of your choice by hand to gain personal experience. I also recommend experimenting with the code; many chapters have a "Chapter Challenges" section which encourages you to find ways to apply the chapter material and find creative solutions to problems on your own. These challenges are strictly elective and any changes to the source code are not meant to carry over to the next chapter.

All the game projects in this series rely on the SDL2 family of libraries for a cross-platform abstraction over the operating system. This should allow you to compile and run each project on the computer of your choice without modifying any code. These libraries were chosen over alternatives as they are time-tested and used frequently in commercial video game products. It's not as difficult as you might think to write your own platform abstraction layer, but it is time consuming and certainly not the subject of this series.

Now that all of that has been said, let's move on to getting your computer prepared for working with D and SDL2.

Reporting Bugs

Though I test all source code published in these tutorials some bugs are bound to be overlooked. If you find any bugs, please send an email to the contact address at the bottom of the page. I’ll do my best to address them quickly.