Make it fun with music and sound FX - Programming a game in PureBasic - The Snake part 06

Опубликовано: 07 Июнь 2026
на канале: Pure Programming
759
33

Learn PureBasic by example. Follow the development step by step of a simple 2D game : the snake. This famous game lets you control a snake on a screen where apples appear at random. When the snake eats an apple, it grows in size. The goal is to survive the longest.

In this episode, I try to make the game more fun by making it more difficult and adding music and sound effects.
To make it more difficult, I reduce the playing area to a 320x320 square in the middle of the screen. The square is filled with a light blue/dark blue checkerboard pattern, surrounded by an orange 5-pixel wide border. The rest of the screen is black.
To add music and sound effects, I add the OGG sound decoder, initializes the sound engine, load the sounds (saved as OGG format) and play them. The music is played when the game start and loops forever. There are 3 sound effects : "apple" when the snake eats an apple, "turn" when the snake turns and "crash" when the snake dies. I also add two keyboard shortcuts. 'F' to switch on/off the sound effects and 'M' to switch on/off the music. For the M key to work on a AZERTY keyboard, I use the KeyboardMode command.

I do not distribute the sound files for copyright reasons. But you can find sound effects at http://freesound.org
To convert files to OGG format, you can go to https://convertio.co

Download the code from this episode at https://bit.ly/351MHWV

Download PureBasic at http://www.purebasic.com/pp

Pure Programming blog
https://pure-programming.com

Facebook
  / pureprogramming  

Follow me on Instagram at @pure.programming

Support the channel with some Merchandising
EU : shop.spreadshirt.net/pure-programming
US : shop.spreadshirt.com/pure-programming