{"id":19167670,"url":"https://github.com/sugidaffection/rust-snake","last_synced_at":"2026-06-23T14:31:16.585Z","repository":{"id":108482937,"uuid":"189599927","full_name":"sugidaffection/rust-snake","owner":"sugidaffection","description":null,"archived":false,"fork":false,"pushed_at":"2026-03-28T08:22:04.000Z","size":38,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-03-28T10:15:15.170Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sugidaffection.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-05-31T13:38:49.000Z","updated_at":"2026-03-28T08:22:08.000Z","dependencies_parsed_at":"2023-04-26T03:17:29.873Z","dependency_job_id":null,"html_url":"https://github.com/sugidaffection/rust-snake","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sugidaffection/rust-snake","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sugidaffection%2Frust-snake","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sugidaffection%2Frust-snake/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sugidaffection%2Frust-snake/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sugidaffection%2Frust-snake/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sugidaffection","download_url":"https://codeload.github.com/sugidaffection/rust-snake/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sugidaffection%2Frust-snake/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34694778,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-23T02:00:07.161Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T09:38:50.017Z","updated_at":"2026-06-23T14:31:16.578Z","avatar_url":"https://github.com/sugidaffection.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🐍 Rust Snake\n\nA classic Snake game built with Rust and the Piston game engine, featuring smooth grid-based animations and progressive difficulty scaling.\n\n![Rust](https://img.shields.io/badge/Rust-2021-orange.svg)\n![License](https://img.shields.io/badge/License-MIT-blue.svg)\n![Version](https://img.shields.io/badge/Version-1.0.0-green.svg)\n\n---\n\n## Table of Contents\n\n- [About](#about)\n- [Features](#features)\n- [Screenshots](#screenshots)\n- [Prerequisites](#prerequisites)\n- [Installation](#installation)\n- [How to Play](#how-to-play)\n- [Game Mechanics](#game-mechanics)\n- [Project Structure](#project-structure)\n- [Dependencies](#dependencies)\n- [Building for Release](#building-for-release)\n- [Troubleshooting](#troubleshooting)\n- [License](#license)\n\n---\n\n## About\n\n**Rust Snake** is a modern implementation of the classic Snake arcade game, built using the [Piston game engine](https://www.piston.rs/) in Rust. The game demonstrates smooth animations, grid-based movement, and progressive difficulty scaling while maintaining the nostalgic feel of the original.\n\nThe implementation showcases Rust's performance capabilities combined with Piston's 2D graphics rendering, resulting in a responsive and visually appealing gaming experience.\n\n---\n\n## Features\n\n- 🎮 **Classic Snake Gameplay** - Eat food, grow longer, avoid collisions\n- ✨ **Smooth Animations** - Interpolated movement with easing functions for fluid visual experience\n- 🎯 **Grid-Based Movement** - Precise 20x20 grid system for predictable gameplay\n- 📈 **Progressive Difficulty** - Snake speed increases as you consume more food\n- 🎨 **Modern Visual Design** - Clean aesthetic with distinct colors for snake head, body, and food\n- ⚡ **60 FPS Rendering** - Smooth visual updates at 60 frames per second\n- 🖥️ **Fixed Window Size** - Consistent 800x600 resolution across all systems\n\n---\n\n## Screenshots\n\n\u003e 📸 *Screenshots coming soon!* \n\n*Feel free to contribute by adding gameplay screenshots to this section.*\n\n---\n\n## Prerequisites\n\nBefore building this project, ensure you have the following installed:\n\n### Rust Toolchain\n\nInstall Rust using `rustup` (recommended):\n\n```bash\n# Install rustup (Rust installer and version manager)\ncurl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh\n\n# Install the stable Rust toolchain\nrustup install stable\n\n# Verify installation\nrustc --version\ncargo --version\n```\n\n### System Dependencies\n\nPiston requires some system libraries for graphics and window management:\n\n#### Linux (Ubuntu/Debian)\n\n```bash\nsudo apt-get install \\\n    libasound2-dev \\\n    libx11-dev \\\n    libxrandr-dev \\\n    libxi-dev \\\n    libxcursor-dev \\\n    libxinerama-dev \\\n    libgl1-mesa-dev \\\n    libwayland-dev \\\n    libxkbcommon-dev\n```\n\n#### Linux (Fedora)\n\n```bash\nsudo dnf install \\\n    alsa-lib-devel \\\n    libX11-devel \\\n    libXrandr-devel \\\n    libXi-devel \\\n    libXcursor-devel \\\n    libXinerama-devel \\\n    mesa-libGL-devel \\\n    wayland-devel \\\n    libxkbcommon-devel\n```\n\n#### macOS\n\n```bash\n# Install Xcode Command Line Tools\nxcode-select --install\n```\n\n#### Windows\n\nWindows users typically don't need additional dependencies. Visual Studio Build Tools or MSVC should be sufficient.\n\n---\n\n## Installation\n\n### Clone the Repository\n\n```bash\ngit clone https://github.com/your-username/rust-snake.git\ncd rust-snake\n```\n\n### Build and Run\n\n```bash\n# Build and run in development mode\ncargo run\n\n# Or build first, then run\ncargo build\ncargo run\n```\n\nThe game window should open immediately with the title \"Snake\".\n\n---\n\n## How to Play\n\n### Controls\n\n| Key | Action |\n|-----|--------|\n| `↑` (Up Arrow) | Move snake upward |\n| `↓` (Down Arrow) | Move snake downward |\n| `←` (Left Arrow) | Move snake leftward |\n| `→` (Right Arrow) | Move snake rightward |\n| `ESC` | Exit the game |\n\n### Objective\n\n1. **Eat the red food** to grow your snake\n2. **Avoid collisions** with walls and your own body\n3. **Survive as long as possible** while achieving the highest score\n\n### Starting the Game\n\n- The snake starts at position (0, 0) moving right\n- Food spawns randomly within the game window\n- The snake grows each time it consumes food\n- Speed increases progressively with each food consumed\n\n---\n\n## Game Mechanics\n\n### Snake Movement\n\nThe snake uses a sophisticated animation system:\n\n- **Grid-based positioning**: Movement snaps to a 20-pixel grid\n- **Smooth interpolation**: Positions are interpolated between grid cells using quadratic easing\n- **Direction locking**: Cannot reverse direction (e.g., can't go left while moving right)\n- **Progressive speed**: Movement speed increases by 10% with each food consumed (capped at minimum 0.1)\n\n### Collision Detection\n\n- **Food collision**: Snake head coordinates must match food coordinates exactly\n- **Wall collision**: Game ends when snake hits window boundaries\n- **Self-collision**: Game ends when snake head collides with any body segment\n\n### Visual Design\n\n| Element | Color (RGBA) | Description |\n|---------|--------------|-------------|\n| Background | `[0.15, 0.15, 0.15, 1.0]` | Dark gray background |\n| Snake Head | `[0.0, 1.0, 0.6, 1.0]` | Bright cyan-green |\n| Snake Body | `[0.3, 0.3, 0.3, 1.0]` | Medium gray |\n| Food | `[1.0, 0.2, 0.2, 1.0]` | Bright red (60% of grid size) |\n\n---\n\n## Project Structure\n\n```\nrust-snake/\n├── Cargo.toml              # Project manifest and dependencies\n├── README.md               # This documentation file\n├── LICENSE                 # MIT License\n└── src/\n    ├── main.rs             # Entry point, window configuration\n    ├── app.rs              # Main game application logic\n    ├── snake.rs            # Snake entity with movement and rendering\n    ├── food.rs             # Food spawning and rendering\n    └── vec2.rs             # 2D vector utility for positions\n```\n\n### Module Descriptions\n\n#### `main.rs`\nGame entry point responsible for:\n- Creating the Piston window (800x600)\n- Configuring update rate (60 UPS) and frame rate (60 FPS)\n- Initializing the game application\n- Running the main game loop (render, update, input)\n\n#### `app.rs`\nCore game application containing:\n- Game state management (snake, food, window dimensions)\n- Render pipeline (clear screen, draw food, draw snake)\n- Update loop (snake movement, collision detection)\n- Input handling (keyboard events)\n\n#### `snake.rs`\nSnake entity implementation:\n- Head and body segment management\n- Direction state machine (LEFT, RIGHT, UP, DOWN)\n- Smooth animation with easing functions\n- Speed progression system\n- Collision detection with food\n\n#### `food.rs`\nFood system:\n- Random position spawning within window bounds\n- Grid-aligned placement\n- Rendering with offset sizing\n\n#### `vec2.rs`\n2D vector utility:\n- Position representation\n- Collision detection\n- Random position generation\n\n---\n\n## Dependencies\n\n| Crate | Version | Purpose |\n|-------|---------|---------|\n| `piston_window` | 0.132.0 | Game window and event loop |\n| `piston2d-graphics` | 0.45.0 | 2D graphics rendering |\n| `rand` | 0.9.0 | Random number generation for food spawning |\n\n---\n\n## Building for Release\n\nTo create an optimized production build:\n\n```bash\n# Build in release mode with optimizations\ncargo build --release\n\n# Run the release build\ncargo run --release\n```\n\nRelease builds are significantly faster due to Rust's optimization passes.\n\n### Binary Location\n\nAfter building:\n- **Debug**: `target/debug/snake`\n- **Release**: `target/release/snake`\n\n---\n\n## Troubleshooting\n\n### Common Issues\n\n#### \"Failed to build PistonWindow\"\n\n**Cause**: Missing system dependencies or graphics drivers.\n\n**Solution**:\n1. Install system dependencies (see [Prerequisites](#prerequisites))\n2. Update graphics drivers\n3. Ensure you're running in a graphical environment (not SSH without X11 forwarding)\n\n#### Game runs slowly or stutters\n\n**Cause**: Running debug build or insufficient hardware.\n\n**Solution**:\n```bash\n# Build in release mode for better performance\ncargo run --release\n```\n\n#### Window doesn't open\n\n**Cause**: Wayland/X11 issues on Linux.\n\n**Solution**:\n```bash\n# Try forcing X11 backend\nexport GDK_BACKEND=x11\ncargo run\n\n# Or try running with Wayland\nexport GDK_BACKEND=wayland\ncargo run\n```\n\n#### Input lag or unresponsive controls\n\n**Cause**: Event loop timing issues.\n\n**Solution**:\n- Ensure no other application is capturing keyboard input\n- Try running in a clean terminal session\n- Check that 60 UPS/FPS settings match your monitor's refresh rate\n\n#### Compilation errors\n\n**Cause**: Outdated Rust version or dependency conflicts.\n\n**Solution**:\n```bash\n# Update Rust toolchain\nrustup update\n\n# Clear build cache and rebuild\ncargo clean\ncargo build\n```\n\n### Performance Tips\n\n- **Release mode**: Always use `--release` for best performance\n- **Close background applications**: Free up system resources\n- **Update graphics drivers**: Ensure optimal GPU performance\n\n---\n\n## License\n\nThis project is licensed under the **MIT License** - see the [LICENSE](LICENSE) file for details.\n\n### Summary\n\n- ✅ Free to use for personal and commercial projects\n- ✅ Modify and distribute\n- ✅ Include original copyright notice\n- ❌ No warranty provided\n\n---\n\n## Contributing\n\nContributions are welcome! Feel free to:\n\n- 🐛 Report bugs\n- 💡 Suggest features\n- 🎨 Add screenshots or visual improvements\n- 📝 Improve documentation\n- 🔧 Submit pull requests\n\n---\n\n## Acknowledgments\n\n- [Piston Game Engine](https://www.piston.rs/) - Excellent Rust game development framework\n- Classic Snake arcade game - Original concept by Gremlin Industries (1976)\n\n---\n\n**Happy Gaming! 🎮🐍**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsugidaffection%2Frust-snake","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsugidaffection%2Frust-snake","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsugidaffection%2Frust-snake/lists"}