Creating the Snake Game using SDL2 and C++

Matthew Clark
Nerd For Tech
Published in
2 min readJul 22, 2024

I have been learning how to use SDL2 and decided to make one of my favorite phone games. This article will show my progress on that project.

I started by creating a window and renderer for the game to be played on.

Next I started working on getting the snakes head moving around and facing the correct way.

Note: set an SDL Delay for recording purposes

I then got the snakes body working correctly. The snake is stored in a vector and each time the snake head moves the last part of the snake is removed and added to the front where the head was previously at.

After I got the body working properly I added the apple for the snake to eat. This makes the snake grow by one each time it eats an apple. The apple then randomly relocates.

I have the game end when the snake hits the edge of the screen or itself.

The last thing I am still working on is creating the menu and UI elements. I am going to create a simple menu that starts the game when the player clicks the start button. I will also allow the player to restart after the game is over.

Sneak peak at game logo

--

--