-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEnemyManager.js
86 lines (51 loc) · 1.59 KB
/
EnemyManager.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
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
81
82
83
84
85
var EnemyManager = {};
EnemyManager.init = function(game) {
this.game = game;
this.enemies = game.add.group();
this.enemiesArray = new Array();
};
EnemyManager.spawnEnemy = function(x, y) {
var enemy = new Enemy(this.game, x, y);
enemy.isAlive = true;
this.enemies.add(enemy);
this.enemiesArray.push(enemy);
};
EnemyManager.killAllEnemies = function() {
for (var i=0;i<this.enemiesArray.length;++i) {
var enemy = this.enemiesArray[i];
enemy.destroy();
}
};
EnemyManager.freezeAllEnemies = function() {
this.enemies.forEach(function(enemy) {
if (enemy.isAlive == true) {
enemy.freeze();
}
}, this);
};
EnemyManager.randomizeAllEnemiesMotion = function() {
this.enemies.forEach(function(enemy) {
enemy.moveRandom();
}, this);
};
EnemyManager.throwEnemyOutOfGamefield = function(enemy) {
enemy.isAlive = false;
enemy.body.angularVelocity = 100;
enemy.body.velocity.setTo(-10 + Math.random()*20 , 200);
enemy.animations.play('stand');
};
EnemyManager.throwAllEnemiesOutOfGamefield = function() {
this.enemies.forEach(function(enemy) {
EnemyManager.throwEnemyOutOfGamefield(enemy);
}, this);
};
EnemyManager.update = function() {
for (var i=0;i<this.enemiesArray.length;++i) {
var enemy = this.enemiesArray[i];
if (enemy.isAlive == false) {
if (enemy.y < -50 || enemy.y > this.game.height + 50 || enemy.x < -50 || enemy.x > this.game.width + 50) {
enemy.destroy();
}
}
}
}