/****
* Classes
****/
// Ball class
var Ball = Container.expand(function () {
var self = Container.call(this);
var ballGraphics = self.attachAsset('ball', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = ballGraphics.width;
self.height = ballGraphics.height;
self.speedX = 5;
self.speedY = 5;
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
// Ball collision with walls
if (self.x <= 0 || self.x >= 2048) {
self.speedX *= -1;
}
// Ball collision with top of the playable area
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.width = brickGraphics.width;
self.height = brickGraphics.height;
self.update = function () {
// Brick update logic if needed
};
});
//<Assets used in the game will automatically appear here>
// Paddle class
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.update = function () {
// Paddle update logic if needed
};
});
/****
* Initialize Game
****/
var game = new LK.Game();
/****
* Game Code
****/
var background = game.attachAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
// Initialize paddle
var paddle = game.addChild(new Paddle());
paddle.x = 2048 / 2;
paddle.y = 2500;
// Initialize ball
var ball = game.addChild(new Ball());
ball.x = 2048 / 2;
ball.y = 2400;
// Initialize bricks
var bricks = [];
var rows = 5;
var cols = 10;
var brickWidth = 150;
var brickHeight = 50;
var padding = 10;
for (var r = 0; r < rows; r++) {
for (var c = 0; c < cols; c++) {
var brick = new Brick();
brick.x = c * ((2048 - padding) / cols) + (2048 - padding) / cols / 2;
brick.y = r * (brickHeight + padding) + brickHeight / 2 + padding;
bricks.push(brick);
game.addChild(brick);
}
}
// Handle paddle movement
var dragNode = null;
game.down = function (x, y, obj) {
if (y > 2000) {
dragNode = paddle;
}
};
game.move = function (x, y, obj) {
if (dragNode) {
dragNode.x = x;
}
};
game.up = function (x, y, obj) {
dragNode = null;
};
// Game update logic
game.update = function () {
ball.update();
paddle.update();
for (var i = 0; i < bricks.length; i++) {
bricks[i].update();
// Ball collision with bricks
if (ball.intersects(bricks[i])) {
ball.speedY *= -1;
bricks[i].destroy();
bricks.splice(i, 1);
i--;
}
}
// Ball collision with paddle
if (ball.intersects(paddle) && ball.speedY > 0) {
ball.speedY *= -1;
}
// Ball out of bounds
if (ball.y > 2732) {
LK.showGameOver();
}
};
Prison cell bars. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Super fat cat with a funny face wearing a prison jumpsuit. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Top down view of a Dirty prison floor. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.