-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBullets.js
64 lines (60 loc) · 1.63 KB
/
Bullets.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
/*Stores all bullets*/
function Bullets() {
this.bullets = new Array();
}
/*Add an Bullet
@param {Point} The current position of a bullet
@param {Number} The starting rotation (in radians)
@param {Enemy} targetEnemy The enemy the bullet is targeting
@param {Integer} targetFrame The target frame of the bullet we are shooting
@param {Number} speed The speed of the bullet (in pixels per frame)
@param {Integer} drawingType 1 = circle, 2 = square, 3 = rectangle, 4 = long rectangle, 5 = rocket
@param {Number} radius used for dimensions of all types of drawing types
@param {String} color The color to draw the bullet
*/
Bullets.prototype.add = function (
position,
rotation,
targetEnemy,
targetFrame,
speed,
drawingType,
radius,
color
) {
var bullet = new Bullet(
position,
rotation,
targetEnemy,
targetFrame,
speed,
drawingType,
radius,
color
);
this.bullets.push(bullet);
};
/*Remove a Bullet
*@param {Integer} index, The element to remove
*/
Bullets.prototype.remove = function (index) {
this.bullets.splice(index, 1);
};
/*Remove all Bullets
*/
Bullets.prototype.removeAll = function () {
for (var i = this.bullets.length - 1; i >= 0; i--) {
this.remove(i);
}
};
/*Draws all bullets, deletes all bullets that have reached the end of their life
* @param {Canvas Drawing Context} ctx
*/
Bullets.prototype.drawAll = function (ctx, frame) {
ctx.clearRect(0, 0, Background.WIDTH, Background.HEIGHT);
for (var i = this.bullets.length - 1; i >= 0; i--) {
if (this.bullets[i].draw(ctx)) {
this.remove(i);
}
}
};