Get Started Now

Intro to C++ Programming

Starting from the fundamentals, become a C++ software engineer, step by step.

LATEST UPDATES

Screenshot from Cyberpunk 2077
Module One

Intro to C++ Programming

Starting from the basics, become a C++ software engineer, step by step

Screenshot from Cyberpunk 2077
Screenshot from The Witcher 3: Wild Hunt
Screenshot from Warhammer: Total War
Screenshot from Cyberpunk 2077
Module Two

Game Dev with SDL2

Learn C++ and SDL development by creating hands on, practical projects inspired by classic retro games

Screenshot from Cyberpunk 2077
Screenshot from The Witcher 3: Wild Hunt
Screenshot from Warhammer: Total War
Screenshot from Cyberpunk 2077
Module Three

Professional C++

Learn C++ and SDL development by recreating classic retro games

Screenshot from Cyberpunk 2077
Screenshot from The Witcher 3: Wild Hunt
Screenshot from Warhammer: Total War
MOST POPULAR

Snake Game Core Components

Introducing the foundational components for our game and setting up the project
Digital art showing a retro snake game
Ryan McCombe
Published

In this lesson, we'll build the foundational components of our Snake game. We'll implement the essential components for window management, asset handling, and user interface. This framework will serve as the backbone for our game's implementation.

Building the Snake Grid

Build the foundational grid structure that will power our Snake game's movement and collision systems.
Digital art showing a retro snake game
Ryan McCombe
Published

In this lesson, we'll build the foundation of our Snake game by implementing a grid system. We'll create Cell and Grid classes to manage the game state, handle rendering, and prepare for the snake's movement.

By the end, you'll have a fully functional grid that displays the initial snake position and first apple.

Snake Movement and Navigation

Learn how to implement core snake game mechanics including movement, controls, and state management
Digital art showing a retro snake game
Ryan McCombe
Published

In this lesson, we'll implement the core mechanics of our snake game. We'll create the game state management system, handle user input for controlling the snake's movement, and implement the snake's movement logic. By the end, you'll have a fully functional snake that responds to player controls.

We'll start by defining the fundamental data structures needed to track our snake's state, including its position, length, and direction. Then we'll expand our state system to advance the game through time.

Finally, we’ll allow our game state to respond to user input, allowing the player to control the direction their snake moves.

Snake Growth

Allowing our snake to eat apples, and grow longer each time it does
Digital art showing a retro snake game
Ryan McCombe
Published

Now that we have our basic movement system in place, it's time to make our Snake game truly playable. We'll implement apple consumption mechanics, handle snake growth, and create a dynamic apple spawning system.

By the end of this section, our snake will be able to move around the grid eating apples, and getting longer for every apple it consumes.

Pausing and Restarting

Giving our Snake game the ability to pause itself, and adding a clickable button for restarting the game
Digital art showing a retro snake game
Ryan McCombe
Published

Now that we have our core Snake game mechanics working, it's time to enhance the user experience by adding interactive UI elements. In this lesson, we'll implement a restart button that allows players to reset the game without having to close and reopen the application.

We’ll also update our GameState class so the game initially starts in a paused state, and doesn’t advance until the user starts moving their snake.

Win/Loss Logic for Snake

Add game-ending logic to our Snake game with custom events, state management, and visual cues for player feedback.
Digital art showing a retro snake game
Ryan McCombe
Published

Now that we have a working Snake game with basic movement and apple collection, it's time to add win-and-loss conditions to create a complete gaming experience.

In this lesson, we'll implement collision detection for game over states, add a winning condition when the snake reaches maximum length, and provide visual feedback for both outcomes.

Building the Score Display

Build a dynamic score counter that tracks the player's progress and displays it with custom graphics and text.
Digital art showing a retro snake game
Ryan McCombe
Published

In this lesson, we'll implement a score counter for our Snake game to help players track their progress.

We'll build a UI component that displays the current score alongside the maximum possible score, complete with a custom background and an apple icon.

Animating Snake Movement

