-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
32 lines (27 loc) · 929 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
var character = document.getElementById("character");
document.addEventListener("click", jump);
var score = 0;
var scoreDiv = document.getElementById("score");
function jump(){
if(character.classList == "animate"){return;}
character.classList.add("animate");
setTimeout(removeJump,300);
};
function removeJump(){
character.classList.remove("animate");
}
var block = document.getElementById("block");
function updateScore(){
score++;
scoreDiv.innerHTML = "Score: " + score;
}
function checkDead(){
let characterTop = parseInt(window.getComputedStyle(character).getPropertyValue("top"));
let blockLeft = parseInt(window.getComputedStyle(block).getPropertyValue("left"));
if(blockLeft<20 && blockLeft>-20 && characterTop>=130){
alert("Game over");
}else if(blockLeft<20 && blockLeft>-20){
updateScore();
}
}
setInterval(checkDead, 10);