/
bullet.js
38 lines (31 loc) · 1.07 KB
/
bullet.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
(function(root) {
var Asteroids = root.Asteroids = (root.Asteroids || {});
var Bullet = Asteroids.Bullet = function(ship, game, scale) {
this.ship = ship;
var shipFront = ship.transformedCoords()[0];
this.game = game;
this.coordinates = _.map(Bullet.COORDS, function(coord) {
return [coord[0] * scale, coord[1] * scale];
})
this.vel = Bullet.VEL * scale;
Asteroids.MovingObject.call(this, shipFront, this.vel, ship.angle, this.coordinates, Bullet.RADIUS, Bullet.COLOR, ship.angle);
}
Bullet.inherits(Asteroids.MovingObject);
Bullet.VEL = -500;
Bullet.COORDS = [[-3,-1],[-3,1],[3,1],[3,-1]];
Bullet.RADIUS = 6;
Bullet.COLOR = "red";
Bullet.fireBullet = function(game, scale) {
if (!game.ship.isDead) {
return new Bullet(game.ship, game, scale);
}
}
Bullet.prototype.isCollidedWith = function(otherObject) {
if (this.isInBounds(otherObject)) {
var poly = otherObject.transformedCoords();
return Asteroids.MovingObject.isWithin([this.pos], poly);
} else {
return false;
}
};
})(this)