Files
HexTrails/src/collision-animation.js
T
cabinw e92cccba82 feat: version campaigns and document original puzzle design
Restore v0.1 and v0.2 archives with separate progress, publish the curved v0.3 campaign, and document the original 24-level design with reproducible evidence. Refine board presentation and movement, and keep video lab tooling within its own directory.
2026-09-09 13:17:30 +08:00

18 lines
869 B
JavaScript

import { segmentHexHit } from './path-math.js';
// Approach, readable contact pause, recoil. Used by both browser and Cocos.
export function collisionPhase(progress, reduced=false){
const t=Math.max(0,Math.min(1,progress));
const distance=t<.42?1-Math.pow(1-t/.42,2):t<.64?1:Math.pow(1-(t-.64)/.36,2);
const impact=t>=.42&&t<.72?Math.sin((t-.42)/.30*Math.PI):0;
return {distance,impact,kick:reduced?0:Math.sin(Math.max(0,t-.42)/.58*Math.PI)*Math.exp(-Math.max(0,t-.42)*2)};
}
// Stop the drawn silhouette at first contact, avoiding visible overlap from collider tolerance.
export function contactPath(points,blocker,radius){
if(!blocker)return points;
for(let i=1;i<points.length;i++){
const a=points[i-1],b=points[i],t=segmentHexHit(a,b,blocker,radius*2);
if(t!==null)return [...points.slice(0,i),{x:a.x+(b.x-a.x)*t,y:a.y+(b.y-a.y)*t}];
}
return points;
}