-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnemy06.js
More file actions
80 lines (69 loc) · 1.91 KB
/
Enemy06.js
File metadata and controls
80 lines (69 loc) · 1.91 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
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
class Enemy06 extends Enemy02{
constructor(ctx) {
super();
this.ctx=ctx;
this.enemyValue=70;
this.enemy.src = 'assets/enemy06.png';
this.width=35;
this.height=20;
this.stopMovX=false;
this.stopMovY=true;
this.velY=1.2;
this.velX=3.5;
this.dirXInterval= {current:0,max:50};
}
createEnemies(x, y) {
this.enemies.push({x: x,y: y,});
this.enemies.push({x: x+150,y: y,});
this.enemies.push({x: x+300,y: y,});
if (this.enemies.length < 18) {
this.createEnemies(x, y-80);
} else {
this.enemiesCreated=true;
}
}
showEnemies() {
if (this.dirXInterval.current<=this.dirXInterval.max&&!this.stopMovX&&!isResetting&&!paused) {
this.dirXInterval.current++;
} else if (this.dirXInterval.current>this.dirXInterval.max) {
this.dirXInterval.current=0;
this.dirX *= -1;
}
for (let i = 0; i < this.enemies.length; i++) {
this.ctx.drawImage(this.enemy,this.enemies[i].x,this.enemies[i].y,this.width,this.height);
if (!this.stopMovX&&!isResetting&&!paused) {
this.enemies[i].x+=this.velX*this.dirX;
}
if (!this.stopMovY&&!isResetting&&!paused) {
this.enemies[i].y+=this.velY;
}
if (this.enemies[i].y >= 330) {
this.enemies[i].y = -150;
}
}
}
manage() {
let randomTimer = Math.floor(Math.random()*1700+2000);
setTimeout(() => {
if (!paused)
this.stopMovY = !this.stopMovY;
}, randomTimer)
randomTimer = Math.floor(Math.random()*2500+500);
setTimeout(() => {
if (!paused)
this.stopMovX = !this.stopMovX;
}, randomTimer)
randomTimer = Math.floor(Math.random()*2000+2000);
setTimeout(() => {
this.manage();
}, randomTimer)
}
draw() {
if(!this.enemiesCreated) {
this.createEnemies(70,-150);
this.manage();
}
this.showEnemies();
this.showShots();
}
}