跳到正文
m0h· 来源· @exploraX_ · X·· 1 小时前AI 评分20
正文 · 原文

Build: HALFTONE RALLY, a comic-ink arcade car racer (three.js), self-evaluating loop
You are building a small, complete browser racing game: six chunky retro rally cars race three laps of an invented coastal cliff circuit, rendered as a moving comic book. Flat two-tone cel shading, navy ink lines, halftone dots in the shadows, print misregistration, anime speed lines, comic burst stars, impact frames and a cut-away crash beat. Gameplay is small but complete. The point of the project is how it looks and how it moves. Work in autonomous loops: build, capture, judge against the rubric, fix, repeat. Do not stop until the stopping condition fires.

The bar: someone scrolling X sees a clip and thinks it is a trailer for an indie cartoon racer from a small studio. Then they learn it is plain JavaScript with no model, texture or font files.

Reference (style only)
../vib3coded-animation-study/STUDY.md and its frames/ hold a frame-by-frame study of a hover-ship racer with this look. Copy its rendering techniques and its FX timing, never its content. Do not use a floating track over clouds, kites, a pinwheel, a stacked tower, hover ships or the name on its start gantry. Do not name or imitate any existing game.

Stack and rules
Work in this folder (halftone-rally/). git init it if it is not a repo yet. Commit after every iteration.
three.js r185 as ES modules from a vendored copy in vendor/ (copy ../games/desert-rats-3d/vendor/), loaded with an import map. No bundler, no npm, no other dependencies.
http://serve.py is a no-store static server on port 9161 (launch.json name halftone-rally).
Modules:
src/main.js (boot, loop, modes), src/game.js (race flow, laps, positions, results), src/input.js, src/camera.js, src/hud.js, src/audio.js, src/debug.js
src/render/toon.js (toon material with halftone), src/render/post.js (ink edge pass, grain, overlay), src/render/decal.js (misregistered ink decals)
src/world/track.js (spline, road, kerbs, walls, dashes, pads), src/world/terrain.js, src/world/sea.js, src/world/sky.js, src/world/props.js (landmarks, gantry, boom gates, signs, palms, huts, boats, balloons, gulls)
src/car/build.js (parametric car builder + 6 presets), src/car/physics.js, src/car/ai.js
src/fx/burst.js (bursts, sparkles, impact frame), src/fx/speed.js (speed lines, boost cones, tyre smoke), src/fx/crash.js (crash beat), src/items.js (pickups, rocket, oil bomb)
src/lib/ (palette, seeded RNG, noise, canvas helpers, geometry helpers)
No downloaded models, textures or fonts. Everything is built from primitives, extrusions, lathes and custom BufferGeometry; every texture is drawn on a canvas at load. UI type uses system fonts (heavy italic, e.g. "Arial Black", Impact) with a navy stroke.
Original design only. Invented car makers and models, invented track and series name. No real brands, badges or sponsors.
Metres, y up. Seeded RNG everywhere. FX and AI run on a game clock that debugAPI can freeze, so every capture is reproducible.
Target 60 fps at 1080p on an M1-class laptop. If something costs frames, optimise it, do not delete the look.
Keep PROGRESS.md as the iteration log.
The game (do not expand this scope)
Track: "Saltcliff Circuit", one closed loop of about 3 km on a single spline, lap about 60 to 70 s at race pace. In order:
Start/finish straight on a harbour quay: start gantry with a "SALTCLIFF RALLY" banner and lights, bollards, fishing boats bobbing in the harbour.
A fast banked sweeper climbing the cliff side: rock face on the inside, low lavender wall and a long drop to the sea on the outside.
The headland hairpin around a red-and-cream striped lighthouse.
A rock tunnel through the headland with ring lights; the exit blows out to bright light for a moment.
The clifftop straight: two boost pads, palms, beach huts on the sand far below, hot-air balloons in the sky.
The cove jump: a ramp crest, a gap with sea under it, a landing on the far cliff.
A descending switchback back down to the harbour.
The harbour boom gates: two striped booms that lower across alternate halves of the road on a 6 s cycle. Then the quay again.
Cars (6): chunky 70s/80s rally cars with oversized wheels, roof light pods, mud flaps, bonnet stripes and door roundels. Each has its own silhouette and one strong colour:
player "Bramble 77" boxy hatch, coral with cream roof and teal stripe, #7
"Marlin GT" low wedge coupe with a big wing, yellow with navy stripes, #3
"Puffin Van" tall rally van with roof rack, mint with pink band, #12
"Dorado Bubble" round 60s coupe, lavender and cream, #5
"Kestrel Ute" pickup with roll bar, teal with coral, #9
"Oyster Estate" wagon with roof box, cream and pink, #21
Flow: loading lines ("Inking the cliffs", "Painting the sea", "Warming the tyres"), a title screen with the attract mode running behind it, a 3-2-1-GO countdown drawn as comic bursts, three laps, a results card (positions, best lap), best time kept in localStorage. R restarts, Esc returns to title.
Handling (arcade, track-relative): the car's state is distance along the spline, lateral offset, yaw relative to the track, speed and height. This makes walls impossible to tunnel through.
Top speed about 190 km/h, boost x1.4 for 1.2 s. The player must steer through curves; a mild auto-align keeps it friendly.
Space is a handbrake drift: faster yaw, small speed loss, tyre smoke puffs.
Walls clamp the car, cut speed by the impact angle and spray sparkles (a scrape, not a stop).
The jump is ballistic with a squash on landing; a launch pad before the lip guarantees the gap is cleared.
Exaggerated cartoon body motion: lean into corners, squat under throttle, dive under braking, squash and stretch on landing.
AI (5 rivals): speed from curvature lookahead, a racing line with personal offsets, overtakes and blocking, item use (rocket when a car is ahead in range, oil when a car is close behind), light rubber-banding. They bump each other and the player.
Items: spinning yellow star tokens in rows of four at three spots. A token gives either:
Rocket: a fat coral rocket with fins and comic puff smoke, homes gently on the car ahead within 60 m.
Oil bomb: a round navy bomb with a sparking fuse and a white glint, dropped behind.
A hit makes a burst, the car spins one full turn and drops to 35% speed.
Crash: hitting a lowered boom gate above 60 km/h, or a wall nearly head-on above 120 km/h, plays the crash beat (below), then respawns the car on the centre line with 1.5 s of ghosting.
Attract mode (?attract): the player car is driven by AI, no HUD, a scripted lap of the clip beats: grid pull-away under the gantry, an early rocket hit right by the lens (impact frame), overtakes in the sweeper, the tunnel exit flash, boost pads, the jump, and a final crash into the boom gate, then fade to black. This is the X clip.
Controls: WASD or arrows, Space drift, Shift/E fire item, C camera (chase, bumper, TV), H hide HUD, M mute, R restart, Esc title.
Audio (M mutes): procedural WebAudio only: engine tone from rpm and load, a pop for bursts, a whoosh for rockets, a crunch for crashes. Starts on first input.
The look (the whole point)
Palette. Use only these, plus the two-tone lighting of each:

