Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
1341264
feat(neon): deterministic vehicle physics, traffic signals, road-grid…
dragosandreibobu Oct 13, 2026
e2655da
fix(neon): pursue via stable road-grid waypoints without intersection…
dragosandreibobu Oct 13, 2026
d714051
feat(neon): cullable crosswalks, neon streetlights, traffic signals, …
dragosandreibobu Oct 13, 2026
3796981
fix: adjust sidewalk positions
dragosandreibobu Oct 13, 2026
d0cfa82
chore: note integration work
dragosandreibobu Oct 13, 2026
789df45
style: prepare modular world
dragosandreibobu Oct 13, 2026
5c8c8af
feat: consume shared world geometry module
dragosandreibobu Oct 13, 2026
3688696
fix(neon): load integrated game as native ES module
dragosandreibobu Oct 13, 2026
e8e89db
refactor(neon): initialize live world simulation actors and native mo…
dragosandreibobu Oct 13, 2026
6485c16
test(neon): vehicle simulation sanity
dragosandreibobu Oct 13, 2026
902fdae
feat(neon): advance world clock
dragosandreibobu Oct 13, 2026
cb15cb8
style(neon): clarify native module integration
dragosandreibobu Oct 13, 2026
007e8f8
chore(neon): mark world integration point
dragosandreibobu Oct 13, 2026
feda90c
fix(neon): restore road collision symbol while world integration proc…
dragosandreibobu Oct 13, 2026
a5e4aa4
test(neon): enforce live world integration, road physics and traffic
dragosandreibobu Oct 13, 2026
8526312
fix(neon): wire real vehicle traffic pedestrian police simulation int…
dragosandreibobu Oct 13, 2026
381cda0
test(neon): correct road assertion and verify diagonal collision
dragosandreibobu Oct 13, 2026
58d7150
test(neon): enforce active pursuit and pedestrian simulation
dragosandreibobu Oct 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 45 additions & 38 deletions experiments/neon-streets/game.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { isRoad, CITY, BLOCK, ROAD, makeVehicle, stepVehicle, createTraffic, stepTraffic, createPolice, stepPolice, collidePlayerWithActors, createPedestrians, stepPedestrians } from './world-sim.mjs';
import { drawCityDetails, drawPedestrians, drawPoliceCar } from './world-art.mjs';
(() => {
'use strict';
const canvas = document.getElementById('canvas');
Expand All @@ -7,21 +9,19 @@ const missionsEl = document.getElementById('missions');
const speedEl = document.getElementById('speed');
const missionEl = document.getElementById('mission');
const startEl = document.getElementById('start');
const CITY = 2500, BLOCK = 250, ROAD = 76;
let w = 0, h = 0, dpr = 1, last = performance.now(), playing = false;
let cash = 0, deliveries = 0, policeHeat = 0, stage = 'pickup';
const keys = new Set();
const car = { x: 500, y: 500, angle: -Math.PI / 2, speed: 0 };
const car = makeVehicle();
const pickups = [[750,500],[1000,1000],[1750,1250],[500,1750],[2000,2000],[1250,750],[750,2000]];
const drops = [[1500,500],[500,1250],[750,1750],[2000,750],[1000,2000],[1750,1500],[250,250]];
let marker = pickups[0];
const traffic = [];
for (let i = 0; i < 24; i++) {
const row = 1 + (i * 7 % 9);
const col = 1 + (i * 11 % 9);
const horizontal = i % 2 === 0;
traffic.push({ x: col * BLOCK, y: row * BLOCK, dx: horizontal ? (i % 4 === 0 ? 1 : -1) : 0, dy: !horizontal ? (i % 3 === 0 ? 1 : -1) : 0, speed: 60 + i % 5 * 14, tint: ['#f6be70','#b16bba','#82caca','#80b66f'][i % 4] });
}
const traffic = createTraffic(28);
const pedestrians = createPedestrians(48);
const police = [];
let worldTime = 0, impactFlash = 0, policeSpawnCooldown = 0;
let lastImpactTime = -10;
// World simulation is activated in the frame loop.
function resize() {
dpr = Math.min(2, window.devicePixelRatio || 1);
w = window.innerWidth;
Expand All @@ -32,11 +32,6 @@ function resize() {
}
window.addEventListener('resize', resize);
resize();
function isRoad(x, y, margin = 0) {
const dx = Math.abs(((x + BLOCK / 2) % BLOCK + BLOCK) % BLOCK - BLOCK / 2);
const dy = Math.abs(((y + BLOCK / 2) % BLOCK + BLOCK) % BLOCK - BLOCK / 2);
return dx < ROAD / 2 - margin || dy < ROAD / 2 - margin;
}
const seed = (x, y) => {
const n = Math.sin(x * 127.1 + y * 311.7) * 43758.5453;
return n - Math.floor(n);
Expand Down Expand Up @@ -141,21 +136,14 @@ function tick(now) {
const dt = Math.min(.05, Math.max(0, (now - last) / 1000));
last = now;
if (playing) {
worldTime += dt;
const throttle = Number(keys.has('ArrowUp') || keys.has('KeyW')) - Number(keys.has('ArrowDown') || keys.has('KeyS'));
const steer = Number(keys.has('ArrowRight') || keys.has('KeyD')) - Number(keys.has('ArrowLeft') || keys.has('KeyA'));
car.speed += throttle * 260 * dt;
car.speed *= Math.pow(.982, dt * 60);
if (!throttle && Math.abs(car.speed) < .5) car.speed = 0;
car.speed = Math.max(-100, Math.min(275, car.speed));
car.angle += steer * dt * 2.25 * Math.min(1, Math.abs(car.speed) / 60) * (car.speed < 0 ? -1 : 1);
const nextX = car.x + Math.cos(car.angle) * car.speed * dt;
const nextY = car.y + Math.sin(car.angle) * car.speed * dt;
if (isRoad(nextX, nextY, 6) && nextX > 20 && nextX < CITY - 20 && nextY > 20 && nextY < CITY - 20) {
car.x = nextX;
car.y = nextY;
} else {
if (Math.abs(car.speed) > 75) policeHeat = Math.min(5, policeHeat + dt);
car.speed *= -.25;
const physics = stepVehicle(car, { throttle, steer, handbrake: keys.has('Space') }, dt);
if (physics.collided && physics.impactSpeed > 55) {
policeHeat = Math.min(5, policeHeat + .5);
impactFlash = .3;
lastImpactTime = worldTime;
}
if (Math.hypot(car.x - marker[0], car.y - marker[1]) < 37) {
if (stage === 'pickup') {
Expand All @@ -170,18 +158,27 @@ function tick(now) {
resetMission();
}
}
for (const t of traffic) {
t.x += t.dx * t.speed * dt;
t.y += t.dy * t.speed * dt;
if (t.x < 0) t.x = CITY;
if (t.x > CITY) t.x = 0;
if (t.y < 0) t.y = CITY;
if (t.y > CITY) t.y = 0;
if (Math.hypot(car.x - t.x, car.y - t.y) < 25 && Math.abs(car.speed) > 10) {
car.speed *= -.3;
policeHeat = Math.min(5, policeHeat + .5);
stepTraffic(traffic, dt, worldTime, car);
stepPedestrians(pedestrians, dt);
policeSpawnCooldown = Math.max(0, policeSpawnCooldown - dt);
const desiredPolice = Math.min(3, Math.floor(policeHeat + .2));
if (police.length < desiredPolice && policeSpawnCooldown === 0) {
police.push(createPolice(car, police.length));
policeSpawnCooldown = 2;
}
if (police.length > desiredPolice && policeHeat < .5) police.length = 0;
stepPolice(police, car, dt);
const actorCollision = collidePlayerWithActors(car, traffic, police);
if (actorCollision.impact) {
impactFlash = .32;
lastImpactTime = worldTime;
policeHeat = Math.min(5, policeHeat + (actorCollision.police ? 1.1 : .55));
if (actorCollision.police && cash >= 100) {
cash -= 100;
cashEl.textContent = '$' + cash.toLocaleString();
}
}
impactFlash = Math.max(0, impactFlash - dt);
speedEl.innerHTML = String(Math.round(Math.abs(car.speed) * .65)).padStart(2,'0') + ' <span>KM/H</span>';
policeHeat = Math.max(0, policeHeat - dt * .025);
}
Expand All @@ -193,10 +190,16 @@ function tick(now) {
ctx.rect(0, 0, w, h);
ctx.clip();
worldBackground(cx, cy);
drawCityDetails(ctx, cx, cy, w, h, worldTime);
drawPedestrians(ctx, pedestrians, cx, cy, w, h, worldTime);
for (const t of traffic) {
const x = t.x - cx, y = t.y - cy;
if (x < -40 || y < -40 || x > w + 40 || y > h + 40) continue;
drawCar(x, y, Math.atan2(t.dy, t.dx), t.tint, false);
drawCar(x, y, t.angle, t.tint, false);
}
for (const p of police) {
const x = p.x - cx, y = p.y - cy;
if (x >= -45 && y >= -45 && x <= w + 45 && y <= h + 45) drawPoliceCar(ctx, x, y, p.angle, worldTime);
}
drawMarker(marker[0] - cx, marker[1] - cy, stage === 'pickup' ? 'PICKUP' : 'DROP', stage === 'pickup' ? '#ffd65c' : '#f68cff', now);
drawCar(w / 2, h / 2, car.angle, '#f777ac', true);
Expand All @@ -206,6 +209,10 @@ function tick(now) {
glow.addColorStop(1,'#070411a3');
ctx.fillStyle=glow;
ctx.fillRect(0,0,w,h);
if (impactFlash > 0) {
ctx.fillStyle = 'rgba(255, 80, 120, ' + (impactFlash * .24) + ')';
ctx.fillRect(0, 0, w, h);
}
if (policeHeat > .2) {
ctx.fillStyle='#ffa4b4';
ctx.font='bold 12px monospace';
Expand Down
2 changes: 1 addition & 1 deletion experiments/neon-streets/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover"><meta name="theme-color" content="#110b22"><title>Neon Streets — Bluebird Studio</title><link rel="stylesheet" href="./style.css"></head>
<body><div id="shell"><canvas id="canvas" aria-label="Neon Streets driving game"></canvas><header><a href="../../">BLUEBIRD / LAB</a><div class="brand">NEON<span>STREETS</span><small>PRE-ALPHA</small></div><div class="score">CASH <b id="cash">$0</b><br>MISSION <b id="missions">0</b></div></header><div id="mission">Find the yellow marker to collect a package.</div><div id="speed">00 <span>KM/H</span></div><div id="controls"><button data-key="ArrowLeft">◀</button><button data-key="ArrowUp">▲</button><button data-key="ArrowDown">▼</button><button data-key="ArrowRight">▶</button></div><div id="start"><div class="panel"><div class="eyebrow">A TOP-DOWN DRIVING EXPERIMENT</div><h1>NEON<br>STREETS</h1><p>A living city. A stolen moment. One more delivery.</p><button id="play">START ENGINE ↗</button><p class="help">↑ accelerate · ↓ reverse · ← → steer · collect yellow pickups, deliver to purple drop-offs · touch buttons supported</p></div></div></div><script src="./game.js" defer></script></body></html>
<body><div id="shell"><canvas id="canvas" aria-label="Neon Streets driving game"></canvas><header><a href="../../">BLUEBIRD / LAB</a><div class="brand">NEON<span>STREETS</span><small>PRE-ALPHA</small></div><div class="score">CASH <b id="cash">$0</b><br>MISSION <b id="missions">0</b></div></header><div id="mission">Find the yellow marker to collect a package.</div><div id="speed">00 <span>KM/H</span></div><div id="controls"><button data-key="ArrowLeft">◀</button><button data-key="ArrowUp">▲</button><button data-key="ArrowDown">▼</button><button data-key="ArrowRight">▶</button></div><div id="start"><div class="panel"><div class="eyebrow">A TOP-DOWN DRIVING EXPERIMENT</div><h1>NEON<br>STREETS</h1><p>A living city. A stolen moment. One more delivery.</p><button id="play">START ENGINE ↗</button><p class="help">↑ accelerate · ↓ reverse · ← → steer · Space handbrake · collect yellow pickups, deliver to purple drop-offs · touch buttons supported</p></div></div></div><script type="module" src="./game.js"></script></body></html>
4 changes: 4 additions & 0 deletions experiments/neon-streets/physics-smoke.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { makeVehicle, stepVehicle } from './world-sim.mjs';
test('car moves',()=>{const car=makeVehicle();stepVehicle(car,{throttle:1,steer:0},0.1);assert.ok(car.speed>0);});
1 change: 1 addition & 0 deletions experiments/neon-streets/physics-smoke.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
physics simulation integration pending
3 changes: 2 additions & 1 deletion experiments/neon-streets/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 84 additions & 0 deletions experiments/neon-streets/world-art.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { BLOCK, CITY } from './world-sim.mjs';
// Visual details are viewport-culled and do not modify collision geometry.
export function drawCityDetails(ctx, cx, cy, w, h, seconds) {
const firstX = Math.max(0, Math.floor((cx - 90) / BLOCK));
const lastX = Math.min(CITY / BLOCK, Math.ceil((cx + w + 90) / BLOCK));
const firstY = Math.max(0, Math.floor((cy - 90) / BLOCK));
const lastY = Math.min(CITY / BLOCK, Math.ceil((cy + h + 90) / BLOCK));
for (let i = firstX; i <= lastX; i++) for (let j = firstY; j <= lastY; j++) {
const x = i * BLOCK - cx, y = j * BLOCK - cy;
// Four high-contrast pedestrian crossings, kept outside the road centre.
ctx.fillStyle = '#e5d7cc50';
for (let k = -3; k <= 3; k++) {
const off = k * 8;
ctx.fillRect(x + off - 2, y - 55, 4, 17);
ctx.fillRect(x + off - 2, y + 38, 4, 17);
ctx.fillRect(x - 55, y + off - 2, 17, 4);
ctx.fillRect(x + 38, y + off - 2, 17, 4);
}
// Animated opposing signal phases at junction corners.
const eastWestGreen = Math.floor(seconds / 6 + (i + j) % 2) % 2 === 1;
ctx.fillStyle = '#0b111c';
ctx.fillRect(x - 42, y - 42, 10, 19);
ctx.fillRect(x + 32, y + 23, 10, 19);
ctx.fillStyle = eastWestGreen ? '#48f4a3' : '#f65d79';
ctx.fillRect(x - 40, y - 39, 6, 6);
ctx.fillRect(x + 34, y + 26, 6, 6);
ctx.fillStyle = eastWestGreen ? '#f65d79' : '#48f4a3';
ctx.fillRect(x - 40, y - 30, 6, 5);
ctx.fillRect(x + 34, y + 35, 6, 5);
// Neon pools around intersection lamp posts.
for (const [dx,dy] of [[-57,-57],[57,57]]) {
const lx = x + dx, ly = y + dy;
const glow = ctx.createRadialGradient(lx,ly,1,lx,ly,36);
glow.addColorStop(0,'#f3a4dc48');
glow.addColorStop(1,'#f3a4dc00');
ctx.fillStyle = glow;
ctx.fillRect(lx - 36,ly - 36,72,72);
ctx.fillStyle = '#d4a7d9';
ctx.fillRect(lx - 2,ly - 2,4,4);
}
// Street labels for wayfinding and visual texture.
if (i < CITY / BLOCK && j < CITY / BLOCK) {
ctx.save();
ctx.translate(x + 52, y - 13);
ctx.fillStyle = '#c4a9e477';
ctx.font = '9px monospace';
ctx.fillText('SECTOR ' + (i + j * 11).toString(16).toUpperCase().padStart(2,'0'), 0, 0);
ctx.restore();
}
}
}
export function drawPedestrians(ctx, pedestrians, cx, cy, w, h, seconds) {
for (const p of pedestrians) {
const x = p.x - cx, y = p.y - cy;
if (x < -20 || y < -20 || x > w + 20 || y > h + 20) continue;
ctx.fillStyle = '#0008';
ctx.beginPath(); ctx.ellipse(x + 2,y + 4,4,2.5,0,0,Math.PI*2);ctx.fill();
ctx.fillStyle = p.color;
ctx.beginPath();ctx.arc(x,y,3.3,0,Math.PI*2);ctx.fill();
ctx.fillStyle = '#f7d9bd';
ctx.beginPath();ctx.arc(x,y - 2,1.6,0,Math.PI*2);ctx.fill();
}
}
export function drawPoliceCar(ctx, x, y, angle, seconds) {
ctx.save();
ctx.translate(x,y);
ctx.rotate(angle + Math.PI / 2);
ctx.shadowColor = '#629bff';
ctx.shadowBlur = 18;
ctx.fillStyle = '#131b36';
ctx.fillRect(-13,-20,26,40);
ctx.fillStyle = '#e7e5ef';
ctx.fillRect(-10,-17,20,34);
ctx.fillStyle = '#1b2947';
ctx.fillRect(-8,-8,16,13);
ctx.shadowBlur = 0;
ctx.fillStyle = Math.sin(seconds * 18) > 0 ? '#f04e78' : '#50a9ff';
ctx.fillRect(-9,-4,9,4);
ctx.fillStyle = Math.sin(seconds * 18) > 0 ? '#50a9ff' : '#f04e78';
ctx.fillRect(0,-4,9,4);
ctx.fillStyle = '#fff7c7';
ctx.fillRect(-9,-19,6,2);ctx.fillRect(3,-19,6,2);
ctx.restore();
}
Loading
Loading