# RCWeb Flappy Draw Control App

The **RCWeb Flappy Draw Control App** (`app/flappy-draw-c`) is the phone companion for Flappy Draw. Before a player can join, it requires them to name and draw the exact bird that will appear on the shared screen.

![icon](pwa-512x512.png "Flappy Draw Control App Icon")

## What it does

- **Bird Studio**: Provides a touch drawing canvas with pen color, thickness, eraser, clear, name, and submission controls.
- **Personal Sprite**: Sends the compact drawing to the shared viewer, where it becomes only that player's game character.
- **One-Button Gameplay**: Presents a large flap button. Tapping it or pressing Space/Arrow Up immediately triggers the remote bird to flap.
- **Redraw and Rename**: Reopens the studio without resetting the player's current score or wins.
- **State Reflection**: Tracks the alive/dead status of the bird on the main screen. If the bird crashes, the app disables the flap button and notifies the user that they must wait for the next round.
- **Haptic & Audio Feedback**: Upon crashing, the phone vibrates (if supported by native hardware) and plays a localized synthetic audio chime to immediately communicate the outcome without looking at the main screen.

## How it works

The controller strictly relies on `rc.sendFunctionCall` to forward input payloads, eliminating the need to continuously send stringified JavaScript blocks.

- **Joining the Flock**: Submission calls `flappyDraw.joinController` with the controller ID, validated name, and PNG sprite. The viewer calls back `flappyDrawControl.onAssignedBird` with the accepted profile and current statistics.
- **Flapping**: Once assigned, interacting with the screen fires `rc.sendFunctionCall("flappy-draw", "flappyDraw.flap", rc.client)`. Local feedback includes triggering `navigator.vibrate(35)` for a tactile response.
- **Profile Updates**: Redrawing or renaming calls `flappyDraw.updateBirdProfile`, updating the same player record rather than adding another bird.
- **Receiving Callbacks**: The app exposes explicitly public methods (`onAssignedBird`, `onScoreUpdate`, `onStateUpdate`, `onRemovedBird`, and `onProfileError`) that the Flappy Draw viewer invokes over WebSockets to synchronize profile, score, and life state back to the controller UI.
- **Audio Synthesis**: The crash sound effect relies entirely on manipulating the Web Audio API natively (`audioCtx.createOscillator()`), rather than downloading static `mp3` files, to ensure the app loads instantaneously over LTE connections.
