Skip to content

Commit 9abe934

Browse files
committed
add functionality
1 parent 5b8e902 commit 9abe934

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

Source-Code/JumpGame/script.js

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
const character = document.getElementById("character");
2+
const block = document.getElementById("block");
3+
const block2 = document.getElementById("block2");
4+
const co = document.getElementById("co");
5+
var counter = 0;
6+
7+
var je = setInterval(() => {
8+
co.classList.add("animate2");
9+
setTimeout(() => {
10+
co.classList.add("show");
11+
}, 2000);
12+
}, 1000);
13+
function jump() {
14+
if (character.classList === "animate") {
15+
return;
16+
}
17+
character.classList.add("animate");
18+
setTimeout(function () {
19+
character.classList.remove("animate");
20+
}, 300);
21+
}
22+
function myFunction(event) {
23+
var x = event.keyCode;
24+
if (x == 32) {
25+
jump();
26+
}
27+
}
28+
var checkDead = setInterval(function () {
29+
let characterTop = parseInt(
30+
window.getComputedStyle(character).getPropertyValue("top")
31+
);
32+
let blockLeft = parseInt(
33+
window.getComputedStyle(block).getPropertyValue("left")
34+
);
35+
if (blockLeft < 20 && blockLeft > -20 && characterTop >= 130) {
36+
block.style.animation = "none";
37+
alert("Game Over. score: " + Math.floor(counter / 100));
38+
counter = 0;
39+
block.style.animation = "block 1s infinite linear";
40+
} else if (ka()) {
41+
} else {
42+
counter++;
43+
document.getElementById("scoreSpan").innerHTML = Math.floor(counter / 100);
44+
}
45+
}, 10);
46+
var add = setInterval(() => {
47+
block2.classList.add("animate1");
48+
setTimeout(() => {
49+
block2.classList.remove("animate1");
50+
}, 9000);
51+
}, 7000);
52+
53+
function ka() {
54+
let characterTop = parseInt(
55+
window.getComputedStyle(character).getPropertyValue("top")
56+
);
57+
let blockTop = parseInt(
58+
window.getComputedStyle(block2).getPropertyValue("left")
59+
);
60+
if (blockTop < 20 && characterTop == 100) {
61+
block2.classList.remove("animate1");
62+
alert("Game Over. score: " + Math.floor(counter / 100));
63+
counter = 0;
64+
}
65+
}
66+
window.addEventListener("keydown", myFunction);

0 commit comments

Comments
 (0)