Ink navy #1d1b3a (never pure black anywhere)
Sky #7fd8cc top to #d6f3e8 horizon, a pale sun haze #fff2b8 in one top corner
Road #f7dfc4 / shadow #e3bfa6; kerbs coral #ff6f59 and cream #fff3e3
Walls lavender #a08bdc / shadow #6f5bb0, with a teal rim #3fd6c0
Cliff rock #e0a172 / shadow #a7675e; grass #a8dba0 / shadow #6fa59a; sand #f8e3b0 / shadow #d6b49a
Sea #4cb8c9, shallows #7fd6d2, foam #fff6e6
Accents yellow #ffcf4a, coral #ff6f59, pink #ff5d8f, mint #8fe3c0, teal #2fb5a6, lavender #b9a6ee, cream #fff3e3
Shadow tones shift toward purple, they are never the lit colour made darker.
Toon shading (render/toon.js). One custom material for everything solid:

Two hard tones from N.L (step at about 0.15), smooth normals so shadows fall in big clean shapes, no specular, no PBR, no shadow maps.
Halftone in shadow only: a screen-space dot grid rotated 45 degrees, 6 px cells at 1080p (scale with resolution), dot radius growing with shadow depth, dots in the shadow tone darkened about 12%. Lit areas have no dots.
Soft purple ellipse blob shadows under cars and props instead of cast shadows.
Optional per-face tint jitter of 2 to 3% on terrain so the big shapes are not dead flat.
Ink (render/post.js). A post pass draws navy lines from depth and normal discontinuities (a separate normal pass with FX on their own layer, excluded). Lines are about 2 px at 1080p, thinner with distance, on every silhouette and on creases sharper than about 40 degrees. No black halos on the sky, no line flicker on the road. The same pass adds very light paper grain.

