diff --git a/src/features/moon.js b/src/features/moon.js new file mode 100644 index 0000000..abdb7eb --- /dev/null +++ b/src/features/moon.js @@ -0,0 +1,18 @@ +// Seed #1: the night sky. Stars twinkle slowly; the moon hangs top left. +import { PAL } from "../palette.js"; +let stars = []; +export default { + id: "moon", + order: 0, + layer: "sky", + init(w) { stars = Array.from({ length: 46 }, () => ({ x: Math.floor(w.rand() * 320), y: Math.floor(w.rand() * 110), p: w.rand() * 6 })); }, + draw(g, w) { + g.fillStyle = PAL.skyDeep; g.fillRect(0, 0, 320, 14); + for (let y = 14; y < 26; y += 2 + Math.floor((y - 14) / 4)) g.fillRect(0, y, 320, 1); + for (const s of stars) { g.fillStyle = (Math.sin(w.t * 1.3 + s.p) > 0.6 && !w.reduced) ? PAL.light : PAL.playerShade; g.fillRect(s.x, s.y, 1, 1); } + const cx = 34, cy = 34; + g.fillStyle = PAL.player; + for (let y = -9; y <= 9; y++) { const hw = Math.floor(Math.sqrt(81 - y * y)); g.fillRect(cx - hw, cy + y, hw * 2 + 1, 1); } + g.fillStyle = PAL.playerShade; g.fillRect(cx - 4, cy - 3, 3, 2); g.fillRect(cx + 2, cy + 3, 2, 2); g.fillRect(cx - 1, cy + 5, 2, 1); + }, +}; diff --git a/src/features/skyline.js b/src/features/skyline.js new file mode 100644 index 0000000..1679c92 --- /dev/null +++ b/src/features/skyline.js @@ -0,0 +1,21 @@ +// Seed #1: the far skyline. Two silhouette layers with a few lit windows. +import { PAL } from "../palette.js"; +let far = [], mid = []; +export default { + id: "skyline", + order: 1, + layer: "bg", + rooms: ["rooftop", "void"], + init(w) { + let x = 0; far = []; while (x < 320) { const bw = 10 + Math.floor(w.rand() * 18); far.push({ x, w: bw, h: 34 + Math.floor(w.rand() * 40) }); x += bw; } + x = -6; mid = []; while (x < 320) { const bw = 14 + Math.floor(w.rand() * 22); const h = 46 + Math.floor(w.rand() * 50); mid.push({ x, w: bw, h, lit: Array.from({ length: 12 }, () => w.rand() < 0.22) }); x += bw + 2; } + }, + draw(g) { + g.fillStyle = PAL.far; for (const b of far) g.fillRect(b.x, 150 - b.h, b.w, b.h + 30); + for (const b of mid) { + g.fillStyle = PAL.wall; g.fillRect(b.x, 160 - b.h, b.w, b.h + 20); + let i = 0; + for (let y = 166 - b.h; y < 150; y += 8) for (let x = b.x + 3; x < b.x + b.w - 3; x += 5) { if (b.lit[i++ % 12]) { g.fillStyle = PAL.light; g.fillRect(x, y, 2, 3); } } + } + }, +};