Shooter Demo
Your phone is a light gun. Hold it like a gun: on its long edge with the screen to the side, one hand under it, your thumb on FIRE and its far end towards the screen. Three targets appear, one after the other: in the middle of the screen, at the top left, at the bottom right. Each pops up on a stick and sways until you shoot it. Point your phone at each and press FIRE, holding it the way you will play: under the target, two cards show a person doing it from the hip and held up like a gun. Those three shots tell the game which way you hold the phone, where your screen is and how large it looks from where you sit. From then on the crosshair is where your phone points.
Run and Gun Demo is the same gun in a first-person shooter: the thumb of your other hand walks a western town with a stick, and the phone aims and turns.
Turn the phone to aim, as you would a gun. Moving your hand sideways without turning it does nothing: the phone feels how it is turned, not where it is. Held flat like a TV remote, or upright with the screen towards you, it works too.
After a count from 3, five cans stand on the fence. A hit knocks a can into the air. Hit it again before it lands and it jumps again: the first hit on a can scores 10, the second 20, the third 30, and so on. Cans thrown from behind the fence score 10 more on every hit. A bottle breaks at once for 15. A round lasts 60 seconds, and BEST keeps your highest score.
The gun holds six shots, then reloads by itself in about a second: the phone ticks as each chamber fills and clacks when it is loaded, and an empty gun gives a click of its own. A quick flick of the phone upward reloads at once. The crosshair never leaves the screen. A shot that is a little off still hits: the shot assist allows about a hundredth of the screen's height around a standing target, and three to five times that around a can in flight, which also counts where it was and where it will be a twentieth of a second either side of the shot. On the results screen, shoot the star to play again, or the ASSIST plate to turn the assist off.
The gatling gun. An ammunition crate stands at the bottom left of the range. Shoot it and you have a gatling gun for the rest of the round: hold FIRE and it fires 14 rounds a second from a belt of 200, then reloads in 1.6 seconds. Its rounds scatter around the crosshair, wider as the barrels heat up, and every fifth is a tracer. A can takes one of its rounds at most every tenth of a second, and they pay half of what the six-shooter pays, for six hits at the most (5, 10, 15 up to 30). The next round starts with the six-shooter and a new crate.
CENTER lines the gun up again at any time: aim at the middle of the screen, press CENTER, then shoot the top left and the bottom right targets. Use it when you have moved, or when the aim has crept to one side. CALIBRATE does the same from the first target. The round waits, then goes on after a count from 3.
With motion off, drag the aim glass and press FIRE; there is nothing to line up. Gamepad: the left stick or D-pad moves the crosshair, A or R2 fires, X puts the crosshair in the middle and START pauses. Keyboard: arrows, Space, X and Enter. A pause also ends with a count from 3.
Run locally
PORT=49230 node examples/games/shooter-host.mjs
Open the local range. 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 for browser motion permission.
Embed it
import {GAMES, createGame} from '@controller-plus/sdk/games';
const {state} = createGame('shooter-demo', [{id: playerId, name: 'Player'}], 117);
const demo = GAMES['shooter-demo'];
const binding = demo.connect(host, state, {autoStart: false});
binding.tick(1 / 30); // seconds
// With createScene the range draws itself, with sound. Without it, on every animation frame:
demo.render(ctx, state.public, {time: performance.now() / 1000});
// On leaving:
binding.close();
The game sets renderer: 'shooter-3d', so a host using scene.mjs loads the range (examples/games/shooter-scene.mjs) and plays its sounds. The scene draws from the newest state and carries the crosshair and the cans on for up to 60 milliseconds between updates. The game works on a 16:9 playfield; a wider screen shows more of the range at the sides, a narrower one more sky and sand. gameplayOnly: true omits the crosshair, the text and the panels.
The Remote view asks for two buttons, Fire and Calibrate, and no stick, with hold: 'point': the phone does not ask for the Remote's upright ready pose, and the player holds it as they like.
ShooterGameState and ShooterPublicState describe the fields. stage is centre (the shot at the middle target), corner1, corner2, countdown, play, paused or over; after says what a count from 3 or a line-up leads to (round, resume or over). axis is the line of the phone the player points with, read from the three shots (top, bottom, back, front, right or left), map the map from its pointing to the screen, and lineup what the last line-up measured: how large the screen looks from the player in degrees (wide, tall) and on which of x and y the shots were too close together (short), then what the phone itself did, in degrees and before any least size: how far it turned right and tipped down from the second target to the third (right, down), and how far above level it pointed at the first (level). aim is the crosshair as fractions of the playfield, x to the right and y down. drawPose is the phone's pose a moment ago and how it turns (q, omega): the scene carries the crosshair on from it between two steps of the game. aimRate is the crosshair's speed per second when a stick or keys move it. gun is revolver or gatling, crate says whether the gatling's crate still stands, and heat (0 to 1) how hot its barrels are. targets lists the cans and bottles with their place in metres and their phase (rise, rest, air, down). effects holds the last 28 things that happened, each with an id, a type and the game time at; the scene turns new ones into sound and pieces.
How the aim works
- The barrel is read from the three shots (
aimBarrel): the line of the phone that stayed near level and tipped down from the top left target to the bottom right one. For a phone on its long edge that is its top or bottom end; its back points sideways there, and read along it the gun could not aim up or down.remoteAimthen gives that line's yaw and pitch. Rolling the phone about it changes nothing. - The game keeps every pose the phone sends, with the phone's own time, as Racket Demo does. Each line-up shot is read from the poses of 120 to 30 milliseconds before its key went down: pressing the screen pushes the phone.
- The three targets are at the middle of the playfield, at 10% and 14% of it, and at 90% and 86% (
AIM_TARGETS, the quicker line-up; Run and Gun Demo uses all four corners).aimMapturns the three shots into a map. A side the phone hardly moved along is taken from the other side and the picture's 16:9 shape, and the screen is never taken to look smaller than 16° by 9°: shots that are too close together still give a gun that works, and the game tells the player to turn the phone itself. A line-up is only started again when a shot was taken with the phone turned more than 80° away from the first one. - The crosshair is drawn from the phone's pose 25 milliseconds ago, carried on by its own turning to the moment of the picture, and calmed a little with
steadyAim(about 30 milliseconds behind a still hand, nothing to speak of behind a moving one). - A shot in play is judged where the gun pointed 70 milliseconds before its key went down, by the key's own time: what the player saw when they pressed. Each target is judged where it was at that moment.
- CENTER turns the phone's whole frame, so the game lines the gun up again from it: it drops the poses from before the key, reads the middle of the screen 0.3 seconds later from where the phone points, and asks for the two corner shots. The round waits meanwhile.
| Rule | Value |
|---|---|
| Round | 60 seconds |
| Shots before a reload | 6 |
| Reload | 0.95 seconds; 0.3 after a flick upward |
| Least time between shots | 0.14 seconds |
| Shot assist | 0.012 of the playfield's height around a standing target; 0.03 to 0.054 around a can in flight (more the faster it flies), judged at the shot and 50 milliseconds either side of it |
| Crosshair margin | 0.015 of the playfield from every edge |
| Least size of the screen | 16° wide and 9° tall, as seen from the player |
| Gravity on a can | 6.4 m/s² |
| Gatling gun | 200 rounds, 14 a second after 0.3 seconds of spinning up, 1.6 seconds to reload |
| Gatling scatter | 0.012 of the playfield's height around the crosshair, up to 0.026 with hot barrels, and up to 0.008 of climb |
These numbers are exported as RULES from examples/games/shooter.mjs.
Repeatable checks
node --test tests/shooter.test.mjs tests/remote-aim.test.mjs
SHOOTER_CAPTURE_DIR=/path/to/pictures \
node --test tests/shooter-browser.test.mjs
The first covers the line-up with a phone held like a gun (either end forward), flat and upright, shots that are too close together, phone samples that arrive between two steps of the game, the count, the cans, the assist, CALIBRATE, the results and a JSON round trip of a round in play. The second joins with a real browser phone held like a gun, turns its sensors on, lines the gun up with three shots and plays, and saves pictures of the phone and the TV.