Print misregistration (render/decal.js). Ink decals (lane dashes, chevron arrows, numbers, boost-pad arrows) draw twice: a teal #35cdb8 copy offset 3 px right and 2 px down in screen space, under the navy one. Fixed direction, every decal.

Painted world.

The sea is a flat painted plane: colour bands by depth from a terrain height texture, a cream foam line with a wobbly cut-paper edge that breathes along the coast, small white wave dashes drifting.
Brush-stroke clouds are flat billboards: white, with a lavender underside stroke.
Distant sea stacks and a far coastline are pale lavender silhouettes, fading into the horizon colour.
Faint pencil construction strokes on the road surface, very low alpha.
Terrain. A low-poly headland heightfield: flattened under the road, a real cliff face beside it, carved down to the sea under the cove gap, left high above the tunnel (a portal facade hides the join). Slope picks the colour: steep is rock, flat is grass, low and near water is sand.

Speed.

Thin white anime speed lines radiate from the screen centre across the upper frame, from 70% of top speed and on boost.
Twin exhaust boost cones are white-hot with a lavender edge; they stretch with speed.
Lane dashes stream under the lens.
A soft additive glow on lamps and exhausts (sprites, no bloom pass).
Comic FX (fx/burst.js), with exact timing:

Burst star: 12 to 16 jagged points in 4 layers: navy outer, yellow #ffc94a, coral #ff6a4f, cream core #fff1d6. Random point lengths and rotation; 6 canvas variants drawn at load.

0 ms: scale 0.35
50 ms: overshoot to 1.15
110 ms: settle at 1.0, hold
220 to 300 ms: pop to 1.3 while fading out
Sparkles: 4-point stars (white, plus tan and pink variants), 3 to 6 per hit, scattered. Each grows 0 to 1 in 60 ms, holds 80 ms, shrinks in 120 ms.

Impact frame: if a burst spawns within 7 m of the camera, a full-screen burst covers the frame for 70 ms. Then a pink sparkle blinks at the hit point and the camera shakes for 150 ms. The game clock does not stop.

Crash beat (fx/crash.js):

phaselengthwhat happens
A330 msa burst grows from car size to fill the screen, with sparkles
B150 msflat ink-navy frame with tan 4-point sparkles
C2.6 shard cut to a wider, slower side-on crash cam; the car tumbles end over end along the wall, smearing a white glow trail, sparkles popping
D500 msfade to black
Erespawn (race) or end the clip (attract)
Camera (camera.js). A low chase cam (about 1.5 m up, 5 m back) on a loose spring, so rivals sweep right past the lens. FOV 74 degrees, rising to 90 on boost. It rolls with the track banking (about 0.8 of the bank) plus a little steering lean, and shakes on hits. The TV cam cuts between fixed trackside spots.

HUD. Comic lettering: position ("2ND") huge and italic, lap "LAP 2/3", an item slot in a round badge, small km/h. All in a navy stroke with the same teal misregistration offset. H hides it.

Debug API and tools
window.debugAPI:

setView(name), freezeClock(t), step(ms)
placeCar(i, metresAlongTrack, lateral, kmh), setInput({throttle, brake, steer, drift, fire})
spawnBurst(worldPos), triggerImpact(), triggerCrash(i)
hideHUD(bool)
stats(), which returns fps, frame-time p95, draw calls and triangles.
Named views:

