===================================================================
--- original.js
+++ change.js
@@ -34,8 +34,22 @@
self.move = function (xPosition) {
self.x = xPosition;
};
});
+// PowerUp class
+var PowerUp = Container.expand(function () {
+ var self = Container.call(this);
+ var powerUpGraphics = self.attachAsset('powerUp', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.effect = function (ball) {
+ ball.width *= 1.5; // Increase ball size by 50%
+ ball.height *= 1.5; // Increase ball size by 50%
+ ballGraphics.scaleX *= 1.5; // Scale up the ball's graphic representation
+ ballGraphics.scaleY *= 1.5; // Scale up the ball's graphic representation
+ };
+});
/****
* Initialize Game
****/
@@ -94,8 +108,23 @@
bricks[i].y += brickHeight + brickPadding;
}
}
ball.move();
+ // Spawn PowerUp randomly
+ if (spawnTick % 3000 == 0) {
+ var powerUpX = Math.random() * (2048 - 100) + 50; // Random X within game bounds
+ var powerUp = game.addChild(new PowerUp());
+ powerUp.x = powerUpX;
+ powerUp.y = 100; // Start from top
+ }
+ // Check for PowerUp collision with ball
+ for (var p = 0; p < game.children.length; p++) {
+ var child = game.children[p];
+ if (child instanceof PowerUp && ball.intersects(child)) {
+ child.effect(ball); // Apply PowerUp effect to the ball
+ child.destroy(); // Remove PowerUp after use
+ }
+ }
// Ball collision with walls
if (ball.x <= 0 || ball.x >= 2048) {
ball.speedX = -ball.speedX;
}