Files
MeatSlicer/js/state.js
T
MeatSlicer Developer d9eae34df4 Normalize ammo economy: per-weapon refill, stream drain, behavior fixes
- Every special weapon gets an explicit 'refill' (units per ammo pickup,
  tuned so one pickup funds ~10 kills) replacing the ammoRefillFraction
  log2 heuristic and ammoWeight overrides
- Bile Blunderbuss + The Cauterizer join Red Right Hand as time-denominated
  stream weapons ('drain' per second) instead of per-shot cost
- Sawblades ricochet through enemies (bounce fix), traps catch 3 victims,
  lobbed projectiles arc overhead and always trigger at the target point
  (Flesh Masher / Trap Queen / Swarm Jar payloads now actually deploy)
- Boss rooms stock one ammo on entry and drop one guaranteed on death
- Cauterizer burn trimmed (2.2s x2 -> 1.5s x0.8), bile acid pools trimmed
  (3.5s x1.5 -> 2.5s x0.8), Marrow Draught now covers stream drain
- New tools/ammo_sim.js calibrates every weapon into the 8-13 kills/refill
  band (all 15 pass); smoke test guards the ammo structure
- v0.3.0, cache bump v=44
2026-07-30 22:06:10 +10:00

84 lines
3.0 KiB
JavaScript

// ---- global game state ----
const W = 960, H = 640, TILE = 64, WALL = 48, DOOR_HALF = 44;
const G = {
mode: 'menu', // menu | play | levelup | pause | gameover
time: 0,
floor: 1,
score: 0,
kills: 0,
player: null,
rooms: {}, // "x,y" -> room
cur: null, // current room
enemies: [],
bullets: [], // player projectiles
ebullets: [], // enemy projectiles
pickups: [],
parts: [], // particles
corpses: [], // short-lived frame-animated deaths
hazards: [], // acid/fire pools, traps (hurt enemies)
telegraphs: [], // boss telegraphs -> effects (hurt player)
toasts: [],
shake: 0,
flash: 0, // red screen flash when hurt
boss: null, // live boss ref
pendingLevelups: 0,
perkChoices: null,
autoPerk: false,
pressure: 1,
pressureDial: 0,
streak: 0,
roomDamaged: false,
roomEnterT: 0,
recentHits: [],
transition: 0, // room transition fade
muted: false,
pauseHelp: false,
helpPage: 0,
sfxVol: 0.45,
musicVol: 0.55,
hudAlpha: 1,
imagesLoaded: false,
roomLayer: null,
roomLayerKey: '',
atmosphereLayer: null,
};
const PERK_POWER_WEIGHT = 0.5;
// ammo economy: global dial for drop frequency (refill size is per-weapon)
const AMMO_DROP_SCALE = 0.75;
const PRESSURE_MIN = 0.75, PRESSURE_MAX = 1.60;
const PRESSURE_UNIT = 0.01; // one "point" on the dial scale
const PRESSURE_GAIN = PRESSURE_UNIT; // retained: dial 0 == 1 point
const PRESSURE_DROP_BASE = 3; // dial 0 == 0.03 relief base
const PRESSURE_DIAL_MIN = -5, PRESSURE_DIAL_MAX = 5;
// -5 -> 0 units, 0 -> 1 unit, +5 -> 5 units (piecewise linear)
function pressureGainUnits(dial) { const d = clamp(dial, PRESSURE_DIAL_MIN, PRESSURE_DIAL_MAX); return d <= 0 ? 1 + d * 0.2 : 1 + d * 0.8; }
// -5 -> 5 units, 0 -> 3 units, +5 -> 0 units (piecewise linear)
function pressureDropUnits(dial) { const d = clamp(dial, PRESSURE_DIAL_MIN, PRESSURE_DIAL_MAX); return d <= 0 ? 3 - d * 0.4 : 3 - d * 0.6; }
function pressureGain() { const base = pressureGainUnits(G.pressureDial) * PRESSURE_UNIT; return base * (G.player && G.player.stats.abattoirEngine > 0 ? 2 : 1); }
function pressureDropScale() { return pressureDropUnits(G.pressureDial) / PRESSURE_DROP_BASE; }
// total player power: perks drafted (level - 1) + item tiers owned, weighted by rarity.
// monsters scale against this so difficulty tracks the build.
function powerScore() {
const p = G.player;
if (!p) return 0;
let n = (p.level - 1) * PERK_POWER_WEIGHT;
for (const iid in p.items) n += p.items[iid] * ITEM_RARITY[ITEMS[iid].rarity].power;
if (p.active) n += 2; // holding an active item is a flat power contribution
return Math.max(0, n);
}
function addShake(n) { G.shake = Math.min(G.shake + n, 18); }
function addToast(text, sub, dur) {
G.toasts.push({ text, sub: sub || '', t: 0, dur: dur || 2.5 });
if (G.toasts.length > 3) G.toasts.shift();
}
function addScore(n) {
if (!n) return;
const scaled = Math.round(n * (G.pressure || 1));
G.score += n > 0 ? Math.max(1, scaled) : scaled;
}