Co-op robustness, audio/a11y, new towers and enemies, Uplink rebalance
Co-op (QA'd with two to three real browsers, TCP-proxy chaos scenarios): - partner's tower changes are never dropped after a render stall or snapshot burst - half-open connections show "reconnecting" in ~6 s instead of 45-65 s - upgrade and next-wave are idempotent (stale commands refused), restart message, promoted host gets Play again, failed joins never kill a live game, listener leaks Audio / keyboard / a11y: - one Audio element per track, fade/stinger supersede tokens, play() retry on the next gesture, 5 s fallback to the synth, mute works everywhere, dialogs with role/aria-modal/focus handling, accessible names for sound/speed/pause New content: - enemies: Daemon (healer), Proxy (regenerating shield), Botnet (flyer swarm); waves weave them in from wave 9 (waves 1-8 unchanged) - towers: Sandbox (stun pulse), Load Balancer (fire-rate aura); hotkeys 1-9 - glyphs/shapes, stun/heal effects, gallery e2e that pixel-checks every kind Orbital Uplink rebalanced after playtesting (was affordable by wave ~6 and buyable in bulk from boss rewards): 1500 credits, upgrades 1200/2000/3200, and every Uplink already owned makes the next one 25% dearer to buy AND to upgrade (each tower remembers its multiplier, carried in the tower list as a 9th field). Shared TD.priceFor/upgradePrice so the UI shows exactly what the sim charges. Also: tablet/foldable viewports in the layout matrix (tolerant colour check), docs (README tower/enemy tables, PROTOCOL shield/stun/pm encodings, NEXT roadmap). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tb8pW2KAN4oFkh1aK1BfD8
This commit is contained in:
parent
962189419a
commit
28502984ec
29 changed files with 3370 additions and 230 deletions
|
|
@ -37,8 +37,8 @@
|
|||
}
|
||||
|
||||
// ------------------------------------------------------------------ tower glyphs (also used for UI icons)
|
||||
// S = tile size, (cx,cy) = centre, ang = barrel angle (radians), t = seconds (animation)
|
||||
function drawGlyph(ctx, type, level, cx, cy, S, ang, t, alpha, rot) {
|
||||
// S = tile size, (cx,cy) = centre, ang = barrel angle (radians), t = seconds (animation), fx = 0..1 flash right after a Sandbox pulse
|
||||
function drawGlyph(ctx, type, level, cx, cy, S, ang, t, alpha, rot, fx) {
|
||||
const def = TD.TOWERS[type]; if (!def) return;
|
||||
const col = def.color;
|
||||
ctx.save();
|
||||
|
|
@ -117,6 +117,43 @@
|
|||
}
|
||||
break;
|
||||
}
|
||||
case 'sandbox': {
|
||||
// containment cell: four corner brackets round a core that hums, held by thin tethers; it flashes when it pulses
|
||||
const g = fx || 0, p = 0.5 + 0.5 * Math.sin(t * 3), a = S * 0.22, k = S * 0.11;
|
||||
ctx.save(); ctx.translate(0, -S * 0.04);
|
||||
ctx.strokeStyle = rgba(col, 0.45); ctx.lineWidth = S * 0.03;
|
||||
ctx.beginPath();
|
||||
for (const [sx, sy] of [[-1, -1], [1, -1], [1, 1], [-1, 1]]) { ctx.moveTo(sx * S * 0.09, sy * S * 0.09); ctx.lineTo(sx * (a - k * 0.35), sy * (a - k * 0.35)); }
|
||||
ctx.stroke();
|
||||
ctx.strokeStyle = col; ctx.lineWidth = S * 0.06;
|
||||
ctx.beginPath();
|
||||
for (const [sx, sy] of [[-1, -1], [1, -1], [1, 1], [-1, 1]]) { ctx.moveTo(sx * a, sy * (a - k)); ctx.lineTo(sx * a, sy * a); ctx.lineTo(sx * (a - k), sy * a); }
|
||||
ctx.stroke();
|
||||
const c = S * (0.095 + 0.015 * p + 0.05 * g);
|
||||
ctx.beginPath(); ctx.moveTo(0, -c); ctx.lineTo(c, 0); ctx.lineTo(0, c); ctx.lineTo(-c, 0); ctx.closePath();
|
||||
ctx.fillStyle = g > 0 ? '#fff3dd' : rgba(col, 0.55 + 0.3 * p); ctx.fill();
|
||||
ctx.lineWidth = S * 0.035; ctx.stroke();
|
||||
ctx.restore();
|
||||
break;
|
||||
}
|
||||
case 'balancer': {
|
||||
// scales: post, a gently rocking beam and two hanging pans
|
||||
const dy = S * 0.27 * Math.sin(Math.sin(t * 1.4) * 0.07), ex = S * 0.27, top = -S * 0.21;
|
||||
ctx.save(); ctx.translate(0, -S * 0.02);
|
||||
ctx.lineWidth = S * 0.05; ctx.strokeStyle = col;
|
||||
ctx.beginPath(); ctx.moveTo(0, top); ctx.lineTo(0, S * 0.14); ctx.moveTo(-S * 0.12, S * 0.15); ctx.lineTo(S * 0.12, S * 0.15); ctx.stroke();
|
||||
ctx.beginPath(); ctx.moveTo(-ex, top - dy); ctx.lineTo(ex, top + dy); ctx.stroke();
|
||||
for (const sx of [-1, 1]) {
|
||||
const px = sx * ex, py = top + sx * dy, w = S * 0.1, d = S * 0.14;
|
||||
ctx.lineWidth = S * 0.03;
|
||||
ctx.beginPath(); ctx.moveTo(px - w, py + d); ctx.lineTo(px, py); ctx.lineTo(px + w, py + d); ctx.stroke();
|
||||
ctx.fillStyle = rgba(col, 0.55); ctx.beginPath(); ctx.arc(px, py + d, w, 0, Math.PI); ctx.closePath(); ctx.fill();
|
||||
ctx.lineWidth = S * 0.04; ctx.beginPath(); ctx.arc(px, py + d, w, 0, Math.PI); ctx.stroke();
|
||||
}
|
||||
ctx.fillStyle = col; ctx.beginPath(); ctx.arc(0, top, S * 0.05, 0, TAU); ctx.fill();
|
||||
ctx.restore();
|
||||
break;
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
// level pips: big enough to read at 14 px cells, with a dark halo so they show on any tile colour
|
||||
|
|
@ -129,8 +166,26 @@
|
|||
}
|
||||
|
||||
// ------------------------------------------------------------------ monsters
|
||||
function drawMonster(ctx, m, ang, t, flash, rot) {
|
||||
// Hit points and shield of one enemy, from either kind of view object. Solo hands the sim's monsters over (hp and shield apart:
|
||||
// m.shield / m.maxShield); co-op gets hp + shield out of maxhp + maxShield from the wire, and the split follows the kind's table
|
||||
// (the shield soaks first, so what is above the hit point part of the total is shield). Result is a shared scratch object.
|
||||
const VIT = { hp: 0, mh: 1, sh: 0, ms: 0 };
|
||||
function vitals(m, def) {
|
||||
if (!def.shield) { VIT.hp = m.hp; VIT.mh = m.maxhp; VIT.sh = 0; VIT.ms = 0; }
|
||||
else if (m.maxShield !== undefined) { VIT.hp = m.hp; VIT.mh = m.maxhp; VIT.sh = m.shield; VIT.ms = m.maxShield; }
|
||||
else {
|
||||
const mh = m.maxhp * def.hp / (def.hp + def.shield);
|
||||
VIT.mh = mh; VIT.ms = m.maxhp - mh; VIT.hp = Math.min(m.hp, mh); VIT.sh = Math.max(0, m.hp - mh);
|
||||
}
|
||||
return VIT;
|
||||
}
|
||||
const SWARM = { botnet: 1 }; // swarm units die in a hit or two: no bar, no ground shadow, few particles (there can be 100+)
|
||||
|
||||
// stun: true while the enemy is frozen by a Sandbox (the caller knows: the sim's stunT in solo, "slow flag and not moving" in co-op)
|
||||
function drawMonster(ctx, m, ang, t, flash, rot, stun) {
|
||||
const def = TD.ENEMIES[m.kind], r = def.r * C, col = def.color;
|
||||
const v = vitals(m, def), sf = v.ms > 0 ? clamp(v.sh / v.ms, 0, 1) : 0;
|
||||
const lift = m.kind === 'ghost' ? -7 : 0;
|
||||
ctx.save();
|
||||
ctx.translate(m.x * C, m.y * C);
|
||||
if (rot) { ctx.rotate(-rot); ang += rot; }
|
||||
|
|
@ -187,20 +242,72 @@
|
|||
ctx.fillStyle = rgba('#ff3b3b', 0.55 + Math.sin(t * 4) * 0.3); ctx.beginPath(); ctx.arc(0, 0, r * 0.45, 0, TAU); ctx.fill();
|
||||
break;
|
||||
}
|
||||
case 'daemon': {
|
||||
// healer: an upright plus (a medic cross), its core breathing in time with the heal pulse
|
||||
const a = r * 1.3, w = r * 0.38, br = 0.5 + 0.5 * Math.sin(t * 5 + m.id);
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(-w, -a); ctx.lineTo(w, -a); ctx.lineTo(w, -w); ctx.lineTo(a, -w); ctx.lineTo(a, w); ctx.lineTo(w, w);
|
||||
ctx.lineTo(w, a); ctx.lineTo(-w, a); ctx.lineTo(-w, w); ctx.lineTo(-a, w); ctx.lineTo(-a, -w); ctx.lineTo(-w, -w); ctx.closePath();
|
||||
ctx.fillStyle = '#0d2b17'; ctx.fill(); ctx.lineWidth = 2.8; ctx.strokeStyle = col; ctx.stroke();
|
||||
ctx.fillStyle = rgba('#d6ffe0', 0.5 + 0.4 * br);
|
||||
ctx.fillRect(-w * 0.45, -a * 0.62, w * 0.9, a * 1.24); ctx.fillRect(-a * 0.62, -w * 0.45, a * 1.24, w * 0.9);
|
||||
break;
|
||||
}
|
||||
case 'proxy': {
|
||||
// shielded relay: a heater-shield badge (never a hexagon: the Trojan is one) inside a bubble that thins as the shield goes
|
||||
if (sf > 0.01) {
|
||||
ctx.fillStyle = rgba('#7ab8ff', 0.07 + 0.2 * sf); ctx.beginPath(); ctx.arc(0, 0, r * 1.55, 0, TAU); ctx.fill();
|
||||
ctx.lineWidth = 0.9 + 2.3 * sf; ctx.strokeStyle = rgba('#b9dcff', 0.3 + 0.65 * sf); ctx.stroke();
|
||||
}
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(-r * 0.92, -r * 0.8); ctx.lineTo(r * 0.92, -r * 0.8); ctx.lineTo(r * 0.92, r * 0.12); ctx.lineTo(0, r * 1.05); ctx.lineTo(-r * 0.92, r * 0.12); ctx.closePath();
|
||||
ctx.fillStyle = '#0d1a3a'; ctx.fill(); ctx.lineWidth = 2.8; ctx.strokeStyle = col; ctx.stroke();
|
||||
ctx.fillStyle = rgba(col, 0.9); ctx.beginPath(); ctx.arc(0, -r * 0.12, r * 0.3, 0, TAU); ctx.fill();
|
||||
ctx.lineWidth = 2; ctx.beginPath(); ctx.moveTo(0, r * 0.2); ctx.lineTo(0, r * 0.72); ctx.stroke();
|
||||
break;
|
||||
}
|
||||
case 'botnet': {
|
||||
// a drone of a swarm: spinning X of two struts with a rotor at each tip, wobbling about its path
|
||||
const a = Math.max(r * 1.7, 8), wb = 2.5;
|
||||
ctx.translate(Math.sin(t * 6 + m.id * 1.9) * wb, Math.cos(t * 5 + m.id * 2.3) * wb);
|
||||
ctx.rotate(t * 7 + m.id);
|
||||
ctx.lineWidth = 3; ctx.strokeStyle = col;
|
||||
ctx.beginPath(); ctx.moveTo(-a, -a); ctx.lineTo(a, a); ctx.moveTo(a, -a); ctx.lineTo(-a, a); ctx.stroke();
|
||||
ctx.fillStyle = '#a6f2ea';
|
||||
ctx.beginPath();
|
||||
for (const [sx, sy] of [[-1, -1], [1, -1], [1, 1], [-1, 1]]) { ctx.moveTo(sx * a + 2.6, sy * a); ctx.arc(sx * a, sy * a, 2.6, 0, TAU); }
|
||||
ctx.fill();
|
||||
ctx.fillStyle = '#e8fffd'; ctx.beginPath(); ctx.arc(0, 0, r * 0.6, 0, TAU); ctx.fill();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
ctx.fillStyle = col; ctx.beginPath(); ctx.arc(0, 0, r, 0, TAU); ctx.fill();
|
||||
}
|
||||
if (flash > 0) { ctx.globalAlpha = Math.min(0.85, flash * 9); ctx.fillStyle = '#fff'; ctx.beginPath(); ctx.arc(0, m.kind === 'ghost' ? -7 : 0, r * 1.05, 0, TAU); ctx.fill(); ctx.globalAlpha = 1; }
|
||||
if (m.slow > 0) { ctx.lineWidth = 1.6; ctx.strokeStyle = 'rgba(77,227,255,.85)'; ctx.beginPath(); ctx.arc(0, m.kind === 'ghost' ? -7 : 0, r + 3.5, 0, TAU); ctx.stroke(); }
|
||||
if (flash > 0) { ctx.globalAlpha = Math.min(0.85, flash * 9); ctx.fillStyle = '#fff'; ctx.beginPath(); ctx.arc(0, lift, r * 1.05, 0, TAU); ctx.fill(); ctx.globalAlpha = 1; }
|
||||
if (stun) {
|
||||
// frozen by a Sandbox: an ice shell with crackling crystal spikes (the cyan ring below is only a slow)
|
||||
const swarm = SWARM[m.kind], s = swarm ? 7 : Math.max(r * 1.3, 7) + 2;
|
||||
ctx.fillStyle = 'rgba(200,240,255,.24)'; ctx.beginPath(); ctx.arc(0, lift, s, 0, TAU); ctx.fill();
|
||||
ctx.lineWidth = swarm ? 1.4 : 2; ctx.strokeStyle = '#eefbff'; ctx.stroke();
|
||||
if (!swarm) {
|
||||
ctx.lineWidth = 2.2; ctx.beginPath();
|
||||
for (let i = 0; i < 6; i++) {
|
||||
const a = i * TAU / 6 + 0.5, len = s + (Math.sin(t * 31 + i * 2.1 + m.id) > 0 ? 6 : 3.5);
|
||||
ctx.moveTo(Math.cos(a) * s, lift + Math.sin(a) * s); ctx.lineTo(Math.cos(a) * len, lift + Math.sin(a) * len);
|
||||
}
|
||||
ctx.stroke();
|
||||
}
|
||||
} else if (m.slow > 0) { ctx.lineWidth = 1.6; ctx.strokeStyle = 'rgba(77,227,255,.85)'; ctx.beginPath(); ctx.arc(0, lift, r + 3.5, 0, TAU); ctx.stroke(); }
|
||||
ctx.restore();
|
||||
// health bar
|
||||
if (m.hp < m.maxhp) {
|
||||
const w = Math.max(15, r * 2.3), y = -r - (m.kind === 'ghost' ? 16 : 9), x = -w / 2;
|
||||
const f = clamp(m.hp / m.maxhp, 0, 1);
|
||||
// health bar (a blue shield strip above it for shielded kinds)
|
||||
if (!SWARM[m.kind] && (v.hp < v.mh || v.sh < v.ms)) {
|
||||
const w = Math.max(15, r * 2.3), y = -r * (sf > 0.01 ? 1.55 : 1) - (m.kind === 'ghost' ? 16 : 9), x = -w / 2;
|
||||
const f = clamp(v.hp / v.mh, 0, 1);
|
||||
ctx.save(); ctx.translate(m.x * C, m.y * C); if (rot) ctx.rotate(-rot);
|
||||
ctx.fillStyle = 'rgba(0,0,0,.65)'; ctx.fillRect(x - 1, y - 1, w + 2, 5);
|
||||
ctx.fillStyle = 'rgba(0,0,0,.65)'; ctx.fillRect(x - 1, y - 1, w + 2, v.ms > 0 ? 8 : 5);
|
||||
ctx.fillStyle = f > 0.5 ? '#35e0a1' : f > 0.25 ? '#ffd24d' : '#ff5c7a';
|
||||
ctx.fillRect(x, y, w * f, 3);
|
||||
ctx.fillRect(x, y + (v.ms > 0 ? 3 : 0), w * f, 3);
|
||||
if (v.ms > 0) { ctx.fillStyle = '#6fb4ff'; ctx.fillRect(x, y, w * sf, 2); }
|
||||
ctx.restore();
|
||||
}
|
||||
}
|
||||
|
|
@ -214,6 +321,8 @@
|
|||
this.cam = { zoom: 1, px: 0, py: 0 };
|
||||
this.board = null;
|
||||
this.parts = []; this.rings = []; this.lines = []; this.texts = []; this.marks = [];
|
||||
this.pulses = []; // heal / stun pulses: their own small pool, so a swarm of daemons can never starve the leak and boom rings
|
||||
this.glow = new Map(); // Sandbox cell index -> seconds of flash left after its pulse
|
||||
this.aim = new Map(); this.trk = new Map();
|
||||
this.wallGrid = null;
|
||||
this.shake = 0; this.flashCore = 0; this.lastNow = 0;
|
||||
|
|
@ -225,8 +334,8 @@
|
|||
setBoard(board) {
|
||||
this.board = board;
|
||||
this.wallGrid = new Uint8Array(board.cols * board.rows);
|
||||
this.parts.length = 0; this.rings.length = 0; this.lines.length = 0; this.texts.length = 0; this.marks.length = 0;
|
||||
this.aim.clear(); this.trk.clear();
|
||||
this.parts.length = 0; this.rings.length = 0; this.lines.length = 0; this.texts.length = 0; this.marks.length = 0; this.pulses.length = 0;
|
||||
this.aim.clear(); this.trk.clear(); this.glow.clear();
|
||||
this.resetCamera();
|
||||
}
|
||||
resize(w, h, dpr) {
|
||||
|
|
@ -296,6 +405,7 @@
|
|||
}
|
||||
}
|
||||
_ring(x, y, r0, r1, col, life, w) { if (this.rings.length < 40) this.rings.push({ x, y, r0, r1, col, life, max: life, w: w || 2 }); }
|
||||
_pulse(x, y, r0, r1, col, life, w, fill) { if (this.pulses.length < 24) this.pulses.push({ x, y, r0, r1, col, life, max: life, w, fill }); }
|
||||
_text(x, y, txt, col) { if (this.texts.length < 24) this.texts.push({ x, y, txt, col, life: 0.9, max: 0.9 }); }
|
||||
addMark(x, y, slot) { this.marks.push({ x, y, slot: slot | 0, life: 1.6, max: 1.6 }); if (this.marks.length > 12) this.marks.shift(); }
|
||||
addEvents(evs) {
|
||||
|
|
@ -303,7 +413,7 @@
|
|||
switch (e.e) {
|
||||
case 'kill': {
|
||||
const d = TD.ENEMIES[e.k];
|
||||
this._burst(e.x * C, e.y * C, d ? d.color : '#fff', e.k === 'rootkit' ? 26 : 6, 90, 0.5);
|
||||
this._burst(e.x * C, e.y * C, d ? d.color : '#fff', e.k === 'rootkit' ? 26 : SWARM[e.k] ? 2 : 6, 90, 0.5);
|
||||
if (e.rw >= 3) this._text(e.x * C, e.y * C - 8, '+' + e.rw, '#ffd24d');
|
||||
break;
|
||||
}
|
||||
|
|
@ -334,6 +444,15 @@
|
|||
case 'place': { const d = TD.TOWERS[e.type]; this._ring((e.x + 0.5) * C, (e.y + 0.5) * C, 6, 34, d ? d.color : '#fff', 0.35, 2.5); this._burst((e.x + 0.5) * C, (e.y + 0.5) * C, d ? d.color : '#fff', 5, 60, 0.35); break; }
|
||||
case 'sell': this._burst((e.x + 0.5) * C, (e.y + 0.5) * C, '#9db4d8', 6, 70, 0.35); break;
|
||||
case 'up': this._ring((e.x + 0.5) * C, (e.y + 0.5) * C, 6, 38, '#ffffff', 0.4, 2.5); break;
|
||||
case 'stun': { // Sandbox pulse: an amber wave out to its range, a white one inside it, and the glyph flashes
|
||||
const d = TD.TOWERS.sandbox, col = d ? d.color : '#ffa447', b = this.board;
|
||||
const rg = (e.r || 3) * C;
|
||||
this._pulse(e.x * C, e.y * C, 10, rg, col, 0.55, 3.5, 0.13);
|
||||
this._pulse(e.x * C, e.y * C, 8, rg * 0.6, '#fff3dd', 0.35, 2, 0);
|
||||
if (b) this.glow.set(Math.floor(e.y) * b.cols + Math.floor(e.x), 0.4);
|
||||
break;
|
||||
}
|
||||
case 'heal': this._pulse(e.x * C, e.y * C, 10, (e.r || 2.2) * C, '#7ee08a', 0.7, 2.2, 0.07); break; // soft green wave out to the daemon's range
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
|
@ -413,6 +532,9 @@
|
|||
const monById = new Map();
|
||||
for (let i = 0; i < view.monsters.length; i++) monById.set(view.monsters[i].id, view.monsters[i]);
|
||||
|
||||
if (this.glow.size) for (const [k, g] of this.glow) { if (g - dt <= 0) this.glow.delete(k); else this.glow.set(k, g - dt); }
|
||||
this._drawLinks(ctx, towers, ui, t);
|
||||
|
||||
const coop = ui.coop;
|
||||
for (let i = 0; i < towers.length; i++) {
|
||||
const tw = towers[i];
|
||||
|
|
@ -421,7 +543,8 @@
|
|||
const tg = tw.tgt ? monById.get(tw.tgt) : null;
|
||||
if (tg) { ang = lerpAngle(ang, Math.atan2(tg.y - (tw.y + 0.5), tg.x - (tw.x + 0.5)), 0.35); this.aim.set(tw.id, ang); }
|
||||
const cx = (tw.x + 0.5) * C, cy = (tw.y + 0.5) * C;
|
||||
drawGlyph(ctx, tw.type, tw.level, cx, cy, C, ang, t, 1, rot);
|
||||
const gl = tw.type === 'sandbox' && this.glow.size ? this.glow.get(tw.y * cols + tw.x) : 0;
|
||||
drawGlyph(ctx, tw.type, tw.level, cx, cy, C, ang, t, 1, rot, gl ? Math.min(1, gl / 0.25) : 0);
|
||||
if (coop && tw.type !== 'wall') { // owner corner flag: at least ~5 CSS px, dark outline so it shows on a tile of the same colour
|
||||
const k = Math.max(12, 5.5 / sc), x0 = cx - C * 0.46, y0 = cy - C * 0.46;
|
||||
ctx.beginPath(); ctx.moveTo(x0, y0); ctx.lineTo(x0 + k, y0); ctx.lineTo(x0, y0 + k); ctx.closePath();
|
||||
|
|
@ -502,6 +625,47 @@
|
|||
if (labels.length) this._cursorLabels(ctx, labels);
|
||||
}
|
||||
|
||||
// Load Balancer links: dashed lines (flowing towards the turret) and an outline on every attack tower it boosts, only for the balancer that is
|
||||
// selected, hovered or about to be built, so a busy board stays calm. Same rule as the sim's updateAuras: attack role, centre to centre
|
||||
// within range. (The wire has no per-tower buff flag, so this is worked out here from the tower list.)
|
||||
_drawLinks(ctx, towers, ui, t) {
|
||||
let src = null;
|
||||
if (ui.selTower) { const st = towers.find((x) => x.id === ui.selTower); if (st) src = st; }
|
||||
if (!src && ui.hover) {
|
||||
for (let i = 0; i < towers.length; i++) if (towers[i].x === ui.hover.x && towers[i].y === ui.hover.y) { src = towers[i]; break; }
|
||||
if (!src && ui.selType && !ui.noGhost) src = { type: ui.selType, level: 1, x: ui.hover.x, y: ui.hover.y };
|
||||
}
|
||||
const def = src && TD.TOWERS[src.type];
|
||||
if (!def || def.role !== 'support') return;
|
||||
const lv = def.levels[src.level - 1] || def.levels[0], r2 = (lv.range || 0) * (lv.range || 0);
|
||||
const bx = (src.x + 0.5) * C, by = (src.y + 0.5) * C;
|
||||
let lines = null;
|
||||
for (let i = 0; i < towers.length; i++) {
|
||||
const tw = towers[i], d = TD.TOWERS[tw.type];
|
||||
if (!d || d.role !== 'attack' || tw === src) continue;
|
||||
const dx = tw.x - src.x, dy = tw.y - src.y;
|
||||
if (dx * dx + dy * dy > r2) continue;
|
||||
(lines || (lines = [])).push(tw);
|
||||
}
|
||||
if (!lines) return;
|
||||
const u = Math.max(1, 0.55 / this.scale), lw = Math.max(2, 1.2 / this.scale); // keep the dashes and arrowheads readable when the cells are small
|
||||
ctx.save();
|
||||
ctx.lineCap = 'round'; ctx.lineJoin = 'round';
|
||||
ctx.strokeStyle = rgba(def.color, 0.75); ctx.lineWidth = lw; ctx.setLineDash([6 * u, 5 * u]); ctx.lineDashOffset = -t * 16;
|
||||
ctx.beginPath();
|
||||
for (const tw of lines) { ctx.moveTo(bx, by); ctx.lineTo((tw.x + 0.5) * C, (tw.y + 0.5) * C); }
|
||||
ctx.stroke();
|
||||
ctx.setLineDash([]);
|
||||
ctx.fillStyle = rgba(def.color, 0.95); ctx.lineWidth = lw;
|
||||
for (const tw of lines) { // an arrowhead just outside the tile, and a frame round it
|
||||
const tx = (tw.x + 0.5) * C, ty = (tw.y + 0.5) * C, a = Math.atan2(ty - by, tx - bx), d = C * 0.62 + 4 * u;
|
||||
const ax = tx - Math.cos(a) * d, ay = ty - Math.sin(a) * d, ca = Math.cos(a), sa = Math.sin(a);
|
||||
ctx.beginPath(); ctx.moveTo(ax + ca * 6 * u, ay + sa * 6 * u); ctx.lineTo(ax - ca * 3 * u - sa * 5 * u, ay - sa * 3 * u + ca * 5 * u); ctx.lineTo(ax - ca * 3 * u + sa * 5 * u, ay - sa * 3 * u - ca * 5 * u); ctx.closePath(); ctx.fill();
|
||||
rr(ctx, tw.x * C + 1.5, tw.y * C + 1.5, C - 3, C - 3, 6); ctx.stroke();
|
||||
}
|
||||
ctx.restore();
|
||||
}
|
||||
|
||||
_rangeRing(ctx, cx, cy, r, col) {
|
||||
ctx.fillStyle = rgba(col, 0.07); ctx.beginPath(); ctx.arc(cx, cy, r, 0, TAU); ctx.fill();
|
||||
ctx.strokeStyle = rgba(col, 0.55); ctx.lineWidth = 1.5; ctx.stroke();
|
||||
|
|
@ -559,17 +723,33 @@
|
|||
|
||||
_drawMonsters(ctx, view, t, dt, air, rot) {
|
||||
const trk = this.trk;
|
||||
if (!air) { // a Daemon's heal range, faint, all in one stroke
|
||||
let any = false;
|
||||
for (const m of view.monsters) {
|
||||
const d = TD.ENEMIES[m.kind];
|
||||
if (!d.healRange) continue;
|
||||
if (!any) { any = true; ctx.beginPath(); }
|
||||
ctx.moveTo(m.x * C + d.healRange * C, m.y * C); ctx.arc(m.x * C, m.y * C, d.healRange * C, 0, TAU);
|
||||
}
|
||||
if (any) { ctx.strokeStyle = rgba(TD.ENEMIES.daemon.color, 0.15); ctx.lineWidth = 1.5; ctx.stroke(); }
|
||||
}
|
||||
for (const m of view.monsters) {
|
||||
if (!!m.air !== air) continue;
|
||||
const def = TD.ENEMIES[m.kind];
|
||||
let k = trk.get(m.id);
|
||||
if (!k) { k = { x: m.x, y: m.y, ang: 0, hp: m.hp, flash: 0 }; trk.set(m.id, k); }
|
||||
if (!k) { k = { x: m.x, y: m.y, ang: 0, hp: m.hp, flash: 0, still: 0, sv: null }; trk.set(m.id, k); }
|
||||
const dm = def.shield && m.maxShield === undefined ? this._shieldView(k, m, def, dt) : m; // co-op: tell hp and shield apart (see there)
|
||||
const v = vitals(dm, def), cur = v.hp + v.sh;
|
||||
const dx = m.x - k.x, dy = m.y - k.y;
|
||||
if (dx * dx + dy * dy > 1e-6) k.ang = lerpAngle(k.ang, Math.atan2(dy, dx), 0.35);
|
||||
k.still = dx * dx + dy * dy < 1e-8 ? k.still + dt : 0;
|
||||
k.x = m.x; k.y = m.y;
|
||||
if (m.hp < k.hp) k.flash = 0.1;
|
||||
k.hp = m.hp; k.flash = Math.max(0, k.flash - dt);
|
||||
if (air) { const er = TD.ENEMIES[m.kind].r * C; ctx.fillStyle = 'rgba(0,0,0,.28)'; ctx.save(); ctx.translate(m.x * C, m.y * C); if (rot) ctx.rotate(-rot); ctx.beginPath(); ctx.ellipse(0, 5, er, er * 0.45, 0, 0, TAU); ctx.fill(); ctx.restore(); }
|
||||
drawMonster(ctx, m, k.ang, t, k.flash, rot);
|
||||
if (cur < k.hp) k.flash = 0.1;
|
||||
k.hp = cur; k.flash = Math.max(0, k.flash - dt);
|
||||
// stunned: solo knows (stunT); in co-op the wire only says "slowed or stunned", and a slowed packet still moves, so a flagged packet that stands still is stunned
|
||||
const stun = m.stunT !== undefined ? m.stunT > 0 : m.slow > 0 && k.still > 0.2 && !view.paused;
|
||||
if (air && !SWARM[m.kind]) { const er = def.r * C; ctx.fillStyle = 'rgba(0,0,0,.28)'; ctx.save(); ctx.translate(m.x * C, m.y * C); if (rot) ctx.rotate(-rot); ctx.beginPath(); ctx.ellipse(0, 5, er, er * 0.45, 0, 0, TAU); ctx.fill(); ctx.restore(); }
|
||||
drawMonster(ctx, dm, k.ang, t, k.flash, rot, stun);
|
||||
}
|
||||
if (air && trk.size > view.monsters.length + 60) { // drop stale trackers
|
||||
const live = new Set(view.monsters.map((x) => x.id));
|
||||
|
|
@ -577,6 +757,27 @@
|
|||
}
|
||||
}
|
||||
|
||||
// Co-op sends a shielded enemy as hp + shield out of maxhp + maxShield. A shield soaks first, so most of the time the split is plain from the
|
||||
// total, but once the hp is hurt and the shield has regrown the total alone is ambiguous (hp 20 + shield 120 looks like hp 90 + shield 50).
|
||||
// So the split is followed over time: a drop in the total hits the shield first, a rise after shieldDelay seconds without a hit refills the
|
||||
// shield, any other rise is a heal. Returns a solo-style view object (hp and shield apart) kept in the tracker entry.
|
||||
_shieldView(k, m, def, dt) {
|
||||
const mh = m.maxhp * def.hp / (def.hp + def.shield), ms = m.maxhp - mh;
|
||||
let s = k.sv;
|
||||
if (!s) s = k.sv = { id: m.id, kind: m.kind, air: m.air, x: 0, y: 0, hp: 0, maxhp: mh, shield: clamp(m.hp - mh, 0, ms), maxShield: ms, slow: 0, tot: m.hp, idle: 0 };
|
||||
else {
|
||||
const d = m.hp - s.tot;
|
||||
if (d < -0.5) { s.shield -= Math.min(s.shield, -d); s.idle = 0; }
|
||||
else if (d > 0.5 && s.idle >= def.shieldDelay - 0.25 && s.shield < ms) s.shield = Math.min(ms, s.shield + d);
|
||||
s.tot = m.hp; s.idle += dt;
|
||||
}
|
||||
s.maxhp = mh; s.maxShield = ms;
|
||||
if (m.hp - s.shield > mh) s.shield = clamp(m.hp - mh, 0, ms); // more than the hp part can hold: the rest is shield
|
||||
s.hp = clamp(m.hp - s.shield, 0, mh);
|
||||
s.x = m.x; s.y = m.y; s.slow = m.slow; s.air = m.air;
|
||||
return s;
|
||||
}
|
||||
|
||||
_drawFx(ctx, dt, sc, rot) {
|
||||
// lines (tracers, arcs)
|
||||
ctx.lineCap = 'round'; ctx.lineJoin = 'round';
|
||||
|
|
@ -600,6 +801,15 @@
|
|||
ctx.beginPath(); ctx.arc(r.x, r.y, r.r0 + (r.r1 - r.r0) * k, 0, TAU); ctx.stroke();
|
||||
}
|
||||
ctx.globalAlpha = 1;
|
||||
for (let i = this.pulses.length - 1; i >= 0; i--) {
|
||||
const r = this.pulses[i]; r.life -= dt;
|
||||
if (r.life <= 0) { this.pulses.splice(i, 1); continue; }
|
||||
const k = 1 - r.life / r.max;
|
||||
ctx.beginPath(); ctx.arc(r.x, r.y, r.r0 + (r.r1 - r.r0) * k, 0, TAU);
|
||||
if (r.fill) { ctx.globalAlpha = (1 - k) * r.fill; ctx.fillStyle = r.col; ctx.fill(); }
|
||||
ctx.globalAlpha = 1 - k; ctx.strokeStyle = r.col; ctx.lineWidth = r.w; ctx.stroke();
|
||||
}
|
||||
ctx.globalAlpha = 1;
|
||||
for (let i = this.parts.length - 1; i >= 0; i--) {
|
||||
const p = this.parts[i]; p.life -= dt;
|
||||
if (p.life <= 0) { this.parts.splice(i, 1); continue; }
|
||||
|
|
@ -651,6 +861,7 @@
|
|||
NW.Renderer = Renderer;
|
||||
NW.drawIcon = drawIcon;
|
||||
NW.drawGlyph = drawGlyph;
|
||||
NW.drawMonster = drawMonster;
|
||||
NW.SLOT_COLORS = SLOT_COLORS;
|
||||
NW.CELL = C;
|
||||
NW.BOARD_MARGIN = MARGIN;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue