-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
243 lines (167 loc) · 5.12 KB
/
app.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
var canvasContainer = document.createElement('div')
document.body.appendChild(canvasContainer);
var statsContainer = document.createElement('div');
canvasContainer.appendChild(statsContainer);
var statsContent = document.createElement('h2');
statsContainer.appendChild(statsContent);
var titleEl = document.getElementById("ball-title");
var startButton = document.getElementById("starter-button")
let startTime = 1500000
let ballDrop = false;
let balls = 0;
var timerStarted = false;
var stopDropping;
var gong = new Audio('./sound/gong.mp3');
var waterDrop = new Audio('./sound/drop.mp3');
var pomodoroComplete = false;
var testingArray = [];
makeTheThingsDance()
function startTheTimer() {
// check if pomodoroComplete and reset everything
if (pomodoroComplete === true) {
balls = 0;
startTime = 1500000;
timerStarted = false;
ballDrop = false;
pomodoroComplete = false;
}
if (timerStarted === false && pomodoroComplete === false) {
timerStarted = true;
console.log("Started")
startButton.textContent = "Let the balls drop!"
gong.play()
countDown()
stopDropping = setInterval(function () {
countDown()
}, 60000)
// stopDropping = setInterval(function () {
// countDown()
// }, 600)
}
}
function rando(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
function countDown() {
console.log("Remaining", startTime)
if (balls === 24) {
statsContent.textContent = "Less than 1 minute remaining!";
titleEl.textContent = "Less than 1 minute remaining!"
}
if (startTime === 0) {
clearInterval(stopDropping);
gong.play();
window.alert("Time's up!")
statsContent.textContent = "All done!";
titleEl.textContent = "Take a break!"
timerStarted = false;
pomodoroComplete = true;
startButton.textContent = "Start another round?"
} else {
statsContent.textContent = (25 - (balls + 1)) + " minutes remaining!";
// startTime = startTime - 60000; -----> real time!
startTime = startTime - 60000;
console.log(startTime);
ballDrop = true;
balls++;
}
}
// function checkForInactiveTab() {
// }
function makeTheThingsDance() {
var bodyArray = [];
// module aliases
var Engine = Matter.Engine,
Render = Matter.Render,
MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse,
World = Matter.World,
Bodies = Matter.Bodies,
Events = Matter.Events;
var engine = Engine.create(document.getElementById('canvas-container'));
var render = Render.create({
element: canvasContainer,
engine: engine,
options: {
width: 800,
height: 480,
background: 'transparent',
showAngleIndicator: false,
wireframes: false
}
});
// Render.run(render);
// var top = Bodies.rectangle(450, 125, 500, 50, {
// isStatic: true,
// render: {
// fillStyle: 'transparent'
// }
// });
var sideRight = Bodies.rectangle(700, 300, 50, 400, {
isStatic: true,
render: {
sprite: {
texture: './img/roWood.png'
}
}
});
var sideLeft = Bodies.rectangle(60, 300, 50, 400, {
isStatic: true,
render: {
sprite: {
texture: './img/roWood.png'
}
}
});
var bottom = Bodies.rectangle(380, 500, 600, 113, {
isStatic: true,
render: {
sprite: {
texture: './img/wood.png'
}
}
});
bodyArray.push(bottom, sideLeft, sideRight)
bottom.restitution = 1.0;
sideLeft.restitution = 1.0;
sideRight.restitution = 1.0;
Events.on(engine, 'beforeUpdate', function () {
if (ballDrop === true) {
titleEl.textContent = (25 - balls) + " minutes remaining!";
const rand = rando(150, 450)
var timeBall2 = Bodies.circle(rand, 80, 40, {
render: {
sprite: {
texture: './img/oaky.png'
}
}
})
World.add(engine.world, timeBall2);
// bodyArray.push(timeBall2)
waterDrop.play();
ballDrop = false;
// balls++
console.log("Balls dropped", balls)
}
// console.log(Bodies)
});
// add mouse control
var mouse = Mouse.create(render.canvas),
mouseConstraint = MouseConstraint.create(engine, {
mouse: mouse,
constraint: {
stiffness: 0.2,
render: {
visible: false
}
}
});
World.add(engine.world, mouseConstraint);
// keep the mouse in sync with rendering
render.mouse = mouse;
World.add(engine.world, bodyArray)
// run the engine
Engine.run(engine);
// run the renderer
Render.run(render);
}