-
Notifications
You must be signed in to change notification settings - Fork 251
Expand file tree
/
Copy pathBridge.ts
More file actions
84 lines (69 loc) · 1.63 KB
/
Bridge.ts
File metadata and controls
84 lines (69 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
* Copyright (c) Erin Catto
* Licensed under the MIT license
*/
import { World, Body, Edge, Box, Polygon, Circle, RevoluteJoint, Testbed } from "planck";
const world = new World({
gravity: { x: 0, y: -4 },
});
const testbed = Testbed.mount();
testbed.start(world);
const COUNT = 30;
let middle: Body;
const ground = world.createBody({
type: "static",
});
ground.createFixture({
shape: new Edge({ x: -40.0, y: 0.0 }, { x: 40.0, y: 0.0 }),
density: 0.0,
});
const bridgeRect = new Box(0.5, 0.125);
const bridgeFD = {
density: 20.0,
friction: 0.2,
};
let prevBody = ground;
for (let i = 0; i < COUNT; ++i) {
const body = world.createBody({
type: "dynamic",
position: { x: -14.5 + 1.0 * i, y: 5.0 },
});
body.createFixture({
shape: bridgeRect,
...bridgeFD,
});
const anchor = { x: -15.0 + 1.0 * i, y: 5.0 };
world.createJoint(new RevoluteJoint({}, prevBody, body, anchor));
if (i * 2 === COUNT) {
middle = body;
}
prevBody = body;
}
const anchor = { x: -15.0 + 1.0 * COUNT, y: 5.0 };
world.createJoint(new RevoluteJoint({}, prevBody, ground, anchor));
for (let i = 0; i < 2; ++i) {
const body = world.createBody({
type: "dynamic",
position: { x: -8.0 + 8.0 * i, y: 12.0 },
});
const vertices = [
{ x: -0.5, y: 0.0 },
{ x: 0.5, y: 0.0 },
{ x: 0.0, y: 1.5 },
];
body.createFixture({
shape: new Polygon(vertices),
density: 1.0,
});
}
const shape = new Circle(0.5);
for (let i = 0; i < 3; ++i) {
const body = world.createBody({
type: "dynamic",
position: { x: -6.0 + 6.0 * i, y: 10.0 },
});
body.createFixture({
shape: shape,
density: 1.0,
});
}