stage: new PIXI.Stage(0x000000),
[null, null, null, null, null, 'blue', null, null, null, null],
[null, null, null, null, 'red', 'red', 'blue', null, null, null],
[null, null, null, 'red', 'red', null, null, 'blue', null, null],
[null, null, 'red', 'red', null, null, null, null, 'blue', null],
[null, 'red', 'red', null, null, 'gold', null, null, 'silver', 'silver'],
[null, null, 'red', 'red', null, null, null, 'silver', 'silver', null],
[null, null, null, 'red', 'red', null, 'silver', 'silver', null, null],
[null, null, null, null, 'silver', 'silver', 'silver', null, null, null],
[null, null, null, null, null, 'silver', null, null, null, null]
for(j = 0; j < blockMap.length; j++) {
for(i = 0; i < blockMap[j].length; i++) {
if(blockMap[j][i] !== null) {
var block = BB.addBlock(10 + (30 * i), 80 + (12 * j), blockMap[j][i]);
* @param {String} color red,blue,silver,gold
addBlock: function(x, y, color) {
var point = SETTINGS_POINT;
var point = SETTINGS_POINT_SILVER;
var point = SETTINGS_POINT_GOLD;
var point = SETTINGS_POINT;
var texture = PIXI.Texture.fromImage(imgPath["block_" + color], false);
var block = new PIXI.Sprite(texture);
BB.stage.addChild(block);
// Create a ball and add it to PIXI.Stage
var texture = PIXI.Texture.fromImage(imgPath["ball"], false);
var ball = new PIXI.Sprite(texture);
ball.position.x = parseInt(BB.renderer.width * 0.5);
'x' : Math.random() - 0.5,
// Create a paddle and add it to PIXI.Stage
var texture = PIXI.Texture.fromImage(imgPath["paddle"], false);
BB.paddle = new PIXI.Sprite(texture);
BB.paddle.anchor.x = 0.5;
BB.paddle.anchor.y = 0.5;
BB.paddle.position.x = parseInt(BB.renderer.width * 0.5);
BB.paddle.position.y = BB.renderer.height - 60;
'x' : Math.random() - 0.5,
BB.stage.addChild(BB.paddle);
* Add points to current score
* @param {int} val points to add
addScore: function(val) {
BB.score += parseInt(val);
BB.scoreLabel.setText(BB.score);
* @param {int} val new score
setScore: function(val) {
BB.scoreLabel.setText(BB.score);
* callback for Core Cordova Plugins Acceleration Watch
* @param {Object} a a.x, a.y, a.z
updateAcceleration: function(a) {
var accelText = "", ac = a.x.toFixed(2);
if(a.x > 0) accelText = '+' + String(ac);
else accelText = String(ac);
// Use parameter x to move paddle
if (BB.paddle !== null) {
if (BB.paddle.accel / ac > 2.0) {
} else if (BB.paddle.accel / ac > 0) {
BB.paddle.accel += ac * SETTINGS_PADDLE_ACCEL;
BB.paddle.accel = ac * SETTINGS_PADDLE_ACCEL;
BB.accelLabel.setText(accelText);
// Reset current game and start new one
//Reset (remove all children in the stage if exists)
for (var i = BB.stage.children.length - 1; i >= 0; i--) {
BB.stage.removeChildAt(i);
for (var i = 0; i < SETTINGS_BALL_NUM; i++) {
var resetLabel = new PIXI.Text("RESET", {font: "24px/1.2 vt", fill: "red"});
resetLabel.position.x = 18;
resetLabel.position.y = BB.renderer.height - 52;
BB.stage.addChild(resetLabel);
resetLabel.buttonMode = true;
resetLabel.interactive = true;
resetLabel.click = resetLabel.tap = function(data) {
resetLabel.setText("RESET"); //for Android
var label = new PIXI.Text("SCORE:", {font: "24px/1.2 vt", fill: "red"});
BB.stage.addChild(label);
label.setText("SCORE:"); //for Android
BB.scoreLabel = new PIXI.Text("0", {font: "24px/1.2 vt", fill: "white"});
BB.scoreLabel.position.x = 90;
BB.scoreLabel.position.y = 20;
BB.stage.addChild(BB.scoreLabel);
var label = new PIXI.Text("ACCEL:", {font: "24px/1.2 vt", fill: "red"});
BB.stage.addChild(label);
label.setText("ACCEL:"); //for Android
BB.accelLabel = new PIXI.Text("0", {font: "24px/1.2 vt", fill: "white"});
BB.accelLabel.position.x = 230;
BB.accelLabel.position.y = 20;
BB.stage.addChild(BB.accelLabel);
BB.gameState = GAMESTATE_PLAY;
* Check whether the ball hits the object
* @param {PIXI.Sprite} ball
* @param {PIXI.Sprite} obj target object
isBallHit: function(ball, obj) {
return (ball.position.x > (obj.position.x - (obj.width * 0.5))) &&
(ball.position.x < (obj.position.x + (obj.width * 0.5))) &&
(ball.position.y > (obj.position.y - (obj.height * 0.5))) &&
(ball.position.y < (obj.position.y + (obj.height * 0.5)));
BB.gameState = GAMESTATE_STOP;
if(typeof navigator.notification !== 'undefined') navigator.notification.alert("Cleared!", function(){}, "Congraturations");
BB.gameState = GAMESTATE_STOP;