1 /**
  2  * Score counter
  3  * @param {BB_Sprite} sprite
  4  * @constructor
  5  */
  6 function BB_Score(sprite) {
  7 	this.sprite = sprite;
  8 	this.score = 0;
  9 	this.buffer = 0;
 10 	this.shot = 3;
 11 	this.high = false;
 12 	this.balls = 0;
 13 	this.highscore = 0;
 14 	this.next = false;
 15 	this.end = false;
 16 };
 17 
 18 /**
 19  * Score event handler
 20  * @param {String} event
 21  */
 22 BB_Score.prototype.on = function(event) {
 23 	switch (event) {
 24 		case 'shot':
 25 			this.shot--;
 26 			break;
 27 		case 'wall':
 28 			this.score += 111;
 29 			break; 
 30 		case 'coin':
 31 			this.score += 3250;
 32 			break; 
 33 		case 'end':
 34 			this.score += 12500 * this.shot;
 35 			this.end = true;
 36 			break;
 37 	}
 38 };
 39 
 40 /**
 41  * Score thread
 42  * @returns {Boolean}
 43  */
 44 BB_Score.prototype.run = function() {
 45 	var result = this.buffer < this.score,
 46 		value = this.buffer + 43;
 47 	if (result) {
 48 		this.buffer = value < this.score ? value : this.score;
 49 	}
 50 	return result;
 51 };
 52 
 53 /**
 54  * Draw score
 55  * @param ctx
 56  */
 57 BB_Score.prototype.paint = function(ctx) {
 58 	var score = this.end ? this.score : this.buffer,
 59 		width = this.shot * 20;
 60 	if (width) {
 61 		this.sprite.paint(ctx, 480-width, 2, width, 16, 0, 100);
 62 	}
 63 	ctx.save();
 64 	ctx.font = "bold 16px Arial";
 65 	ctx.lineWidth = 2;
 66 	ctx.strokeStyle = "#852";
 67 	ctx.strokeText(score, 25, 16);
 68 	ctx.fillStyle = "#f90";
 69 	ctx.fillText(score, 25, 16);
 70 	ctx.restore();
 71 };
 72