-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathEnemy.js
More file actions
33 lines (29 loc) · 675 Bytes
/
Enemy.js
File metadata and controls
33 lines (29 loc) · 675 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
27
28
29
30
31
32
33
export default class Enemy {
constructor(x, y, imageNumber) {
this.x = x;
this.y = y;
this.width = 44;
this.height = 32;
this.image = new Image();
this.image.src = `images/enemy${imageNumber}.png`;
}
draw(ctx) {
ctx.drawImage(this.image, this.x, this.y, this.width, this.height);
}
move(xVelocity, yVelocity) {
this.x += xVelocity;
this.y += yVelocity;
}
collideWith(sprite) {
if (
this.x + this.width > sprite.x &&
this.x < sprite.x + sprite.width &&
this.y + this.height > sprite.y &&
this.y < sprite.y + sprite.height
) {
return true;
} else {
return false;
}
}
}