Run and Gun Demo
A first-person shooter in a little western town, on Shooter Demo's gun. Hold your phone like a gun, as in Shooter Demo: on its long edge with the screen to the side, one hand round its near end with the thumb on FIRE, the other hand under its far end. Held that way the phone shows a controller's stick in the top corner of the far end, under the thumb of that other hand. The stick walks; the phone aims, and FIRE shoots.
Five shots line the gun up: the middle of the screen, then its four corners (top left, top right, bottom right, bottom left). Four corners measure each half of the screen on its own, so the aim stays true when you sit to one side of the TV, and each half twice, so one shaky shot counts for less. Each target pops up on a stick and sways until you shoot it. Under it, two cards show a person aiming the phone at that target: one from the hip, one held up like a gun. Shoot the targets the way you will play and from where you will play: the shots show the game where your screen is from there. CALIBRATE on the phone starts the five again. During the count from 3 you can already walk, so that is the moment to try the stick: up walks the way you look, down walks back, left and right step to the side.
The crosshair stays in the middle of the screen, as in any first-person shooter, and the view follows the phone. Point the phone at a spot on the screen and the view turns until that spot is in the middle; point it at the middle of the screen and you look straight ahead. To turn round, point past the left or right side of the screen: the view keeps turning that way, faster the further past. Up and down go as far as looking up at the roofs and down at your feet.
Then a round of 90 seconds:
- Outlaw boards flip up in the saloon's windows and door, in the store's and the sheriff's, on the porch roofs, on the water tower's walkway and behind the wagon, the barrels and the bales. The first stands in front of you; later ones stand all round, up to three at once. A ring over each board empties as its time runs out, and an arrow at the side of the screen points to each one out of sight. Shoot a board within a second of it standing up for 30 points (a quick draw), later for 20. One left standing aims for a moment, then fires: its toy gun's flag says BANG and you lose 5 points.
- Cans and bottles stand on the practice plank at the open end of the square, the hitching rail and the saloon's porch rail: 10 for a can's first hit and 10 more for each hit in the air, 15 for a bottle. A rail fills again a few seconds after its can or bottle is gone.
- Every shot board, a can's first hit and every bottle drop a star on your side of it. Walk over it within 9 seconds for 10 points.
- A tumbleweed comes in at a corner of the square or its open end, 14 seconds into the round and then every 7 seconds. It comes in where you are looking when it can, hops over the edge of the square and rolls straight at where you stood, which takes three seconds or more. Step aside, or shoot it for 5 points. If it gets to you it costs 5 points and knocks you for a moment.
- The green crate by the store gives the gatling gun, as in Shooter Demo.
It is the easier of the two gun games: a shot counts from 0.03 of the screen's height around a board, a can or a tumbleweed (Shooter Demo allows 0.012), more around a can in flight, and 0.015 more with a gamepad. The crosshair turns gold when a shot from where it is would hit. The gun reloads in 0.6 seconds. A wall hides what is behind it.
CENTER and CALIBRATE line the gun up again, as in Shooter Demo. The round waits meanwhile.
With motion off, drag a finger on the aim glass to look about; held at a side of the glass it keeps turning. Gamepad: the left stick or D-pad walks, the right stick looks about (slower over a target), A or R2 fires and START pauses. Keyboard: up and down walk, left and right turn, and with neither held the view comes round by itself to what is in sight; Space fires and Enter pauses. The crosshair stays in the middle with all of them.
Run locally
PORT=49231 node examples/games/run-and-gun-host.mjs
Open the local town. 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('run-and-gun-demo', [{id: playerId, name: 'Player'}], 117);
const demo = GAMES['run-and-gun-demo'];
const binding = demo.connect(host, state, {autoStart: false});
binding.tick(1 / 30); // seconds
// With createScene the town 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 is Shooter Demo's module started as its second variant (examples/games/run-and-gun.mjs over shooter.mjs), so the aim and the gun are the same code; its line-up has four corners (AIM_CORNERS), Shooter Demo's two (lineupTargets in shooter.mjs). The line-up screen of both is drawLineup in examples/games/hold-picture.mjs. The view that follows the phone is lookFrom in town-play.mjs; how its pose is drawn between the phone's late, bursty samples (drawn a little in the past, at most 40 ms, a longer gap bridged by the phone's own turning) is followPose in town-view.mjs. The town is examples/games/town.mjs (where everything stands, and the player's eyes: eyes, seeFrom, ray, solidAlong, keepOut), its rules examples/games/town-play.mjs, and its picture examples/games/town-scene.mjs (renderer run-and-gun-3d), with the gun in the hand drawn over the town.
The Remote view asks for two buttons, Fire and Calibrate, and a stick, with hold: 'point' and stickHand: 'other', and during the line-up names the target to point at (aimAt), which the phone's aim glass shows: on a phone held sideways the stick sits in the very corner of the far end, a controller's stick with room round it; held upright it sits in the top left corner, as large, with the small keys two by two beside it. On a screen too small for that, the stick is on the keys' deck. Phone apps older than 1.19.0 keep the upright stick on the deck, and older than 1.17.2 draw the sideways one smaller and nearer the screens.
RunAndGunGameState and RunAndGunPublicState describe the fields: Shooter Demo's, with variant: 'run', and these. hero is the player: where it stands and looks (x, z, yaw, pitch), how fast it walks and turns, and hurtAt, the game time a tumbleweed last reached it. boards are the outlaw boards standing or falling (spot indexes SPOTS in town.mjs, until is when one fires); targets the cans and bottles (slot indexes SLOTS); stars and weeds what lies and rolls about; outlaws, grabbed and bangs the round's counts; lock what a shot from where the crosshair is would hit (outlaw, can, bottle, weed, crate or null). The effects add board, outlaw, bang, refill, grab, weed, weedin and ouch.
| Rule | Value |
|---|---|
| Round | 90 seconds |
| Reload | 0.6 seconds; 0.3 after a flick upward |
| Shot assist | 0.03 of the playfield's height around a board, a standing can or bottle, a tumbleweed or the crate (0.045 with a gamepad); 0.055 around a can in flight |
| Walking | 3.6 metres a second at a full push of the stick, on a square 18 metres wide |
| Turning | The view follows the phone across the screen (the middle of the screen is straight ahead). Past a side it turns on, up to 120 degrees a second 0.3 of the screen's width past it |
| Outlaw board | 30 within 1.2 seconds of standing up, then 20; stands 5 seconds early in a round and 4 at its end, the last 1.3 aiming; then costs 5 (never below 0) |
| Boards at once | 1 for the first 15 seconds, then 2, then 3 after 50 seconds |
| Star | 10 points; lands after 0.45 seconds, lies for 9 seconds, taken from 0.8 metres |
| Tumbleweed | The first 14 seconds into a round, then every 7 seconds; 3 metres a second; shot 5 points; one that gets there costs 5 and knocks you for 0.5 seconds, then nothing can hurt for 1.6 seconds |
These numbers are exported as RULES from examples/games/run-and-gun.mjs; the rest are Shooter Demo's.
Repeatable checks
node --test tests/run-and-gun.test.mjs
RUN_AND_GUN_CAPTURE_DIR=/path/to/pictures \
node --test tests/run-and-gun-browser.test.mjs
The first covers walking and the walls, looking about on a Remote (the crosshair in the middle, the view following the phone, turning on past a side), a gamepad and a keyboard (the view coming round by itself), the boards (the first in front, quick draws, one that fires, boards all round over 70 seconds, none close or steep, each facing the player), the help and the walls, the rails, the stars, the tumbleweeds (one that gets there, one stepped away from, one shot), the keyboard's crosshair, the results and a JSON round trip of a round in play. The second joins with a real browser phone held sideways, checks that the stick is in the corner and as large as a controller's with 40 pixels clear round it, lines the gun up, walks with the stick while the phone aims at a board and fires, turns with the crosshair at the edge, and saves pictures of the phone and the TV.