A classic Snake game written in Rust with the Bevy game engine (0.19, ECS architecture).
Play online: retro30.github.io/rusty-snake
Author: RETRO30
- Playfield with a border frame and a score bar at the top-left that never overlaps the board.
- Menu flow: Start → play → pause (Esc or the on-screen pause button) → Resume/Restart.
- Game over when the snake hits the border or its own tail.
- On-screen control hints.
- Swipe controls on mobile devices.
| Action | Keys / gesture |
|---|---|
| Move | Arrow keys or W A S D |
| Pause / resume | Esc or the pause button |
| Move (mobile) | Swipe in the desired direction |
Requires Rust (edition 2024) to be installed.
cargo runrustup target add wasm32-unknown-unknown
cargo install wasm-bindgen-cliThe wasm-bindgen-cli version must match the wasm-bindgen version Bevy uses — if the build
reports a version mismatch, install the version named in the error with
cargo install wasm-bindgen-cli --version <version>.
Requires Python 3 (the engine itself is built with cargo; Python is
only used for the build and local-server scripts, which are cross-platform and work on Windows
too).
python build_web.pyThe script builds the release wasm binary without the dev feature, generates the JS bindings
with wasm-bindgen, and packages everything together with web/index.html and the assets/
folder into dist/.
The project ships a small Python HTTP server:
python serve.pyIt serves dist/ at http://127.0.0.1:8080. The port and directory can be changed with flags:
python serve.py --port 3000 --dir distMakefile targets are also available: make web (build), make serve (server), make preview
(build and serve).
Publishing is automated with GitHub Actions
(.github/workflows/deploy.yml): pushing a version tag
(vX.Y.Z) whose commit is on main builds the web version and deploys it to GitHub Pages.
In the repository settings on GitHub: Settings → Pages → Build and deployment → Source, choose GitHub Actions.
Make sure the desired commit is merged into main, then create a version tag on it:
git tag v0.0.1
git push origin v0.0.1The workflow runs automatically, builds the web version, and publishes it. Progress is visible in
the Actions tab. Once it finishes, the game is available at a URL like
https://<user>.github.io/<repository>/.
A tag pointing at a commit that isn't on
mainwon't trigger a deploy — the workflow checks that the tag's commit is reachable frommainand fails otherwise.
Build locally (python build_web.py) and publish the contents of dist/ to a gh-pages branch,
e.g. git subtree push --prefix dist origin gh-pages, selecting the gh-pages branch as the
source under Settings → Pages.
src/
main.rs — window, camera, entry point
config.rs — playfield, window, and cell sizes
game/
state.rs — game states (menu/playing/paused/game over)
grid/ — board, frame, cell coordinates
snake/ — movement, input, swipes, collisions
food/ — food
ui/ — menu, pause, game over, score, hints
assets/
fonts/ — UI font (arrows/Cyrillic)
build_web.py — builds the web version into dist/
serve.py — local HTTP server for previewing the web build
.github/workflows/
deploy.yml — auto-deploy to GitHub Pages on a version tag
Released under the MIT License.