PC Games

Orb
Lasagne Monsters
Three Guys Apocalypse
Water Closet
Blob Wars : Attrition
The Legend of Edgar
TBFTSS: The Pandoran War
Three Guys
Blob Wars : Blob and Conquer
Blob Wars : Metal Blob Solid
Project: Starfighter
TANX Squadron

Tutorials

2D shoot 'em up
2D top-down shooter
2D platform game
Sprite atlas tutorial
Working with TTF fonts
2D adventure game
Widget tutorial
2D shoot 'em up sequel
2D run and gun
Roguelike
Medals (Achievements)
2D turn-based strategy game
2D isometric game
2D map editor
2D mission-based shoot 'em up
2D Santa game
2D split screen game
SDL 1 tutorials (outdated)

Latest Updates

SDL2 Versus game tutorial
Wed, 20th March 2024

Download keys for SDL2 tutorials on itch.io
Sat, 16th March 2024

The Legend of Edgar 1.37
Mon, 1st January 2024

SDL2 Santa game tutorial 🎅
Thu, 23rd November 2023

SDL2 Shooter 3 tutorial
Wed, 15th February 2023

All Updates »

Tags

android (3)
battle-for-the-solar-system (10)
blob-wars (10)
brexit (1)
code (6)
edgar (9)
games (43)
lasagne-monsters (1)
making-of (5)
match3 (1)
numberblocksonline (1)
orb (2)
site (1)
tanx (4)
three-guys (3)
three-guys-apocalypse (3)
tutorials (17)
water-closet (4)

Books


A North-South Divide

For over a hundred years, messenger Duncan has wandered the world, searching for the missing pieces of an amulet that will rid him of his curse; a curse that has burdened him with an extreme intolerance of the cold, an unnaturally long life, and the despair of watching all he knew and loved become lost to the ravages of time. But now, Duncan is close to the end of his long quest.

Click here to learn more and read an extract!

SDL2 Game Tutorials

Overview

This series of tutorials focuses on creating games using SDL2. The tutorials are split into several parts, to make it easier to understand the steps involved and not to overload the reader with information from the start.

Note: These tutorials assume that you are already familiar with C programming and you are comfortable with advanced topics such as pointers, as well as using CMake and Makefiles. You are also advised to follow the tutorials in order, rather than just jumping around as prior knowledge is assumed throughout. You can read more about setting up SDL2 on the API's wiki page: https://wiki.libsdl.org/Installation.

The SDL1 tutorials have moved here. Since these use SDL 1, they are considered out of date and it is suggested you use the SDL 2 tutorials instead.

Building

Dependencies

cmake*
SDL
SDL Image
SDL Mixer
SDL TTF
SDL Net

(* - if using an IDE, plugins may be available to support cmake without requiring any downloads by the user)

Compiling

These tutorials use cmake to build. You may build them in one of several ways:

cmake CMakeLists.txt
make

This will generate the make file and all build-related data in the same directory as the CMakeLists.txt file. While this is the simplest approach, it does result in all the cmake files being created alongside the other assets. It is the fastest way to get going, however, and the approach taken in the tutorial listings.

mkdir build
cd build
cmake ..
cd ..
make -C build

This is a much neater approach, as all the cmake related build data is stored in a directory called "build". The downside is that it requires some extra steps on behalf of the user. Actual compiling also needs to be performed by either changing into the build directory before running make, or by using make -C build to tell make to work with the build directory.

Via your IDE

An IDE such as VSCode has support for cmake, and may have its own rules as to where it creates the build data, and how it compiles. So long as it respects the rules within the CMakeLists.txt, this shouldn't be an issue.

In all cases, the resulting binary will be produced alongside the CMakeLists.txt file, and relative to the required assets (data, gfx, sound, music). If you are using an IDE, ensure the binary is produced this way, as it will expect to load data relative to its location. If not, you will likely find the binary won't run, as it will fail to load any assets.

Purchase

The full source code and assets for all the listed tutorials is available for purchase.

From itch.io

You may purchase the complete set of tutorials from itch.io, using the link below.

Extras

