User prompt
Hey Ava, this is excellent. Now make the paddle and the ball three times bigger and make the bricks bigger as well but also remove the amount of them by half.
Code edit (1 edits merged)
Please save this source code
User prompt
Brick Breaker Classic
Initial prompt
create a single-player game where the player controls a paddle at the bottom of the screen to bounce a ball upwards. The objective is to use the ball to break all the colored bricks arranged at the top of the screen, without letting the ball fall past the paddle
/**** * Classes ****/ var Ball = Container.expand(function () { var self = Container.call(this); var ballGraphics = self.attachAsset('ball', { anchorX: 0.5, anchorY: 0.5 }); self.velocityX = 0; self.velocityY = 0; self.update = function () { self.x += self.velocityX; self.y += self.velocityY; }; return self; }); var Brick = Container.expand(function () { var self = Container.call(this); var brickGraphics = self.attachAsset('brick', { anchorX: 0.5, anchorY: 0.5 }); self.setColor = function (color) { brickGraphics.tint = color; }; return self; }); var Paddle = Container.expand(function () { var self = Container.call(this); var paddleGraphics = self.attachAsset('paddle', { anchorX: 0.5, anchorY: 0.5 }); return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ // Game constants var PADDLE_SPEED = 15; var BALL_SPEED = 8; var BRICK_ROWS = 3; var BRICK_COLS = 7; var BRICK_SPACING = 5; // Game variables var paddle; var ball; var bricks = []; var gameStarted = false; var ballLaunched = false; // Score display var scoreTxt = new Text2('0', { size: 80, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Initialize paddle paddle = game.addChild(new Paddle()); paddle.x = 1024; paddle.y = 2400; // Initialize ball ball = game.addChild(new Ball()); ball.x = 1024; ball.y = 2355; // Create bricks var brickColors = [0xff0000, 0xff7700, 0xffff00, 0x00ff00, 0x0077ff, 0x7700ff]; for (var row = 0; row < BRICK_ROWS; row++) { for (var col = 0; col < BRICK_COLS; col++) { var brick = new Brick(); brick.x = 320 + col * (180 + BRICK_SPACING * 2); brick.y = 300 + row * (60 + BRICK_SPACING * 2); brick.setColor(brickColors[row % brickColors.length]); bricks.push(brick); game.addChild(brick); } } // Touch controls var touchX = null; game.down = function (x, y, obj) { touchX = x; if (!ballLaunched) { // Launch ball on first touch ballLaunched = true; ball.velocityX = BALL_SPEED * 0.7; ball.velocityY = -BALL_SPEED; } }; game.move = function (x, y, obj) { if (touchX !== null) { var deltaX = x - touchX; paddle.x += deltaX; // Keep paddle within screen bounds var halfPaddleWidth = 300; if (paddle.x < halfPaddleWidth) { paddle.x = halfPaddleWidth; } else if (paddle.x > 2048 - halfPaddleWidth) { paddle.x = 2048 - halfPaddleWidth; } // Move ball with paddle if not launched if (!ballLaunched) { ball.x = paddle.x; } touchX = x; } }; game.up = function (x, y, obj) { touchX = null; }; // Main game update game.update = function () { if (!ballLaunched) return; // Ball collision with walls if (ball.x <= 30 || ball.x >= 2018) { ball.velocityX = -ball.velocityX; LK.getSound('hit').play(); } // Ball collision with ceiling if (ball.y <= 30) { ball.velocityY = -ball.velocityY; LK.getSound('hit').play(); } // Ball fell off screen if (ball.y > 2732) { LK.showGameOver(); } // Ball collision with paddle if (ball.intersects(paddle) && ball.velocityY > 0) { ball.velocityY = -ball.velocityY; // Add spin based on where ball hits paddle var hitPosition = (ball.x - paddle.x) / 300; ball.velocityX = hitPosition * BALL_SPEED; LK.getSound('hit').play(); } // Ball collision with bricks for (var i = bricks.length - 1; i >= 0; i--) { var brick = bricks[i]; if (ball.intersects(brick)) { // Remove brick brick.destroy(); bricks.splice(i, 1); // Reverse ball direction ball.velocityY = -ball.velocityY; // Update score LK.setScore(LK.getScore() + 10); scoreTxt.setText(LK.getScore()); LK.getSound('break').play(); // Check win condition if (bricks.length === 0) { LK.showYouWin(); } break; } } };
===================================================================
--- original.js
+++ change.js
@@ -47,10 +47,10 @@
****/
// Game constants
var PADDLE_SPEED = 15;
var BALL_SPEED = 8;
-var BRICK_ROWS = 6;
-var BRICK_COLS = 14;
+var BRICK_ROWS = 3;
+var BRICK_COLS = 7;
var BRICK_SPACING = 5;
// Game variables
var paddle;
var ball;
@@ -70,16 +70,16 @@
paddle.y = 2400;
// Initialize ball
ball = game.addChild(new Ball());
ball.x = 1024;
-ball.y = 2370;
+ball.y = 2355;
// Create bricks
var brickColors = [0xff0000, 0xff7700, 0xffff00, 0x00ff00, 0x0077ff, 0x7700ff];
for (var row = 0; row < BRICK_ROWS; row++) {
for (var col = 0; col < BRICK_COLS; col++) {
var brick = new Brick();
- brick.x = 180 + col * (120 + BRICK_SPACING);
- brick.y = 200 + row * (40 + BRICK_SPACING);
+ brick.x = 320 + col * (180 + BRICK_SPACING * 2);
+ brick.y = 300 + row * (60 + BRICK_SPACING * 2);
brick.setColor(brickColors[row % brickColors.length]);
bricks.push(brick);
game.addChild(brick);
}
@@ -99,9 +99,9 @@
if (touchX !== null) {
var deltaX = x - touchX;
paddle.x += deltaX;
// Keep paddle within screen bounds
- var halfPaddleWidth = 100;
+ var halfPaddleWidth = 300;
if (paddle.x < halfPaddleWidth) {
paddle.x = halfPaddleWidth;
} else if (paddle.x > 2048 - halfPaddleWidth) {
paddle.x = 2048 - halfPaddleWidth;
@@ -119,14 +119,14 @@
// Main game update
game.update = function () {
if (!ballLaunched) return;
// Ball collision with walls
- if (ball.x <= 10 || ball.x >= 2038) {
+ if (ball.x <= 30 || ball.x >= 2018) {
ball.velocityX = -ball.velocityX;
LK.getSound('hit').play();
}
// Ball collision with ceiling
- if (ball.y <= 10) {
+ if (ball.y <= 30) {
ball.velocityY = -ball.velocityY;
LK.getSound('hit').play();
}
// Ball fell off screen
@@ -136,9 +136,9 @@
// Ball collision with paddle
if (ball.intersects(paddle) && ball.velocityY > 0) {
ball.velocityY = -ball.velocityY;
// Add spin based on where ball hits paddle
- var hitPosition = (ball.x - paddle.x) / 100;
+ var hitPosition = (ball.x - paddle.x) / 300;
ball.velocityX = hitPosition * BALL_SPEED;
LK.getSound('hit').play();
}
// Ball collision with bricks