User prompt
improve balls physics
User prompt
can you arrange bricks in a better display, make sure thee is space between them
User prompt
also bounce on the bottom, and remove game over
User prompt
balls should bounce on the screen walls
User prompt
if ball destoys a brick it should still bounce of
User prompt
ball should bounce off of briks
User prompt
ball should bounce off off wals
User prompt
arrange brick better in the screen
User prompt
remove game over condition
User prompt
On tap, destroy a brick do not spawn more balls
Initial prompt
Idel Breakout
/**** * Classes ****/ //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Ball class representing the ball that breaks bricks var Ball = Container.expand(function () { var self = Container.call(this); var ballGraphics = self.attachAsset('ball', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.direction = { x: 1, y: -1 }; self.update = function () { self.x += self.speed * self.direction.x; self.y += self.speed * self.direction.y; // Bounce off walls if (self.x <= 0 || self.x >= 2048) { self.direction.x *= -1; } if (self.y <= 0) { self.direction.y *= -1; } }; }); // Brick class representing the bricks to be broken var Brick = Container.expand(function () { var self = Container.call(this); var brickGraphics = self.attachAsset('brick', { anchorX: 0.5, anchorY: 0.5 }); self.health = 1; self.hit = function () { self.health -= 1; if (self.health <= 0) { self.destroy(); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize game variables var balls = []; var bricks = []; var score = 0; // Create and position bricks function createBricks() { for (var i = 0; i < 5; i++) { for (var j = 0; j < 10; j++) { var brick = new Brick(); brick.x = 200 + j * 150; brick.y = 100 + i * 100; bricks.push(brick); game.addChild(brick); } } } // Create a new ball function createBall() { var ball = new Ball(); ball.x = 1024; ball.y = 2000; balls.push(ball); game.addChild(ball); } // Handle game updates game.update = function () { // Update balls for (var i = balls.length - 1; i >= 0; i--) { var ball = balls[i]; ball.update(); // Check for collisions with bricks for (var j = bricks.length - 1; j >= 0; j--) { var brick = bricks[j]; if (ball.intersects(brick)) { brick.hit(); ball.direction.y *= -1; score += 10; } } // Remove ball if it goes off screen if (ball.y > 2732) { ball.destroy(); balls.splice(i, 1); } } // Check for game over if (balls.length === 0) { LK.showGameOver(); } }; // Handle screen tap to launch a new ball game.down = function (x, y, obj) { // No new balls are created on screen tap }; // Initialize game elements createBricks(); createBall();
===================================================================
--- original.js
+++ change.js
@@ -1,112 +1,112 @@
-/****
+/****
* Classes
-****/
+****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Ball class representing the ball that breaks bricks
var Ball = Container.expand(function () {
- var self = Container.call(this);
- var ballGraphics = self.attachAsset('ball', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 5;
- self.direction = {
- x: 1,
- y: -1
- };
- self.update = function () {
- self.x += self.speed * self.direction.x;
- self.y += self.speed * self.direction.y;
- // Bounce off walls
- if (self.x <= 0 || self.x >= 2048) {
- self.direction.x *= -1;
- }
- if (self.y <= 0) {
- self.direction.y *= -1;
- }
- };
+ var self = Container.call(this);
+ var ballGraphics = self.attachAsset('ball', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 5;
+ self.direction = {
+ x: 1,
+ y: -1
+ };
+ self.update = function () {
+ self.x += self.speed * self.direction.x;
+ self.y += self.speed * self.direction.y;
+ // Bounce off walls
+ if (self.x <= 0 || self.x >= 2048) {
+ self.direction.x *= -1;
+ }
+ if (self.y <= 0) {
+ self.direction.y *= -1;
+ }
+ };
});
// Brick class representing the bricks to be broken
var Brick = Container.expand(function () {
- var self = Container.call(this);
- var brickGraphics = self.attachAsset('brick', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.health = 1;
- self.hit = function () {
- self.health -= 1;
- if (self.health <= 0) {
- self.destroy();
- }
- };
+ var self = Container.call(this);
+ var brickGraphics = self.attachAsset('brick', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.health = 1;
+ self.hit = function () {
+ self.health -= 1;
+ if (self.health <= 0) {
+ self.destroy();
+ }
+ };
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000 //Init game with black background
+ backgroundColor: 0x000000 //Init game with black background
});
-/****
+/****
* Game Code
-****/
+****/
// Initialize game variables
var balls = [];
var bricks = [];
var score = 0;
// Create and position bricks
function createBricks() {
- for (var i = 0; i < 5; i++) {
- for (var j = 0; j < 10; j++) {
- var brick = new Brick();
- brick.x = 200 + j * 150;
- brick.y = 100 + i * 100;
- bricks.push(brick);
- game.addChild(brick);
- }
- }
+ for (var i = 0; i < 5; i++) {
+ for (var j = 0; j < 10; j++) {
+ var brick = new Brick();
+ brick.x = 200 + j * 150;
+ brick.y = 100 + i * 100;
+ bricks.push(brick);
+ game.addChild(brick);
+ }
+ }
}
// Create a new ball
function createBall() {
- var ball = new Ball();
- ball.x = 1024;
- ball.y = 2000;
- balls.push(ball);
- game.addChild(ball);
+ var ball = new Ball();
+ ball.x = 1024;
+ ball.y = 2000;
+ balls.push(ball);
+ game.addChild(ball);
}
// Handle game updates
game.update = function () {
- // Update balls
- for (var i = balls.length - 1; i >= 0; i--) {
- var ball = balls[i];
- ball.update();
- // Check for collisions with bricks
- for (var j = bricks.length - 1; j >= 0; j--) {
- var brick = bricks[j];
- if (ball.intersects(brick)) {
- brick.hit();
- ball.direction.y *= -1;
- score += 10;
- }
- }
- // Remove ball if it goes off screen
- if (ball.y > 2732) {
- ball.destroy();
- balls.splice(i, 1);
- }
- }
- // Check for game over
- if (balls.length === 0) {
- LK.showGameOver();
- }
+ // Update balls
+ for (var i = balls.length - 1; i >= 0; i--) {
+ var ball = balls[i];
+ ball.update();
+ // Check for collisions with bricks
+ for (var j = bricks.length - 1; j >= 0; j--) {
+ var brick = bricks[j];
+ if (ball.intersects(brick)) {
+ brick.hit();
+ ball.direction.y *= -1;
+ score += 10;
+ }
+ }
+ // Remove ball if it goes off screen
+ if (ball.y > 2732) {
+ ball.destroy();
+ balls.splice(i, 1);
+ }
+ }
+ // Check for game over
+ if (balls.length === 0) {
+ LK.showGameOver();
+ }
};
// Handle screen tap to launch a new ball
game.down = function (x, y, obj) {
- createBall();
+ // No new balls are created on screen tap
};
// Initialize game elements
createBricks();
createBall();
\ No newline at end of file