You can also download some of the games created by these tutorials by clicking here.

Creating a 2D shoot 'em up

This tutorial will show how to create a simple 2D shoot 'em up, starting with opening a window, all the way to building a highscore table. If you're new to SDL2, this would be a good place to start.

  1. Opening a window
  2. Drawing the player
  3. Moving the player
  4. Firing
  5. Refactoring
  6. Enemies
  7. Shooting enemies
  8. Enemies fighting back!
  9. Effects and background graphics
  10. Sound and music
  11. Bitmap fonts and scoring
  12. Score pods
  13. Highscore table (Part 1)
  14. Highscore table (Part 2)
  15. Title screen and finishing touches

Creating a 2D top-down shooter

This tutorial will show how to create a simple top-down 2D shooter that we're going to call Battle Arena Donk! Mouse controls will be used extensively throughout.

  1. Reading the mouse
  2. Angles and rotation
  3. Mouse buttons and shooting
  4. Battling enemies
  5. Scrolling the arena
  6. Finishing touches

Creating a 2D platformer

Learn how to create a simple multi-scrolling 2D platformer, code-named Pete's Pizza Party.

  1. Loading and displaying the map
  2. Scrolling the map
  3. Controlling the character
  4. Interacting with entities
  5. Moving platforms
  6. Finishing touches

Creating a sprite atlas

In this tutorial, we'll demonstrate how to create and use a sprite atlas.

  1. Preparing the files
  2. Creating the atlas texture
  3. Creating the atlas meta data
  4. Using the atlas with SDL2
  5. Rotating, scaling, blending, and colour modulation

Working with TTF fonts

In this tutorial, we'll demonstrate how to use SDL2 TTF for text rendering.

  1. Basic font rendering
  2. Creating a glyph atlas
  3. Wrapping, aligning, and typewriter effect
  4. Unicode support

Creating a simple 2D adventure game

Learn how to make a basic 2D adventure game.

  1. Movement and map rendering
  2. Map scrolling and collisions
  3. Loading a map
  4. Entity interactions, part 1
  5. Inventory management
  6. Entity interactions, part 2
  7. Fog of war
  8. Message boxes
  9. Loading the dungeon
  10. The Grumpy Goblin
  11. The Cursed Maze
  12. Vampire Bats!
  13. The Escape Room
  14. Finishing touches

Creating a basic widget system

Learn how to make a widget system, for use with in-game menus.

  1. Basic non-functional menu
  2. Actionable menu
  3. Loading a widget set
  4. Select widget
  5. Slider widget
  6. Text input widget
  7. Control widget
  8. In-game menu
  9. Widget groups

Creating a 2D vertical shoot 'em up

Learn how to create a vertical 2D shoot 'em up, that includes power-ups and enemy attack patterns.

  1. Setting up
  2. Enemy attack patterns (first sequence)
  3. Power-ups
  4. Return fire!
  5. Enemy attack patterns (full sequence)
  6. Bosses
  7. More power-ups
  8. Enemy attack patterns (final sequence)
  9. Finishing touches

Creating a 2D run and gun game

Learn how to create a 2D run and gun game, like Contra, Turrican, and Duke Nukem.

  1. First steps
  2. Aiming, shooting, and ducking
  3. Destroying targets
  4. Enemies
  5. Basic map
  6. Gameplay tweaks
  7. Larger, scrolling map
  8. Player health + power-ups
  9. Keycards, doors, and other solid entities
  10. Adding a quadtree
  11. More gameplay tweaks
  12. Player death + effects
  13. A full level!
  14. Game controller support
  15. Finishing touches

Creating a roguelike

Learn how to create a simple roguelike.

  1. Map generation
  2. First monster
  3. Combat
  4. Adding the HUD
  5. Monsters attacking!
  6. A* Pathfinding
  7. Items and inventory display
  8. Using items
  9. Equipping items
  10. Comparing stats
  11. XP and levelling
  12. Stairs
  13. More monsters, more loot!
  14. Doors
  15. Death and Highscores
  16. Status effects
  17. Saving
  18. Loading
  19. The Mouse King
  20. Finishing touches

