Skip to content

swati048/serpent-bites

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

11 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ Serpent Bites - Classical Snake Game

A polished, feature-rich implementation of the classic Snake game built with C++ and SFML. This project showcases clean code architecture, smooth gameplay mechanics, and engaging visual effects.

Game Version C++ SFML License

๐ŸŽฅ Demo

Gameplay Demo

Featuring particle effects, smooth animations, and polished gameplay

โœจ Features

Gameplay

  • Classic Snake Mechanics - Grow by eating food, avoid collisions
  • Toggleable Wall Collision - Play with or without boundary walls
  • Progressive Difficulty - Speed increases every 5 points
  • Screen Wrapping - Snake wraps around edges when walls are disabled
  • Persistent High Score - Your best score is saved between sessions

Visual Effects

  • ๐ŸŽ† Particle System - Sparkle effects when eating food
  • ๐Ÿ’ฅ Death Explosion - Dramatic particle burst on collision
  • ๐Ÿ“Š Score Popups - Floating score indicators
  • ๐ŸŽจ Smooth Animations - Polished transitions and effects

User Interface

  • ๐ŸŽฎ Main Menu - Clean, intuitive navigation
  • โš™๏ธ Settings Toggle - Enable/disable walls from menu
  • ๐Ÿ“– Instructions Screen - Clear game controls and rules
  • โธ๏ธ Pause Functionality - Pause/resume with 'P' key
  • ๐Ÿ† High Score Display - Always visible during gameplay

๐ŸŽฎ Controls

Key Action
Arrow Keys Move snake (Up/Down/Left/Right)
P Pause/Resume game
Enter Start game from menu
R Restart from game over screen
M Return to menu from game over
Mouse Navigate menus and click buttons

๐Ÿ› ๏ธ Technical Details

Architecture

  • Object-Oriented Design - Clean separation of concerns
  • Component-Based - Modular game systems (Snake, Food, Score, Particles)
  • State Management - Robust game state system (Menu, Playing, Game Over, Instructions)
  • Memory Optimized - Pre-allocated vectors, efficient particle management

Key Components

โ”œโ”€โ”€ Snake       - Player-controlled entity with collision detection
โ”œโ”€โ”€ Food        - Spawning system with grid-based placement
โ”œโ”€โ”€ Game        - Core game loop and logic coordinator
โ”œโ”€โ”€ Score       - Scoring system with persistent high score
โ”œโ”€โ”€ ParticleSystem - Visual effects and particle physics
โ”œโ”€โ”€ UIManager   - Menu system and user interface
โ””โ”€โ”€ UIButton    - Interactive menu buttons

Code Highlights

  • Predictive Collision Detection - Checks next position before moving
  • Smart Food Spawning - Avoids snake body with infinite loop prevention
  • Visual Effects - Sparkle effects, death explosion and score floating effects
  • Comprehensive Comments - Well-documented code for easy understanding

๐Ÿ“‹ Requirements

Dependencies

  • SFML 2.5+ - Simple and Fast Multimedia Library
  • CMake 3.10+ - Build system generator
  • C++17 Compiler - GCC, Clang, or MSVC
  • MinGW-w64 (Windows) - For compiling on Windows

Platform Support

  • โœ… Windows (Primary)
  • โœ… Linux
  • โœ… macOS

๐Ÿš€ Building the Game

Windows (MinGW)

  1. Install Dependencies

    # Install MSYS2 from https://www.msys2.org/
    # Open MSYS2 MinGW 64-bit terminal
    pacman -S mingw-w64-x86_64-gcc
    pacman -S mingw-w64-x86_64-cmake
    pacman -S mingw-w64-x86_64-sfml
  2. Clone and Build

    git clone https://github.com/swati048/snake-game.git
    cd snake-game
    mkdir build && cd build
    cmake -G "MinGW Makefiles" ..
    cmake --build .
  3. Run

    ./snake.exe

Linux

  1. Install Dependencies

    # Ubuntu/Debian
    sudo apt-get install build-essential cmake
    sudo apt-get install libsfml-dev
    
    # Arch Linux
    sudo pacman -S base-devel cmake sfml
  2. Clone and Build

    git clone https://github.com/swati048/snake-game.git
    cd snake-game
    mkdir build && cd build
    cmake ..
    make
  3. Run

    ./snake

macOS

  1. Install Dependencies

    # Install Homebrew from https://brew.sh/
    brew install cmake
    brew install sfml
  2. Clone and Build

    git clone https://github.com/swati048/snake-game.git
    cd snake-game
    mkdir build && cd build
    cmake ..
    make
  3. Run

    ./snake

๐Ÿ“ธ Screenshots

Main Menu

Main Menu Clean, intuitive menu with wall toggle option

Gameplay With Walls Enabled

Gameplay With Walls Smooth gameplay with walls enabled and score display

Gameplay With Walls Disabled

Gameplay Without Walls Smooth gameplay with walls disabled and score display

Game Over

