The game's brain: the governor burn, gravity, scrolling, collisions, and the landing rules. This is where Glidepath actually plays.
// ---------- update ----------
let last = performance.now();
function update(dt) {
frames++;
for (const s of stars) {
s.x -= s.sp * dt * (state === 'playing' ? 1 : 0.35);
if (s.x < -4) { s.x = W + 4; s.y = Math.random() * H; }
s.tw += dt * 3;
}
for (const p of rocks) {
p.x -= 8 * dt * (state === 'playing' ? 1 : 0.35);
if (p.x < -50) { p.x = W + 50; p.y = 40 + Math.random() * (H - 80); }
}
if (flash > 0) flash--;
if (shake > 0) shake--;
// Exhaust drifts and fades in every state, so a crash doesn't freeze it.
for (const p of parts) { p.x += p.vx * dt; p.y += p.vy * dt; p.life -= dt; }
parts = parts.filter(p => p.life > 0);
if (state !== 'playing') return;
// Rocket burn (governor): steer toward the same climb speed on every
// burn. Target -665 offsets gravity (+1750/s over the burn) so the burn
// ENDS near -540. Never brakes a climb already faster than the target.
if (burnT > 0) {
const bt = Math.min(dt, burnT);
burnT -= dt;
if (shipV > -665) shipV += (-665 - shipV) * Math.min(1, bt * 14);
emitExhaust();
}
shipV = Math.min(shipV + GRAV * dt, MAXFALL);
shipY += shipV * dt;
shipTilt = Math.max(-0.45, Math.min(0.55, shipV / 900));
// The world scrolls: course coordinates stay fixed, the camera moves.
courseX += speed * dt;
const gx = (g) => g.cx - courseX;
// Scoring + difficulty.
for (const g of gates) {
if (!g.passed && gx(g) + GATE_W < SHIP_X - SHIP_R) {
g.passed = true; score++; levelScore++;
speed = Math.min(280, speed + 3);
sfx('score');
}
}
gates = gates.filter(g => gx(g) > -120);
// The pad: land on it gently, or miss it and the run ends.
const padX = pad.cx - courseX;
const overPad = SHIP_X + SHIP_R > padX && SHIP_X - SHIP_R < padX + pad.w;
// Landing assist: the pad steadies your descent when you're over it and low.
if (overPad && shipY > PAD_TOP - 140 && shipV > 420) shipV = 420;
if (overPad && shipY + SHIP_R >= PAD_TOP) {
if (shipV <= 660) { landPad(); return; }
shipY = PAD_TOP - SHIP_R; gameOver('TOO FAST TO LAND!'); return;
}
if (padX + pad.w < SHIP_X - SHIP_R) { gameOver('MISSED THE PAD!'); return; }
// Collisions: forgiving circle vs gate slabs + floor/ceiling.
if (shipY + SHIP_R >= H || shipY - SHIP_R <= 0) { shipY = Math.min(Math.max(shipY, SHIP_R), H - SHIP_R); gameOver(); return; }
for (const g of gates) {
if (SHIP_X + SHIP_R > gx(g) && SHIP_X - SHIP_R < gx(g) + GATE_W) {
const topBot = g.cy - g.gap / 2, botTop = g.cy + g.gap / 2;
if (shipY - SHIP_R < topBot || shipY + SHIP_R > botTop) { gameOver(); return; }
}
}
}This file is the game's brain. update(dt) runs every frame and moves everything, checks every collision, and decides whether you score, crash, or land. If you understand this file, you understand how Glidepath plays.
update(dt) receives dt — the seconds since the last frame, usually about 0.016 (60 frames per second). Every movement in the file is multiplied by dt, so the game runs at the same speed no matter the frame rate. A ship falling at 880 pixels per second moves 880 * 0.016 = about 14 pixels per frame.
The first part of update() runs in every state — even on the title screen — so the game never looks frozen:
Then: if (state !== 'playing') return; — if you're not in a live run, nothing else happens. The ship doesn't fall, gates don't scroll, no collisions. Only the background moves.
if (burnT > 0) {
const bt = Math.min(dt, burnT);
burnT -= dt;
if (shipV > -665) shipV += (-665 - shipV) * Math.min(1, bt * 14);
emitExhaust();
}
This is the core mechanic. While burnT (seconds of burn left) is above zero:
Why -665 and not -540? Because gravity (+1750 per second) acts during the 0.15-second burn. Starting at -665 and adding gravity over the burn, you end near -540. So every tap ends at the same climb speed, -540, no matter how fast you were falling when you tapped. That's why the game feels consistent.
shipV = Math.min(shipV + GRAV * dt, MAXFALL);
shipY += shipV * dt;
shipTilt = Math.max(-0.45, Math.min(0.55, shipV / 900));
courseX += speed * dt;
const gx = (g) => g.cx - courseX;
courseX is the camera. It increases by speed * dt every frame. Every gate has a fixed course x-position (g.cx); its screen position is gx(g) = g.cx - courseX. The gates never move — the camera moves past them. When a gate's screen position goes off the left edge, it's removed from the list.
for (const g of gates) {
if (!g.passed && gx(g) + GATE_W < SHIP_X - SHIP_R) {
g.passed = true; score++; levelScore++;
speed = Math.min(280, speed + 3);
sfx('score');
}
}
A gate counts as passed when its right edge has gone fully behind the ship's left edge. When that happens: the gate is marked passed, score and levelScore each go up by 1, the scroll speed goes up by 3 (capped at 280), and the score sound plays. levelScore also shrinks future gate gaps (see file 02), so scoring makes the game harder.
const padX = pad.cx - courseX;
const overPad = SHIP_X + SHIP_R > padX &&
SHIP_X - SHIP_R < padX + pad.w;
overPad is true when the ship's circle horizontally overlaps the pad.
update() checks things in this order: burn, gravity, scrolling, gate passing, pad, then collisions. The pad is checked BEFORE the gates, so if you land on the pad on the same frame you'd also clip a gate, the landing wins. And landPad() / gameOver() both return immediately, so only one outcome happens per frame.