/****
* Classes
****/
//<Assets used in the game will automatically appear here>
// Ball class
var Ball = Container.expand(function () {
var self = Container.call(this);
var ballGraphics = self.attachAsset('ball', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = 5;
self.speedY = -5;
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
// Bounce off 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.hit = function () {
// Logic for when a brick is hit
self.destroy();
};
});
// Paddle class
var Paddle = Container.expand(function () {
var self = Container.call(this);
var paddleGraphics = self.attachAsset('paddle', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Paddle movement logic can be added here
};
});
// Score Text class
var ScoreText = Text2.expand(function () {
var self = Text2.call(this);
self = new Text2('0', {
size: 150,
fill: "#FFFFFF",
backgroundColor: "rgb(255, 255, 255)"
});
self.update = function () {
self.setText(score);
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize game elements
var ball = game.addChild(new Ball());
var score = 0;
ball.x = 1024; // Center horizontally
ball.y = 2000; // Start near the bottom
// Add the score text to the game
var scoreText = LK.gui.top.addChild(new ScoreText());
scoreText.anchor.set(0.5, 0); // Center the score text horizontally
// Add the name PRASHANTH to the game
var nameText = new Text2('PRASHANTH', {
size: 150,
fill: "#FFFFFF",
backgroundColor: "rgb(255, 255, 255)"
});
nameText.anchor.set(0.5, 0); // Center the name text horizontally
LK.gui.top.addChild(nameText);
var paddle = game.addChild(new Paddle());
paddle.x = 1024; // Center horizontally
paddle.y = 2500; // Position near the bottom
var bricks = [];
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);
}
}
// Game update loop
game.update = function () {
ball.update();
paddle.update();
// Check for ball-paddle collision
if (ball.intersects(paddle)) {
ball.speedY *= -1;
}
// Check for ball-brick collision
for (var i = bricks.length - 1; i >= 0; i--) {
if (ball.intersects(bricks[i])) {
ball.speedY *= -1;
bricks[i].hit();
bricks.splice(i, 1);
score += 2;
}
}
// Check if all bricks are destroyed
if (bricks.length == 0) {
for (var i = 0; i < 6; i++) {
for (var j = 0; j < 12; j++) {
var brick = new Brick();
brick.x = 200 + j * 150;
brick.y = 100 + i * 100;
bricks.push(brick);
game.addChild(brick);
}
}
}
// Check for game over
if (ball.y > 2732) {
LK.showGameOver();
}
};
// Paddle control
game.move = function (x, y, obj) {
paddle.x = x;
}; /****
* Classes
****/
//<Assets used in the game will automatically appear here>
// Ball class
var Ball = Container.expand(function () {
var self = Container.call(this);
var ballGraphics = self.attachAsset('ball', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = 5;
self.speedY = -5;
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
// Bounce off 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.hit = function () {
// Logic for when a brick is hit
self.destroy();
};
});
// Paddle class
var Paddle = Container.expand(function () {
var self = Container.call(this);
var paddleGraphics = self.attachAsset('paddle', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Paddle movement logic can be added here
};
});
// Score Text class
var ScoreText = Text2.expand(function () {
var self = Text2.call(this);
self = new Text2('0', {
size: 150,
fill: "#FFFFFF",
backgroundColor: "rgb(255, 255, 255)"
});
self.update = function () {
self.setText(score);
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize game elements
var ball = game.addChild(new Ball());
var score = 0;
ball.x = 1024; // Center horizontally
ball.y = 2000; // Start near the bottom
// Add the score text to the game
var scoreText = LK.gui.top.addChild(new ScoreText());
scoreText.anchor.set(0.5, 0); // Center the score text horizontally
// Add the name PRASHANTH to the game
var nameText = new Text2('PRASHANTH', {
size: 150,
fill: "#FFFFFF",
backgroundColor: "rgb(255, 255, 255)"
});
nameText.anchor.set(0.5, 0); // Center the name text horizontally
LK.gui.top.addChild(nameText);
var paddle = game.addChild(new Paddle());
paddle.x = 1024; // Center horizontally
paddle.y = 2500; // Position near the bottom
var bricks = [];
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);
}
}
// Game update loop
game.update = function () {
ball.update();
paddle.update();
// Check for ball-paddle collision
if (ball.intersects(paddle)) {
ball.speedY *= -1;
}
// Check for ball-brick collision
for (var i = bricks.length - 1; i >= 0; i--) {
if (ball.intersects(bricks[i])) {
ball.speedY *= -1;
bricks[i].hit();
bricks.splice(i, 1);
score += 2;
}
}
// Check if all bricks are destroyed
if (bricks.length == 0) {
for (var i = 0; i < 6; i++) {
for (var j = 0; j < 12; j++) {
var brick = new Brick();
brick.x = 200 + j * 150;
brick.y = 100 + i * 100;
bricks.push(brick);
game.addChild(brick);
}
}
}
// Check for game over
if (ball.y > 2732) {
LK.showGameOver();
}
};
// Paddle control
game.move = function (x, y, obj) {
paddle.x = x;
};