User prompt
When setting score text also update LK.setScore
User prompt
Make ball move twice as fast
User prompt
Increase the bounce angle of the ball by 2x
User prompt
Make output angle of ball depend on where on the paddle the ball hits
User prompt
Pass I+j to new brick
User prompt
Fix Bug: 'ReferenceError: Can't find variable: i' in this line: 'brickGraphics.tint = colors[i % colors.length];' Line Number: 30
User prompt
Fix Bug: 'ReferenceError: Can't find variable: j' in this line: 'brickGraphics.tint = colors[j % colors.length];' Line Number: 30
User prompt
Color the bricks such that it has a rainbow edge t
User prompt
Only allow paddle bounce if the ball is moving towards the paddle
User prompt
Move down all bricks by the height of one block
User prompt
Make ball twice as fast
User prompt
Make background even darker blue
User prompt
Make background dark blue
User prompt
Use a distance of 3 blocks from the top rather than 5
User prompt
Only use bright colors for the brick colors
User prompt
Move down bricks by 5x the height of a brick
User prompt
All XS.assets have their center point in the middle of the asset. This results in the current center logic for bricks being off by half the width of a brick. Please fix this
User prompt
Calculate the fill width of the brick area. Then use that to center the bricks on the screen
User prompt
Make paddle always follow the mouse
User prompt
Make ball bounce of of walls
User prompt
Use tint to give tiles random colors
User prompt
Progress the development of the game.
Initial prompt
Progress the development of the game.
/**** * Classes ****/ var Ball = Container.expand(function () { var self = Container.call(this); var ballGraphics = LK.getAsset('ball', { anchorX: 0.5, anchorY: 0.5 }); self.addChild(ballGraphics); self.speed = { x: 20, y: -20 }; self.move = function () { self.x += self.speed.x; self.y += self.speed.y; if (self.x < 0 || self.x > 2048) { self.speed.x *= -1; } }; }); var Paddle = Container.expand(function () { var self = Container.call(this); var paddleGraphics = LK.getAsset('paddle', { anchorX: 0.5, anchorY: 0.5 }); self.addChild(paddleGraphics); self.speed = 5; self.move = function (pos) { self.x = pos.x; }; }); var Brick = Container.expand(function (i) { var self = Container.call(this); var brickGraphics = LK.getAsset('brick', { anchorX: 0.5, anchorY: 0.5 }); var colors = [0xFF0000, 0xFF7F00, 0xFFFF00, 0x00FF00, 0x0000FF, 0x4B0082, 0x8B00FF]; brickGraphics.tint = colors[i % colors.length]; self.addChild(brickGraphics); }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ game.setBackgroundColor(0x000040); var ball = game.addChild(new Ball()); var paddle = game.addChild(new Paddle()); var bricks = []; var score = 0; var scoreText = new Text2('0', { size: 150, fill: '#ffffff' }); scoreText.anchor.set(.5, 0); LK.gui.topCenter.addChild(scoreText); ball.x = 2048 / 2; ball.y = 2732 / 2; paddle.x = 2048 / 2; paddle.y = 2732 - paddle.height; var brickRows = 10; var brickColumns = 5; var brickAreaWidth = brickRows * new Brick().width; var brickAreaStartX = (2048 - brickAreaWidth) / 2; for (var i = 0; i < brickRows; i++) { for (var j = 0; j < brickColumns; j++) { var brick = game.addChild(new Brick(i + j)); brick.x = brickAreaStartX + i * brick.width + brick.width / 2; brick.y = j * brick.height + brick.height / 2 + 4 * brick.height; bricks.push(brick); } } LK.on('tick', function () { ball.move(); if (ball.intersects(paddle) && ball.speed.y > 0) { var hitPos = (ball.x - paddle.x) / paddle.width; ball.speed.x = hitPos * 20; ball.speed.y *= -1; } if (ball.y < 0) { ball.speed.y *= -1; } for (var i = 0; i < bricks.length; i++) { if (ball.intersects(bricks[i])) { ball.speed.y *= -1; bricks[i].destroy(); bricks.splice(i, 1); i--; score++; LK.setScore(score); scoreText.setText(score.toString()); } } if (ball.y > 2732 || bricks.length === 0) { LK.showGameOver(); } }); game.on('move', function (obj) { var pos = obj.event.getLocalPosition(game); paddle.move(pos); });
===================================================================
--- original.js
+++ change.js
@@ -1,7 +1,13 @@
+/****
+* Classes
+****/
var Ball = Container.expand(function () {
var self = Container.call(this);
- var ballGraphics = XS.getAsset('ball', 'Ball Graphics', .5, .5);
+ var ballGraphics = LK.getAsset('ball', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
self.addChild(ballGraphics);
self.speed = {
x: 20,
y: -20
@@ -15,76 +21,91 @@
};
});
var Paddle = Container.expand(function () {
var self = Container.call(this);
- var paddleGraphics = XS.getAsset('paddle', 'Paddle Graphics', .5, .5);
+ var paddleGraphics = LK.getAsset('paddle', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
self.addChild(paddleGraphics);
self.speed = 5;
self.move = function (pos) {
self.x = pos.x;
};
});
var Brick = Container.expand(function (i) {
var self = Container.call(this);
- var brickGraphics = XS.getAsset('brick', 'Brick Graphics', .5, .5);
+ var brickGraphics = LK.getAsset('brick', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
var colors = [0xFF0000, 0xFF7F00, 0xFFFF00, 0x00FF00, 0x0000FF, 0x4B0082, 0x8B00FF];
brickGraphics.tint = colors[i % colors.length];
self.addChild(brickGraphics);
});
-var Game = Container.expand(function () {
- var self = Container.call(this);
- XS.stageContainer.setBackgroundColor(0x000040);
- var ball = self.addChild(new Ball());
- var paddle = self.addChild(new Paddle());
- var bricks = [];
- var score = 0;
- var scoreText = new Text2('0', {
- size: 150,
- fill: '#ffffff'
- });
- scoreText.anchor.set(.5, 0);
- XS.gui.topCenter.addChild(scoreText);
- ball.x = 2048 / 2;
- ball.y = 2732 / 2;
- paddle.x = 2048 / 2;
- paddle.y = 2732 - paddle.height;
- var brickRows = 10;
- var brickColumns = 5;
- var brickAreaWidth = brickRows * new Brick().width;
- var brickAreaStartX = (2048 - brickAreaWidth) / 2;
- for (var i = 0; i < brickRows; i++) {
- for (var j = 0; j < brickColumns; j++) {
- var brick = self.addChild(new Brick(i + j));
- brick.x = brickAreaStartX + i * brick.width + brick.width / 2;
- brick.y = j * brick.height + brick.height / 2 + 4 * brick.height;
- bricks.push(brick);
- }
+
+/****
+* Initialize Game
+****/
+var game = new LK.Game({
+ backgroundColor: 0x000000
+});
+
+/****
+* Game Code
+****/
+game.setBackgroundColor(0x000040);
+var ball = game.addChild(new Ball());
+var paddle = game.addChild(new Paddle());
+var bricks = [];
+var score = 0;
+var scoreText = new Text2('0', {
+ size: 150,
+ fill: '#ffffff'
+});
+scoreText.anchor.set(.5, 0);
+LK.gui.topCenter.addChild(scoreText);
+ball.x = 2048 / 2;
+ball.y = 2732 / 2;
+paddle.x = 2048 / 2;
+paddle.y = 2732 - paddle.height;
+var brickRows = 10;
+var brickColumns = 5;
+var brickAreaWidth = brickRows * new Brick().width;
+var brickAreaStartX = (2048 - brickAreaWidth) / 2;
+for (var i = 0; i < brickRows; i++) {
+ for (var j = 0; j < brickColumns; j++) {
+ var brick = game.addChild(new Brick(i + j));
+ brick.x = brickAreaStartX + i * brick.width + brick.width / 2;
+ brick.y = j * brick.height + brick.height / 2 + 4 * brick.height;
+ bricks.push(brick);
}
- XS.on('tick', function () {
- ball.move();
- if (ball.intersects(paddle) && ball.speed.y > 0) {
- var hitPos = (ball.x - paddle.x) / paddle.width;
- ball.speed.x = hitPos * 20;
+}
+LK.on('tick', function () {
+ ball.move();
+ if (ball.intersects(paddle) && ball.speed.y > 0) {
+ var hitPos = (ball.x - paddle.x) / paddle.width;
+ ball.speed.x = hitPos * 20;
+ ball.speed.y *= -1;
+ }
+ if (ball.y < 0) {
+ ball.speed.y *= -1;
+ }
+ for (var i = 0; i < bricks.length; i++) {
+ if (ball.intersects(bricks[i])) {
ball.speed.y *= -1;
+ bricks[i].destroy();
+ bricks.splice(i, 1);
+ i--;
+ score++;
+ LK.setScore(score);
+ scoreText.setText(score.toString());
}
- if (ball.y < 0) {
- ball.speed.y *= -1;
- }
- for (var i = 0; i < bricks.length; i++) {
- if (ball.intersects(bricks[i])) {
- ball.speed.y *= -1;
- bricks[i].destroy();
- bricks.splice(i, 1);
- i--;
- score++;
- scoreText.setText(score.toString());
- }
- }
- if (ball.y > 2732 || bricks.length === 0) {
- XS.showGameOver();
- }
- });
- stage.on('move', function (obj) {
- var pos = obj.event.getLocalPosition(self);
- paddle.move(pos);
- });
+ }
+ if (ball.y > 2732 || bricks.length === 0) {
+ LK.showGameOver();
+ }
});
+game.on('move', function (obj) {
+ var pos = obj.event.getLocalPosition(game);
+ paddle.move(pos);
+});
\ No newline at end of file