| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
import { drawBlob, drawScene as drawWorld, makeScene, WALL } from "./engine/scene.js"; |
| 9 |
|
| 10 |
export { makeScene }; |
| 11 |
|
| 12 |
export const AGENT_COLOUR = { |
| 13 |
ember: "#f08a4b", |
| 14 |
veil: "#8f7fe8", |
| 15 |
sable: "#4fd6a0", |
| 16 |
mender: "#e0c060", |
| 17 |
rook: "#d96a8f", |
| 18 |
}; |
| 19 |
|
| 20 |
|
| 21 |
function fog(snap, out) { |
| 22 |
for (const zone of snap.zones) if ((zone.k === "smoke" || zone.k === "wall") && zone.f <= 0) out.push(zone); |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
function props(snap, out) { |
| 27 |
for (const zone of snap.zones) { |
| 28 |
if (zone.k === "smoke") continue; |
| 29 |
out.push({ kind: "zone", zone, x: zone.x, y: zone.y, draw: drawZone }); |
| 30 |
} |
| 31 |
for (const orb of snap.orbs) out.push({ kind: "orb", x: orb.x, y: orb.y, draw: drawOrb }); |
| 32 |
if (snap.spike.x !== null && !snap.spike.carried) |
| 33 |
out.push({ kind: "spike", x: snap.spike.x, y: snap.spike.y, planted: snap.spike.planted, draw: drawSpike }); |
| 34 |
} |
| 35 |
|
| 36 |
const trim = (p) => AGENT_COLOUR[p.agent] || "#999"; |
| 37 |
const badge = (p) => (p.spike ? "#f0d060" : null); |
| 38 |
|
| 39 |
export function drawScene(ctx, scene, world, eye, snap, view) { |
| 40 |
drawWorld(ctx, scene, world, eye, snap, { ...view, fog, props, trim, badge }); |
| 41 |
} |
| 42 |
|
| 43 |
function drawSpike(ctx, thing, floorY, proj, clip) { |
| 44 |
const h = thing.size * 0.42; |
| 45 |
const cx = thing.column; |
| 46 |
const planted = thing.planted; |
| 47 |
const blink = planted && Math.floor(Date.now() / 220) % 2 === 0; |
| 48 |
clip(thing, cx - h, cx + h, () => { |
| 49 |
ctx.fillStyle = planted ? (blink ? "#ff5b4a" : "#7d2a22") : "#c8b45c"; |
| 50 |
ctx.fillRect(cx - h * 0.28, floorY - h, h * 0.56, h); |
| 51 |
ctx.fillStyle = planted && blink ? "#ffd7a0" : "#2a2418"; |
| 52 |
ctx.fillRect(cx - h * 0.14, floorY - h * 0.85, h * 0.28, h * 0.22); |
| 53 |
}); |
| 54 |
} |
| 55 |
|
| 56 |
const drawOrb = (ctx, thing, floorY, proj, clip) => drawBlob(ctx, thing, floorY, "#c9a0ff", 0.35, clip); |
| 57 |
|
| 58 |
function drawZone(ctx, thing, floorY, proj, clip) { |
| 59 |
const z = thing.zone; |
| 60 |
const wide = (z.r * proj) / thing.perp; |
| 61 |
const cx = thing.column; |
| 62 |
if (z.k === "wall") { |
| 63 |
const h = (WALL * proj) / thing.perp; |
| 64 |
clip(thing, cx - wide, cx + wide, () => { |
| 65 |
ctx.fillStyle = "rgba(120,200,255,0.45)"; |
| 66 |
ctx.fillRect(cx - wide, floorY - h, wide * 2, h); |
| 67 |
ctx.strokeStyle = "rgba(180,225,255,0.8)"; |
| 68 |
ctx.strokeRect(cx - wide, floorY - h, wide * 2, h); |
| 69 |
}); |
| 70 |
return; |
| 71 |
} |
| 72 |
const colour = |
| 73 |
z.k === "molly" ? "rgba(235,120,50,0.6)" : z.k === "flash" ? "rgba(255,235,170,0.9)" : z.k === "heal" ? "rgba(120,230,140,0.55)" : z.k === "trip" ? "rgba(230,200,90,0.75)" : "rgba(90,220,170,0.5)"; |
| 74 |
clip(thing, cx - wide, cx + wide, () => { |
| 75 |
ctx.fillStyle = colour; |
| 76 |
ctx.beginPath(); |
| 77 |
ctx.ellipse(cx, floorY, wide, Math.max(2, wide * 0.3), 0, 0, 7); |
| 78 |
ctx.fill(); |
| 79 |
}); |
| 80 |
} |