-
Notifications
You must be signed in to change notification settings - Fork 251
Expand file tree
/
Copy pathEdgeTest.ts
More file actions
93 lines (80 loc) · 1.67 KB
/
EdgeTest.ts
File metadata and controls
93 lines (80 loc) · 1.67 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
85
86
87
88
89
90
91
92
93
/*
* Copyright (c) Erin Catto
* Licensed under the MIT license
*/
import { World, Circle, Box, Edge, Testbed } from "planck";
const world = new World({
gravity: { x: 0, y: -10 },
});
const testbed = Testbed.mount();
testbed.start(world);
const ground = world.createBody({
type: "static",
});
const v1 = { x: -10.0, y: 0.0 };
const v2 = { x: -7.0, y: -2.0 };
const v3 = { x: -4.0, y: 0.0 };
const v4 = { x: 0.0, y: 0.0 };
const v5 = { x: 4.0, y: 0.0 };
const v6 = { x: 7.0, y: 2.0 };
const v7 = { x: 10.0, y: 0.0 };
const shape1 = new Edge(v1, v2);
shape1.setNextVertex(v3);
ground.createFixture({
shape: shape1,
density: 0.0,
});
const shape2 = new Edge(v2, v3);
shape2.setPrevVertex(v1);
shape2.setNextVertex(v4);
ground.createFixture({
shape: shape2,
density: 0.0,
});
const shape3 = new Edge(v3, v4);
shape3.setPrevVertex(v2);
shape3.setNextVertex(v5);
ground.createFixture({
shape: shape3,
density: 0.0,
});
const shape4 = new Edge(v4, v5);
shape4.setPrevVertex(v3);
shape4.setNextVertex(v6);
ground.createFixture({
shape: shape4,
density: 0.0,
});
const shape5 = new Edge(v5, v6);
shape5.setPrevVertex(v4);
shape5.setNextVertex(v7);
ground.createFixture({
shape: shape5,
density: 0.0,
});
const shape6 = new Edge(v6, v7);
shape6.setPrevVertex(v5);
ground.createFixture({
shape: shape6,
density: 0.0,
});
world
.createBody({
type: "dynamic",
position: { x: -0.5, y: 0.6 },
allowSleep: false,
})
.createFixture({
shape: new Circle(0.5),
density: 1.0,
});
world
.createBody({
type: "dynamic",
position: { x: 1.0, y: 0.6 },
allowSleep: false,
})
.createFixture({
shape: new Box(0.5, 0.5),
density: 1.0,
});