/****
* Classes
****/
// AnimatedBlast class
var AnimatedBlast = Container.expand(function () {
var self = Container.call(this);
// Create 10 smaller balls
for (var i = 0; i < 10; i++) {
var smallBall = self.attachAsset('ball', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.2,
scaleY: 0.2
});
smallBall.x = Math.random() * 100 - 50;
smallBall.y = Math.random() * 100 - 50;
smallBall.angle = Math.random() * Math.PI * 2; // Add an angle for the revolving animation
smallBall.distance = Math.sqrt(smallBall.x * smallBall.x + smallBall.y * smallBall.y); // Calculate the distance from the center
}
self.timer = 0; // Add a timer for the animation
self.update = function () {
// Animate the smaller balls
for (var i = 0; i < self.children.length; i++) {
var smallBall = self.children[i];
smallBall.angle += 0.1; // Increase the angle to create the revolving animation
smallBall.x = smallBall.distance * Math.cos(smallBall.angle);
smallBall.y = smallBall.distance * Math.sin(smallBall.angle);
smallBall.alpha -= 0.01;
if (smallBall.alpha <= 0) {
self.removeChild(smallBall);
}
}
self.timer++;
// Destroy the blast after 3 seconds
if (self.timer >= 180) {
self.destroy();
}
};
});
//<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 () {
// Add gravity to the ball
self.speedY += 0.2;
self.x += self.speedX;
self.y += self.speedY;
if (self.x <= 0 || self.x >= 2048) {
self.speedX *= -1;
}
if (self.y <= 0 || self.y >= 2732) {
self.speedY *= -1;
}
};
});
// Bumper class
var Bumper = Container.expand(function () {
var self = Container.call(this);
var bumperGraphics = self.attachAsset('bumper', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Bumper logic if needed
};
});
// LifeDisplay class
var LifeDisplay = Container.expand(function () {
var self = Container.call(this);
// Create 3 balls for the lives
for (var i = 0; i < 3; i++) {
var lifeBall = self.attachAsset('ball', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.2,
scaleY: 0.2
});
lifeBall.x = i * 50;
}
self.update = function () {
// Update the life display based on the current lives
for (var i = 0; i < self.children.length; i++) {
self.children[i].visible = i < game.lives;
}
};
});
// Paddle class
var Paddle = Container.expand(function () {
var self = Container.call(this);
var paddleGraphics = self.attachAsset('paddle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3
});
self.update = function () {
// Paddle movement logic will be handled in the game move event
};
});
// PinballBoard class
var PinballBoard = Container.expand(function () {
var self = Container.call(this);
// The board will be a simple rectangle for now
var boardGraphics = self.attachAsset('board', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Board logic if needed
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize game elements
var board = game.addChild(new PinballBoard());
board.x = 1024;
board.y = 1366;
var paddle = game.addChild(new Paddle());
paddle.x = 1024;
paddle.y = 2500;
var ball = game.addChild(new Ball());
ball.x = paddle.x;
ball.y = paddle.y - paddle.height / 2 - ball.height / 2;
// Initialize the lives and the life display
game.lives = 3;
var lifeDisplay = LK.gui.top.addChild(new LifeDisplay());
lifeDisplay.x = 50;
lifeDisplay.y = 50;
// Initialize the lives and the life display
game.lives = 3;
var lifeDisplay = LK.gui.top.addChild(new LifeDisplay());
lifeDisplay.x = 50;
lifeDisplay.y = 50;
var bumpers = [];
for (var i = 0; i < 5; i++) {
var bumper = game.addChild(new Bumper());
bumper.x = Math.random() * 2048;
bumper.y = Math.random() * 1500 + 500;
bumpers.push(bumper);
}
// Create a new Text2 object for the score display
var scoreTxt = new Text2('P:0', {
size: 50,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Handle paddle movement
game.move = function (x, y, obj) {
paddle.x = x;
};
// Check for collisions
function checkCollisions() {
if (ball.intersects(paddle)) {
ball.speedY = -Math.random() * 25 - 25;
ball.speedX += (Math.random() - 0.5) * 10; // Add a slight angle difference in the bounce back
} else if (ball.y > paddle.y) {
// The ball has fallen below the paddle
game.lives--;
if (game.lives > 0) {
// Re-launch the ball from the paddle
ball.x = paddle.x;
ball.y = paddle.y - paddle.height / 2 - ball.height / 2;
ball.speedX = 20; // Increase the horizontal speed
ball.speedY = -20; // Increase the vertical speed
} else {
// Game over
LK.showGameOver();
}
}
for (var i = 0; i < bumpers.length; i++) {
if (ball.intersects(bumpers[i])) {
ball.speedX *= -1;
ball.speedY *= -1;
// Play the bumper sound
LK.getSound('bumperSound').play();
// Generate the animated blast
var blast = game.addChild(new AnimatedBlast());
blast.x = bumpers[i].x;
blast.y = bumpers[i].y;
// Increase the score and update the score display
LK.setScore(LK.getScore() + 50);
scoreTxt.setText('P:' + LK.getScore());
}
}
}
// Update game state
game.update = function () {
ball.update();
paddle.update();
for (var i = 0; i < bumpers.length; i++) {
bumpers[i].update();
}
checkCollisions();
}; /****
* Classes
****/
// AnimatedBlast class
var AnimatedBlast = Container.expand(function () {
var self = Container.call(this);
// Create 10 smaller balls
for (var i = 0; i < 10; i++) {
var smallBall = self.attachAsset('ball', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.2,
scaleY: 0.2
});
smallBall.x = Math.random() * 100 - 50;
smallBall.y = Math.random() * 100 - 50;
smallBall.angle = Math.random() * Math.PI * 2; // Add an angle for the revolving animation
smallBall.distance = Math.sqrt(smallBall.x * smallBall.x + smallBall.y * smallBall.y); // Calculate the distance from the center
}
self.timer = 0; // Add a timer for the animation
self.update = function () {
// Animate the smaller balls
for (var i = 0; i < self.children.length; i++) {
var smallBall = self.children[i];
smallBall.angle += 0.1; // Increase the angle to create the revolving animation
smallBall.x = smallBall.distance * Math.cos(smallBall.angle);
smallBall.y = smallBall.distance * Math.sin(smallBall.angle);
smallBall.alpha -= 0.01;
if (smallBall.alpha <= 0) {
self.removeChild(smallBall);
}
}
self.timer++;
// Destroy the blast after 3 seconds
if (self.timer >= 180) {
self.destroy();
}
};
});
//<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 () {
// Add gravity to the ball
self.speedY += 0.2;
self.x += self.speedX;
self.y += self.speedY;
if (self.x <= 0 || self.x >= 2048) {
self.speedX *= -1;
}
if (self.y <= 0 || self.y >= 2732) {
self.speedY *= -1;
}
};
});
// Bumper class
var Bumper = Container.expand(function () {
var self = Container.call(this);
var bumperGraphics = self.attachAsset('bumper', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Bumper logic if needed
};
});
// LifeDisplay class
var LifeDisplay = Container.expand(function () {
var self = Container.call(this);
// Create 3 balls for the lives
for (var i = 0; i < 3; i++) {
var lifeBall = self.attachAsset('ball', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.2,
scaleY: 0.2
});
lifeBall.x = i * 50;
}
self.update = function () {
// Update the life display based on the current lives
for (var i = 0; i < self.children.length; i++) {
self.children[i].visible = i < game.lives;
}
};
});
// Paddle class
var Paddle = Container.expand(function () {
var self = Container.call(this);
var paddleGraphics = self.attachAsset('paddle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3
});
self.update = function () {
// Paddle movement logic will be handled in the game move event
};
});
// PinballBoard class
var PinballBoard = Container.expand(function () {
var self = Container.call(this);
// The board will be a simple rectangle for now
var boardGraphics = self.attachAsset('board', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Board logic if needed
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize game elements
var board = game.addChild(new PinballBoard());
board.x = 1024;
board.y = 1366;
var paddle = game.addChild(new Paddle());
paddle.x = 1024;
paddle.y = 2500;
var ball = game.addChild(new Ball());
ball.x = paddle.x;
ball.y = paddle.y - paddle.height / 2 - ball.height / 2;
// Initialize the lives and the life display
game.lives = 3;
var lifeDisplay = LK.gui.top.addChild(new LifeDisplay());
lifeDisplay.x = 50;
lifeDisplay.y = 50;
// Initialize the lives and the life display
game.lives = 3;
var lifeDisplay = LK.gui.top.addChild(new LifeDisplay());
lifeDisplay.x = 50;
lifeDisplay.y = 50;
var bumpers = [];
for (var i = 0; i < 5; i++) {
var bumper = game.addChild(new Bumper());
bumper.x = Math.random() * 2048;
bumper.y = Math.random() * 1500 + 500;
bumpers.push(bumper);
}
// Create a new Text2 object for the score display
var scoreTxt = new Text2('P:0', {
size: 50,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Handle paddle movement
game.move = function (x, y, obj) {
paddle.x = x;
};
// Check for collisions
function checkCollisions() {
if (ball.intersects(paddle)) {
ball.speedY = -Math.random() * 25 - 25;
ball.speedX += (Math.random() - 0.5) * 10; // Add a slight angle difference in the bounce back
} else if (ball.y > paddle.y) {
// The ball has fallen below the paddle
game.lives--;
if (game.lives > 0) {
// Re-launch the ball from the paddle
ball.x = paddle.x;
ball.y = paddle.y - paddle.height / 2 - ball.height / 2;
ball.speedX = 20; // Increase the horizontal speed
ball.speedY = -20; // Increase the vertical speed
} else {
// Game over
LK.showGameOver();
}
}
for (var i = 0; i < bumpers.length; i++) {
if (ball.intersects(bumpers[i])) {
ball.speedX *= -1;
ball.speedY *= -1;
// Play the bumper sound
LK.getSound('bumperSound').play();
// Generate the animated blast
var blast = game.addChild(new AnimatedBlast());
blast.x = bumpers[i].x;
blast.y = bumpers[i].y;
// Increase the score and update the score display
LK.setScore(LK.getScore() + 50);
scoreTxt.setText('P:' + LK.getScore());
}
}
}
// Update game state
game.update = function () {
ball.update();
paddle.update();
for (var i = 0; i < bumpers.length; i++) {
bumpers[i].update();
}
checkCollisions();
};
Pin ball game background with counter for mega points in futuristic style with clear blocks for rewards points for the pin ball physics in the game. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
metal ball in 3D. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
metal bumber with golden shine. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.