-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenemy.js
More file actions
30 lines (22 loc) · 795 Bytes
/
enemy.js
File metadata and controls
30 lines (22 loc) · 795 Bytes
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
class Enemy {
constructor(x, y, width, height, speed = 2) { // Default speed set to 2
this.element = document.createElement('img');
this.element.src = './assets/img/enemyFinal.png';
this.element.classList.add('enemy');
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.speed = speed; // Assign speed to the enemy
}
render() {
this.element.style.left = `${this.x}px`;
this.element.style.top = `${this.y}px`;
this.element.style.width = `${this.width}px`;
this.element.style.height = `${this.height}px`;
document.getElementById('board').appendChild(this.element);
}
move() {
this.x += this.speed; // Use speed to adjust movement
}
}