-
Notifications
You must be signed in to change notification settings - Fork 0
/
logic.js
47 lines (32 loc) · 1000 Bytes
/
logic.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
var character = document.getElementById("character");
var block = document.getElementById("block");
var counter=0;
function jump()
{
if(character.classList == "animate")
{
return
}
character.classList.add("animate");
setTimeout(function()
{
character.classList.remove("animate");
},300);
}
var checkDead = setInterval(function()
{
let characterTop = parseInt(window.getComputedStyle(character).getPropertyValue("top"));
let blockLeft = parseInt(window.getComputedStyle(block).getPropertyValue("left"));
if(blockLeft<20 && blockLeft>-20 && characterTop>=130)
{
block.style.animation = "none";
alert("Game Over... YOUR SCORE IS: "+Math.floor(counter/100));
counter=0;
block.style.animation = "block 1.3s infinite linear";
}
else
{
counter++;
document.getElementById("score").innerHTML = Math.floor(counter/100);
}
}, 10);