-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenemy.js
More file actions
44 lines (38 loc) · 1.31 KB
/
enemy.js
File metadata and controls
44 lines (38 loc) · 1.31 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
class Obstacle {
constructor(gameScreen) {
this.gameScreen = gameScreen
this.left = Math.random() * 1000
this.top = -150
this.width = 100
this.height = 50
this.element = document.createElement("img");
this.element.src = './6alien.png';
this.element.style.position = "absolute";
this.element.style.left = `${this.left}px`;
this.element.style.top = `${this.top}px`;
this.element.style.height = `${this.height}px`;
this.element.style.width = `${this.width}px`;
this.gameScreen.appendChild(this.element);
}
move() {
this.top += 3
this.updatePostion()
}
updatePostion() {
this.element.style.left = `${this.left}px`;
this.element.style.top = `${this.top}px`;
}
createExplosion() {
let newElement = document.createElement("img");
newElement.src = "./9explosion.gif";
newElement.style.position = "absolute";
newElement.style.left = `${this.left}px`;
newElement.style.top = `${this.top}px`;
newElement.style.width = `${this.width}px`;
newElement.style.height = `${this.height}px`;
this.gameScreen.appendChild(newElement);
setTimeout(() => {
newElement.remove();
}, 1250);
}
}