-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
68 lines (57 loc) · 1.54 KB
/
script.js
File metadata and controls
68 lines (57 loc) · 1.54 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
let left = document.querySelector("#left");
let up = document.querySelector("#up");
let right = document.querySelector("#right");
let down = document.querySelector("#down");
let box = document.querySelector("#box");
let target = document.querySelector("#target");
let cover = document.querySelector("#cover");
let hold = false;
let x = 0;
let y = 0;
document.addEventListener("keydown", (event) => {
if(!hold) {
if(event.key === "w") {
// console.log("W key was pressed");
y += 10;
box.style.bottom = `${y}px`;
} else if(event.key === "s") {
y -= 10;
box.style.bottom = `${y}px`;
} else if(event.key === "a") {
x -= 10;
box.style.left = `${x}px`;
} else if(event.key === "d") {
x += 10;
box.style.left = `${x}px`;
}
}
if(x >= 600 && x <= 700 && y < 50) {
cover.style.display = "block";
hold = true;
}
})
left.addEventListener("click", () => {
x -= 10;
box.style.left = `${x}px`;
})
right.addEventListener("click", () => {
x += 10;
box.style.left = `${x}px`;
})
up.addEventListener("click", () => {
y += 10;
box.style.bottom = `${y}px`;
})
down.addEventListener("click", () => {
y -= 10;
box.style.bottom = `${y}px`;
})
let retry = document.querySelector("#retry");
retry.addEventListener("click", () => {
hold = false;
x = 0;
y = 0;
cover.style.display = "none";
box.style.left = "0px";
box.style.bottom = "0px";
})