1 /**
  2  * Main menu scene
  3  * @param {BB_App} app
  4  * @constructor
  5  */
  6 function BB_Main(app) {
  7 	var sprite = app.sprite,
  8 		drawer = app.drawer;
  9 	this.app = app;
 10 	this.ball = new BB_Ball(sprite, 120, 90);
 11 	this.coin = new BB_Coin(sprite, 130, 135);
 12 	this.sound = new BB_Button(sprite, 140, 245, 100, 32, 360, 100);
 13 	this.sound.disabled = app.sound.disabled;
 14 	this.start = new BB_Button(sprite, 240, 245, 100, 32, 160, 100);
 15 	this.border = 20;
 16 	this.repaint = true;
 17 	drawer.wood(0, 0, this.w, this.h, 10);
 18 	drawer.wood(0, 0, this.w, this.border, 2, 2);
 19 	drawer.wood(0, this.border, this.border, this.h, 2, 2);
 20 	drawer.wood(this.w-this.border, this.border, this.border, this.h, 2, 2);
 21 	drawer.wood(0, this.h-this.border, this.w, this.border, 2, 2);
 22 	drawer.info();
 23 }
 24 
 25 /**
 26  * Extends CP_Item
 27  */
 28 BB_Main.prototype = new CP_Item(480, 320);
 29 
 30 /**
 31  * Draw scene
 32  * @param {Object} ctx
 33  */
 34 BB_Main.prototype.paint = function(ctx) {
 35 	if (this.repaint) {
 36 		this.clear(ctx);
 37 		this.coin.paint(ctx);
 38 		this.ball.paint(ctx);
 39 		this.start.paint(ctx);
 40 		this.sound.paint(ctx);
 41 	}
 42 };
 43 
 44 /**
 45  * Check button status changes
 46  * @param {Number} x
 47  * @param {Number} y
 48  * @returns {Boolean}
 49  */
 50 BB_Main.prototype.check = function(x, y) {
 51 	return this.sound.active ^ this.sound.check(x, y) |
 52 		this.start.active ^ this.start.check(x, y) > 0;
 53 };
 54 
 55 /**
 56  * Scene event handler
 57  * @param {String} e
 58  * @param {Number} x
 59  * @param {Number} y
 60  * @param {Boolean} touch
 61  */
 62 BB_Main.prototype.on = function(e, x, y, touch) {
 63 	this.repaint = this.check(x, y) || this.repaint;
 64 	switch (e) {
 65 		case 'end':
 66 			if (this.start.active) {
 67 				this.app.sound.stop(4);
 68 				this.app.start();
 69 			} else if (this.sound.active) {
 70 				this.sound.disabled = this.app.sound.disable();
 71 				this.app.storage.setSound(!this.sound.disabled);
 72 				if (!this.sound.disabled) {
 73 					this.app.sound.play(4, .5 , true);
 74 				}
 75 			}
 76 			break;
 77 		case 'load':
 78 			this.repaint = true;
 79 			break;
 80 		case 'music':
 81 			this.app.sound.play(4, .5 , true);
 82 			break;
 83 	}
 84 };
 85