Grow Long!
Snake in C++
The 1997 classic rebuilt with modern C++: a std::deque body, grid movement on a timer, food, self-collision and speed-up. This episode is secretly about data structures, the fun way.
The 1997 classic rebuilt with modern C++: a std::deque body, grid movement on a timer, food, self-collision and speed-up. This episode is secretly about data structures, the fun way.
main.cpp plus a build file, right in the browser with no install. Open the C++ Mod Studio →g++ game.cpp -o game -lsfml-graphics -lsfml-window -lsfml-system && ./gamesf::VideoMode({800, 500})sf::VideoMode({800, 500}) (curly braces), the new event loop while (const std::optional e = window.pollEvent())while (const std::optional e = window.pollEvent()) with e->is<sf::Event::Closed>()e->is<sf::Event::Closed>(), sf::Keyboard::Key::Leftsf::Keyboard::Key::Left (add ::Key::Key), and setPosition({x, y})setPosition({x, y}) / move({dx, dy})move({dx, dy}) (curly braces). The ? complete finished code at the bottom of this page is full SFML 3 and compiles on a fresh install, use it as your reference.sf::RenderWindowsf::RenderWindow, the game loop and event polling. If you're starting here or need that boilerplate, grab it in one click: Episode 1 setup ? âĸ C++ Cheatsheet ?Each step adds one feature. Write the code, watch it come alive in the canvas, then make it your own.
Keep the SFML cheatsheet handy
Window, sprites and input in one place - use it beside this workshop.
Draw your snake sprites!
Design your snake head, body, and food in Pixel Studio - then add them to your C++ game.
Drag the SFML game loop steps into the correct order:
Build it in the browser first
Try this project step by step right here: write the code, watch it run, then download it and keep building in your engine.