, or the link to get it; opens a new tab (the game may be framed)
(function () { var g = ME_EXTRA.gamepass, el = $('lPass'); if (!el) { el = document.createElement('p'); el.id = 'lPass'; el.className = 'fine'; $('lPool').parentNode.insertBefore(el, $('lPool').nextSibling); }
if (!g || !g.on) { el.hidden = true; return; } el.hidden = false;
el.innerHTML = g.active ? '🎫 Game Pass active' + (g.untilText ? ' until ' + esc(g.untilText) : '') + ' · a shield at the start of every run' : '🎫 Get the Game Pass · higher daily POL caps across all nine games, a shield every run here'; })();
$('bHangar').textContent = P.freeUpgrades > 0 ? 'Hangar · ' + P.freeUpgrades + ' free' : 'Hangar';
// signed in through the game: these open InstantAdPay already signed in (in-game sign-in pass, 2026-10-03)
if (window.IAPGames && !$('moreGames').dataset.done) { $('moreGames').dataset.done = 1; IAPGames.strip($('moreGames'), { current: 'driprunner', title: 'More games that pay POL' }); } // cross-promo strip (2026-10-03)
[['lIap', 'overview'], ['bLevel', 'buy']].forEach(function (x) { var a = $(x[0]); if (a && !a.dataset.pass) { a.dataset.pass = 1; a.addEventListener('click', function (ev) { if (window.IAPSignin && IAPSignin.hasPass()) { ev.preventDefault(); IAPSignin.enter(x[1]); } }); } });
if (ME.guest) {
$('lMember').innerHTML = 'Playing as a guest · sign in to keep your progress and collect POL';
$('bSignin').hidden = false; $('bSignin').href = ME_EXTRA.signin || '/signin'; $('lShare').hidden = true;
} else {
$('lMember').innerHTML = 'InstantAdPay · ' + (ME.username ? '@' + ME.username : '#' + ME.memberId) + ' · ' + (ME.wallet ? ME.wallet.slice(0, 6) + '…' + ME.wallet.slice(-4) : hasW() ? 'wallet linked' : 'no wallet on file · ' + linkW());
$('bSignin').hidden = true;
var rf = ME_EXTRA.referrals || {};
// the invite card shows for every signed-in player; without a username there is no link yet, so it says how to get one
$('lShare').hidden = false; $('invHas').hidden = !ME_EXTRA.share; $('invNone').hidden = !!ME_EXTRA.share; $('invNoneGo').href = IAP + '/my';
$('invLink').value = ME_EXTRA.share || ''; $('bShare').hidden = !navigator.share;
$('lShareHow').innerHTML = 'Players whose InstantAdPay sponsor is you are your team. Each time one of them refuels, ' + (rf.pct || 10) + '% of what that refuel adds to the pool is credited to your balance, and it is sent to your wallet with your drips at ' + Number((BAL && BAL.threshold) || 0.25).toFixed(2) + ' POL. How it works';
$('lShareStat').innerHTML = 'Your link: ' + (rf.clicks || 0) + ' visit' + (rf.clicks === 1 ? '' : 's') + ' · ' + (rf.count || 0) + ' player' + (rf.count === 1 ? '' : 's') + ' on your team · ' + f3(rf.earned) + ' POL earned from their refuels (' + (rf.pct || 0) + '% of each)';
}
show('ovLobby');
}
/* ---------- the run ---------- */
function newRun() {
ac();
return api('/api/run/start', { W: W, H: H }).then(function (r) {
if (r._status !== 200) { toast(r.error || 'Could not start a run.'); return; }
R = { id: r.runId, seed: r.seed, speed: r.speed, chapter: r.chapter, goal: r.goal, on: true, paused: false, t: 0, dist: 0, drips: 0, chapDrips: 0, fuel: 100, ents: [], parts: [], shake: 0, inv: 2, shield: !!r.armed.shield, magnet: !!r.armed.magnet, slow: r.armed.slow ? 15 : 0, ship: r.ship, refuels: 0, pending: [], consumed: { d: 0, b: 0, g: 0 }, lastFlush: 0, W: W, H: H };
makeGens(); player.y = floorY - 120; player.vy = 0; hudCache = {}; setHud(); $('hud').classList.add('on'); $('tapdesk').hidden = !matchMedia('(min-width:700px)').matches; hideAll();
if (R.magnet) toast('Drip magnet on'); if (R.shield) toast('Shield core armed');
});
}
function makeGens() { R.gen = { d: DRSpawn.drips(R.seed, R.W, R.H), b: DRSpawn.bots(R.seed, R.chapter, R.H), g: DRSpawn.gates(R.seed, R.chapter, R.H) }; R.next = { d: R.gen.d(), b: R.gen.b(), g: R.gen.g() }; for (var i = 0; i < R.consumed.d; i++) R.next.d = R.gen.d(); for (var j = 0; j < R.consumed.b; j++) R.next.b = R.gen.b(); for (var k = 0; k < R.consumed.g; k++) R.next.g = R.gen.g(); }
function spawn() {
while (R.next.d.t <= R.t) { var g = R.next.d; for (var i = 0; i < g.drips.length; i++) { var d = g.drips[i]; R.ents.push({ k: 'd', i: d.i, x: d.x0 - (R.t - g.t) * R.speed, y: d.y, r: 9, ph: Math.random() * 6 }); } R.next.d = R.gen.d(); R.consumed.d++; }
while (R.next.b.t <= R.t) { var b = R.next.b; R.ents.push({ k: 'b', x: R.W + 60 - (R.t - b.t) * R.speed, y: b.y, r: 15, amp: b.amp, ph: b.ph, rot: 0 }); R.next.b = R.gen.b(); R.consumed.b++; }
while (R.next.g.t <= R.t) { var q = R.next.g; if (R.chapter >= 2) R.ents.push({ k: 'g', x: R.W + 60 - (R.t - q.t) * R.speed, y: q.y, gap: q.gap, w: 34 }); R.next.g = R.gen.g(); R.consumed.g++; }
}
function hop() { if (!R || !R.on || R.paused) return; player.vy = -(R.ship === 2 ? 500 : 520); sfx.hop(); burst(player.x - 12, player.y + 4, 4, R.ship === 2 ? '255,194,75' : '34,211,238', 60); }
canvas.addEventListener('pointerdown', function (e) { e.preventDefault(); ac(); hop(); });
window.addEventListener('keydown', function (e) { if (e.code === 'Space' || e.code === 'ArrowUp') { if (R && R.on && !R.paused) { e.preventDefault(); hop(); } } });
function burst(x, y, n, rgb, sp) { if (!R) return; for (var i = 0; i < n; i++) { var a = Math.random() * 6.283, s = sp * (.4 + Math.random()); R.parts.push({ x: x, y: y, vx: Math.cos(a) * s, vy: Math.sin(a) * s, l: .5 + Math.random() * .4, c: rgb, r: 1.5 + Math.random() * 2 }); } }
function flush(goal) {
if (!R) return Promise.resolve({});
var evs = R.pending; R.pending = []; R.lastFlush = R.t;
if (!evs.length && !goal) return Promise.resolve({});
return api('/api/run/events', { runId: R.id, t: R.t, events: evs, goal: !!goal }).then(function (r) {
if (r._status !== 200) { if (r.over && R) { R.on = false; } toast(r.error || 'Sync problem'); return r; }
if (R) { R.drips = r.drips; R.chapDrips = r.chapDrips; R.goal = r.goal; if (r.refused) toast('Server refused ' + r.refused + ' drip' + (r.refused > 1 ? 's' : '') + ' (' + (r.why || []).join(',') + ')'); }
return r;
}).catch(function () { R && (R.pending = evs.concat(R.pending)); return {}; });
}
function update(dt) {
if (!R || !R.on || R.paused) return; R.t += dt; var sp = R.speed; R.dist += sp * dt; if (R.slow > 0) R.slow -= dt; if (R.inv > 0) R.inv -= dt;
R.fuel -= dt * 2.4; if (R.fuel <= 0) { R.fuel = 0; return over('Out of fuel', 'The tank is dry.'); }
player.vy += 1500 * dt; if (player.vy > 900) player.vy = 900; player.y += player.vy * dt;
if (player.y > floorY - player.r) { player.y = floorY - player.r; if (player.vy > 200) burst(player.x, player.y + 8, 3, '34,211,238', 40); player.vy = 0; }
if (player.y < 70) { player.y = 70; player.vy = 0; }
player.tilt += ((player.vy / 900) * .6 - player.tilt) * Math.min(1, dt * 10);
spawn();
var ents = R.ents, i;
for (i = ents.length - 1; i >= 0; i--) { var e = ents[i]; var es = e.k === 'b' && R.slow > 0 ? sp * .45 : sp; e.x -= es * dt;
if (e.k === 'd') { e.ph += dt * 4; if (R.magnet) { var dx = player.x - e.x, dy = player.y - e.y, dd = Math.hypot(dx, dy); if (dd < 150) { e.x += dx / dd * 420 * dt; e.y += dy / dd * 420 * dt; } }
if (Math.hypot(player.x - e.x, player.y - e.y) < player.r + e.r + 2) { ents.splice(i, 1); R.drips++; R.chapDrips++; R.fuel = Math.min(100, R.fuel + 3.5); sfx.coin(); burst(e.x, e.y, 8, '255,194,75', 140); R.pending.push({ k: 'd', i: e.i, t: Math.round(R.t * 1000) / 1000 });
if (R.chapDrips >= R.goal) return cleared(); continue; } }
if (e.k === 'b') { e.rot += dt * 3; var by = e.y + (e.amp ? Math.sin(R.t * 2 + e.ph) * e.amp : 0); e.cy = by; if (R.inv <= 0 && Math.hypot(player.x - e.x, player.y - by) < player.r + e.r - 2) { if (R.shield) { R.shield = false; R.inv = 1.5; ents.splice(i, 1); sfx.shield(); burst(e.x, by, 20, '255,106,26', 220); pill('Shield!'); R.shake = .25; continue; } return crash(e.x, by); } }
if (e.k === 'g') { if (R.inv <= 0 && player.x + player.r > e.x && player.x - player.r < e.x + e.w && (player.y - player.r < e.y || player.y + player.r > e.y + e.gap)) { if (R.shield) { R.shield = false; R.inv = 1.5; sfx.shield(); pill('Shield!'); R.shake = .25; } else return crash(player.x, player.y); } }
if (e.x < -90) ents.splice(i, 1); }
var ps = R.parts; for (i = ps.length - 1; i >= 0; i--) { var p = ps[i]; p.l -= dt; p.x += p.vx * dt; p.y += p.vy * dt; p.vy += 300 * dt; if (p.l <= 0) ps.splice(i, 1); }
if (R.shake > 0) R.shake -= dt;
if (Math.random() < .9) R.parts.push({ x: player.x - 16, y: player.y + (Math.random() - .5) * 6, vx: -sp * .5 - 40, vy: (Math.random() - .5) * 30, l: .3, c: R.ship === 2 ? '255,194,75' : '34,211,238', r: 2 + Math.random() * 2 });
if (R.t - R.lastFlush > 2.5 && R.pending.length) flush(false);
setHud();
}
function crash(x, y) { sfx.crash(); burst(x, y, 36, '255,59,122', 260); burst(x, y, 14, '255,255,255', 160); R.shake = .5; over('Courier hit', 'A bot got you.'); }
function over(title, why) {
R.paused = true; flush(false);
setTimeout(function () { if (!R) return; $('oEyebrow').textContent = title; $('oTitle').textContent = 'Run over at ' + R.drips; $('oText').textContent = why + ' Refuel with a sponsor visit and keep this run, drips and chapter progress intact.'; $('bRefuel').hidden = false; $('oChip').hidden = false; tip('oTip'); show('ovOver'); }, 450);
}
function cleared() {
R.paused = true; pill('Verifying…'); $('cOffer').hidden = true;
flush(true).then(function (r) {
if (!R) return;
if (!r.cleared) { R.paused = false; if (r.short) toast('Server count says ' + r.short + ' more to go'); return; }
var c = r.cleared; sfx.clear(); burst(player.x, player.y, 40, '255,194,75', 220);
$('cEyebrow').textContent = 'Chapter ' + c.chapter + ' cleared'; $('cTitle').textContent = 'Banked ' + (R.goal) + ' drips';
var m = Math.floor(c.playTime / 60), s = c.playTime % 60; var tm = m + ':' + (s < 10 ? '0' : '') + s;
$('cBig').innerHTML = '+' + f3(c.pol) + 'POL'; $('cBig').classList.toggle('dim', !c.pol);
var why = { paid: 'First clear, verified. Added to your game balance.', replay: c.first ? 'Verified.' : 'You cleared this one before. Only the first clear pays.', pool: 'The POL pool is empty right now. Refuel visits fill it, so this clear counts but pays nothing.', cap: 'Today’s pool cap is spent. Chapter counts, no POL today.', flagged: 'This run was flagged by the server check, so it pays nothing.', guest: 'You are playing as a guest. Sign in with InstantAdPay and this clear pays ' + f3(POOL.dripPol) + ' POL into your balance. Your progress comes with you.' };
$('bShareClear').hidden = !!ME.guest || !ME_EXTRA.share; $('bShareClear').dataset.text = 'I just cleared Chapter ' + c.chapter + ' in Drip Runner' + (c.pol ? ' and it paid ' + f3(c.pol) + ' POL' : '') + '. Hop the network, dodge the bots:';
$('bClearSignin').hidden = !ME.guest; if (ME.guest) $('bClearSignin').href = ME_EXTRA.signin || '/signin';
$('cText').textContent = why[c.reason] || '';
// the Game Pass truth (deferred to later days, or recorded while InstantAdPay confirms) + the nudge, in a new tab (the game may be framed)
if (c.note) { var gpp = ME_EXTRA.gamepass; $('cText').innerHTML = esc(c.note) + (gpp && gpp.on && !gpp.active && /Get the Pass/.test(c.note) ? ' Get the Game Pass' : ''); } if (c.pol && !ME.guest && !hasW()) $('cText').innerHTML += ' ' + linkW() + '.'; $('cChip').className = 'chip ' + (c.pol ? 'ok' : 'sig'); $('cChip').textContent = (c.pol ? 'verified' : c.reason) + ' · ' + tm + ' play time';
R.chapter = c.next; R.goal = c.nextGoal; R.chapDrips = 0; if (r.pool != null) POOL.available = r.pool;
tip('cTip'); setTimeout(function () { show('ovClear'); if (r.starterOffer) starterOffer(r.starterOffer); }, 500); // the offer card fades in under the result (CSS delay)
});
}
/* member welcome offer (2026-10-05): the server sends it after a clear, at most once a Central day, to signed-in players who are
not InstantAdPay members yet. Dismissible, never blocks the next chapter. In a frame the link opens a new tab. */
function starterOffer(o) {
var b = Number(o.bonus) > 0 ? '+' + Number(o.bonus).toLocaleString() + ' bonus ad credits' : 'bonus ad credits';
$('cOfferText').innerHTML = 'Your first $5 package comes with ' + esc(b) + ', and ' + esc(o.perk || 'a free hangar upgrade') + ' here in Drip Runner.';
var a = $('cOfferGo'); a.href = o.url || (IAP + '/my?from=driprunner#buy');
var framed = false; try { framed = window.self !== window.top; } catch (e) { framed = true; }
if (framed) { a.target = '_blank'; a.rel = 'noopener'; } else { a.removeAttribute('target'); a.removeAttribute('rel'); }
$('cOffer').hidden = false;
}
$('cOfferNo').addEventListener('click', function () { $('cOffer').hidden = true; });
$('bNext').addEventListener('click', function () { if (!R) return; R.paused = false; R.inv = 1.5; hideAll(); });
$('bShareClear').addEventListener('click', function () { share(this.dataset.text || 'Play Drip Runner with me:'); });
$('bShare').addEventListener('click', function () { share('Come play Drip Runner with me. Hop the network, dodge the bots:'); });
// Copy: the clipboard API where the page may use it, else select the field and copy, else a prompt to copy by hand
var copyT = null;
function copied(ok) {
var b = $('bCopy'); clearTimeout(copyT);
if (!ok) { window.prompt('Copy your invite link', ME_EXTRA.share); return; }
b.textContent = 'Copied!'; b.classList.add('done'); toast('Invite link copied. Paste it anywhere.');
copyT = setTimeout(function () { b.textContent = 'Copy link'; b.classList.remove('done'); }, 2200);
}
function copyFallback() { var f = $('invLink'), ok = false; try { f.focus(); f.select(); f.setSelectionRange(0, f.value.length); ok = document.execCommand('copy'); } catch (e) { ok = false; } f.blur(); copied(ok); }
$('bCopy').addEventListener('click', function () {
var url = ME_EXTRA.share; if (!url) return;
if (navigator.clipboard && navigator.clipboard.writeText && window.isSecureContext !== false) navigator.clipboard.writeText(url).then(function () { copied(true); }, copyFallback);
else copyFallback();
});
$('invLink').addEventListener('focus', function () { this.select(); });
$('bRestart').addEventListener('click', function () { endRun().then(newRun); });
function endRun() { var id = R && R.id; R = null; hideAll(); return id ? api('/api/run/end', { runId: id }).catch(function () {}) : Promise.resolve(); }
['bLobby1', 'bLobby2'].forEach(function (id) { $(id).addEventListener('click', function () { endRun().then(loadMe).then(lobby); }); });
['bLobby3', 'bLobby4'].forEach(function (id) { $(id).addEventListener('click', function () { loadMe().then(lobby); }); });
$('bPlay').addEventListener('click', function () { newRun(); });
/* ---------- refuel: hand the run to InstantAdPay and come back ---------- */
function snapshot(nonce) {
var s = { runId: R.id, nonce: nonce, seed: R.seed, speed: R.speed, chapter: R.chapter, goal: R.goal, t: R.t, dist: R.dist, drips: R.drips, chapDrips: R.chapDrips, ents: R.ents.map(function (e) { var o = {}; for (var k in e) if (k !== 'cy') o[k] = e[k]; return o; }), consumed: R.consumed, y: player.y, shield: R.shield, magnet: R.magnet, slow: R.slow, ship: R.ship, refuels: R.refuels, pending: R.pending, W: R.W, H: R.H, at: Date.now() };
try { sessionStorage.setItem('dr.snap', JSON.stringify(s)); } catch (e) {}
}
$('bRefuel').addEventListener('click', function () {
if (!R) return;
if (ME.guest) { location.href = ME_EXTRA.signin || '/signin'; return; } // guests sign in first; their progress follows them
$('bRefuel').disabled = true;
api('/api/refuel/start', { runId: R.id }).then(function (r) {
$('bRefuel').disabled = false;
if (r._status !== 200) return toast(r.error || 'Refuel is not available right now.');
snapshot(r.nonce); location.href = r.url;
});
});
function tryResume(q) {
var snap = null; try { snap = JSON.parse(sessionStorage.getItem('dr.snap') || 'null'); } catch (e) {}
if (!snap || snap.runId !== q.get('resume')) { toast('That run could not be restored.'); return lobby(); }
return api('/api/refuel/resume', { runId: snap.runId, nonce: q.get('n') || snap.nonce, receipt: q.get('r') || '', none: q.get('none') === '1' }).then(function (r) {
try { sessionStorage.removeItem('dr.snap'); } catch (e) {}
R = { id: snap.runId, seed: snap.seed, speed: snap.speed, chapter: snap.chapter, goal: snap.goal, on: true, paused: true, t: snap.t, dist: snap.dist, drips: snap.drips, chapDrips: snap.chapDrips, fuel: 0, ents: snap.ents, parts: [], shake: 0, inv: 3, shield: snap.shield, magnet: snap.magnet, slow: snap.slow, ship: snap.ship, refuels: snap.refuels, pending: snap.pending || [], consumed: snap.consumed, lastFlush: snap.t, W: snap.W, H: snap.H };
if (R.W !== W || R.H !== H) { var sx = W / R.W, sy = H / R.H; R.ents.forEach(function (e) { e.x *= sx; e.y *= sy; }); }
makeGens(); player.y = snap.y; player.vy = 0; hudCache = {}; $('hud').classList.add('on'); hideAll();
if (!r.ok) { $('oEyebrow').textContent = r.reason === 'none' ? 'No sponsor pages right now' : 'Visit not verified'; $('oTitle').textContent = 'Run over at ' + R.drips; $('oText').textContent = r.reason === 'none' ? 'InstantAdPay had no verified-visit page for you at the moment. Restart, or try refuelling again later.' : 'The visit did not complete, so the tank stays empty. Refuel again or restart.'; $('bRefuel').hidden = r.reason === 'none'; $('oChip').hidden = r.reason === 'none'; setHud(); return show('ovOver'); }
R.fuel = 100; R.refuels++; R.ents = R.ents.filter(function (e) { return e.k === 'd' || e.x > player.x + 260; }); if (r.pool != null) POOL.available = r.pool;
setHud(); var n = 3; pill('Refuelled · ' + n); var iv = setInterval(function () { n--; if (n <= 0) { clearInterval(iv); pill('Go'); if (R) R.paused = false; if (R && R.pending.length) flush(false); } else pill('' + n); }, 800);
});
}
/* ---------- hangar / balance ---------- */
function hangar() {
show('ovHangar'); $('hgBal').textContent = P.bank.toLocaleString() + ' drips · ' + f3(BAL.unpaid) + ' POL';
var pr = P.prices, free = P.freeUpgrades > 0; $('hgFree').hidden = !free; // the member perk: the next purchase costs nothing
set('itMagnet', 'magnet', P.items.magnet, P.bank >= pr.drips.magnet, pr.drips.magnet + ' drips', 'armed');
set('itShip', 'ship', P.items.ship, P.bank >= pr.drips.ship, pr.drips.ship + ' drips', 'owned');
set('itShield', 'shield', P.items.shield, BAL.unpaid >= pr.pol.shield, f3(pr.pol.shield) + ' POL', 'armed');
set('itSlow', 'slow', P.items.slow, BAL.unpaid >= pr.pol.slow, f3(pr.pol.slow) + ' POL', 'armed');
function set(id, key, own, can, label, ownLabel) { var it = $(id), b = it.querySelector('.buy'); it.classList.toggle('owned', !!own); b.className = 'buy' + (/POL/.test(label) ? ' pol' : '') + (own ? ' own' : (free ? ' free' : (can ? '' : ' no'))); b.textContent = own ? ownLabel : (free ? 'Free' : label); }
}
$('ovHangar').addEventListener('click', function (e) { var b = e.target.closest('[data-buy]'); if (!b) return; b.disabled = true;
api('/api/hangar/buy', { item: b.dataset.buy }).then(function (r) { b.disabled = false; if (r._status !== 200) return toast(r.error || 'Could not buy that.'); P = r.player; BAL = r.balance; sfx.buy(); toast(r.free ? 'Free upgrade used. Enjoy the run!' : 'Paid ' + r.paid); hangar(); }); });
function balance() {
show('ovBal'); api('/api/balance').then(function (b) { BAL = b;
$('bPol').textContent = f3(b.unpaid); var pct = Math.min(100, b.unpaid / b.threshold * 100); $('bProg').style.width = pct + '%';
$('bNote').textContent = 'Pays to your wallet at ' + b.threshold + ' POL. ' + pct.toFixed(0) + '% of the way. Paid so far: ' + f3(b.paidTotal) + ' POL.';
var h = ''; if (!b.history.length) h = 'No drips yet. Clear a chapter.0.000
';
b.history.forEach(function (l) { var cls = l.kind === 'payout' ? (l.status === 'paid' ? 'm ok' : l.status === 'failed' ? 'm neg' : 'm') : (l.pol < 0 ? 'm neg' : 'm'); h += '' + esc(l.label) + (l.tx ? ' · tx' : '') + '' + (l.kind === 'payout' ? '' : (l.pol < 0 ? '' : '+')) + f3(l.pol) + ' '; });
$('ledger').innerHTML = h;
// no wallet yet (2026-10-27): the link, never a line that implies the POL was sent; a player with a wallet sees the same line as before
var wl = b.wallet || (ME && ME.wallet);
if (wl) $('bWallet').textContent = 'Wallet: ' + wl + ' (from your InstantAdPay account).';
else if (hasW()) $('bWallet').textContent = 'Wallet linked on your InstantAdPay account. Your balance is sent to it at ' + b.threshold + ' POL.';
else $('bWallet').innerHTML = (b.unpaid > 0 ? '' + f3(b.unpaid) + ' POL is waiting. ' : '') + '' + linkW() + ' (one free signature on InstantAdPay) and it is sent automatically, including everything earned so far.';
});
}
function esc(s) { return String(s == null ? '' : s).replace(/[&<>"']/g, function (c) { return { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]; }); }
$('bHangar').addEventListener('click', hangar); $('bBalance').addEventListener('click', balance);
/* ---------- draw ---------- */
function draw() {
ctx.clearRect(0, 0, W, H); var t = R ? R.t : performance.now() / 1000, dist = R ? R.dist : performance.now() * .05;
var bg = ctx.createLinearGradient(0, 0, 0, H); bg.addColorStop(0, '#03060E'); bg.addColorStop(.6, '#0A1327'); bg.addColorStop(1, '#101C3C'); ctx.fillStyle = bg; ctx.fillRect(0, 0, W, H);
var s2 = ctx.createRadialGradient(W * .5, H * .85, 10, W * .5, H * .85, W * .9); s2.addColorStop(0, 'rgba(34,211,238,.12)'); s2.addColorStop(1, 'rgba(34,211,238,0)'); ctx.fillStyle = s2; ctx.fillRect(0, 0, W, H);
ctx.save(); if (R && R.shake > 0) ctx.translate((Math.random() - .5) * R.shake * 24, (Math.random() - .5) * R.shake * 24);
var i; for (i = 0; i < stars.length; i++) { var st = stars[i]; var sx = ((st.x - dist * .15) % W + W) % W; ctx.globalAlpha = .35 + .5 * Math.abs(Math.sin(t * 1.5 + st.a * 6)); ctx.fillStyle = '#CFE3FF'; ctx.fillRect(sx, st.y, st.s, st.s); } ctx.globalAlpha = 1;
for (i = 0; i < cols.length; i++) { var c = cols[i]; var cx = ((c.x - dist * .3) % (W + 120) + W + 120) % (W + 120) - 60; ctx.fillStyle = 'rgba(31,111,235,' + c.a + ')'; ctx.fillRect(cx, floorY - c.h, c.w, c.h); ctx.fillStyle = 'rgba(143,240,255,' + c.a * 1.5 + ')'; for (var wy = floorY - c.h + 8; wy < floorY - 6; wy += 12) for (var wx = cx + 5; wx < cx + c.w - 5; wx += 10) if (((wx * 7 + wy * 3) | 0) % 5 < 2) ctx.fillRect(wx, wy, 4, 5); }
ctx.lineWidth = 1; for (i = 0; i < nodes.length; i++) { var n = nodes[i]; n.sx = ((n.x - dist * .55) % (W + 80) + W + 80) % (W + 80) - 40; }
for (i = 0; i < nodes.length; i++) { var a = nodes[i]; for (var j = i + 1; j < nodes.length; j++) { var b = nodes[j], dd = Math.hypot(a.sx - b.sx, a.y - b.y); if (dd < 150) { ctx.strokeStyle = 'rgba(34,211,238,' + (0.16 * (1 - dd / 150)) + ')'; ctx.beginPath(); ctx.moveTo(a.sx, a.y); ctx.lineTo(b.sx, b.y); ctx.stroke(); } } }
for (i = 0; i < nodes.length; i++) { var q = nodes[i]; ctx.fillStyle = 'rgba(143,240,255,.5)'; ctx.beginPath(); ctx.arc(q.sx, q.y, q.r, 0, 6.283); ctx.fill(); }
ctx.strokeStyle = 'rgba(34,211,238,.08)'; var gx = -(dist * .8 % 44); for (var x = gx; x < W; x += 44) { ctx.beginPath(); ctx.moveTo(x, 60); ctx.lineTo(x, floorY); ctx.stroke(); } for (var y = 60; y < floorY; y += 44) { ctx.beginPath(); ctx.moveTo(0, y); ctx.lineTo(W, y); ctx.stroke(); }
var fg = ctx.createLinearGradient(0, floorY, 0, H); fg.addColorStop(0, '#0E1B3B'); fg.addColorStop(1, '#060B18'); ctx.fillStyle = fg; ctx.fillRect(0, floorY, W, H - floorY);
var rail = ctx.createLinearGradient(0, floorY - 6, 0, floorY + 6); rail.addColorStop(0, 'rgba(34,211,238,0)'); rail.addColorStop(.5, 'rgba(143,240,255,.9)'); rail.addColorStop(1, 'rgba(34,211,238,0)'); ctx.fillStyle = rail; ctx.fillRect(0, floorY - 6, W, 12);
ctx.strokeStyle = 'rgba(34,211,238,.35)'; ctx.lineWidth = 2; ctx.setLineDash([26, 18]); ctx.lineDashOffset = -(dist * 1.6 % 44); ctx.beginPath(); ctx.moveTo(0, floorY + 26); ctx.lineTo(W, floorY + 26); ctx.stroke(); ctx.setLineDash([]);
ctx.fillStyle = 'rgba(255,106,26,.5)'; for (var fx = -(dist * 2.2 % 60); fx < W; fx += 60) ctx.fillRect(fx, floorY + 48, 22, 3);
if (!R) { ctx.restore(); return; }
for (i = 0; i < R.ents.length; i++) { var e = R.ents[i];
if (e.k === 'g') { var gg = ctx.createLinearGradient(e.x, 0, e.x + e.w, 0); gg.addColorStop(0, '#FF6A1A'); gg.addColorStop(.5, '#FFB088'); gg.addColorStop(1, '#D44E00'); ctx.fillStyle = gg; ctx.fillRect(e.x, 60, e.w, e.y - 60); ctx.fillRect(e.x, e.y + e.gap, e.w, floorY - e.y - e.gap); ctx.fillStyle = 'rgba(0,0,0,.35)'; for (var sy = 64 + (dist % 24); sy < e.y - 4; sy += 24) ctx.fillRect(e.x, sy, e.w, 8); for (sy = e.y + e.gap + 4 + (dist % 24); sy < floorY - 4; sy += 24) ctx.fillRect(e.x, sy, e.w, 8); ctx.fillStyle = '#FFE1CC'; ctx.shadowColor = '#FF6A1A'; ctx.shadowBlur = 18; ctx.fillRect(e.x - 3, e.y - 4, e.w + 6, 4); ctx.fillRect(e.x - 3, e.y + e.gap, e.w + 6, 4); ctx.shadowBlur = 0; }
else if (e.k === 'd') { var dy = e.y + Math.sin(e.ph) * 3, sc = 1 + Math.sin(e.ph * 1.3) * .08; ctx.drawImage(dripSpr, e.x - 18 * sc, dy - 18 * sc, 36 * sc, 36 * sc); }
else { ctx.save(); ctx.translate(e.x, e.cy || e.y); ctx.rotate(e.rot); if (R.slow > 0) ctx.globalAlpha = .75; ctx.drawImage(botSpr, -28, -28, 56, 56); ctx.restore(); } }
for (i = 0; i < R.parts.length; i++) { var p = R.parts[i]; ctx.globalAlpha = Math.max(0, Math.min(1, p.l * 2)); ctx.fillStyle = 'rgb(' + p.c + ')'; ctx.beginPath(); ctx.arc(p.x, p.y, p.r, 0, 6.283); ctx.fill(); } ctx.globalAlpha = 1;
ctx.save(); ctx.translate(player.x, player.y); ctx.rotate(player.tilt); if (R.inv > 0 && Math.floor(R.t * 12) % 2 === 0) ctx.globalAlpha = .45;
if (R.magnet) { ctx.strokeStyle = 'rgba(255,194,75,.35)'; ctx.lineWidth = 1.5; ctx.setLineDash([4, 6]); ctx.beginPath(); ctx.arc(0, 0, 150, 0, 6.283); ctx.stroke(); ctx.setLineDash([]); }
ctx.drawImage(R.ship === 2 ? shipB : shipA, -32, -32, 64, 64);
if (R.shield) { ctx.strokeStyle = 'rgba(255,106,26,.85)'; ctx.lineWidth = 2; ctx.shadowColor = '#FF6A1A'; ctx.shadowBlur = 14; ctx.beginPath(); ctx.arc(0, 0, 22, 0, 6.283); ctx.stroke(); ctx.shadowBlur = 0; }
ctx.restore();
if (R.slow > 0) { ctx.fillStyle = 'rgba(139,92,246,' + Math.min(.12, R.slow * .03) + ')'; ctx.fillRect(0, 0, W, H); }
ctx.restore();
}
var last = performance.now(); function loop(now) { var dt = Math.min(.033, (now - last) / 1000); last = now; update(dt); draw(); requestAnimationFrame(loop); }
/* ---------- boot ---------- */
resize(); requestAnimationFrame(loop);
loadMe().then(function () {
var q = new URLSearchParams(location.search);
if (q.get('resume')) { history.replaceState(null, '', '/play'); return tryResume(q); }
if (q.get('collected')) { history.replaceState(null, '', '/play'); setTimeout(function () { toast('Signed in. Your guest clears paid ' + q.get('collected') + ' drip' + (q.get('collected') === '1' ? '' : 's') + ' into your balance.'); }, 600); }
lobby();
}).catch(function (r) {
var b = $('loadBtn'); b.hidden = false; b.href = (r && (r.signin || r.iap)) || '/signin';
if (r && r.guestOk) { // came through a share or tester link: play first, sign in later
$('loadTitle').textContent = 'Ready to run'; $('loadText').textContent = 'Play a run right now, no sign-in. Sign in with InstantAdPay when you want to keep your progress, refuel, and collect POL.';
b.textContent = 'Sign in with InstantAdPay'; b.className = 'btn ghost'; var g = $('loadGuest'); g.hidden = false;
g.onclick = function () { g.disabled = true; api('/api/guest', {}).then(function (x) { if (x._status !== 200) { g.disabled = false; return toast(x.error || 'Could not start a guest run.'); } return loadMe().then(function () { lobby(); newRun(); }); }); };
return;
}
$('loadTitle').textContent = 'Sign in first'; $('loadText').textContent = (r && r.error) || 'Open Drip Runner from your InstantAdPay dashboard.'; b.textContent = 'Open through InstantAdPay';
});
})();