Repository navigation
Expand file tree
/
Copy pathEnemies.js
More file actions
63 lines (58 loc) · 1.85 KB
/
Copy pathEnemies.js
File metadata and controls
63 lines (58 loc) · 1.85 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
/*Provides the list for all enemies
*/
function Enemies() {
this.enemies = new Array();
}
/*Add an enemy
*@param {String} type The type of enemy
*@param {Integer} The current frame
*@param {Path} The monster's path
*@param {Number} distanceTravelled (used for spawning monsters during split)
*/
Enemies.prototype.add = function (type, frame, path, distanceTravelled) {
var enemy = EnemyList.createEnemy(type, frame, path, distanceTravelled);
this.enemies.push(enemy);
};
/*Remove an elementFromPoint
*@param {Integer} index, The element to remove
*/
Enemies.prototype.remove = function (index) {
//if this is the last frame, damage the player
var curEnemy = this.enemies[index];
if (this.enemies[index].lastFrame < SuperTower.frame) {
SuperTower.lives -= curEnemy.damage;
SuperTower.missed++;
} else {
SuperTower.cash += curEnemy.money;
SuperTower.kills++;
//spawn the other enemies
for (var i = curEnemy.deathSplit.length - 1; i >= 0; i--) {
this.add(
curEnemy.deathSplit[i],
curEnemy.frame,
curEnemy.path,
curEnemy.distanceTravelled
);
}
}
this.enemies.splice(index, 1);
};
Enemies.prototype.removeAll = function () {
for (var i = this.enemies.length - 1; i >= 0; i--) {
this.remove(i);
}
};
/*Draws all enemies, deletes enemies that have reached the end of the track and returns damage
* @param {Canvas Drawing Context} ctx
* @param {Integer} currentFrame (our currentFrame)
* @return {Number} The damage the enemies should do to the player
*/
Enemies.prototype.drawAll = function (ctx, frame) {
var damage = 0;
ctx.clearRect(0, 0, Background.WIDTH, Background.HEIGHT);
for (var i = this.enemies.length - 1; i >= 0; i--) {
if (this.enemies[i].draw(ctx, frame)) {
this.remove(i);
}
}
};