-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnemy08.js
More file actions
68 lines (57 loc) · 1.53 KB
/
Enemy08.js
File metadata and controls
68 lines (57 loc) · 1.53 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
class Enemy08 extends Enemy06{
constructor(ctx) {
super();
this.ctx=ctx;
this.enemyValue=90;
this.enemy.src = 'assets/enemy08.png';
this.width=35;
this.height=30;
this.vel=3;
}
createEnemies(x, y) {
let random = Math.random()*this.ctx.canvas.width;
this.enemies.push({x: random,y: y,});
this.enemies.push({x: random+140,y: y,});
this.enemies.push({x: random+280,y: y,});
if (this.enemies.length < 18) {
this.createEnemies(x, y-80);
} else {
this.enemiesCreated=true;
}
}
showEnemies() {
let random = Math.random()*this.ctx.canvas.width+1;
let counter=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(!isResetting && !paused)
this.enemies[i].y+=this.vel;
if (this.enemies[i].y >= 350) {
this.enemies[i].y = -130;
if (counter===1 && !paused) {
this.enemies[i].x = random;
} else if (counter===2 && !paused) {
this.enemies[i].x = random+140;
} else if (counter===3 && !paused) {
this.enemies[i].x = random+280;
}
if (!paused)
counter++;
if (counter===4 && !paused) {
random = Math.random()*this.ctx.canvas.width+1;
counter=1;
}
}
}
}
createShot() {
}
showShots() {
}
draw() {
if(!this.enemiesCreated) {
this.createEnemies(70,-150);
}
this.showEnemies();
}
}