Isle-Slingers/js/physics/aim/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

45 lines
1.8 KiB
JavaScript

/* ISLE SLINGERS -- physics/aim/index.js (submodule: aim)
* 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: aimVector, trajectory.
*/
(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.aimVector = function(g, sling, drag) {
var dx = sling.x - drag.x, dy = sling.y - drag.y;
var len = Math.sqrt(dx * dx + dy * dy);
if (len < P.MIN_PULL) return null;
var cl = Math.min(len, P.MAX_PULL);
var v = cl * P.LAUNCH_POWER;
return { vx: (dx / len) * v, vy: (dy / len) * v, pull: cl };
}
// Pure P.trajectory preview: identical integrator + substepping as the live
// sim (2x 1/120 per output point), so the dotted preview matches the real
// flight exactly. Gravity + drag only; stops at the ground.
P.trajectory = function(g, sx, sy, vx, vy, steps) {
var pts = [];
var x = sx, y = sy, i, sub;
for (i = 0; i < steps; i++) {
for (sub = 0; sub < 2; sub++) {
var dt = 1 / 120;
var nvy = vy + P.GRAVITY * dt;
x += vx * dt;
y += (vy + nvy) * 0.5 * dt;
vx *= P.AIR_DRAG;
vy = nvy;
}
if (y > P.WORLD.ground - 18) { pts.push({ x: x, y: P.WORLD.ground - 18, last: true }); break; }
pts.push({ x: x, y: y, last: false });
}
return pts;
}
};
});