five-on-it / packages/sim/src/flyers
packages/sim/src/flyers
Things that fly (GAME_DESIGN §12: the police's surveillance drone at five stars, their helicopter at seven; a drone swarm and the player's scout drone are classes still to come): an entity each on a kinematic body that the simulation moves from its input, as a car's input drives a car. The input is the horizontal velocity the flyer asks for and the height it asks to fly at (setFlyerInput, written by the AI); the flyer comes round to it within its class's acceleration, top speed and climb rate (FLYER_CLASSES), facing the way it goes. Nothing it meets stops it (the AI picks a height over the roofs) and nothing meets it: its collider is in no group a body, a wheel or a person collides with, but a shot's ray finds it, so it is shot like anything else, its class's hit points. Shot down (downFlyer) it falls with gravity, its way through the air slowing, to whatever scenery is under it (a roof, a deck, the street; never a car or a person) and lies there as a wreck until whoever owns it takes it away (removeFlyer). The snapshots carry every flyer (kind flyer), and a client's world keeps a twin of each, a proxy the snapshots place (setFlyerTwin), so the targets on its player's line of fire are the server's.
A class may carry a searchlight (FlyerLight: the helicopter's): its input says where on the ground to point it, and its pool of light comes on there and swings after it at the light's own pace, no farther from under the flyer than its reach; it has hit points of its own, which a hit on the flyer spends first (it hangs under the nose, what a shooter below meets first: damage.ts), and once they are gone it is out for good. A class may carry a door gun (the helicopter's marksman): its input asks for a round at a point, and the flyer fires one (marksmanShot, marksman.ts) when the gun is ready, no faster than its class's rate. Deterministic: the flyers go in ascending id order, their state and their input are hashed with the world.