Everything you see: the sky, the asteroid gates, the pad with its PERFECT / GREAT / GOOD strips, the rocket, and the HUD.
// ---------- drawing ----------
function drawBackground() {
const grd = ctx.createLinearGradient(0, 0, 0, H);
grd.addColorStop(0, '#070b26'); grd.addColorStop(0.55, '#0b1030'); grd.addColorStop(1, '#120a2e');
ctx.fillStyle = grd; ctx.fillRect(0, 0, W, H);
// Nebula blobs.
const blobs = [[120, 140, 150, 'rgba(63, 94, 251, 0.20)'], [380, 420, 170, 'rgba(112, 72, 232, 0.20)'], [240, 560, 130, 'rgba(0, 201, 167, 0.10)']];
for (const [x, y, r, c] of blobs) {
const g = ctx.createRadialGradient(x, y, 0, x, y, r);
g.addColorStop(0, c); g.addColorStop(1, 'rgba(0,0,0,0)');
ctx.fillStyle = g; ctx.fillRect(x - r, y - r, r * 2, r * 2);
}
for (const p of rocks) {
ctx.save();
ctx.globalAlpha = 0.5;
ctx.fillStyle = p.hue;
ctx.beginPath(); ctx.arc(p.x, p.y, p.r, 0, Math.PI * 2); ctx.fill();
ctx.fillStyle = 'rgba(255,255,255,0.18)';
ctx.beginPath(); ctx.arc(p.x - p.r * 0.3, p.y - p.r * 0.3, p.r * 0.5, 0, Math.PI * 2); ctx.fill();
if (p.ring) {
ctx.strokeStyle = 'rgba(230,236,255,0.55)'; ctx.lineWidth = 2.5;
ctx.beginPath(); ctx.ellipse(p.x, p.y, p.r * 1.7, p.r * 0.5, -0.4, 0, Math.PI * 2); ctx.stroke();
}
ctx.restore();
}
for (const s of stars) {
const a = 0.45 + 0.4 * Math.sin(s.tw);
ctx.globalAlpha = a;
ctx.fillStyle = '#dfe6ff';
ctx.beginPath(); ctx.arc(s.x, s.y, s.r, 0, Math.PI * 2); ctx.fill();
}
ctx.globalAlpha = 1;
}
function drawAsteroidSlab(x, y, w, h, seed) {
// PREVIEW ONLY (staging copy) v7: every other big rock removed (lip rock
// kept), and a small cluster of 3 little ones between the big ones.
// Collision unchanged โ the gate rect + gap still decide hits.
ctx.save();
let s = Math.floor(Math.abs(seed) * 1000) + 7;
const rnd = () => { s = (s * 16807) % 2147483647; return s / 2147483647; };
const rock = (cx, cy, rad) => {
const sh = ctx.createRadialGradient(cx, cy, rad * 0.2, cx, cy, rad * 1.7);
sh.addColorStop(0, 'rgba(8,9,14,0.50)'); sh.addColorStop(1, 'rgba(8,9,14,0)');
ctx.fillStyle = sh;
ctx.beginPath(); ctx.arc(cx, cy, rad * 1.7, 0, Math.PI * 2); ctx.fill();
const g = ctx.createRadialGradient(cx - rad * 0.35, cy - rad * 0.35, rad * 0.15, cx, cy, rad);
g.addColorStop(0, '#828793'); g.addColorStop(0.6, '#565963'); g.addColorStop(1, '#33353d');
ctx.fillStyle = g;
ctx.beginPath(); ctx.arc(cx, cy, rad, 0, Math.PI * 2); ctx.fill();
ctx.strokeStyle = 'rgba(18,19,26,0.85)'; ctx.lineWidth = 2.5; ctx.stroke();
ctx.fillStyle = 'rgba(255,255,255,0.22)';
ctx.beginPath(); ctx.arc(cx - rad * 0.3, cy - rad * 0.35, rad * 0.45, 0, Math.PI * 2); ctx.fill();
ctx.fillStyle = 'rgba(18,19,26,0.35)';
const nc = 3 + Math.floor(rnd() * 2);
for (let k = 0; k < nc; k++) {
const an = rnd() * Math.PI * 2, d = rnd() * rad * 0.55;
ctx.beginPath(); ctx.arc(cx + Math.cos(an) * d, cy + Math.sin(an) * d, Math.max(2, rad * 0.12) + rnd() * 3, 0, Math.PI * 2); ctx.fill();
}
};
const cx0 = x + w / 2, rad0 = w * 0.52;
const gapAtBottom = y <= 0;
let rocks = [];
if (gapAtBottom) {
let cy = y + h - rad0 * 0.55;
while (cy + rad0 > y) { const rad = rad0 * (0.88 + rnd() * 0.24); rocks.unshift({ cx: cx0 + (rnd() - 0.5) * w * 0.16, cy, rad }); cy -= rad * 1.6; }
rocks.reverse();
} else {
let cy = y + rad0 * 0.55;
while (cy - rad0 < y + h) { const rad = rad0 * (0.88 + rnd() * 0.24); rocks.push({ cx: cx0 + (rnd() - 0.5) * w * 0.16, cy, rad }); cy += rad * 1.6; }
}
// rocks[0] is the lip rock in both cases; keep every other big one.
rocks = rocks.filter((_, i) => i % 2 === 0);
for (const r of rocks) rock(r.cx, r.cy, r.rad);
// cluster of 3 small ones between each pair of big ones, triangle layout
for (let i = 0; i + 1 < rocks.length; i++) {
const y0 = rocks[i].cy, y1 = rocks[i + 1].cy;
const spots = [[0.30, 0.28], [0.70, 0.48], [0.34, 0.72]];
for (const [fx, fy] of spots) {
rock(x + w * fx + (rnd() - 0.5) * 6, y0 + (y1 - y0) * fy, 9 + rnd() * 4);
}
}
ctx.restore();
}
function drawGates() {
for (const g of gates) {
const x = g.cx - courseX;
const topH = g.cy - g.gap / 2, botY = g.cy + g.gap / 2;
drawAsteroidSlab(x, -8, GATE_W, topH + 8, g.seed);
drawAsteroidSlab(x, botY, GATE_W, H - botY + 8, g.seed + 5);
// Glowing gate markers at the gap edges.
ctx.fillStyle = '#ffd43b';
ctx.beginPath(); ctx.arc(x + GATE_W / 2, g.cy - g.gap / 2, 4, 0, Math.PI * 2); ctx.fill();
ctx.beginPath(); ctx.arc(x + GATE_W / 2, g.cy + g.gap / 2, 4, 0, Math.PI * 2); ctx.fill();
}
// Landing pad, painted in five point-zone strips: outer GOOD, mid GREAT,
// center PERFECT. The top edge carries the zone colors where the ship touches.
const padX = pad.cx - courseX;
if (padX < W + 60 && padX + pad.w > -60) {
const strips = [
['#2b3247', '#8b94b8'], // GOOD
['#3a4a6e', '#7df0d4'], // GREAT
['#6b5a1e', '#ffd43b'], // PERFECT
['#3a4a6e', '#7df0d4'], // GREAT
['#2b3247', '#8b94b8'], // GOOD
];
const edges = [0, 1 / 6, 1 / 3, 2 / 3, 5 / 6, 1];
for (let i = 0; i < 5; i++) {
const x0 = padX + pad.w * edges[i], x1 = padX + pad.w * edges[i + 1];
ctx.fillStyle = strips[i][0];
ctx.fillRect(x0, PAD_TOP, x1 - x0, H - PAD_TOP);
ctx.fillStyle = strips[i][1];
ctx.fillRect(x0, PAD_TOP, x1 - x0, 5);
}
const blink = Math.floor(frames / 12) % 2 === 0;
ctx.fillStyle = blink ? '#ff6b6b' : '#7a1f1f';
for (let i = 0; i < 4; i++) {
ctx.beginPath(); ctx.arc(padX + 10 + i * ((pad.w - 20) / 3), PAD_TOP + 14, 3, 0, Math.PI * 2); ctx.fill();
}
// Beacon arrow above the pad.
ctx.fillStyle = '#7df0d4';
const bob = Math.sin(frames / 10) * 4;
ctx.beginPath();
ctx.moveTo(padX + pad.w / 2 - 10, PAD_TOP - 52 + bob);
ctx.lineTo(padX + pad.w / 2 + 10, PAD_TOP - 52 + bob);
ctx.lineTo(padX + pad.w / 2, PAD_TOP - 36 + bob);
ctx.closePath(); ctx.fill();
}
}
function drawShip() {
ctx.save();
ctx.translate(SHIP_X, shipY);
ctx.rotate(shipTilt);
// Flame: only while the bottom rockets are firing, shrinking as the
// burn runs out. No flame when the rockets are off.
const fl = burnT > 0 ? 26 + Math.random() * 14 + (burnT / BURN_TIME) * 10 : 0;
if (fl > 0) {
const fg = ctx.createLinearGradient(0, 14, 0, 14 + fl + 12);
fg.addColorStop(0, '#fff3bf'); fg.addColorStop(0.4, '#ffa94d'); fg.addColorStop(1, 'rgba(255, 60, 40, 0)');
ctx.fillStyle = fg;
ctx.beginPath();
ctx.moveTo(-8, 14); ctx.quadraticCurveTo(0, 14 + fl + 12, 8, 14); ctx.closePath(); ctx.fill();
}
// Grid fins: small lattice fins near the top (kept small and steel-gray,
// nothing like a Falcon โ this is a cartoon cylinder, not a booster).
for (const s of [-1, 1]) {
const x0 = s * 11, x1 = s * 20, y0 = -18, y1 = -6, w = Math.abs(x1 - x0);
const rx = Math.min(x0, x1);
ctx.fillStyle = '#3b4351';
ctx.fillRect(rx, y0, w, y1 - y0);
ctx.strokeStyle = '#8fa0b3'; ctx.lineWidth = 1;
ctx.beginPath();
ctx.moveTo(rx + w / 2, y0); ctx.lineTo(rx + w / 2, y1);
ctx.moveTo(rx, y0 + 4); ctx.lineTo(rx + w, y0 + 4);
ctx.moveTo(rx, y0 + 8); ctx.lineTo(rx + w, y0 + 8);
ctx.stroke();
ctx.strokeStyle = '#868e96';
ctx.strokeRect(rx, y0, w, y1 - y0);
}
// Fins.
ctx.fillStyle = '#e03131';
ctx.beginPath(); ctx.moveTo(-10, 2); ctx.lineTo(-20, 16); ctx.lineTo(-10, 14); ctx.closePath(); ctx.fill();
ctx.beginPath(); ctx.moveTo(10, 2); ctx.lineTo(20, 16); ctx.lineTo(10, 14); ctx.closePath(); ctx.fill();
// Body: a cylinder โ straight sides, rounded nose cap, seam where the cap meets the tube.
const bg = ctx.createLinearGradient(-12, 0, 12, 0);
bg.addColorStop(0, '#f1f3f5'); bg.addColorStop(0.5, '#ffffff'); bg.addColorStop(1, '#c1c7d4');
ctx.fillStyle = bg;
ctx.beginPath();
ctx.moveTo(-11, 12);
ctx.lineTo(-11, -12);
ctx.quadraticCurveTo(-11, -26, 0, -26);
ctx.quadraticCurveTo(11, -26, 11, -12);
ctx.lineTo(11, 12);
ctx.quadraticCurveTo(11, 16, 0, 16);
ctx.quadraticCurveTo(-11, 16, -11, 12);
ctx.closePath();
ctx.fill();
ctx.strokeStyle = '#868e96'; ctx.lineWidth = 1.5; ctx.stroke();
ctx.strokeStyle = 'rgba(134, 142, 150, 0.6)'; ctx.lineWidth = 1;
ctx.beginPath(); ctx.moveTo(-11, -10); ctx.lineTo(11, -10); ctx.stroke();
// Window.
ctx.fillStyle = '#4dabf7';
ctx.beginPath(); ctx.arc(0, -4, 6, 0, Math.PI * 2); ctx.fill();
ctx.fillStyle = 'rgba(255,255,255,0.85)';
ctx.beginPath(); ctx.arc(-2, -6, 2, 0, Math.PI * 2); ctx.fill();
// Stripe.
ctx.fillStyle = '#1971c2';
ctx.fillRect(-11, 8, 22, 3);
ctx.restore();
}
function text(str, x, y, size, color, align, weight) {
ctx.font = (weight || '800') + ' ' + size + 'px "Segoe UI", system-ui, sans-serif';
ctx.textAlign = align || 'center'; ctx.textBaseline = 'middle';
ctx.lineWidth = Math.max(3, size / 8); ctx.strokeStyle = 'rgba(3,5,18,0.85)';
ctx.strokeText(str, x, y);
ctx.fillStyle = color || '#ffffff';
ctx.fillText(str, x, y);
}
function drawHUD() {
// Score (top center) + level/pad distance + best + mute.
if (state === 'playing' || state === 'over' || state === 'clear') text(String(score), W / 2, 52, 52, '#ffffff');
const padM = Math.max(0, Math.ceil((pad.cx - (courseX + SHIP_X)) / 14));
text('LEVEL ' + level + (state === 'playing' ? ' ยท PAD ' + padM + 'm' : ''), W / 2, 92, 15, '#b8c2e8', 'center', '700');
text(best > 0 ? ('BEST ' + best) : '', 14, 26, 15, '#b8c2e8', 'left', '700');
ctx.font = '700 22px "Segoe UI", system-ui, sans-serif';
ctx.textAlign = 'center'; ctx.textBaseline = 'middle';
ctx.fillText(muted ? '๐' : '๐', W - 26, 26);
ctx.font = '700 13px "Segoe UI", system-ui, sans-serif';
ctx.fillStyle = '#8b94b8';
ctx.fillText('GLIDEPATH ยท AI & ME STUDIOS', W / 2, H - 16);
}
function drawOverlays() {
if (state === 'ready') {
text('GLIDEPATH', W / 2, H * 0.28, 54, '#ffd43b');
text('Guide the rocket down its glidepath', W / 2, H * 0.28 + 42, 18, '#dfe6ff', 'center', '600');
text('(the descent path to the pad) and land on the pad.', W / 2, H * 0.28 + 64, 16, '#b8c2e8', 'center', '600');
const bob = Math.sin(frames / 14) * 6;
ctx.save(); ctx.translate(SHIP_X, shipY + bob); ctx.rotate(0);
// Reuse the ship drawing at the idle position.
ctx.translate(-SHIP_X, -shipY);
drawShip(); ctx.restore();
text('TAP OR PRESS SPACE', W / 2, H * 0.68, 22, '#ffffff');
if (best > 0 || bestLevel > 0) text('BEST ' + best + (bestLevel > 0 ? ' ยท LEVEL ' + bestLevel : ''), W / 2, H * 0.68 + 34, 16, '#b8c2e8', 'center', '700');
} else if (state === 'over') {
ctx.fillStyle = 'rgba(3,5,18,0.45)'; ctx.fillRect(0, 0, W, H);
text(overReason || 'CRASHED!', W / 2, H * 0.34, 40, '#ff6b6b');
text('SCORE ' + score, W / 2, H * 0.34 + 52, 26, '#ffffff');
if (score >= best && score > 0) text('NEW BEST!', W / 2, H * 0.34 + 86, 18, '#ffd43b');
else text('BEST ' + best, W / 2, H * 0.34 + 86, 18, '#b8c2e8', 'center', '700');
text('TAP TO FLY AGAIN', W / 2, H * 0.62, 20, '#ffffff');
} else if (state === 'clear') {
text('LEVEL ' + level + ' CLEAR!', W / 2, H * 0.34, 44, '#7df0d4');
const zoneColor = clearZone === 'PERFECT' ? '#ffd43b' : clearZone === 'GREAT' ? '#7df0d4' : '#dfe6ff';
text(clearZone + ' LANDING!', W / 2, H * 0.34 + 50, 24, zoneColor);
text('LANDING BONUS +' + clearBonus, W / 2, H * 0.34 + 80, 20, '#ffffff');
text('TAP FOR LEVEL ' + (level + 1), W / 2, H * 0.62, 20, '#ffffff');
}
if (state === 'playing' && frames < 75) {
ctx.globalAlpha = Math.min(1, (75 - frames) / 25);
text('LEVEL ' + level, W / 2, H * 0.30, 44, '#ffd43b');
ctx.globalAlpha = 1;
}
}This file paints everything you see. It's the biggest file because drawing is where most of the game's visual detail lives. The order the functions are called (in file 07) is: background, gates, ship, exhaust particles, flash, HUD, overlays.
Each gate is two slabs (top and bottom) with a gap between them. The slabs aren't plain rectangles โ they're drawn as clusters of grey asteroid rocks. This is the most complex drawing function, so here's how it works:
For each gate:
The pad is drawn only when it's on screen (or near it):
The ship is drawn at (SHIP_X, shipY), rotated by shipTilt:
Every piece of text in the game goes through text(): it sets the font (bold, Segoe UI), centers it, draws a dark outline (strokeText) then the fill (fillText). The outline is what makes white text readable against a busy starfield.