92 lines
2.0 KiB
TypeScript
Raw Permalink Normal View History

/*
2024-11-23 16:32:23 +03:30
* Copyright (c) Erin Catto
* Licensed under the MIT license
*/
2024-12-23 18:24:21 +03:30
import { World, Edge, Box, stats, Testbed } from "planck";
2024-12-24 15:07:16 +03:30
const world = new World({
gravity: { x: 0, y: -10 },
});
2023-08-20 03:24:33 -07:00
const testbed = Testbed.mount();
testbed.start(world);
2024-12-24 15:07:16 +03:30
const ground = world.createBody({
type: "static",
});
2024-12-24 19:58:07 +03:30
ground.createFixture({
shape: new Edge({ x: -10.0, y: 0.0 }, { x: 10.0, y: 0.0 }),
density: 0.0,
});
ground.createFixture({
shape: new Box(0.2, 1.0, { x: 0.5, y: 1.0 }, 0.0),
density: 0.0,
});
2024-12-24 15:07:16 +03:30
const body = world.createBody({
type: "dynamic",
position: { x: 0.0, y: 4.0 },
});
2024-12-24 19:58:07 +03:30
body.createFixture({
shape: new Box(2.0, 0.1),
density: 1.0,
});
// x = Math.random(-1.0, 1.0);
2023-08-14 13:59:23 -07:00
let x = 0.20352793;
2024-12-18 14:18:45 +03:30
const bullet = world.createBody({
type: "dynamic",
2024-12-23 18:24:21 +03:30
position: { x: x, y: 10.0 },
bullet: true,
2024-12-24 19:58:07 +03:30
linearVelocity: { x: 0.0, y: -50.0 },
});
bullet.createFixture({
shape: new Box(0.25, 0.25),
density: 100.0,
});
function Launch() {
2024-12-23 18:24:21 +03:30
body.setTransform({ x: 0.0, y: 4.0 }, 0.0);
body.setLinearVelocity({ x: 0, y: 0 });
body.setAngularVelocity(0.0);
2023-08-10 20:55:02 -07:00
x = Math.random() * 2 - 1;
2024-12-23 18:24:21 +03:30
bullet.setTransform({ x: x, y: 10.0 }, 0.0);
bullet.setLinearVelocity({ x: 0.0, y: -50.0 });
bullet.setAngularVelocity(0.0);
stats.gjkCalls = 0;
stats.gjkIters = 0;
stats.gjkMaxIters = 0;
stats.toiCalls = 0;
stats.toiIters = 0;
stats.toiMaxIters = 0;
stats.toiRootIters = 0;
stats.toiMaxRootIters = 0;
}
2023-08-14 13:59:23 -07:00
let stepCount = 0;
testbed.step = function () {
testbed.status(stats);
// if (stats.gjkCalls > 0) {
// "gjk calls = %d, ave gjk iters = %3.1, max gjk iters = %d",
// stats.gjkCalls, stats.gjkIters / float32(stats.gjkCalls), stats.gjkMaxIters);
// }
// if (stats.toiCalls > 0) {
// "toi calls = %d, ave toi iters = %3.1, max toi iters = %d",
// stats.toiCalls, stats.toiIters / float32(stats.toiCalls), stats.toiMaxRootIters);
//
// "ave toi root iters = %3.1, max toi root iters = %d", stats.toiRootIters
// / float32(stats.toiCalls), stats.toiMaxRootIters);
// }
if (stepCount++ % 60 === 0) {
Launch();
}
};