User prompt
add 4 more layers of bricks
Code edit (1 edits merged)
Please save this source code
User prompt
make the background space
User prompt
make a random brick green and make the paddle auto aim for 15 seconds
User prompt
remove the 2 hits stuff
User prompt
fix it
User prompt
remove the color changing and replace it by shrinking the brick instead
User prompt
change the color that the bricks change to
User prompt
make the bricks take 2 hits and change color when they are hit once
User prompt
Please fix the bug: 'ReferenceError: secondBall is not defined' in or related to this line: 'if (secondBall) {' Line Number: 116
User prompt
remove the power ups
User prompt
make the power-ups fall twice as fast
User prompt
the power-up doesn't disappear when collected and it doesn't spawn a second ball
User prompt
even rarer
User prompt
make it fall faster and spawn far less often
User prompt
make a power-up that falls randomly and when collected adds a second ball for 1 minute
User prompt
make the ball slower
User prompt
reset the game with a faster ball when all the bricks are broken
Initial prompt
Breakout
/**** * Classes ****/ // Ball class var Ball = Container.expand(function () { var self = Container.call(this); var ballGraphics = self.attachAsset('ball', { anchorX: 0.5, anchorY: 0.5 }); self.width = ballGraphics.width; self.height = ballGraphics.height; self.speedX = 5; self.speedY = -5; self.update = function () { self.x += self.speedX; self.y += self.speedY; // Ball collision with walls if (self.x <= 0 || self.x >= 2048) { self.speedX *= -1; } if (self.y <= 0) { self.speedY *= -1; } }; }); // Brick class var Brick = Container.expand(function () { var self = Container.call(this); var brickGraphics = self.attachAsset('brick', { anchorX: 0.5, anchorY: 0.5 }); self.width = brickGraphics.width; self.height = brickGraphics.height; self.update = function () { // Brick update logic if needed }; }); //<Assets used in the game will automatically appear here> // Paddle class var Paddle = Container.expand(function () { var self = Container.call(this); var paddleGraphics = self.attachAsset('paddle', { anchorX: 0.5, anchorY: 0.5 }); self.width = paddleGraphics.width; self.height = paddleGraphics.height; self.update = function () { // Paddle update logic if needed }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize paddle var paddle = game.addChild(new Paddle()); paddle.x = 2048 / 2; paddle.y = 2500; // Initialize ball var ball = game.addChild(new Ball()); ball.x = 2048 / 2; ball.y = 2400; // Initialize bricks var bricks = []; var rows = 5; var cols = 10; var brickWidth = 200; var brickHeight = 50; var padding = 10; for (var r = 0; r < rows; r++) { for (var c = 0; c < cols; c++) { var brick = new Brick(); brick.x = c * (brickWidth + padding) + brickWidth / 2 + padding; brick.y = r * (brickHeight + padding) + brickHeight / 2 + padding; bricks.push(brick); game.addChild(brick); } } // Handle paddle movement game.move = function (x, y, obj) { paddle.x = x; }; // Update game logic game.update = function () { ball.update(); paddle.update(); for (var i = 0; i < bricks.length; i++) { bricks[i].update(); if (ball.intersects(bricks[i])) { ball.speedY *= -1; bricks[i].destroy(); bricks.splice(i, 1); break; } } if (ball.intersects(paddle)) { ball.speedY *= -1; } if (ball.y > 2732 || bricks.length == 0) { ball.speedX *= 1.2; ball.speedY *= 1.2; LK.showGameOver(); } };
===================================================================
--- original.js
+++ change.js
@@ -1,68 +1,68 @@
-/****
+/****
* Classes
-****/
+****/
// Ball class
var Ball = Container.expand(function () {
- var self = Container.call(this);
- var ballGraphics = self.attachAsset('ball', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.width = ballGraphics.width;
- self.height = ballGraphics.height;
- self.speedX = 5;
- self.speedY = -5;
- self.update = function () {
- self.x += self.speedX;
- self.y += self.speedY;
- // Ball collision with walls
- if (self.x <= 0 || self.x >= 2048) {
- self.speedX *= -1;
- }
- if (self.y <= 0) {
- self.speedY *= -1;
- }
- };
+ var self = Container.call(this);
+ var ballGraphics = self.attachAsset('ball', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.width = ballGraphics.width;
+ self.height = ballGraphics.height;
+ self.speedX = 5;
+ self.speedY = -5;
+ self.update = function () {
+ self.x += self.speedX;
+ self.y += self.speedY;
+ // Ball collision with walls
+ if (self.x <= 0 || self.x >= 2048) {
+ self.speedX *= -1;
+ }
+ if (self.y <= 0) {
+ self.speedY *= -1;
+ }
+ };
});
// Brick class
var Brick = Container.expand(function () {
- var self = Container.call(this);
- var brickGraphics = self.attachAsset('brick', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.width = brickGraphics.width;
- self.height = brickGraphics.height;
- self.update = function () {
- // Brick update logic if needed
- };
+ var self = Container.call(this);
+ var brickGraphics = self.attachAsset('brick', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.width = brickGraphics.width;
+ self.height = brickGraphics.height;
+ self.update = function () {
+ // Brick update logic if needed
+ };
});
//<Assets used in the game will automatically appear here>
// Paddle class
var Paddle = Container.expand(function () {
- var self = Container.call(this);
- var paddleGraphics = self.attachAsset('paddle', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.width = paddleGraphics.width;
- self.height = paddleGraphics.height;
- self.update = function () {
- // Paddle update logic if needed
- };
+ var self = Container.call(this);
+ var paddleGraphics = self.attachAsset('paddle', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.width = paddleGraphics.width;
+ self.height = paddleGraphics.height;
+ self.update = function () {
+ // Paddle update logic if needed
+ };
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000 //Init game with black background
+ backgroundColor: 0x000000 //Init game with black background
});
-/****
+/****
* Game Code
-****/
+****/
// Initialize paddle
var paddle = game.addChild(new Paddle());
paddle.x = 2048 / 2;
paddle.y = 2500;
@@ -77,36 +77,38 @@
var brickWidth = 200;
var brickHeight = 50;
var padding = 10;
for (var r = 0; r < rows; r++) {
- for (var c = 0; c < cols; c++) {
- var brick = new Brick();
- brick.x = c * (brickWidth + padding) + brickWidth / 2 + padding;
- brick.y = r * (brickHeight + padding) + brickHeight / 2 + padding;
- bricks.push(brick);
- game.addChild(brick);
- }
+ for (var c = 0; c < cols; c++) {
+ var brick = new Brick();
+ brick.x = c * (brickWidth + padding) + brickWidth / 2 + padding;
+ brick.y = r * (brickHeight + padding) + brickHeight / 2 + padding;
+ bricks.push(brick);
+ game.addChild(brick);
+ }
}
// Handle paddle movement
game.move = function (x, y, obj) {
- paddle.x = x;
+ paddle.x = x;
};
// Update game logic
game.update = function () {
- ball.update();
- paddle.update();
- for (var i = 0; i < bricks.length; i++) {
- bricks[i].update();
- if (ball.intersects(bricks[i])) {
- ball.speedY *= -1;
- bricks[i].destroy();
- bricks.splice(i, 1);
- break;
- }
- }
- if (ball.intersects(paddle)) {
- ball.speedY *= -1;
- }
- if (ball.y > 2732) {
- LK.showGameOver();
- }
+ ball.update();
+ paddle.update();
+ for (var i = 0; i < bricks.length; i++) {
+ bricks[i].update();
+ if (ball.intersects(bricks[i])) {
+ ball.speedY *= -1;
+ bricks[i].destroy();
+ bricks.splice(i, 1);
+ break;
+ }
+ }
+ if (ball.intersects(paddle)) {
+ ball.speedY *= -1;
+ }
+ if (ball.y > 2732 || bricks.length == 0) {
+ ball.speedX *= 1.2;
+ ball.speedY *= 1.2;
+ LK.showGameOver();
+ }
};
\ No newline at end of file