-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha.js
77 lines (68 loc) · 2.15 KB
/
a.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
score=0;
cross=true;
audio=new Audio('mario.mp3');
gameO=new Audio('gameOver.mp3');
setTimeout(()=>{
audio.play();
},100)
document.onkeydown=function(e){
if(e.keyCode==38)
{
const dino=document.querySelector('.dino');
dino.classList.add('animate');
setTimeout(()=>{
dino.classList.remove('animate')
},800);
}
if(e.keyCode==39)
{
dino=document.querySelector('.dino');
dx=parseInt(window.getComputedStyle(dino,null).getPropertyValue('left'));
dino.style.left=dx+100+'px';
}
if(e.keyCode==37)
{
dino=document.querySelector('.dino');
dx=parseInt(window.getComputedStyle(dino,null).getPropertyValue('left'));
dino.style.left=dx-200+'px';
}
}
var handle=setInterval(()=>{
audio.play();
dino=document.querySelector('.dino');
gameOver=document.querySelector('.gameOver');
obstacle=document.querySelector('.obstacle');
dx=parseInt(window.getComputedStyle(dino,null).getPropertyValue('left'));
dy=parseInt(window.getComputedStyle(dino,null).getPropertyValue('top'));
ox=parseInt(window.getComputedStyle(obstacle,null).getPropertyValue('left'));
oy=parseInt(window.getComputedStyle(obstacle,null).getPropertyValue('top'));
offsetX=Math.abs(ox-dx);
offsetY=Math.abs(dy-oy);
console.log(offsetX,offsetY)
if(offsetX<90 && offsetY<100){
gameOver.style.visibility='visible';
obstacle.classList.remove('obstacleDrag');
setTimeout(()=>{
gameO.play();
audio.pause();
clearInterval(handle);
},100)
}
else if(cross&&offsetX<145){
score=score+10;
update(score);
cross=false;
setTimeout(()=>{
cross=true;
},1000);
setTimeout(()=>{
aniDur=parseFloat(window.getComputedStyle(obstacle,null).getPropertyValue('animation-duration'));
newDur=anidur-0.1;
obstacle.style.animationDuration=newDur+'s';
},1000);
}
},100)
function update(score){
scoreCount=document.querySelector('.scoreCount');
scoreCount.innerHTML='Your score '+score;
}