-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
38 lines (24 loc) · 894 Bytes
/
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
const mario = document.querySelector('.mario');
const pipe = document.querySelector('.pipe');
const jump = () => {
mario.classList.add('jump');
setTimeout( () => {
mario.classList.remove('jump');
}, 500);
}
const loop = setInterval(() => {
const pipeposition = pipe.offsetLeft;
const marioposition = +window.getComputedStyle(mario).bottom.replace('px', '');
console.log(marioposition);
if (pipeposition <= 120 && pipeposition > 0 && marioposition < 80) {
pipe.style.animation = 'none';
pipe.style.left = `${pipeposition}px`;
mario.style.animation = 'none';
mario.style.bottom = `${marioposition}px`;
mario.src = 'imagens/game-over.png';
mario.style.width = '80px'
mario.style.marginLeft = '50px'
clearInterval(loop);
}
},10)
document.addEventListener('keydown', jump);