How SilverEye is made
SilverEye is one Sprout program, about 1,150 lines. Every piece of code below is cut from that file as you read, so it's always the code that runs.
1. A game is three cells
start is how the game begins, update turns one moment into the next, and draw says what to show. The state is a value: nothing changes in place, so a moment can be kept, compared, sent to another phone or rewound.
2. Controls are values too
The handheld sends the stick's tilt, how far you've dragged to look and which buttons are down as held values. wants turns those (or keys, or a finger in the editor) into what a player is asking for this frame.
3. The map is text
Each map is a list of rows: # is wall, . is floor. solid asks whether a point is inside a wall; the same text makes the 3D walls, the mini-map and the line-of-sight checks.
4. Aiming, with a little help
A shot goes to the nearest mark close to the middle of your view and nearer than the wall in front of you. How close counts as "near the middle" grows for far targets and with the aim help you chose; aiming with Z tightens it.
5. Turrets think in Sprout
Every frame each turret calls turret-program with what it knows, in plain words: sees-someone, off-target (how far round it must turn to face them), how-far, can-fire and how-many. It answers turn and fire, and the game does the rest. On the console's program sheet each of those words is shown with its value right now, and tapping one puts it in. Change the program and every turret thinks the new way at once (on both phones in a two-player game).
6. So do the simulants
Simulants are computer players. Each has a style (hunter, flanker or camper), and simulant-program decides how it walks, strafes, turns and fires. facing below is a name made up inside the program: whichever way it needs to turn, to the one it sees or else to where it's going.
7. Players and guards
A player is a record of numbers: where they are, which way they face, health, armour, ammo, what they carry. A guard is smaller: where it patrols, whether it's on alert, when it last fired.
8. Drawing in 3D
The same draw cell that draws 2D shapes also says view (the camera), block (a wall), model (a character or prop) and hold (the gun in your hands). The page draws those with three.js at a low resolution, for the look of an old console, and puts the 2D words on top.
9. Looks are data
Who you play as, and who guards each mission, are tables. Each row names a model and the clips it plays to walk, run, aim, fire and fall, how tall it stands, and what it carries in its hand. The character creator on the console reads its choices straight from looks, so a new row is a new look there too; your choice goes to the other phone with your controls, so they see you as you chose.
Each mission names its guard-kinds, rows of guard-looks: field agents in the lab, soldiers in the depot, sealed suits at the relay. A soldier has no walk, so its run plays slowly (pace) for a patrol.
10. Two phones, no server
An invite and a reply travel as links in a text message; after that the two phones talk straight to each other. They run in lockstep: each sends only its controls, both run the same frames, and the random numbers come from one shared seed, so both phones always agree. Every couple of seconds they compare a fingerprint of the state to be sure.
Nothing in the game had to change for this: update reads input2 when there's a second player, and draw reads me to know whose eyes to look through.
11. A campaign is data, and two phones move on together
Each mission is a record: its map, guards and their patrols, the targets to wreck, where the intel lies, where you start and where you leave. Adding a mission is adding a record.
Moving on to the next mission is just a code change: the console swaps in the same program with stage one higher. Over the two-phone link a code change is applied on the same frame on both, and the first thing update does is notice the state belongs to a different mission and start fresh from the new one. No message to the other phone, no server.
12. Change it
On the console, the program sheet's TUNE tab puts every number at the top of the game on a slider, with the comment that explains it: how fast you walk, how far a blast reaches, how far a turret sees. Or open SilverEye in the editor and change anything: the settings, the maps, the programs. The game swaps your change in while it runs.