Apex Raceway: Race Tracks, Laps and AI Rivals Kit
README.md
Racer
Makes a kart a racer. The peer that owns the kart (its driver's machine, or the host for an AI kart) tracks its race: ordered checkpoint gates, laps, lap times, progress for positions, finishing, the item it holds and what that item does. Every other peer reads the synced fields, so all screens agree. It also holds the kart on its grid slot during the countdown, puts it back on the road when it falls off or leaves the track, spins it out on oil, and lets it collect item boxes.
It goes on a vehiclesKit kart root, alongside vehiclesKit.Vehicle. It races on a RaceTrack (found by name through the registry) and reports finishes to the scene's RaceDirector; item boxes come from pickupsKit, and an oil item drops an OilSlick. Racing.kart and Racing.race in the api module add it for you. RaceAI drives it for an AI racer, and RaceHud shows the local player's.
Fields
slot: grid slot (1-based), fixed for the kart; the race seats people and AI by slot.track: name of the RaceTrack entity; empty takes the first track.racerId,racerName,kind: who races it this race (a peer id for a person, a negative id for AI), their display name, and human or ai.round: the race number this state belongs to (RaceDirector raceNumber).lap,nextGate,passed,score: lap in progress, the gate that counts next, valid gate crossings and comparable progress.finished,raceTime: whether it has crossed the line after the last lap, and seconds since the start (frozen at the finish).lastLap,bestLap: last and best lap times in seconds (0 means none yet).missed,wrongWay: gates crossed out of order this race, and whether it is driving against the track.item,itemUses,boosting: the held item (boost, turbo, oil or empty), its uses left, and whether an item boost is pushing it now.
Methods
useItem(): fires the held item (on the kart's owner); returns whether something happened.grantItem(): gives the kart an item box roll now, as if it drove through a box.pressItem(): presses the item button from UI (the HUD's touch button).toGrid(): puts the kart on its grid slot now.backOnTrack(): puts the kart back on the road at the nearest point.effects(): whether an item boost is pushing it and whether it is spinning on oil.simulateMove(a, b): runs the lap logic on a move fromatob(tests and tools); returns the event and the state.