-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
56 lines (32 loc) · 1.22 KB
/
script.js
File metadata and controls
56 lines (32 loc) · 1.22 KB
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
const catbus = document.querySelector('.catbus');
const house = document.querySelector('.house');
const gameover = document.querySelector('.game-over');
const gameboard = document.querySelector('.game-board');
const jump = () => {
catbus.classList.add('jump');
setTimeout(() => {
catbus.classList.remove('jump')
} , 1000);
}
const loop = setInterval(() => {
const housePosition = house.offsetLeft;
const catbusPosition = +window.getComputedStyle(catbus).bottom.replace('px' , '');
if (housePosition <= 200 && housePosition > 0 && catbusPosition < 130){
house.style.animation = 'none';
house.style.left = `${housePosition}px`;
catbus.style.animation = 'none';
catbus.style.bottom = `${catbusPosition}px`;
catbus.src = './assets/catbus-gameover.png';
catbus.style.width = '200px';
catbus.style.marginleft = '0px';
clearInterval(loop);
crash();
}
}, 10);
function crash (){
gameover.classList.add('over');
gameboard.classList.add('over');
house.classList.add('inverter');
catbus.classList.add('inverter');
}
document.addEventListener('keydown' , jump);