Skip to content

A modern Vite-powered Snake with 60 FPS canvas graphics, responsive controls, progressive difficulty, and persistent high scores.

Notifications You must be signed in to change notification settings

debugfest/snake-game

Repository files navigation

๐Ÿ Snake Game

Snake Game (Vite Edition) is a modern, interactive remake of the timeless arcade classic. Built with Vite for lightning-fast performance, it delivers smooth animations, responsive controls, and fluid gameplay that feels natural on any screen size.

With multiple grid sizes, theme presets, and scalable difficulty, this project combines nostalgia with modern web design principles. Whether you're chasing your next high score or exploring the code, this reimagined version of Snake showcases the beauty of clean, modular, and performance-driven game development on the web.

Vite JavaScript HTML5 CSS3 License

๐ŸŒŸ Features

  • Classic Gameplay: Traditional Snake mechanics with modern enhancements
  • Multiple Grid Sizes: Choose from Small (15ร—15), Medium (20ร—20), or Large (30ร—30) play areas
  • Smooth Animations: 60 FPS gameplay with fluid snake movement
  • Responsive Controls: Keyboard arrow keys and WASD support
  • Score System: Real-time score tracking with high score persistence
  • Modern UI: Clean, minimalistic design with smooth transitions
  • Progressive Difficulty: Game speed increases as snake grows longer
  • Local Storage: Persistent high score storage across sessions
  • Responsive Design: Works seamlessly on desktop and mobile devices

๐ŸŽฏ Game Features

Play Area Sizes

  • Small (15ร—15): Easy mode with more space to maneuver - perfect for beginners
  • Medium (20ร—20): Balanced classic experience - the traditional Snake game feel
  • Large (30ร—30): Hard mode with tight spaces requiring high skill and precision

Core Mechanics

  • ๐Ÿ Snake Movement: Smooth directional controls with collision detection
  • ๐ŸŽ Food System: Randomly spawned food items that grow the snake
  • ๐Ÿ’€ Collision Detection: Wall and self-collision game over mechanics
  • ๐Ÿ“Š Scoring: Points awarded for each food item consumed
  • โšก Speed Progression: Increasing difficulty as score grows
  • ๐Ÿ† High Score: Persistent leaderboard using localStorage

๐Ÿ› ๏ธ Technology Stack

  • Build Tool: Vite 5.0+ (Lightning-fast development)
  • Frontend: Vanilla JavaScript (ES6+)
  • Graphics: HTML5 Canvas API
  • Styling: Modern CSS3 with Flexbox/Grid
  • Bundling: Vite's optimized build system
  • Development: Hot Module Replacement (HMR)

๐Ÿ“‹ Prerequisites

  • Node.js 18.0 or higher
  • npm or yarn package manager
  • Modern web browser with Canvas support

๐Ÿš€ Quick Start

1. Clone the Repository

git clone https://github.com/debugfest/snake-game.git
cd snake-game

2. Install Dependencies

# Using npm
npm install

# Or using yarn
yarn install

# Or using pnpm
pnpm install

3. Start Development Server

# Using npm
npm run dev

# Or using yarn
yarn dev

# Or using pnpm
pnpm dev

The game will be available at http://localhost:5173

4. Build for Production

# Using npm
npm run build

# Or using yarn
yarn build

# Or using pnpm
pnpm build

๐Ÿ“ Project Structure

