Skip to content

soupi/sdl2-snake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Snake

This is an example application for sdl2.

Click on the SDL module in the link for a tutorial on how to get started with sdl2.

Gameplay

Gameplay gif

Build and Run

Prerequisites

You will need to install Stack.

You will also need sdl2 libraries:

Note: You don't have to install ttf, image and mixer for this snake game to work, but you might want to use fonts, images and sounds later.

Ubuntu

sudo apt install libsdl2-dev libsdl2-ttf-dev libsdl2-image-dev libsdl2-mixer-dev

OS X

brew install sdl2 sdl2_ttf sdl2_image sdl2_mixer

Windows

stack exec -- pacman -Syu
stack exec -- pacman -S mingw-w64-x86_64-pkg-config mingw-w64-x86_64-SDL2 mingw-w64-x86_64-SDL2_image mingw-w64-x86_64-SDL2_ttf mingw-w64-x86_64-SDL2_mixer

Build and Run

Stack

stack build && stack exec app

Want to tinker with this game? Here are a few ideas

  • Do nothing when the user tries to move to the direction the snake is coming from instead of failing
  • Change the snake's speed
  • Add a key to restart the game
  • Keep score and report to the user
  • Add obstacles
  • Play a sound when the snake eats the apple
  • Report game over to the game window instead of to the console