-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
105 lines (101 loc) · 3.08 KB
/
script.js
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
94
95
96
97
98
99
100
101
102
103
104
105
// Creator: Nathan A
// Description: Its Just Plinko
// Creation Date: 7/31/2020
// Update Date:
// module aliases
const Engine = Matter.Engine,
Render = Matter.Render,
World = Matter.World,
Bodies = Matter.Bodies,
Body = Matter.Body;
// create an engine
const engine = Engine.create();
// create a renderer
const render = Render.create({
element: document.getElementById('can'),
engine: engine
});
// create flanges
const fOptions = {
isStatic: true,
}
const flanges = [
//row one
Bodies.polygon(45,150,3,20,fOptions),
Bodies.polygon(100,250,3,20,fOptions),
Bodies.polygon(60,350,3,20,fOptions),
Bodies.polygon(100,450,3,20,fOptions),
//row two
Bodies.polygon(150,150,3,20,fOptions),
Bodies.polygon(200,250,3,20,fOptions),
Bodies.polygon(150,350,3,20,fOptions),
Bodies.polygon(200,450,3,20,fOptions),
//row three
Bodies.polygon(250,150,3,20,fOptions),
Bodies.polygon(300,250,3,20,fOptions),
Bodies.polygon(250,350,3,20,fOptions),
Bodies.polygon(300,450,3,20,fOptions),
//row four
Bodies.polygon(350,150,3,20,fOptions),
Bodies.polygon(400,250,3,20,fOptions),
Bodies.polygon(350,350,3,20,fOptions),
Bodies.polygon(400,450,3,20,fOptions),
//row five
Bodies.polygon(450,150,3,20,fOptions),
Bodies.polygon(500,250,3,20,fOptions),
Bodies.polygon(450,350,3,20,fOptions),
Bodies.polygon(500,450,3,20,fOptions),
//row six
Bodies.polygon(550,150,3,20,fOptions),
Bodies.polygon(600,250,3,20,fOptions),
Bodies.polygon(550,350,3,20,fOptions),
Bodies.polygon(600,450,3,20,fOptions),
//row seven
Bodies.polygon(650,150,3,20,fOptions),
Bodies.polygon(700,250,3,20,fOptions),
Bodies.polygon(650,350,3,20,fOptions),
Bodies.polygon(700,450,3,20,fOptions),
//row 8
Bodies.polygon(755,150,3,20,fOptions),
Bodies.polygon(740,350,3,20,fOptions),
];
for (i = 0; i < flanges.length; i++){
World.add(engine.world,[flanges[i]])
Body.setAngle(flanges[i], 16.23)
}
//create catches
const cOptions = {
isStatic:true
}
const catches = [
Bodies.rectangle(40,560,2,40,cOptions)
];
xasx = 82;
for (v = 0; v < 20; v++){
catches.push(Bodies.rectangle(xasx,560,2,40,cOptions))
World.add(engine.world,[catches[v]])
xasx = xasx + 45;
}
// create disk
let disk = [];
let count = 0;
const dOptions = {
friction: .2,
restitution:1
}
function addD() {
disk.push(Bodies.circle(event.offsetX ,event.offsetY, 20,dOptions ))
World.add(engine.world,[disk[count]])
count++
}
// create ground sky and walls
const ground = Bodies.rectangle(400, 610, 810, 60, { isStatic: true });
const leftWall = Bodies.rectangle(0, 305,2 , 810, { isStatic: true });
const righttWall = Bodies.rectangle(800, 305,2 , 810, { isStatic: true });
const sky = Bodies.rectangle(400, 0,810,2, { isStatic: true });
// add all of the bodies to the world
World.add(engine.world, [sky,righttWall,leftWall,ground]);
// run the engine
Engine.run(engine);
// run the renderer
Render.run(render);