Game Development Reference
In-Depth Information
if (brick.freeLife) {
lives++;
createjs.Tween.get(brick.freeLife)
.to({alpha:0, y:brick.freeLife.y - 100}, 1000)
.call(function () {
stage.removeChild(this);
});
}
if (combo > 4) {
score += (combo * 10);
var comboTxt = new createjs.Text('COMBO X' + (combo * 10),
'14px Times', '#FF0000');
comboTxt.x = brick.x;
comboTxt.y = brick.y;
comboTxt.regX = brick.width / 2;
comboTxt.regY = brick.height / 2;
comboTxt.alpha = 0;
stage.addChild(comboTxt);
createjs.Tween.get(comboTxt)
.to({alpha:1, scaleX:2, scaleY:2, y:comboTxt.y - 60}, 1000)
.call(function () {
stage.removeChild(this);
});
}
stage.removeChild(brick);
bricks.splice(i, 1);
puck.velY *= -1;
break;
}
}
}
The loop is set to cycle through the bricks array, which holds every brick visible on the stage. The same collision
detection that was used on the paddle is used on each brick. If a hit is found, several things are then considered.
First, the score is increased by the number of points that were assigned to the brick during the building of its level,
and the combo count is incremented by one. If the brick was a bonus brick, the player is awarded a new life. When this
brick was created, it was assigned a reference to the '1UP' text object so it could be removed later. Before doing this, it
is given a classic up-and-fade animation, and is ultimately removed from the stage when the tween is complete.
The combo bonuses are next determined by checking if the combo count is over four. For every one of these
hits, the current score is increased by the value of the combo count times 10. To add dramatic effect for these combo
points, a text object is created on the fly, added to the stage above the brick, and then animated up while growing in
size. Adding a short delay prevents too much overlapping of text as the bonus messages populate the screen. When
the animation is complete, the text object is removed from the stage. Figure 4-7 shows the visuals during a combo
streak.
Search WWH ::




Custom Search