-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
137 lines (113 loc) · 4.46 KB
/
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
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
var kite=document.querySelector('.kite');
var kite1=document.querySelector(".kite1");
var item0=document.querySelector(".item0");
var item1=document.querySelector(".item1");
var item2=document.querySelector(".item2");
var item3=document.querySelector(".item3");
var item00=document.querySelector(".item00");
var item11=document.querySelector(".item11");
var item22=document.querySelector(".item22");
var item33=document.querySelector(".item33");
var upper=document.querySelector(".upper");
var lower=document.querySelector(".lower");
var scorep=0;
var score=document.querySelector('.score');
var gameoptions=document.querySelector(".options");
var scorepp=0;
var yourscore=document.querySelector(".yourscore");
var replay=document.querySelector(".replay");
var backgroundaudio=new Audio("background_audio.mp3");
var jumpaudio=new Audio("jump.wav");
var deadaudio=new Audio("dead_sound.wav");
var jumpbutton=document.querySelector(".jumpbutton");
document.onkeydown=function(e)
{
if(e.key=="Enter")
{
backgroundaudio.play();
var dy=parseFloat(window.getComputedStyle(kite1,null).getPropertyValue('bottom'));
kite1.classList.remove("kite1");
kite.style.bottom=dy+8+"px";
setTimeout(()=>{
kite1.classList.add("kite1");
},100)
}
}
jumpbutton.addEventListener('click',()=>{
backgroundaudio.play();
var dy=parseFloat(window.getComputedStyle(kite1,null).getPropertyValue('bottom'));
kite1.classList.remove("kite1");
kite.style.bottom=dy+8+"px";
setTimeout(()=>{
kite1.classList.add("kite1");
},100)
});
setInterval(()=>{
dy=parseInt(window.getComputedStyle(kite,null).getPropertyValue('bottom'));
dx=parseInt(window.getComputedStyle(kite,null).getPropertyValue('left'));
dy1=parseInt(window.getComputedStyle(item0,null).getPropertyValue('bottom'));
dx1=parseInt(window.getComputedStyle(item0,null).getPropertyValue('left'));
var newdx1=Math.abs(dx1-dx);
var newdy1=dy1-(dy+40);
dy2=parseInt(window.getComputedStyle(item1,null).getPropertyValue('bottom'));
dx2=parseInt(window.getComputedStyle(item1,null).getPropertyValue('left'));
var newdx2=Math.abs(dx2-dx);
var newdy2=dy2-(dy+40);
dy3=parseInt(window.getComputedStyle(item2,null).getPropertyValue('bottom'));
dx3=parseInt(window.getComputedStyle(item2,null).getPropertyValue('left'));
var newdx3=Math.abs(dx3-dx);
var newdy3=dy3-(dy+40);
dy4=parseInt(window.getComputedStyle(item3,null).getPropertyValue('bottom'));
dx4=parseInt(window.getComputedStyle(item3,null).getPropertyValue('left'));
var newdx4=Math.abs(dx4-dx);
var newdy4=dy4-(dy+40);
//for lower
dy11=parseInt(window.getComputedStyle(item00,null).getPropertyValue('height'));
var newdy11=dy-dy11;
dy22=parseInt(window.getComputedStyle(item11,null).getPropertyValue('height'));
var newdy22=dy-dy22;
dy33=parseInt(window.getComputedStyle(item22,null).getPropertyValue('height'));
var newdy33=dy-dy33;
dy44=parseInt(window.getComputedStyle(item33,null).getPropertyValue('height'));
var newdy44=dy-dy44;
//for down
setInterval(()=>{
var out=parseInt(window.getComputedStyle(kite,null).getPropertyValue('bottom'));
if(out==0)
{
kite.style.display="none";
lower.style.display="none";
upper.style.display="none";
score.style.display="none";
gameoptions.style.display="grid";
deadaudio.play();
yourscore.innerHTML="Your Score:"+scorep;
backgroundaudio.pause();
backgroundaudio.currentTime=0;
}
},500);
if((newdy1<=0 && newdx1<20) || (newdy2<=0 && newdx2<20) || (newdy3<=0 && newdx3<20) || (newdy4<=0 && newdx4<20) || (newdy11<=0 && newdx1<20) || (newdy22<=0 && newdx2<20) || (newdy33<=0 && newdx3<20) || (newdy44<=0 && newdx4<20))
{
backgroundaudio.pause();
backgroundaudio.currentTime=0;
kite.style.display="none";
lower.style.display="none";
upper.style.display="none";
score.style.display="none";
gameoptions.style.display="grid";
yourscore.innerHTML="Your Score:"+(--scorep);
deadaudio.play();
}
},0);
setTimeout(()=>{
function f1()
{
score.innerHTML="Score: "+scorep;
scorep++;
setTimeout(f1,2500);
}
f1();
},6500);
replay.addEventListener('click',()=>{
window.location.reload();
})