RepositoryRustCZCzechia
georgik

georgik/esp32-spooky-maze-game

Rust Bare Metal implementation of maze game for ESP32 with Bevy ECS no_std

73stars
9forks
1issues
2views

ESP32 Spooky Maze Game

ESP32 Spooky Maze Game is a technical demo game built using Bevy ECS 0.16.1 with no_std support via esp-hal 1.0.0-beta.1. The game demonstrates how to build cross-platform applications that run on both embedded hardware and desktop environments using a shared core.

In this game, a ghost navigates through a maze collecting coins while avoiding obstacles. Special artifacts such as dynamite and the "walker" power-up introduce additional gameplay mechanics. On collision with various objects, events are dispatched to decouple hardware-specific logic from game rules.

Targets

For now, the project supports three primary targets:

  • Desktop Rust Standard Version Use keyboard controls to move the ghost and trigger actions.

    Spooky Maze Game Desktop

  • WebAssembly (WASM) Version Play the game directly in your browser using WebAssembly. Features the same gameplay as the desktop version with both keyboard and mouse controls.

  • ESP32-S3-BOX-3 Embedded Version Uses an ICM42670 accelerometer for input (tilt the board to move the ghost).

    Spooky Maze Game ESP32-S3-BOX-3

  • M5Stack-Atom-S3 Embedded Version Uses an MPU6886 accelerometer for input (tilt the board to move the ghost).

    Spooky Maze Game M5Stack-Atom-S3

  • M5Stack-Atom-S3R Embedded Version Uses a BMI270 inertial measurement unit (IMU) for input (tilt the board to move the ghost).

    Spooky Maze Game M5Stack-Atom-S3R

  • M5Stack-CoreS3 Embedded Version Features a large 320x240 display and BMI270 IMU for tilt-based controls.

    Spooky Maze Game M5Stack-CoreS3

  • M5Stack-Core2 Embedded Version Based on the original ESP32 (Xtensa) with external PSRAM. Features a 320x240 display and MPU6886 accelerometer for tilt-based controls.

    Spooky Maze Game M5Stack-Core2

Note: For older targets (e.g., ESP32-C3, ESP32-S2, etc.), please refer to the v0.10.0 tag.

Technical Specifications

Hardware Requirements

  • ESP32-S3-BOX-3: 8MB PSRAM, ICM42670 accelerometer, 320x240 ILI9486 display
  • M5Stack-Atom-S3: 180KB internal RAM (no PSRAM), MPU6886 accelerometer, 130x129 GC9A01 display
  • M5Stack-Atom-S3R: 8MB PSRAM, BMI270 IMU, 128x128 pixels GC9107 display
  • M5Stack-CoreS3: 8MB PSRAM, BMI270 IMU, 320x240 ILI9342C display
  • M5Stack-Core2: External PSRAM support, MPU6886 accelerometer, 320x240 ILI9342C display, ESP32 (original Xtensa chip)

Software Versions

  • Bevy ECS: 0.16.1 (with minimal plugin configuration for embedded)
  • esp-hal: 1.0.0-beta.1
  • Rust Edition: 2024
  • Target: xtensa-esp32s3-none-elf (or xtensa-esp32-none-elf for M5Stack-Core2)

Memory Management

  • ESP32-S3-BOX-3: Uses PSRAM allocator for large framebuffer (320x240x2 = 153,600 bytes)
  • M5Stack-Atom-S3: Uses internal RAM heap allocator (180KB) for small framebuffer (130x129x2 = 33,540 bytes)
  • M5Stack-Atom-S3R: Uses internal RAM heap allocator (180KB) for small framebuffer (128x128x2 = 32,768 bytes)
  • M5Stack-CoreS3: Uses PSRAM allocator for large framebuffer (320x240x2 = 153,600 bytes)
  • M5Stack-Core2: Uses external PSRAM allocator for large framebuffer (320x240x2 = 153,600 bytes). The original ESP32 chip requires external PSRAM to be enabled and configured at runtime.
  • Event Processing: Minimal Bevy plugins (TaskPoolPlugin, TimePlugin, ScheduleRunnerPlugin) to enable event processing without memory overhead of DefaultPlugins

Key Technical Decisions

  • Bevy ECS & no_std: The core game logic is implemented in spooky-core using Bevy ECS. For the embedded version, we use a no_std configuration along with esp-hal.
  • Renderer & HUD on Embedded: Since Bevy's built-in rendering and UI systems aren't available in no_std mode, we've implemented our own renderer using the Embedded Graphics crate. This renderer also handles HUD text output using Embedded Graphics primitives.
  • Event-based Architecture: Input events (whether from keyboard on desktop or accelerometer on embedded) are dispatched and processed by separate systems, allowing for a clean decoupling between hardware input and game logic.
  • Hardware Peripheral Integration: Peripherals like the ICM42670 or BMI270 accelerometers are injected as Bevy resources (using NonSend where required), enabling seamless access to hardware data within ECS systems.
  • Random Maze Generation: The maze is generated dynamically, with a seed provided as a resource to ensure variability across game sessions. For the embedded version, the seed is generated using the hardware RNG and passed into the maze generation logic.

