# Racket Demo

Hold your phone upright, top up and screen facing you. Face the TV and press **CENTER**. Once the phone shows **CENTERED**, the machine feeds a ball. Turn the phone to aim at a target on the wall, then swing for power. The dot on the wall shows your aim.

The racket helps you meet the ball. Your return flies over the net to the wall, then comes back in one arc to the other side of your body. Hold the phone still in the ball’s way for a soft **Block**, or swing as the thin ring closes. A swing uses the aim you held before it; its direction does not steer the shot. Tip back for a lob or forward for a lower shot. The game learns your resting lean, so you do not have to hold the phone exactly upright during play.

Each wall hit adds one to **RALLY**. **BEST** keeps the longest rally. A plain wall hit scores 1, a target scores 3 and the lit target scores 5. The middle of a target doubles its points. Hitting the lit target lights another one. There is no time limit or winning score.

Ordinary shots clear the net and reach the wall. A face held too far sideways sends the ball **Wide**; too far down sends it **Into the net**; too far up sends it **Over the wall**. A ball that passes you is **Missed**. Each ends the rally. **Feed** starts a new rally at zero while keeping your score and best.

**SWING** works with motion on or off. With motion off, drag the glass or use the stick to aim, then tap **SWING**. Gamepad: left stick or D-pad aims, A swings, B feeds, X centres and START pauses. Keyboard: arrows aim, Space swings, Shift feeds, X centres and Enter pauses. Keys and sticks need a swing; they do not block automatically. **MENU** opens settings. Choose Hand → Left for left-handed play.

Only the racket is drawn; its grip, strings and shadow stay inside the court. The camera looks over it toward the wall. One thin meeting ring appears in the last 0.7 seconds. The lit target glows, a hit flashes, and points appear at the wall. Sound and rumble mark contact. A small centre reminder appears after a still, upright, off-centre hold lasting 2.5 seconds.

## Run locally

```sh
PORT=49220 node examples/games/racket-host.mjs
```

Open [the local court](http://127.0.0.1:49220/). The preview binds to loopback, uses no account and prints a browser-controller join link. Ports 49200–49299 are accepted. A real phone needs a reachable host and the [local HTTPS setup](local-setup.md) for browser motion permission.

## Embed it

```js
import {GAMES, createGame} from '@controller-plus/sdk/games';
const {state} = createGame('racket-demo', [{id: playerId, name: 'Player'}], 117);
const demo = GAMES['racket-demo'];
const binding = demo.connect(host, state, {autoStart: false});
binding.tick(1 / 30); // seconds
// Draw on every animation frame, using the newest state:
demo.render(ctx, state.public, {time: performance.now() / 1000});
// On leaving:
binding.close();
demo.disposeRenderer(ctx.canvas);
```

The racket and ball carry on from the newest state for up to 50 milliseconds between updates. The WebGL court draws at no more than 1920 pixels wide, then scales to the shared canvas. `gameplayOnly: true` omits text and draws the supplied pose without carrying it forward.

`RacketGameState` and `RacketPublicState` describe the wall-rally fields. `aimPoint` is `[x, height]` on the wall. `aimTarget` is the target index, or −1. `aimFault` is `NET`, `WIDE`, `LONG` or null. `score`, `rally`, `best`, `streak` and `lit` track progress. `wallHit` gives the last hit’s position, target, points and whether it hit the middle or the lit target. `outcome` gives the fault or `MISS`, its time and the ended rally length. State and input latches survive JSON restoration.

The Remote view carries `autoCentre: true`. Before readiness it also carries `centre: {prompt: 'Top up, screen to you. Face the TV.'}`. The prompt clears once ready. See [the shared centre definition](remote.md#the-ready-pose). CENTER preserves tilt and resets the measured stroke. Reconnect and mode changes clear timestamped pose history. The motion format and hand estimator are unchanged.

## Shot rules

- Twenty degrees of turn reaches a side target. Targets pull nearby aim toward themselves; the lit target pulls from farther away.
- Resting lean is learned while the phone is calm, limited to 35 degrees. Ten degrees above or below that rest counts as level. The `lift` helper removes that allowance before checking the `AIM` limits: sideways past 60 degrees, down past −38 degrees or up past 48 degrees.
- A calm aim is saved below 1.2 radians per second and within 45 degrees of facing the wall. During a swing, it stands for 1.5 seconds. A pending measured stroke keeps the aim it started with through contact.
- Timing tightens the small spread around the aim; raw power widens it. Power shortens flight time. The shot gets enough height to clear the 1.05-unit net by at least 0.3 scene units.
- Position help reaches 0.9 metres from the estimated racket head and fades over another 0.45 metres. Orientation stays the player’s. SWING accepts a press from 650 milliseconds before arrival through 200 milliseconds after it. Motion starts or peaks from 250 milliseconds before through 200 milliseconds after arrival can connect.
- A still phone in reach blocks after the motion grace period. Wall returns cross the net without a floor bounce and arrive within reach on the other side.

## Repeatable checks

```sh
node testing/racket-season.mjs
node --test tests/racket-wall.test.mjs tests/racket-hand.test.mjs
RACKET_FRAME_OUTPUT=/path/to/evidence \
  node --test tests/racket-frames-browser.test.mjs
```

The season plays ten simulated minutes each with keys chasing the lit target, a held phone, and natural swing fixtures aimed left, centre and right. It reports contacts, wall hits, targets, lit targets, bullseyes, faults and rally lengths. `testing/racket-play.mjs` remains an entry point for the same players.

The swing fixtures model a moving forearm and reuse the existing sensor calculations. They are synthetic, not recordings from a person. The browser check sends sensor events through a real browser controller, measures the drawn racket between 30-per-second state updates, records frame script time and captures ten rally and fault pictures. Physical sensor noise, grip comfort, vibration and sound still need a real phone.
