User prompt
When you lose the game, get an effect.
User prompt
Don't lose sight of the ball when it goes to the sidelines.
User prompt
Make a noise, even when you're breaking bricks. Let there be noise when you lose.
User prompt
The ball just can't get off the stage. If the ball goes down, the game is lost.
User prompt
Right now the ball can go out of bounds. But I don't want it to go out of bounds.
User prompt
Change the game completely.
User prompt
Change the game's colour tone to green.
Remix started
Copy Flap & Float
/**** * Classes ****/ var Ball = Container.expand(function () { var self = Container.call(this); var ballGraphics = self.attachAsset('ball', { anchorX: 0.5, anchorY: 0.5 }); self.radius = ballGraphics.width / 2; self.xSpeed = 0; self.ySpeed = 0; self.lastX = 0; self.lastY = 0; self.update = function () { self.lastX = self.x; self.lastY = self.y; self.x += self.xSpeed; self.y += self.ySpeed; }; return self; }); 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; return self; }); 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.moveTo = function (x) { // Clamp paddle within game bounds var halfWidth = self.width / 2; if (x < halfWidth) x = halfWidth; if (x > 2048 - halfWidth) x = 2048 - halfWidth; self.x = x; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ game.score = 0; var paddle = game.addChild(new Paddle()); paddle.x = 1024; paddle.y = 2600; var ball = game.addChild(new Ball()); ball.x = 1024; ball.y = 2500; ball.xSpeed = 12; ball.ySpeed = -18; var bricks = []; var brickRows = 5; var brickCols = 8; var brickSpacingX = 30; var brickSpacingY = 30; var brickStartY = 300; var brickStartX = 120; for (var row = 0; row < brickRows; row++) { for (var col = 0; col < brickCols; col++) { var brick = game.addChild(new Brick()); brick.x = brickStartX + col * (brick.width + brickSpacingX); brick.y = brickStartY + row * (brick.height + brickSpacingY); bricks.push(brick); } } var scoreText = new Text2('0', { size: 150, fill: '#1e90ff', font: 'Impact', dropShadow: true, dropShadowColor: '#003366', dropShadowBlur: 5, dropShadowDistance: 7, dropShadowAngle: 0 }); scoreText.anchor.set(.5, 0); LK.gui.top.addChild(scoreText); game.isDragging = false; game.down = function (x, y, obj) { // Start dragging paddle if touch is near paddle if (Math.abs(y - paddle.y) < 200) { game.isDragging = true; paddle.moveTo(x); } }; game.up = function (x, y, obj) { game.isDragging = false; }; game.move = function (x, y, obj) { if (game.isDragging) { paddle.moveTo(x); } }; game.update = function () { // Move ball ball.update(); // Wall collision (left/right) if (ball.x - ball.radius <= 0 && ball.lastX - ball.radius > 0) { ball.x = ball.radius; ball.xSpeed = -ball.xSpeed; LK.getSound('hitPaddle').play(); } if (ball.x + ball.radius >= 2048 && ball.lastX + ball.radius < 2048) { ball.x = 2048 - ball.radius; ball.xSpeed = -ball.xSpeed; LK.getSound('hitPaddle').play(); } // Ceiling collision if (ball.y - ball.radius <= 0 && ball.lastY - ball.radius > 0) { ball.y = ball.radius; ball.ySpeed = -ball.ySpeed; LK.getSound('hitPaddle').play(); } // Paddle collision (only if moving down) if (ball.ySpeed > 0 && ball.y + ball.radius >= paddle.y - paddle.height / 2 && ball.lastY + ball.radius < paddle.y - paddle.height / 2 && ball.x > paddle.x - paddle.width / 2 && ball.x < paddle.x + paddle.width / 2) { ball.y = paddle.y - paddle.height / 2 - ball.radius; ball.ySpeed = -Math.abs(ball.ySpeed); // Add some xSpeed based on where it hit the paddle var hitPos = (ball.x - paddle.x) / (paddle.width / 2); ball.xSpeed += hitPos * 6; LK.getSound('hitPaddle').play(); } // Brick collision for (var i = bricks.length - 1; i >= 0; i--) { var brick = bricks[i]; if (ball.x + ball.radius > brick.x - brick.width / 2 && ball.x - ball.radius < brick.x + brick.width / 2 && ball.y + ball.radius > brick.y - brick.height / 2 && ball.y - ball.radius < brick.y + brick.height / 2) { // Simple collision: reverse ySpeed if (ball.lastY + ball.radius <= brick.y - brick.height / 2 && ball.y + ball.radius > brick.y - brick.height / 2 || ball.lastY - ball.radius >= brick.y + brick.height / 2 && ball.y - ball.radius < brick.y + brick.height / 2) { ball.ySpeed = -ball.ySpeed; } else { ball.xSpeed = -ball.xSpeed; } brick.destroy(); bricks.splice(i, 1); game.score += 1; LK.setScore(game.score); scoreText.setText(game.score); LK.getSound('hitBrick').play(); break; } } // Lose condition if (ball.y - ball.radius > 2732) { LK.setScore(game.score); LK.getSound('gameOverJingle').play(); LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } // Win condition if (bricks.length === 0) { LK.setScore(game.score); LK.showYouWin(); } };
===================================================================
--- original.js
+++ change.js
@@ -117,15 +117,13 @@
if (ball.x - ball.radius <= 0 && ball.lastX - ball.radius > 0) {
ball.x = ball.radius;
ball.xSpeed = -ball.xSpeed;
LK.getSound('hitPaddle').play();
- LK.effects.flashScreen(0x1e90ff, 200); // Flash blue when hitting left wall
}
if (ball.x + ball.radius >= 2048 && ball.lastX + ball.radius < 2048) {
ball.x = 2048 - ball.radius;
ball.xSpeed = -ball.xSpeed;
LK.getSound('hitPaddle').play();
- LK.effects.flashScreen(0x1e90ff, 200); // Flash blue when hitting right wall
}
// Ceiling collision
if (ball.y - ball.radius <= 0 && ball.lastY - ball.radius > 0) {
ball.y = ball.radius;
@@ -163,8 +161,9 @@
// Lose condition
if (ball.y - ball.radius > 2732) {
LK.setScore(game.score);
LK.getSound('gameOverJingle').play();
+ LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
// Win condition
if (bricks.length === 0) {