-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ball.js
53 lines (48 loc) · 1.45 KB
/
Ball.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
function Ball() {
this.origin = new Vector2(10, 10);
this.position = new Vector2(0, 0);
this.velocity = new Vector2(0, 0);
this.hitDistanceX = 200;
this.hitDistanceY = 200;
this.rotation = 0;
this.hitBalloon = false;
this.active = true;
this.hitBlimp = false;
this.reset();
this.currentColor = Game.gameWorld.cannon.currentColor;
}
Ball.prototype.reset = function () {
this.position = Game.gameWorld.cannon.ballPosition().subtractBy(this.origin);
if (!Touch.isTouchDevice) {
this.velocity = Mouse.position.subtract(this.position).multiplyBy(1.2);
if (Game.gameWorld.specialtiesEquipped === "double_ball_upgrade") {
this.velocity = Mouse.position
.subtract(this.position)
.multiplyBy(Math.random() * 0.3 + 0.8);
}
}
else if (Touch.isTouchDevice) {
this.velocity = Game.gameWorld.cannon.velocity;
if (Game.gameWorld.specialtiesEquipped === "double_ball_upgrade") {
this.velocity = Touch.getPosition(0)
.subtract(this.position)
.multiplyBy(Math.random() * 0.3 + 0.8);
}
}
};
Ball.prototype.draw = function () {
if (this.active)
Canvas.drawImage(
sprites.balls[this.currentColor].normal,
this.position,
0,
this.origin
);
};
Ball.prototype.update = function (delta) {
if (this.active === false) return;
this.velocity.x *= 0.99;
this.velocity.y += 6;
this.position.addTo(this.velocity.multiply(delta));
};
Ball.prototype.handleInput = function () {};