1 /** 2 * Game overlay 3 * @param {BB_Sprite} sprite 4 * @param {BB_Score} score 5 * @param {BB_Storage} storage 6 * @constructor 7 */ 8 function BB_Overlay(sprite, score, level) { 9 this.sprite = sprite; 10 this.score = score; 11 this.level = level; 12 this.levels = BB_Game.maps.length; 13 this.back = new BB_Button(sprite, 90, 220, 100, 32, 60, 100); 14 this.start = new BB_Button(sprite, 190, 220, 100, 32, 160, 100); 15 this.next = new BB_Button(sprite, 290, 220, 100, 32, 260, 100); 16 } 17 18 /** 19 * Extends CP_Item 20 */ 21 BB_Overlay.prototype = new CP_Item(480, 320); 22 23 /** 24 * Draw overlay 25 */ 26 BB_Overlay.prototype.paint = function(ctx) { 27 var high = this.score.high ? 'New Highscore!' : 'Highscore: ' + this.score.highscore, 28 level = 'Level: ' + (this.level + 1) + '/' + this.levels, 29 balls = this.score.balls, 30 score = this.score.score, 31 sprite = this.sprite; 32 ctx.save(); 33 ctx.fillStyle = "rgba(0, 0, 0, .6)"; 34 ctx.fillRect(this.x, this.y, this.w, this.h); 35 ctx.textAlign = "center"; 36 ctx.textBaseline = "middle"; 37 ctx.lineWidth = 4; 38 ctx.fillStyle = "#f90"; 39 ctx.strokeStyle = "#420"; 40 ctx.font = "bold 24px Arial"; 41 ctx.strokeText(high, 240, 70); 42 ctx.fillText(high, 240, 70); 43 ctx.font = "bold 16px Arial"; 44 ctx.strokeText(level, 240, 100); 45 ctx.fillText(level, 240, 100); 46 ctx.lineWidth = 6; 47 ctx.font = "bold 48px Arial"; 48 ctx.strokeText(score, 240, 150); 49 ctx.fillText(score, 240, 150); 50 ctx.restore(); 51 this.back.paint(ctx); 52 this.start.paint(ctx); 53 this.next.paint(ctx); 54 if (balls) { 55 sprite.paint(ctx, 216, 180, 48, 16, 0, 116); 56 } 57 }; 58 59 /** 60 * Check bucton status changes 61 * @param {Number} x 62 * @param {Number} y 63 * @returns {Boolean} 64 */ 65 BB_Overlay.prototype.check = function(x, y) { 66 return this.back.active ^ this.back.check(x, y) | 67 this.start.active ^ this.start.check(x, y) | 68 this.next.active ^ this.next.check(x, y) > 0; 69 };