Table of Contents
- Initializing SDL
- Keyboard Input
- Drawing Graphics
- Playing Sound
- Drawing Text
- Regulating FPS
- Enumerations and Random Numbers
- Bounding Box Collision Detection
- Planning the Game
- Super Basic Game Structure
- Wrapping up
Part 1 – Introduction
Welcome to Beginner’s Guide to Game Programming – A problem-solving approach.
This tutorial is designed to teach you how to write a super-basic game in C++ using either Allegro or SDL to handle graphics, sound, input, and timers.
First off, yes that is a lot of pages! But I’ve made liberal use of whitespace to try to keep the document easy to read, plus there is a lot to cover if this is your first game! Please keep an open mind and give it a try. Everything is pretty basic, and if you don’t understand something I am available for any questions via either my YouTube channel (http://www.youtube.com/LusikkaMage) or my email address (RachelJMorris@gmail.com).
This tutorial will cover the key elements of making the sample game, but will not actually give you the full code on how to implement it. (Thus, the “problem-solving” approach).
For this first tutorial, we will be making a game called Pickin’ Sticks (though you can use whatever graphics and sounds you want in your version), and while the source code is online, I suggest you try to figure out how to write everything on your own first. This way, you begin to build the skills you need to write more complicated games.
There will also be a video tutorial portion of the tutorial, covering the same things in relatively small video chunks. Major questions answered by viewers (and readers) will be updated both in the text format (this thing), and as additional videos.
Also, a lot of the code examples in this tutorial are bare-bones. It is up to you to figure out how you want to implement them in a class, and I will try to have some example classes later on in the chapters.
What are we making?
Pickin’ Sticks is a very basic game I use as a sort of “Hello World” game I make when trying something new – a new library, language, etc. The gist of the game is that you have a top-down view of your character and a single stick on the screen, which is placed randomly. When you touch the stick, a point is added and the stick gets new coordinates, which are also randomly generated.
What you should already know
This tutorial assumes that you have no prior knowledge of Allegro or SDL, but are familiar enough with C++. This includes the following:
- If statements and loops
- Classes and inheritance
Setting up Allegro
Also, which IDE you choose to use is up to you, but I only have experience using Visual Studio with SDL + OpenGL. For the most part, I use Code::Blocks as it is free. If you’ve never installed a library for your IDE before, you may look int DevC++, which uses things called “DevPak”s that auto-install libraries for you just by double-clicking them.
As a note, this tutorial uses Allegro 4.2. There is an Allegro 4.9 out, which is the beta for Allegro 5, and some things have changed with it.
Free IDE download links
Tutorials for setting up Allegro
Other handy tutorials and resources
Game Dev in general
Resources for public domain graphics and sounds
When creating games, you should try to get used to using original or public-domain resources, rather than, say, sprites ripped from another game. This way, there are no concerns with Intellectual Property infringement.
On my site, http://www.moosader.com , there is a Resources section that has a few public domain songs and sprites that you can use for any projects. You can also find public domain resources by googling ”public domain graphics/sound”.
Note: The latest version of SDL is 2. This tutorial uses SDL 1.2 and is incompatible with SDL 2!
This tutorial © Rachel J. Morris, 2009