-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
35 lines (21 loc) · 843 Bytes
/
Copy pathscript.js
File metadata and controls
35 lines (21 loc) · 843 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
31
32
33
34
35
const gato = document.querySelector('.gato');
const obstaculo = document.querySelector('.obstaculo');
const jump = () => {
gato.classList.add('jump');
setTimeout(() => {
gato.classList.remove('jump');
}, 500);
}
const loop = setInterval(() => {
const obstaculoposicao = obstaculo.offsetLeft;
const gatoposicao = +window.getComputedStyle(gato).bottom.replace('px', '');
if(obstaculoposicao <= 155 && obstaculoposicao > 0 && gatoposicao < 50) {
obstaculo.style.animation = 'none';
obstaculo.style.left = `${obstaculoposicao}px`;
gato.style.animation = 'none';
gato.style.bottom = `${gatoposicao}px`;
// gato.src = 'images/game-over.png'
clearInterval(loop);
}
}, 10);
document.addEventListener('keydown', jump);