-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
40 lines (37 loc) · 1.41 KB
/
script.js
File metadata and controls
40 lines (37 loc) · 1.41 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
let block = document.getElementById("block");
let hole = document.getElementById("hole");
let charcter = document.getElementById("character");
let jumping = 0;
let score = 0;
hole.addEventListener("animationiteration",function(){
let random = -((Math.random()*300)+150)
hole.style.top = random+"px";
score++;
})
setInterval(function(){
let characterPosition = parseInt(window.getComputedStyle(charcter).getPropertyValue("top"));
if (jumping == 0){
charcter.style.top = characterPosition+ 3 + "px";
}
let blockPosition = parseInt(window.getComputedStyle(block).getPropertyValue("left"));
let holePosition = parseInt(window.getComputedStyle(hole).getPropertyValue("top"));
if (((characterPosition>490) || (characterPosition<1))||(((blockPosition<45)&&(blockPosition>-5))&&((characterPosition<holePosition+500)||(characterPosition>holePosition+585)))){
alert("Game over!, Your score is "+score);
score = 0;
charcter.style.top = 100+ "px";
}
},10)
function jump(){
jumping = 1;
jumpcount = 0;
let characterjumping = setInterval(function(){
let characterPosition = parseInt(window.getComputedStyle(charcter).getPropertyValue("top"));
charcter.style.top = characterPosition- 5 + "px";
if (jumpcount>20){
clearInterval(characterjumping);
jumpcount=0;
jumping =0;
}
jumpcount++;
},10);
}