in libs/game/physics.ts [211:301]
protected createMovingSprite(sprite: Sprite, dtMs: number, dt2: number): MovingSprite {
const ovx = this.constrain(sprite._vx);
const ovy = this.constrain(sprite._vy);
sprite._lastX = sprite._x;
sprite._lastY = sprite._y;
if (sprite._ax) {
sprite._vx = Fx.add(
sprite._vx,
Fx.idiv(
Fx.imul(
sprite._ax,
dtMs
),
1000
)
);
} else if (sprite._fx) {
const fx = Fx.idiv(
Fx.imul(
sprite._fx,
dtMs
),
1000
);
const c = Fx.compare(sprite._vx, fx);
if (c < 0) // v < f, v += f
sprite._vx = Fx.min(Fx.zeroFx8, Fx.add(sprite._vx, fx));
else if (c > 0) // v > f, v -= f
sprite._vx = Fx.max(Fx.zeroFx8, Fx.sub(sprite._vx, fx));
else
sprite._vx = Fx.zeroFx8
}
if (sprite._ay) {
sprite._vy = Fx.add(
sprite._vy,
Fx.idiv(
Fx.imul(
sprite._ay,
dtMs
),
1000
)
);
} else if (sprite._fy) {
const fy = Fx.idiv(
Fx.imul(
sprite._fy,
dtMs
),
1000
);
const c = Fx.compare(sprite._vy, fy);
if (c < 0) // v < f, v += f
sprite._vy = Fx.min(Fx.zeroFx8, Fx.add(sprite._vy, fy));
else if (c > 0) // v > f, v -= f
sprite._vy = Fx.max(Fx.zeroFx8, Fx.sub(sprite._vy, fy));
else
sprite._vy = Fx.zeroFx8;
}
sprite._vx = this.constrain(sprite._vx);
sprite._vy = this.constrain(sprite._vy);
const dx = Fx8(Fx.toFloat(Fx.add(sprite._vx, ovx)) * dt2 / 1000);
const dy = Fx8(Fx.toFloat(Fx.add(sprite._vy, ovy)) * dt2 / 1000);
let xStep = dx;
let yStep = dy;
// make step increments smaller until under max step size
while (Fx.abs(xStep) > this.maxSingleStep || Fx.abs(yStep) > this.maxSingleStep) {
if (Fx.abs(xStep) > this.minSingleStep) {
xStep = Fx.idiv(xStep, 2);
}
if (Fx.abs(yStep) > this.minSingleStep) {
yStep = Fx.idiv(yStep, 2);
}
}
return new MovingSprite(
sprite,
sprite._vx,
sprite._vy,
dx,
dy,
xStep,
yStep
);
}