-
Notifications
You must be signed in to change notification settings - Fork 1
/
asteroid.js
30 lines (24 loc) · 889 Bytes
/
asteroid.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
(function (root) {
var Asteroids = root.Asteroids = (root.Asteroids || {});
var Asteroid = Asteroids.Asteroid = function (posX, posY, vel) {
Asteroids.MovingObject.call(this, posX, posY, vel, Asteroid.RADIUS, Asteroid.COLOR);
};
Asteroid.inherits(Asteroids.MovingObject);
Asteroid.COLOR = '#424370';
Asteroid.RADIUS = 20;
Asteroid.SPEED = 4;
var randomAsteroid = Asteroid.randomAsteroid = function (dimX, dimY) {
var startX = dimX * Math.random();
var startY = dimY * Math.random();
var startVel = randomVec(Asteroid.SPEED);
var ast = new Asteroid (startX, startY, startVel);
return ast;
};
var randomVec = Asteroids.randomVec = function (speed) {
var x = Math.random() - 0.5;
var y = Math.random() - 0.5;
var preNorm = Asteroids.Util.norm([x, y]);
var mult = speed / preNorm;
return [mult * x, mult * y];
};
})(this);