Creating a lookup system

A short tutorial on how to make a key-value lookup system.

  1. Creating a lookup system

Creating an in-game achievement system

Learn how to create an achievement system, known as Medals.

  1. Unlocking Medals
  2. Integrating with gameplay
  3. Saving progress
  4. A full game!
  5. Online functionality
  6. Threading

Creating a simple 2D turn-based strategy game

A tutorial about how to create a 2D turn-based strategy game.

  1. Basic unit control
  2. Controlling multiple units
  3. Limiting movement
  4. AP (action point) handling
  5. Enemies and simple AI
  6. Combat #1: Player attacking
  7. Combat #2: Weapons, accuracy, and damage
  8. Combat #3: Feedback and effects
  9. Combat #4: Line of sight
  10. Combat #5: AI attacking
  11. Handling player death
  12. Item handling
  13. Adding the camera
  14. Expanding the HUD
  15. Map generation
  16. Slime pools
  17. Lilac Ghost
  18. Blue Ghost
  19. Red Ghost
  20. Green Ghost
  21. Winning and losing
  22. Smooth camera
  23. Threaded map generation
  24. Finishing touches

Making a 2D isometric game

A tutorial about how to create a 2D isometric game, in an old-school flip-screen style.

  1. Drawing tiles
  2. Selecting tiles
  3. Adding entities
  4. Adding Purple Guy
  5. Walls and trees
  6. Occlusion testing
  7. Loading and traversing the map
  8. Entities and items
  9. Buttons and bridges
  10. Simple lighting
  11. Mini map
  12. Finishing touches

Making a basic 2D map editor

A tutorial about how to create a basic 2D map editor.

  1. Simple map editor
  2. Tile selection
  3. Entity selection
  4. Scrolling and picking entities
  5. Expanded UI and mini map

Making a mission-based 2D shoot 'em up

Learn how to create a mission and objective-based 2D multi-directional shoot 'em up.

  1. Basic fighter control
  2. Main guns
  3. Adding enemies
  4. Simple AI
  5. Collectables
  6. The HUD
  7. Secondary weapon: Rockets
  8. Secondary weapon: Homing missiles
  9. Secondary weapon: Red beam
  10. Secondary weapon: Mines
  11. Secondary weapon: Shield
  12. Objectives
  13. Start / end screens
  14. Start of intermission
  15. Intermission: Planets
  16. Intermission: Comms
  17. Intermission: Shop (1/2)
  18. Intermission: Shop (2/2)
  19. Intermission: Stats
  20. Intermission: Loading / Saving
  21. Intermission: Options
  22. Main game loop
  23. Scripting
  24. Mission: Training
  25. Mission: Collect catnip
  26. Mission: Bombers
  27. Mission: Rescue POWs
  28. Mission: SS Goodboy
  29. Mission: The Gravlax (Boss)
  30. Title screen
  31. Finishing touches

Making a 2D Santa game

Learn how to create a simple Santa game to celebrate Xmas!

  1. Scrolling
  2. Houses
  3. Chimneys
  4. Santa's sleigh
  5. Gifts and coal
  6. Scoring
  7. HUD
  8. Game Over
  9. Highscore table
  10. Sacks
  11. Enchanted Snowman #1
  12. Enchanted Snowman #2
  13. Snow
  14. Hills and trees
  15. Finishing touches

Making a 2D split screen game

A traditional 2D split screen two-player game, using SDL2's geometry functions.

  1. Loading models
  2. Steering and shooting
  3. Loading Zone(s)
  4. Ready Player Two
  5. Split screen
  6. Live. Die. Repeat.
  7. Heads Up!
  8. Live. Die. Repeat. And Repeat.
  9. Particles and effects
  10. Collectables
  11. Gooooooooooooooal(s)
  12. Spatial Grid, part 1
  13. Spatial Grid, part 2
  14. Aliens3
  15. Zones (again)
  16. Game options
  17. Title screen
  18. Finishing touches

Downloads

Binary downloads (Linux + Windows) for some of the tutorials included here:

Mobile site