snake-game/
โ”œโ”€โ”€ public/                    # Static assets
โ”‚   โ””โ”€โ”€ favicon.ico           # Game favicon
โ”œโ”€โ”€ src/                      # Source code
โ”‚   โ”œโ”€โ”€ js/                   # JavaScript modules
โ”‚   โ”‚   โ”œโ”€โ”€ game.js          # Main game logic
โ”‚   โ”‚   โ”œโ”€โ”€ snake.js         # Snake class and mechanics
โ”‚   โ”‚   โ”œโ”€โ”€ food.js          # Food generation and rendering
โ”‚   โ”‚   โ””โ”€โ”€ utils.js         # Utility functions
โ”‚   โ”œโ”€โ”€ css/                 # Stylesheets
โ”‚   โ”‚   โ”œโ”€โ”€ style.css        # Main styles
โ”‚   โ”‚   โ””โ”€โ”€ responsive.css   # Mobile responsive styles
โ”‚   โ””โ”€โ”€ main.js              # Entry point
โ”œโ”€โ”€ index.html               # Main HTML file
โ”œโ”€โ”€ package.json             # Dependencies and scripts
โ”œโ”€โ”€ vite.config.js           # Vite configuration
โ”œโ”€โ”€ README.md               # Project documentation
โ”œโ”€โ”€ CONTRIBUTING.md         # Contributing guidelines
โ”œโ”€โ”€ CODE_OF_CONDUCT.md     # Community standards
โ””โ”€โ”€ LICENSE                # MIT License

๐ŸŽฎ How to Play

Controls

  • Arrow Keys: Move snake (โ†‘ โ†“ โ† โ†’)
  • WASD Keys: Alternative movement controls
  • Swipe Gestures: Swipe up, down, left, or right on mobile
  • Space Bar: Pause/Resume game
  • R Key: Restart game

Gameplay

  1. Start the Game: Open the application and press any arrow key to begin
  2. Control the Snake: Use arrow keys or WASD to change direction
  3. Eat Food: Guide the snake to consume red food items
  4. Avoid Collisions: Don't hit walls or the snake's own body
  5. Score Points: Each food item increases your score and snake length
  6. Beat High Score: Try to surpass your previous best performance

Game Rules

Action Points Effect
Eat Food +10 Snake grows by 1 segment
Wall Collision Game Over Reset to start screen
Self Collision Game Over Reset to start screen
Speed Increase Every 50 points Game becomes faster

### Vite Configuration

The project uses Vite's default configuration with:
- **Hot Module Replacement**: Instant updates during development
- **Optimized Builds**: Tree-shaking and code splitting
- **Asset Processing**: Automatic optimization of images and assets
- **Development Server**: Fast startup and rebuild times

## ๐ŸŽจ Customization

### Game Settings
Modify game parameters in `src/js/game.js`:
```javascript
const CONFIG = {
  GRID_SIZE: 20,           // Size of game grid
  INITIAL_SPEED: 200,      // Starting game speed (ms)
  SPEED_INCREASE: 10,      // Speed increase per level
  POINTS_PER_FOOD: 10      // Points awarded per food
};

Visual Styling

Customize appearance in src/css/style.css:

  • Snake colors and animations
  • Food appearance and effects
  • UI theme and typography
  • Canvas styling and borders

๐Ÿค Contributing

We welcome contributions!

Ways to Contribute

  • ๐ŸŽฎ Game Features: Power-ups, obstacles, multiplayer modes
  • ๐ŸŽจ Visual Effects: Animations, particle systems, themes
  • ๐Ÿ“ฑ Mobile Support: Touch controls and responsive design
  • โšก Performance: Optimization and smooth gameplay
  • ๐Ÿงช Testing: Unit tests and game logic validation
  • ๐Ÿ“š Documentation: Tutorials and code examples

Development Setup

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/new-powerup)
  3. Install dependencies (npm install)
  4. Start development server (npm run dev)
  5. Make changes and test thoroughly
  6. Commit with descriptive messages
  7. Push and create Pull Request

๐Ÿ† Acknowledgments

  • Vite Team for the amazing build tool
  • MDN Web Docs for Canvas API documentation
  • Classic Snake Game creators for the timeless gameplay
  • Open source community for inspiration and support
  • All contributors who help improve this project

โญ If you found this project fun, please give it a star! โญ

Made with โค๏ธ

๐Ÿ Enjoy the classic Snake experience! ๐ŸŽฎ

About

A modern Vite-powered Snake with 60 FPS canvas graphics, responsive controls, progressive difficulty, and persistent high scores.

Topics

Resources

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 8