-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
39 lines (24 loc) · 944 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
39
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 < 110) {
pipe.style.animation = 'none';
pipe.style.left = `${pipePosition}px`;
mario.style.animation = 'none';
mario.style.bottom = `${marioPosition}px`;
mario.src = './Imagens/game-over.png'; /* Link Imagem Game Over Mario*/
mario.style.width = '75px'
mario.style.marginLeft = '50px'
clearInterval(loop);
}
}, 10);
document .addEventListener('keydown', jump);