-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
30 lines (27 loc) · 848 Bytes
/
Copy pathapp.js
File metadata and controls
30 lines (27 loc) · 848 Bytes
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
const dino = document.getElementById('dino');
const cactus = document.getElementById('cactus');
const jump = () => {
if(dispatchEvent.classList != "jump") {
dino.classList.add("jump");
setTimeout(() => {
dino.classList.remove("jump")
}, 500);
}
}
const checkAlive = setInterval(() => {
const dinoTop = parseInt(
window.getComputedStyle(dino).getPropertyValue('top')
)
const cactusLeft = parseInt(
window.getComputedStyle(cactus).getPropertyValue('left')
)
if(cactusLeft > 0 && cactusLeft < 70 && dinoTop >= 132) {
dino.style.animationPlayState = 'paused';
cactus.style.animationPlayState = 'paused';
alert('Ooops you lost ☹️');
window.location.reload()
}
}, 10)
document.addEventListener("keydown", () => {
jump()
})