-
Notifications
You must be signed in to change notification settings - Fork 1
/
.tmp
99 lines (98 loc) · 3.45 KB
/
.tmp
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
btnUlangi.addEventListener('click', function () {
// Re-Declare for restart game
lives = 10,
score = 0;
bannerAkhir[0].style.display = "none";
let batasKiri = 10,
batasKanan = 280,
batasAtas = 0,
batasBawah = 130;
let ship = {
x: batasKanan / 2,
y: batasBawah
}
let peluru = [],
enemy = [];
for (i = 0; i < 4; i++) {
enemy[i] = {
x: 20 + i * 80,
y: -10,
die: false,
score: true
}
}
for (i = 0; i < 4; i++) {
peluru[i] = {
x: ship.x + 5,
y: ship.y + 5,
status: 'ready',
baca: false
}
}
init();
document.addEventListener('keydown', function (anu) {
switch (anu.code) {
case "Space":
if (peluru[0].status == 'ready') {
laserEffect.play()
peluru[0].status = 'used';
} else if (peluru[1].status == 'ready') {
laserEffect.play()
peluru[1].status = 'used';
} else if (peluru[2].status == 'ready') {
laserEffect.play()
peluru[2].status = 'used';
} else if (peluru[3].status == 'ready') {
laserEffect.play()
peluru[3].status = 'used';
} else {
reload();
}
break;
case "ArrowRight":
if (ship.x < batasKanan) {
ship.x += 10;
}
for (var i = 0; i < peluru.length; i++) {
if (peluru[i].status !== "used") {
if (peluru[i].x <= batasKanan)
peluru[i].x += 10;
}
}
break;
case "ArrowLeft":
if (ship.x > batasKiri) {
ship.x -= 10;
}
for (var i = 0; i < peluru.length; i++) {
if (peluru[i].status !== "used") {
if (peluru[i].x >= batasKiri + 10)
peluru[i].x -= 10;
}
}
break;
case "ArrowUp":
if (ship.y > batasAtas) {
ship.y -= 10;
}
for (var i = 0; i < peluru.length; i++) {
if (peluru[i].status !== "used") {
if (peluru[i].y > batasAtas + 10)
peluru[i].y -= 10;
}
}
break;
case "ArrowDown":
if (ship.y < batasBawah) {
ship.y += 10;
}
for (var i = 0; i < peluru.length; i++) {
if (peluru[i].status !== "used") {
if (peluru[i].y < batasBawah)
peluru[i].y += 10;
}
}
break;
}
})
})