Game Over Game over screen displaying score and highscore with restart, menu and exit button

Instructions

Instructions Precise game control and rules instructions

๐Ÿ“ Project Structure

snake-game/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ main.cpp              # Entry point
โ”‚   โ”œโ”€โ”€ Snake.cpp             # Snake entity logic
โ”‚   โ”œโ”€โ”€ Food.cpp              # Food spawning system
โ”‚   โ”œโ”€โ”€ Game.cpp              # Game coordinator
โ”‚   โ”œโ”€โ”€ Score.cpp             # Score management
โ”‚   โ”œโ”€โ”€ ParticleSystem.cpp    # Visual effects
โ”‚   โ”œโ”€โ”€ UIManager.cpp         # UI and menu system
โ”‚   โ””โ”€โ”€ UIButton.cpp          # Button component
โ”œโ”€โ”€ include/
โ”‚   โ”œโ”€โ”€ Snake.hpp
โ”‚   โ”œโ”€โ”€ Food.hpp
โ”‚   โ”œโ”€โ”€ Game.hpp
โ”‚   โ”œโ”€โ”€ Score.hpp
โ”‚   โ”œโ”€โ”€ ParticleSystem.hpp
โ”‚   โ”œโ”€โ”€ GameState.hpp
โ”‚   โ”œโ”€โ”€ UIManager.hpp
โ”‚   โ””โ”€โ”€ UIButton.hpp
โ”œโ”€โ”€ resources/
โ”‚   โ”œโ”€โ”€ snake_head.png        # Snake head texture
โ”‚   โ”œโ”€โ”€ snake_body.png        # Snake body texture
โ”‚   โ”œโ”€โ”€ food.png              # Food texture
โ”‚   โ”œโ”€โ”€ background.png        # Game background
โ”‚   โ”œโ”€โ”€ menu_background.png   # Menu background
โ”‚   โ”œโ”€โ”€ gameOver_bg.png       # Game over background
โ”‚   โ””โ”€โ”€ CherryBombOne-Regular.ttf  # Game font
โ”œโ”€โ”€ .vscode/
โ”‚   โ”œโ”€โ”€ c_cpp_properties.json # VSCode C++ config
โ”‚   โ”œโ”€โ”€ launch.json           # Debug configuration
โ”‚   โ””โ”€โ”€ settings.json         # CMake settings
โ”œโ”€โ”€ CMakeLists.txt            # Build configuration
โ”œโ”€โ”€ highscore.txt             # Persistent high score
โ””โ”€โ”€ README.md                 # This file

๐ŸŽจ Customization

Modify Game Speed

In main.cpp:

const float SNAKE_SPEED = 20.0f;  // Change block size/speed

Adjust Difficulty Curve

In Game.cpp:

// Speed increases every 5 points by default
if (score.getValue() % 5 == 0) {
    speedMultiplier += 0.1f;  // Adjust increment
}

Change Particle Count

In Game.cpp:

// Food collection particles
particleSystem.createBurst(position, 15, color);  // Adjust count

// Death explosion particles
particleSystem.createExplosion(position, 40, color);  // Adjust count

Modify Colors

In respective .cpp files:

// Wall color
wall.setFillColor(sf::Color(150, 75, 0));  // Brown

// Particle colors
sf::Color::Yellow  // Food particles
sf::Color::Red     // Death particles

๐Ÿ› Known Issues

  • None currently! ๐ŸŽ‰

๐Ÿ”ฎ Future Enhancements

  • Sound effects and background music
  • Multiple difficulty levels
  • Power-ups (speed boost, invincibility, score multiplier)
  • Obstacles and special food types
  • Leaderboard with player names
  • Theme selector (different color schemes)
  • Multiplayer mode
  • Mobile touch controls

๐Ÿ“ Development Notes

Design Decisions

Why SFML?

  • Cross-platform compatibility
  • Simple API for 2D graphics
  • Good performance for particle effects
  • Active community support

Why Static Linking?

  • Single executable distribution
  • No external DLL dependencies
  • Easier for portfolio deployment

Particle System Design

  • Used vector with reserve() for memory efficiency
  • Lifetime-based particle removal
  • Physics simulation (velocity, gravity, fade)
  • Separate burst and explosion types for variety

Collision Detection

  • Predictive checking prevents teleportation bugs
  • Separate wall and self-collision logic
  • Grid-aligned movement prevents sub-pixel issues

๐Ÿค Contributing

Contributions are welcome! Feel free to:

  • Report bugs
  • Suggest features
  • Submit pull requests
  • Improve documentation

๐Ÿ‘ค Author

Swati Thakur

๐Ÿ™ Acknowledgments

  • SFML Team - For the excellent multimedia library
  • Cherry Bomb Font - Font used in the game
  • Classic Snake Game - Original inspiration from Nokia phones

โญ Star this repository if you found it helpful! โญ

Made with โค๏ธ and C++

About

A classical Snake game with progressive difficulty, wall toggling, screen wrapping, and persistent scoring.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors