Skip to content
1        10        20        30        40        50        60        70        80        90        1001import { WARMTH } from './config.js';23// Body warmth for maps with `warmth` set. It drains outside the shack and comes back by the stove.4// At zero the run ends (main.js handles that).5export class Warmth {6  constructor() {7    this.reset();8  }910  reset() {11    this.value = WARMTH.max;12    this.armed = true;13  }1415  get dead() {16    return this.value <= 0;17  }1819  // Moves the warmth toward the stove, or away from it. Returns 'cold' on the frame it drops under the20  // warning line. It warns again only after the player has warmed back up.21  update(dt, inShack) {22    const rate = inShack ? WARMTH.gainPerSec : -WARMTH.lossPerSec;23    this.value = Math.max(0, Math.min(WARMTH.max, this.value + rate * dt));24    if (this.value >= WARMTH.warnAt + 20) this.armed = true;25    if (this.armed && this.value < WARMTH.warnAt) {26      this.armed = false;27      return 'cold';28    }29    return null;30  }31}3233// Whether a point is inside a box of the form {x0, x1, z0, z1}.34export function within(box, x, z) {35  return x > box.x0 && x < box.x1 && z > box.z0 && z < box.z1;36}