forked from vlzhr/beet-js-game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Enemy.js
49 lines (38 loc) · 1.29 KB
/
Enemy.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
48
class Enemy extends PIXI.Sprite {
constructor() {
super(resources["images/knife.png"].texture);
this.y = (Math.random() * (app.renderer.height-100) + 10) * sizeScale();
this.width = 64*1.6*1.5 * sizeScale();
this.x = app.renderer.width-this.width;
this.height = 9.87234*1.6*1.5 * sizeScale();
this.speed = 5 + Math.random()*5;
this.type = "knife";
app.stage.addChild(this);
}
}
class BarrierElement extends PIXI.Sprite {
constructor(y) {
super(resources["images/meat-grinder.png"].texture);
this.width = 120 * sizeScale();
this.height = 120 * sizeScale();
this.y = y;
this.x = app.renderer.width+this.width - 10 * sizeScale();
this.speed = 2.5;
this.anchor.set(0.5);
app.stage.addChild(this);
}
}
class Barrier {
constructor() {
this.elements = [];
for (let n=0; n < Math.floor(Math.random()*3)+2; n++) {
this.elements.push(new BarrierElement( app.renderer.height-((n+0.4)*105) * sizeScale()));
}
}
move(xPlusFactor) {
for (let n in this.elements) {
this.elements[n].x -= this.elements[n].speed * (xPlusFactor ? xPlusFactor : 1);
this.elements[n].rotation += 0.1;
}
}
}