Learn to animate the snake's movement across cells for a smooth, dynamic visual effect.
Digital art showing a retro snake game
Ryan McCombe
Published

Right now, our snake moves instantly between cells. We'll enhance this by implementing a sliding animation, giving the illusion of the snake smoothly traversing the grid. This involves dynamically adjusting the portion of each cell occupied by the snake.

To do this, we’ll be using our Tick() mechanism to provide frame-by-frame adjustments to our snake’s visuals.

This is the final part of our project, so we’ll also finish things off with a list of suggestions on how we can further develop the game and put our skills to the test!

Writing Data to Files

Learn to write and append data to files using SDL2's I/O functions.
Abstract art representing computer programming
Ryan McCombe
Updated
Published

In this lesson, we’ll introduce how to write data from our program to external sources. We’ll focus on writing to files for now, but the techniques we cover lay the foundations for working with other data streams, such as network traffic.

As we might expect, SDL’s mechanism for writing data shares much in common with their API for reading data. We’ll rely on SDL_RWops objects, and the functions we use will be familiar to what we learned in the previous lesson.

Like before, we’ll start with a basic main function that initializes SDL, and calls Write() and Read() functions within an included File namespace.

// main.cpp
#include <SDL.h>
#include "File.h"

int main(int argc, char** argv) {
  SDL_Init(0);
  File::Write("output.txt");
  File::Read("output.txt");
  return 0;
}

Our Read() function logs out the file’s contents, using techniques we covered in the previous lesson. In this lesson, we’ll work on the Write() function, which is currently empty:

// File.h
#pragma once
#include <iostream>
#include <SDL.h>

namespace File {
  void Read(const std::string& Path) {
    char* Content{static_cast<char*>(
      SDL_LoadFile(Path.c_str(), nullptr)
    )};
    
    if (Content) {
      std::cout << "Content: " << Content;
    } else {
      std::cout << "Error loading file: "
        << SDL_GetError();
    }
    
    SDL_free(Content);
  }
  
  void Write(const std::string& Path) {
    // ...
  }

}

Running our program, we should see an error output from our Read() function, as it’s trying to read a file that we haven’t created yet:

Error loading file: Parameter 'src' is invalid

Customising Mouse Cursors

Learn how to control cursor visibility, switch between default system cursors, and create custom cursors
Abstract art representing computer programming
Ryan McCombe
Published

When we’re working on a mouse-based game, creating an engaging user interface typically requires us to change the visual appearance of the cursor.

For example, we might customize the cursor to fit the theme of our game. We may also want to apply further modifications to the cursor based on what the user is pointing at, like changing the cursor to a sword if the pointer is hovering over an enemy. This helps players quickly understand what effect clicking will have.

This lesson will guide you through the various cursor customization options available in SDL2. We’ll cover:

  • Simple visibility toggles to show and hide the cursor
  • Switching between a range of default cursor options provided by the platform
  • Implementing custom cursors from image files
  • Completely replacing the cursor implementation to take full control on how mouse interaction is implemented
Module One
3D art showing a progammer setting up a development environment

Intro to C++ Programming

Become a software engineer with C++. Starting from the basics, we guide you step by step along the way

This course includes:

  • 60 Lessons
  • Over 200 Quiz Questions
  • 95% Positive Reviews
  • Regularly Updated
  • Help and FAQ
Module Two
sdl2-promo.jpg

Game Dev with SDL2

Learn C++ and SDL development by creating hands on, practical projects inspired by classic retro games

This course includes:

  • 84 Lessons
  • 92% Positive Reviews
  • Regularly Updated
  • Help and FAQs
Module Three
A computer programmer

Professional C++

Comprehensive course covering advanced concepts, and how to use them on large-scale projects.

This course includes:

  • 125 Lessons
  • 550+ Code Samples
  • 96% Positive Reviews
  • Regularly Updated
  • Help and FAQ
Get Started Now

Intro to C++ Programming

Starting from the fundamentals, become a C++ software engineer, step by step.

Contact|Privacy Policy|Terms of Use
Copyright © 2025 - All Rights Reserved