# Tilt Drop

A tilt-controlled procedural maze game for the
**Waveshare ESP32-S3-Touch-AMOLED-1.75-B/C**.

![Tilt Drop running on the round AMOLED](docs/images/tilt-drop-waveshare.png)

Tilt the physical display to roll a luminous ball through ordered checkpoint
gates and into the unlocked goal. Avoid decoy holes, bumpers, and the exposed
outer edge. Every win generates a new board with a different palette, geometry,
route, hazards, and difficulty.

## Gameplay

- Place the device flat and keep it still while the startup calibration bar fills.
- Roll through the pulsing gates in order; completed gates change color.
- The green/cyan goal remains visibly barred and physically locked until all
  gates are complete.
- Red holes reset the current stage. Rolling off the circular board does too.
- Stages 1–2 have one wide gate, stages 3–4 have two, stages 5–6 have
  three, and stage 7 onward has four progressively narrower gates.
- **Tap** to recenter the ball, **swipe up** to reshuffle the stage, and
  **swipe down** to restart at stage one.

Original procedural tones distinguish gates, wins, decoy holes, falls, and
manual controls. No network connection, account, cloud API, sprite partition,
or microSD card is required.

## Hardware

- Waveshare ESP32-S3-Touch-AMOLED-1.75-B/C
- 466x466 CO5300 AMOLED
- CST9217 touch controller
- QMI8658 accelerometer
- ES8311 codec and onboard amplifier
- 8 MB OPI PSRAM / 16 MB flash

The renderer uses a centered 408x408 RGB565 framebuffer in PSRAM and a bounded
DMA staging buffer. Audio synthesis runs on the opposite core from the 30 FPS
render loop.

## Build

Requirements:

- Arduino CLI 1.5.1
- Espressif Arduino core `esp32:esp32@3.3.10`
- `git`, Python is not required

Install the pinned ESP32 core once:

```bash
arduino-cli config init
arduino-cli config add board_manager.additional_urls \
  https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
arduino-cli core update-index
arduino-cli core install esp32:esp32@3.3.10
```

Build the native game tests and firmware:

```bash
bash tools/test.sh
bash tools/arduino.sh build
```

`tools/arduino.sh` clones the exact Waveshare library revision into `.deps/`
when needed. Firmware artifacts are written to `build/firmware/`.

## Flash

Flashing replaces the application and partition table on the selected device.
It does not erase or access the microSD card.

```bash
bash tools/arduino.sh upload /dev/cu.usbmodem1101
```

Use the actual Espressif USB serial/JTAG port shown by your operating system.
Whole-chip erase is not required.

## Architecture

- `firmware/TiltDrop/TiltDrop.ino` — hardware setup, calibration, frame pacing,
  touch gestures, IMU mapping, and display transfer.
- `firmware/TiltDrop/src/TiltDropRenderer.*` — deterministic physics,
  procedural stages, gates, holes, bumpers, and RGB565 rendering.
- `firmware/TiltDrop/src/TouchInput.*` — bounded CST9217 gesture tracking.
- `firmware/TiltDrop/src/ToneAudio.*` — nonblocking ES8311/I2S procedural tones.
- `tests/test_tilt_drop.cpp` — native success, locked-goal, gate, hazard, fall,
  stage, and rendering coverage.

The screenshot is a deterministic native framebuffer capture composed into a
device presentation. The current Waveshare emulator interprets single-file
Arduino graphics calls and cannot directly execute this multi-file framebuffer
renderer.

## License

MIT
