2017-03-11 02:55:31 -05:00
|
|
|
/*
|
2024-11-23 16:32:23 +03:30
|
|
|
* Copyright (c) Erin Catto
|
2024-12-15 13:30:32 +03:30
|
|
|
* Licensed under the MIT license
|
2017-03-11 02:55:31 -05:00
|
|
|
*/
|
|
|
|
|
|
2024-12-23 18:24:21 +03:30
|
|
|
import { World, Edge, Box, Testbed } from "planck";
|
2017-03-11 02:55:31 -05:00
|
|
|
|
2024-12-24 15:07:16 +03:30
|
|
|
const world = new World({
|
|
|
|
|
gravity: { x: 0, y: -10 },
|
|
|
|
|
});
|
2017-03-11 02:55:31 -05:00
|
|
|
|
2023-08-20 03:24:33 -07:00
|
|
|
const testbed = Testbed.mount();
|
2023-07-31 21:47:06 -07:00
|
|
|
testbed.start(world);
|
2017-03-11 02:55:31 -05:00
|
|
|
|
2024-12-18 14:18:45 +03:30
|
|
|
const COUNT = 20;
|
2017-03-11 02:55:31 -05:00
|
|
|
|
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: -40.0, y: 0.0 }, { x: 40.0, y: 0.0 }),
|
|
|
|
|
density: 0.0,
|
|
|
|
|
});
|
2017-03-11 02:55:31 -05:00
|
|
|
|
2024-12-18 14:18:45 +03:30
|
|
|
const a = 0.5;
|
|
|
|
|
const box = new Box(a, a);
|
2017-03-11 02:55:31 -05:00
|
|
|
|
2024-12-23 18:24:21 +03:30
|
|
|
const x = { x: -7.0, y: 0.75 };
|
|
|
|
|
const y = { x: 0, y: 0 };
|
|
|
|
|
const deltaX = { x: 0.5625, y: 1.25 };
|
|
|
|
|
const deltaY = { x: 1.125, y: 0.0 };
|
2017-03-11 02:55:31 -05:00
|
|
|
|
2023-08-14 13:59:23 -07:00
|
|
|
for (let i = 0; i < COUNT; ++i) {
|
2024-12-23 18:24:21 +03:30
|
|
|
y.x = x.x;
|
|
|
|
|
y.y = x.y;
|
2023-08-14 13:59:23 -07:00
|
|
|
for (let j = i; j < COUNT; ++j) {
|
2024-12-24 15:07:16 +03:30
|
|
|
const body = world.createBody({
|
|
|
|
|
type: "dynamic",
|
|
|
|
|
position: y,
|
|
|
|
|
});
|
2024-12-24 19:58:07 +03:30
|
|
|
body.createFixture({
|
|
|
|
|
shape: box,
|
|
|
|
|
density: 5.0,
|
|
|
|
|
});
|
2017-03-11 02:55:31 -05:00
|
|
|
|
2024-12-23 18:24:21 +03:30
|
|
|
y.x += deltaY.x;
|
|
|
|
|
y.y += deltaY.y;
|
2023-07-31 21:47:06 -07:00
|
|
|
}
|
2024-12-23 18:24:21 +03:30
|
|
|
x.x += deltaX.x;
|
|
|
|
|
x.y += deltaX.y;
|
2023-07-31 21:47:06 -07:00
|
|
|
}
|
|
|
|
|
|
2024-12-15 13:30:32 +03:30
|
|
|
testbed.step = function () {
|
2023-08-14 13:59:23 -07:00
|
|
|
// let tree = world.m_broadPhase.m_tree;
|
2023-07-31 21:47:06 -07:00
|
|
|
// if (stepCount++ == 400) {
|
|
|
|
|
// tree.rebuildBottomUp();
|
|
|
|
|
// }
|
|
|
|
|
};
|