ballz.js/powerup-coin.js

25 lines
648 B
JavaScript
Raw Permalink Normal View History

2019-04-06 17:19:26 +00:00
class PowerUpCoin {
constructor(game, cx, cy) {
this.game = game;
this.cx = cx;
this.cy = cy;
}
draw() {
this.game.ctx.fillStyle = '#fa0';
this.game.ctx.beginPath();
this.game.ctx.ellipse(this.cx, this.cy, Math.abs(this.game.powerUpRadius * Math.cos(this.game.coinAngle)), this.game.powerUpRadius, 0, 0, 2 * Math.PI);
this.game.ctx.fill();
}
hit() {
sounds.hitCoin.play();
this.game.increaseCoinCount();
this.remove();
}
remove() {
this.game.powerUps.splice(this.game.powerUps.findIndex(powerUp => powerUp === this), 1);
}
}