viewwhat it shows
gridstart grid, six cars under the gantry, low behind the player
chase_fastfull speed on the clifftop straight, boost on, speed lines
burst_peaka rocket hit 15 m ahead, frozen at 50 ms
impactthe impact frame
crash_camphase C, mid-tumble
lighthousewide shot of the headland hairpin, the lighthouse and the sea below
tunnel_exita car leaving the tunnel into the light
jumpa car mid-air over the cove
lineupall six cars side by side on the quay, front three-quarter
halftone_macroclose on a shadowed cliff face and wall, to judge the dots
Tools (Python, /usr/bin/python3 with Playwright; real GPU only: WebKit, or Chromium with --use-angle=metal --enable-gpu --ignore-gpu-blocklist; never judge a SwiftShader render):

tools/shots.py: every named view at 1920x1080 into shots/iter_N/.
tools/fxclip.py: steps the frozen clock at 1/30 s and saves frame strips of one burst, one impact frame and the full crash beat. These are judged frame by frame against the timing table, exactly as the reference was studied.
tools/race.py: an AI-only 3-lap race at 4x clock. It writes race.json with: fps p5/p50, lap times per car, item uses and hits, crashes, the maximum wall penetration, any car stuck under 20 km/h for over 3 s, and any car that left the track bounds.
tools/clip.py: records the attract lap at 60 fps, frame-exact, to video/attract.mp4 (silent).
The loop
Numbered iterations. Each iteration:

Implement the current fix list.
Run the server, http://shots.py, http://fxclip.py and http://race.py.
Open every image and look at it. Read race.json.
Score every rubric item pass/fail in PROGRESS.md with a short fix list. Be harsh; a maybe is a fail.
Loop.
Do not ask me anything mid-loop.

Stopping condition
Every rubric item passes on two consecutive iterations, or 12 iterations, whichever comes first. Then record video/attract.mp4 and write a final summary in PROGRESS.md: what passed, what is weak, what five more iterations would fix.

Rubric (pass/fail, from the captures and race.json)
Reads as drawn, not rendered. Every solid surface is two flat tones. No gradients on geometry, no specular, no grey default anywhere.
Ink. Navy lines on every car, prop and landmark silhouette and on hard creases. Steady width, no flicker on the road, no halos on the sky, no pure black.
Halftone. Dots only in shadow, steady screen-space cells, no moire or crawl in motion (check two consecutive frames).
Misregistration. Every ink decal has the teal offset copy, same direction and distance everywhere.
Palette. Only the listed colours and their two tones, consistent across all ten views.
Speed reads. At speed: speed lines, stretched boost cones, streaming dashes, camera roll. At rest: none of them.
Burst anatomy and timing. Four layers, 12 to 16 jagged points, the grow/overshoot/settle/pop curve matches the table to within one frame at 30 fps.
Impact frame. It covers the screen for exactly 2 frames at 30 fps, then the sparkle and shake follow.
Crash beat. Phases A to D match the table to within one frame; the cut is hard; the tumble reads end over end.
Camera feel. Spring lag visible (rivals pass close to the lens), roll with banking, FOV kick on boost, no jitter.
Cars. Six distinct silhouettes: at 64 px wide in lineup you can tell each one apart. Wheels spin and steer, bodies lean and squash.
World. Every track section has its landmark, no large bare surface in any view, the sea and the cliffs read as painted.
It races. In race.json all cars finish, no car is stuck, no wall penetration over 0.3 m, items are used and hit, and lap times are within 8% of each other.
It works. Title, countdown, laps, positions, items, boost, drift, crash and respawn, results, best time, restart, attract, camera cycle, hide HUD, mute, with no console errors.
Tech. fps p5 of 60 or better in the race, no z-fighting on decals, no outline gaps or spikes, no popping.
Cold-look test. Shown chase_fast and burst_peak with zero context, a person would say "screenshot from an indie cartoon racer", not "three.js demo". If you hesitate, it fails.
Scope is frozen. Every iteration spends its whole budget on the failed rubric items, worst first.

来源:m0h · x.com