Skip to content
1        10        20        30        40        50        60        70        80        90        100       1101import * as THREE from 'three';2import { box, solidBox, addGeom, commitMesh, resetWorld, walkPads } from './city.js';3import { detailRng } from './detail.js';45// The wall: a long concrete barrier, twelve metres high, with a walkway along its top. The forest6// is on the outside (north, +z) and the compound on the inside (south, -z). The shack sits on the7// walkway, with a stove, a workbench, the pill and one slit to shoot through.8const H = 12; // top of the wall: the walkway and the shack floor9const LEN = 350; // the wall runs from -LEN to LEN along x10const HALF = 2.5; // half the thickness: five metres across the top11const INNER = HALF - 0.3; // the walkway's edge, just inside the parapets12const PARAPET = 1.0; // low enough to see over while standing on the walkway13const WALK = 80; // towers at x = ±WALK close the walkway off14const FIELD_END = 350; // the forest runs out to here, and the fog takes over1516const SHACK_H = 2.6;17const SHACK_T = 0.22; // thickness of the shack walls18const SHACK = { x0: -2.5, x1: 2.5, z0: -INNER, z1: 1.2 }; // outer footprint19const SHACK_IN = { x0: -2.28, x1: 2.28, z0: -1.98, z1: 0.98 }; // inside the walls: where the stove warms you20const SLIT = { half: 0.11, y0: 1.35, y1: 1.85 }; // the slit in the north wall, above the shack floor2122const WALL_SPAWN = { x: 0, z: -0.2, feet: H, yaw: Math.PI }; // in front of the slit, facing north23const WALL_WORKBENCH = { x: -1.6, z: -1.6 };24const WALL_PILL = { x: 1.7, z: -1.5 };25const STOVE_AT = { x: 1.6, z: 0.35 };2627const CONCRETE = 0x8e8a82;28const CONCRETE_DARK = 0x6c6963;29const DECK = 0x7a766e;30const STEEL = 0x5d646c;31const STEEL_DARK = 0x33373d;32const LAMP = 0xf2efe0;33const WIRE = 0x2a2d31;34const TOWER = 0x4f5a52;35const FOREST = 0x2c3d24;36const GRAVEL = 0x5f5b54;37const CONTAINER = [0x7a3b2a, 0x3b5566, 0x5c6b3a, 0x6b5a3a];38const TIMBER = 0x6a5238;39const ROOF = 0x2e2c2a;40const PLYWOOD = 0x9a7d55;41const BENCH = 0x6e4e2e;42const TOOLBOX = 0x8a2e26;43const PEGBOARD = 0x8c7b5e;44const PILL_RED = 0xc83a3a;45const PILL_WHITE = 0xf2f0ea;46const STOVE = 0x2a2a2d;47const FLUE = 0x4a4d52;48const FIRE = 0xffa040;49const TRUNK = 0x3e2c1b;50const LEAVES = [0x2e4f25, 0x3a5e2b, 0x27431f];5152const TREES = 900;53const STOVE_LIGHT = 1.6; // candela. Enough to warm the room without washing out the timber.5455// Builds the wall into `root`. Returns the merged mesh, the zombie bounds, the layout the game needs, and56// an update(dt) for the stove's flicker.57export function buildWall(root) {58  resetWorld();59  const rnd = detailRng(2024);60  buildGround();61  buildWallBody();62  const update = buildShack(root);63  buildForest(rnd);64  buildCompound(rnd);65  const mesh = commitMesh();66  root.add(mesh);67  return {68    mesh,69    bounds: { x0: -LEN, x1: LEN, z0: HALF + 3, z1: FIELD_END },70    layout: { spawn: WALL_SPAWN, workbench: WALL_WORKBENCH, pill: WALL_PILL, shack: SHACK_IN },71    update,72  };73}7475function buildGround() {76  box(-LEN - 60, -0.1, HALF, LEN + 60, 0, FIELD_END + 60, FOREST);77  box(-LEN - 60, -0.1, -FIELD_END - 60, LEN + 60, 0, -HALF, GRAVEL);78}7980function buildWallBody() {81  solidBox(-LEN, 0, -HALF, LEN, H, HALF, CONCRETE);82  // Parapets on both edges. The outer one has razor wire along its top.83  solidBox(-LEN, H, HALF - 0.3, LEN, H + PARAPET, HALF, CONCRETE_DARK);84  solidBox(-LEN, H, -HALF, LEN, H + PARAPET, -HALF + 0.3, CONCRETE_DARK);85  for (let x = -LEN; x < LEN; x += 3) {86    box(x, H + PARAPET, HALF - 0.12, x + 0.06, H + PARAPET + 0.45, HALF - 0.06, WIRE);87  }88  box(-LEN, H + PARAPET + 0.42, HALF - 0.14, LEN, H + PARAPET + 0.46, HALF - 0.1, WIRE);8990  // The walkway. Its walkable pad is the wall top itself, so you stand at the same height as the shack floor.91  walkPads.push({ x0: -WALK, x1: WALK, z0: -INNER, z1: INNER, h0: H, h1: H });92  box(-WALK, H, -INNER, WALK, H + 0.02, INNER, DECK);93  for (const x0 of [-WALK - 3, WALK]) {94    solidBox(x0, H, -HALF, x0 + 3, H + 4.2, HALF, TOWER);95    box(x0 - 0.2, H + 4.2, -HALF - 0.2, x0 + 3.2, H + 4.5, HALF + 0.2, CONCRETE_DARK);96  }9798  // Pilasters on the outer face, and floodlights on poles in front of the wall.99  for (let x = -LEN + 5; x < LEN; x += 10) box(x, 0, HALF, x + 0.6, H - 0.2, HALF + 0.35, CONCRETE_DARK);100  for (let x = -LEN + 25; x < LEN; x += 50) {101    solidBox(x, 0, HALF + 1.2, x + 0.3, H + 5, HALF + 1.5, STEEL_DARK);102    box(x - 0.2, H + 4.6, HALF + 1.2, x + 0.5, H + 5.1, HALF + 3.4, STEEL);103    box(x - 0.2, H + 4.2, HALF + 3.0, x + 0.5, H + 4.6, HALF + 3.4, LAMP);104  }105}106107// The shack on the walkway. Returns the function that flickers the stove light.108function buildShack(root) {109  const { x0, x1, z0, z1 } = SHACK;110  const top = H + SHACK_H;111  const T = SHACK_T;112  const I = SHACK_IN;113114  // South and east walls.115  solidBox(x0, H, z0, x1, top, z0 + T, TIMBER);116  solidBox(x1 - T, H, z0, x1, top, z1, TIMBER);117  // North wall (faces the forest): the slit is the only gap, a hand's width of open air at eye height.118  solidBox(x0, H, z1 - T, -SLIT.half, top, z1, TIMBER);119  solidBox(SLIT.half, H, z1 - T, x1, top, z1, TIMBER);120  solidBox(-SLIT.half, H, z1 - T, SLIT.half, H + SLIT.y0, z1, TIMBER);121  solidBox(-SLIT.half, H + SLIT.y1, z1 - T, SLIT.half, top, z1, TIMBER);122  // West wall, with the doorway onto the walkway (z from -1.2 to -0.1).123  solidBox(x0, H, z0, x0 + T, top, -1.2, TIMBER);124  solidBox(x0, H, -0.1, x0 + T, top, z1, TIMBER);125  solidBox(x0, H + 2.2, -1.2, x0 + T, top, -0.1, TIMBER);126  box(x0 - 0.15, top, z0 - 0.15, x1 + 0.15, top + 0.25, z1 + 0.15, ROOF);127  box(I.x0, H + 0.02, I.z0, I.x1, H + 0.03, I.z1, PLYWOOD);128129  // Workbench on the west side, with a pegboard on the wall above it and a toolbox on top.130  const wb = WALL_WORKBENCH;131  solidBox(wb.x - 0.6, H, wb.z - 0.3, wb.x + 0.6, H + 0.9, wb.z + 0.3, BENCH);132  box(wb.x - 0.65, H + 0.9, wb.z - 0.35, wb.x + 0.65, H + 0.96, wb.z + 0.35, PLYWOOD);133  box(I.x0, H + 1.2, -1.9, I.x0 + 0.03, H + 2.2, -1.3, PEGBOARD);134  box(wb.x + 0.2, H + 0.96, wb.z - 0.2, wb.x + 0.5, H + 1.1, wb.z + 0.2, TOOLBOX);135136  // Pill table on the east side. The pill sits on top, red and white.137  const pl = WALL_PILL;138  solidBox(pl.x - 0.5, H, pl.z - 0.4, pl.x + 0.5, H + 0.9, pl.z + 0.4, BENCH);139  box(pl.x - 0.55, H + 0.9, pl.z - 0.45, pl.x + 0.55, H + 0.95, pl.z + 0.45, PLYWOOD);140  box(pl.x - 0.05, H + 0.95, pl.z - 0.02, pl.x, H + 1.0, pl.z + 0.02, PILL_RED);141  box(pl.x, H + 0.95, pl.z - 0.02, pl.x + 0.05, H + 1.0, pl.z + 0.02, PILL_WHITE);142143  // Stove against the east wall, its flue going up through the roof.144  const st = STOVE_AT;145  solidBox(st.x - 0.3, H, st.z - 0.3, st.x + 0.3, H + 0.85, st.z + 0.3, STOVE);146  addGeom(new THREE.CylinderGeometry(0.07, 0.07, 2.4, 8).translate(st.x, H + 0.85 + 1.2, st.z), FLUE);147148  const light = new THREE.PointLight(FIRE, STOVE_LIGHT, 6, 2);149  light.position.set(st.x, H + 1.1, st.z);150  root.add(light);151  const glow = new THREE.Mesh(new THREE.BoxGeometry(0.4, 0.3, 0.02), new THREE.MeshBasicMaterial({ color: FIRE }));152  glow.position.set(st.x, H + 0.4, st.z - 0.3 - 0.01);153  root.add(glow);154155  let t = 0;156  return (dt) => {157    t += dt;158    light.intensity = STOVE_LIGHT * (1 + 0.08 * Math.sin(t * 9.1) + 0.05 * Math.sin(t * 23.7));159  };160}161162// Trees on the forest floor. Trunks are solid, so zombies walk round them and shots stop at them.163// Canopies are not, so a zombie behind a crown is hidden from you but still in the line of fire.164function buildForest(rnd) {165  for (let i = 0; i < TREES; i++) {166    const x = (rnd() * 2 - 1) * (LEN - 4);167    const z = HALF + 10 + rnd() * (FIELD_END - HALF - 14);168    const h = 3.4 + rnd() * 1.2;169    const r = 1.5 + rnd() * 1.1;170    solidBox(x - 0.2, 0, z - 0.2, x + 0.2, h, z + 0.2, TRUNK);171    addGeom(new THREE.SphereGeometry(r, 7, 5).translate(x, h + r * 0.5, z), LEAVES[i % LEAVES.length]);172  }173}174175// Shipping containers in rows on the inside, out of the zombies' reach.176function buildCompound(rnd) {177  for (const z of [-14, -25, -36]) {178    for (let x = -LEN + 10; x < LEN - 10; x += 9) {179      if (rnd() < 0.6) continue;180      solidBox(x, 0, z - 1.22, x + 6.1, 2.6, z + 1.22, CONTAINER[Math.floor(rnd() * CONTAINER.length)]);181    }182  }183}