-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnemy1.js
47 lines (38 loc) · 1.04 KB
/
Enemy1.js
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
class Enemy1 {
static img = new Image();
static {
this.img.src = 'src/assets/enemy1/enemy1.png';
}
constructor(x, y) {
this.width = 40 * 1.5;
this.height = 64 * 1.5;
this.x = x;
this.y = y - this.height;
}
tick = function() {
const player = handler.player;
if (gamestate == 'INFINITE_RUNNER') {
this.x -= player.velX;
}
if (this.x + this.width <= 0) {
handler.remove(this);
return;
}
if (intersects(this, player)) {
holder = this;
player.takeDamage();
}
handler.selectByType('projectile').forEach(obj => {
if (intersects(this, obj)) {
handler.remove(obj);
}
});
}
render = function(g) {
// g.strokeStyle = 'red';
// g.beginPath();
// g.rect(this.x, this.y, this.width, this.height);
// g.stroke();
g.drawImage(Enemy1.img, this.x, this.y, this.width, this.height);
}
}