function apply_plan(body, engine, plans_all = []) {
const {
world,
timing: { timestamp }
} = engine;
const next_timestamp = timestamp + ms_per_frame;
const plans = plans_all
.map(([timestamp, label, magnitude, angle]) => ({
timestamp,
label,
magnitude,
angle
}))
.filter((d) => d.timestamp >= timestamp && d.timestamp <= next_timestamp);
for (const plan_ of plans) {
const { angle, magnitude } = plan_;
const force = vector_from_angle(angle, magnitude);
const flame_mass = body.mass * 0.5;
const flame = Matter.Bodies.circle(
body.position.x,
body.position.y,
body.circleRadius * 5,
{
label: `flame-${Math.floor(Math.random())}`,
plugin: {
order: -1,
beforeUpdate: () => {
const flame_shrink_percent = 0.98;
Matter.Body.scale(
flame,
flame_shrink_percent,
flame_shrink_percent
);
const newArea = flame.area;
if (newArea < 0.1) {
Matter.Composite.remove(world, flame);
}
}
},
render: {
style: `fill: orange; stroke: none;`
},
collisionFilter: { mask: 0b0 },
mass: flame_mass,
friction: 0,
frictionAir: 0,
restitution: 0
}
);
Matter.Body.applyForce(body, body.position, force);
Matter.Body.applyForce(flame, flame.position, Matter.Vector.neg(force));
Matter.Composite.add(world, flame);
}
body.plugin.plans = plans;
}