-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (31 loc) · 885 Bytes
/
index.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
let distanceLeft = 0;
let distanceTop = 0;
let intervalId;
function playGame() {
document.getElementById("play_game").style.display = "none";
intervalId = setInterval(() => {
player.style.left = distanceLeft++ + 'px';
player.style.top = distanceTop++ + 'px';
if (distanceTop >= 500) {
player.src = "./images/explosion,gif";
clearInterval(intervalId);
alert("Game Over");
}
}, 50);
}
function getPlayerKey(e) {
if (e.key == "ArrowUp") {
player.style.top = distanceTop-- + 5+'px';
}
else if (e.key == " ") {
clearInterval(intervalId);
document.getElementById("play_game").style.display = "block";
}
}
setTimeout(() => {
clearInterval(intervalId);
distanceLeft = 0;
distanceTop = 0;
play_game.style.display = "block";
alert("time Over");
}, 60000);