Build and Run Instructions

Desktop Version

Prerequisites:

  • Rust

Build:

cd spooky-maze-desktop
cargo run

Controls:

Movement: Arrow keys

WebAssembly (WASM) Version

Prerequisites:

  • Rust
  • wasm-pack (installed automatically by build script)

Build and run:

cd spooky-maze-wasm
./build.sh
# Then serve with any HTTP server:
python3 -m http.server 8000
# Open http://localhost:8000 in your browser

Controls:

  • Movement: Arrow keys or WASD
  • Teleport: Space key
  • Place Dynamite: Enter key
  • Alternative: Use on-screen buttons for all actions

Embedded Version

ESP32-S3 and ESP32

These instructions are valid for boards based on ESP32-S3 and ESP32:

  • ESP32-S3-BOX-3 (ESP32-S3)
  • M5Stack-Atom-S3 (ESP32-S3)
  • M5Stack-Atom-S3R (ESP32-S3)
  • M5Stack-CoreS3 (ESP32-S3)
  • M5Stack-Core2 (ESP32)

Prerequisites:

espflash installed:

cargo install espflash

Rust Xtensa toolchain installed:

cargo install espup
espup install

Compiler toolchain from ESP-IDF v5.5 (required only for Xtensa targets):

git clone git@github.com:espressif/esp-idf.git --depth 10 --recursive --shallow-submodules
source esp-idf/export.sh

Properly configured hardware

Build and run:

  • ESP32-S3-BOX-3
cd spooky-maze-esp32-s3-box-3
cargo run --release
  • M5Stack-Atom-S3
cd spooky-maze-m5stack-atom-s3
cargo run --release
  • M5Stack-Atom-S3R
cd spooky-maze-m5stack-atom-s3r
cargo run --release
  • M5Stack-CoreS3
cd spooky-maze-m5stack-cores3
cargo run --release
  • M5Stack-Core2
cd spooky-maze-m5stack-core2
cargo run --release

Controls:

Movement: Tilt the board accelerometer

Differences of Embedded Bevy no_std from Classical Bevy std

  • Embedded Renderer: The embedded version uses a custom renderer built with Embedded Graphics. This renderer handles both drawing the maze and HUD, filtering out a specific "magic pink" color used to represent transparent pixels in sprites.
  • Peripheral Resources: Hardware peripherals like the accelerometer are injected as Bevy resources (using NonSend), enabling the decoupling of hardware interactions from game logic.
  • Event-driven Input: Input events are dispatched and processed by ECS systems, allowing for a unified event-driven architecture across both desktop and embedded platforms.

Contributing

Contributions are welcome! If you'd like to help improve the game, add new features, or adapt the project to additional hardware targets, please feel free to submit a pull request. We especially welcome contributions that help improve the no_std integration with Bevy ECS or enhance the embedded graphics rendering.

For more information on embedded development with ESP32, visit the Espressif Developer Portal.

IDE support

Rust Rover

Recommendation: Open whole project and attach to particular Cargo.toml for specific target.

License

This project is licensed under the MIT License. See LICENSE for details.

Similar Projects

Discover other similar projects and AI models.

Modelsentence-similarity
sentence-transformers/all-MiniLM-L6-v2

all-MiniLM-L6-v2 This is a sentence-transformers(https://www.SBERT.net) model: It maps sentences & paragraphs to a 384 dimensional dense vector space and can be used for tasks like clustering or semantic search. Usage (Sentence-Transformers) Using t...

♥0
157.6M
Jun 1, 2026
RepositoryRust
tauri-apps/tauri

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.

113.4k
Dec 1, 2026
RepositoryRust
warpdotdev/warp

Warp is an agentic development environment, born out of the terminal.

66.2k
Dec 1, 2026
RepositoryRust
tw93/Pake

Turn any website into a lightweight desktop app with one command, on macOS, Windows and Linux.

64.1k
Nov 28, 2026
RepositoryRust
tinyhumansai/openhuman

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

43.0k
Nov 24, 2026
RepositoryRust
DioxusLabs/dioxus

Fullstack app framework for web, desktop, and mobile.

40.0k
Nov 30, 2026
RepositoryRust
farion1231/cc-switch

A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode,DeepSeek Harness and more. Only official website: ccswitch.io

158.7k
Dec 2, 2026
RepositoryRust
ruvnet/RuView

π RuView turns commodity WiFi signals into real-time spatial intelligence, vital sign monitoring, and presence detection — all without a single pixel of video.

105.9k
Dec 2, 2026
RepositorySwift
onehumanbeing/esp32-iphone-agent

Manina AI: let an AI model use a real iPhone with a $7 ESP32: AirPlay eyes, USB HID hands, any OpenAI-compatible vision model. No Mac, no developer account, no jailbreak.

5.8k
Dec 1, 2026