Isle-Slingers/js/physics/abilities/index.js
Relay dc68c6e3dd Physics upgrade + repo modularization (RC-375D84)
Delivered by Hermies Qwen, gated and deployed by Relay.

- Board tip/topple: full continuous rotation when a board's center of
  mass passes its support edge (Q1: smooth pivot swing, no discrete
  snap). Falling boards deal impact damage and can kill enemies in
  their fall path.
- Falling-object impact damage: blocks and birds can now kill enemies
  from vertical drops and side plows (velocity-aware crush gate),
  chain momentum transfers correctly through stacks (mass-weighted
  contact), repeated impacts finish tougher enemies.
- Landed-bird physics: a bird resting on a board remains a real
  physical body under continuous gravity (Q2: no lifetime timer). If
  its platform is destroyed it falls, damages what it lands on
  (chain reaction), and can kill enemies.
- Repo modularized: folders = modules, subfolders = submodules,
  architecture.md + MODULES.md at root, an agents.md card in every
  module and submodule (17 total).
- Test suite grown from 27 to 47 (20 new RED-watched tests for the
  above behaviors), all green. Golden differential against the
  original core confirmed the only behavioral changes are the
  intended ones.

Live at http://10.244.136.121:8093/, independently re-verified by
Relay (full suite re-run, module structure check, headless Chromium
smoke) before this push.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-29 13:21:18 +00:00

65 lines
2.5 KiB
JavaScript

/* ISLE SLINGERS -- physics/abilities/index.js (submodule: abilities)
* RC-375D84 S-2 modularization (behavior-neutral split of the original
* js/core.js monolith). Installs its units into ONE shared physics scope `P`
* that every physics submodule sees -- the same single-scope semantics the
* monolith had. Must load before js/physics/index.js (the aggregator that
* attaches the public ISLE_CORE API). Surface installed: launch, triggerAbility.
*/
(function (root, factory) {
var part = factory();
if (typeof module !== 'undefined' && module.exports) module.exports = part;
else (root.ISLE_PHYSICS_PARTS = root.ISLE_PHYSICS_PARTS || []).push(part);
})(typeof globalThis !== 'undefined' ? globalThis : this, function () {
'use strict';
return function (P) {
P.launch = function(g, dragPos) {
var b = P.activeBird(g);
if (!b || b.state !== 'aiming' || g.status !== 'ready') return false;
var v = P.aimVector(g, { x: g.level.sling.x, y: g.level.sling.y }, dragPos);
if (!v) return false;
b.x = g.level.sling.x; b.y = g.level.sling.y;
b.vx = v.vx; b.vy = v.vy;
b.state = 'flying';
b.launchT = g.time;
g.status = 'flying';
g.launched++;
g.events.push({ type: 'P.launch', x: b.x, y: b.y });
return true;
}
P.triggerAbility = function(g) {
var b = P.activeBird(g);
if (!b || b.state !== 'flying' || b.abilityUsed) return false;
if (g.time - b.launchT < P.ABILITY_CD) return false;
var kind = b.kind;
if (kind === 'wren') {
b.vx = b.vx * 0.4 + 980;
g.events.push({ type: 'ability_fury', x: b.x, y: b.y });
} else if (kind === 'zippy') {
b.vy = Math.max(b.vy, 0) + 1050;
b.vx *= 0.55;
g.events.push({ type: 'ability_dive', x: b.x, y: b.y });
} else if (kind === 'boulder') {
var R = 150;
var i, d, f, ent;
for (i = 0; i < g.blocks.length; i++) {
var bl = g.blocks[i];
if (bl.hp <= 0) continue;
d = Math.hypot(bl.x - b.x, bl.y - b.y) - (bl.w + bl.h) / 4;
if (d < R) { f = 1 - Math.max(0, d) / R; P.damageBlock(g, bl, 120 + 300 * f, 'quake'); }
}
for (i = 0; i < g.enemies.length; i++) {
ent = g.enemies[i];
if (ent.dead) continue;
d = Math.hypot(ent.x - b.x, ent.y - b.y) - ent.r;
if (d < R) { f = 1 - Math.max(0, d) / R; P.damageEnemy(g, ent, 0.7 + 1.6 * f); }
}
g.camera.shake = Math.max(g.camera.shake, 14);
g.events.push({ type: 'ability_quake', x: b.x, y: b.y, r: R });
}
b.abilityUsed = true;
g.stats.abilityUses++;
return true;
}
};
});