-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbullet.js
34 lines (26 loc) · 873 Bytes
/
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
(function(root) {
var Asteroids = root.Asteroids = (root.Asteroids || {});
var Bullet = Asteroids.Bullet = function(pos, vel, direction, game){
Asteroids.MovingObject.call(this, pos, vel, direction, Bullet.RADIUS,
Bullet.COLOR);
this.game = game
};
Bullet.COLOR = 'red';
Bullet.RADIUS = 5;
Bullet.inherits(Asteroids.MovingObject);
Bullet.prototype.hitAsteroids = function(){
var that = this
this.game.asteroids.forEach(function(asteroid){
if (that.isCollidedWith(asteroid)) {
that.game.removeAsteroid(asteroid);
that.game.removeBullet(that);
}
})
};
Bullet.prototype.move = function(){
var newX = this.pos[0] + (this.direction[0] * this.vel);
var newY = this.pos[1] + (this.direction[1] * this.vel);
this.pos = [newX, newY];
this.hitAsteroids();
}
})(this);