/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1", { highScore: 0, totalBalls: 10 }); /**** * Classes ****/ var Ball = Container.expand(function () { var self = Container.call(this); var ballGraphics = self.attachAsset('ball', { anchorX: 0.5, anchorY: 0.5 }); self.velocity = { x: 0, y: 0 }; self.gravity = 2.0; self.friction = 0.98; self.restitution = 0.7; self.active = true; self.update = function () { if (!self.active) { return; } // Apply gravity self.velocity.y += self.gravity; // Apply velocity self.x += self.velocity.x; self.y += self.velocity.y; // Apply friction self.velocity.x *= self.friction; self.velocity.y *= self.friction; // Check boundaries if (self.x < ballGraphics.width / 2) { self.x = ballGraphics.width / 2; self.velocity.x *= -self.restitution; } else if (self.x > 2048 - ballGraphics.width / 2) { self.x = 2048 - ballGraphics.width / 2; self.velocity.x *= -self.restitution; } // Check if ball has fallen off screen if (self.y > 2732 + 100) { self.active = false; self.destroy(); } }; self.applyImpulse = function (x, y) { self.velocity.x += x; self.velocity.y += y; }; return self; }); var Cup = Container.expand(function (isJackpot, value) { var self = Container.call(this); var assetId = isJackpot ? 'jackpotCup' : 'cup'; var cupGraphics = self.attachAsset(assetId, { anchorX: 0.5, anchorY: 0 }); self.isJackpot = isJackpot || false; self.value = value || 10; var pointsText = new Text2(self.value.toString(), { size: 30, fill: 0xFFFFFF }); pointsText.anchor.set(0.5, 0.5); pointsText.x = 0; pointsText.y = cupGraphics.height / 2; self.addChild(pointsText); self.width = cupGraphics.width; self.checkCollision = function (ball) { var ballRadius = ball.getChildAt(0).width / 2; // Check if ball is inside cup if (ball.y + ballRadius > self.y && ball.y - ballRadius < self.y + cupGraphics.height && ball.x > self.x - cupGraphics.width / 2 + ballRadius && ball.x < self.x + cupGraphics.width / 2 - ballRadius) { // Center the ball in the cup ball.x = self.x; ball.y = self.y + ballRadius; // Stop ball movement ball.velocity.x = 0; ball.velocity.y = 0; ball.active = false; // Play sound if (self.isJackpot) { LK.getSound('jackpot').play(); } else { LK.getSound('score').play(); } // Play cup collision sound LK.getSound('ball_hit').play(); // Visual feedback LK.effects.flashObject(self, 0xFFFF00, 500); tween(ball, { alpha: 0 }, { duration: 1000, onFinish: function onFinish() { ball.destroy(); } }); return true; } return false; }; return self; }); var Launcher = Container.expand(function () { var self = Container.call(this); var launcherGraphics = self.attachAsset('launcher', { anchorX: 0.5, anchorY: 0.5 }); self.canLaunch = true; self.down = function (x, y, obj) { if (self.canLaunch && remainingBalls > 0) { self.launchBall(); } }; self.launchBall = function () { if (!self.canLaunch || remainingBalls <= 0) { return; } // Create a new ball var ball = new Ball(); ball.x = self.x; ball.y = self.y + 40; balls.push(ball); game.addChild(ball); // Apply initial velocity ball.applyImpulse(Math.random() * 4 - 2, 2); // Update UI remainingBalls--; updateUI(); // Cooldown period self.canLaunch = false; tween(self, { alpha: 0.5 }, { duration: 200, onFinish: function onFinish() { tween(self, { alpha: 1 }, { duration: 200, onFinish: function onFinish() { self.canLaunch = true; } }); } }); }; return self; }); var Peg = Container.expand(function (isMultiplier) { var self = Container.call(this); var assetId = isMultiplier ? 'multiplierPeg' : 'peg'; var pegGraphics = self.attachAsset(assetId, { anchorX: 0.5, anchorY: 0.5 }); self.isMultiplier = isMultiplier || false; self.radius = pegGraphics.width / 2; self.checkCollision = function (ball) { var dx = self.x - ball.x; var dy = self.y - ball.y; var distance = Math.sqrt(dx * dx + dy * dy); var ballRadius = ball.getChildAt(0).width / 2; if (distance < self.radius + ballRadius) { // Calculate collision response var angle = Math.atan2(dy, dx); var speed = Math.sqrt(ball.velocity.x * ball.velocity.x + ball.velocity.y * ball.velocity.y); // Apply impulse in the opposite direction of collision ball.velocity.x = -Math.cos(angle) * speed * ball.restitution; ball.velocity.y = -Math.sin(angle) * speed * ball.restitution; // Ensure ball is outside the peg var overlap = self.radius + ballRadius - distance; ball.x -= Math.cos(angle) * overlap; ball.y -= Math.sin(angle) * overlap; // Play sound LK.getSound('ball_hit').play(); // Visual feedback tween(self, { scaleX: 1.2, scaleY: 1.2 }, { duration: 100, onFinish: function onFinish() { tween(self, { scaleX: 1, scaleY: 1 }, { duration: 100 }); } }); return true; } return false; }; return self; }); var Wall = Container.expand(function () { var self = Container.call(this); var wallGraphics = self.attachAsset('wall', { anchorX: 0.5, anchorY: 0.5 }); self.checkCollision = function (ball) { var ballRadius = ball.getChildAt(0).width / 2; var halfWidth = wallGraphics.width / 2; var halfHeight = wallGraphics.height / 2; // Check if ball is colliding with wall if (ball.x + ballRadius > self.x - halfWidth && ball.x - ballRadius < self.x + halfWidth && ball.y + ballRadius > self.y - halfHeight && ball.y - ballRadius < self.y + halfHeight) { // Determine which side the collision occurred on var dx = (ball.x - self.x) / halfWidth; var dy = (ball.y - self.y) / halfHeight; if (Math.abs(dx) > Math.abs(dy)) { // Horizontal collision ball.velocity.x *= -ball.restitution; ball.x = self.x + (halfWidth + ballRadius) * Math.sign(dx); } else { // Vertical collision ball.velocity.y *= -ball.restitution; ball.y = self.y + (halfHeight + ballRadius) * Math.sign(dy); } // Play sound LK.getSound('ball_hit').play(); return true; } return false; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x2F4F4F }); /**** * Game Code ****/ // Game variables var balls = []; var pegs = []; var cups = []; var walls = []; var score = 0; var remainingBalls = 10; var highScore = storage.highScore || 0; var launcher; // UI elements var scoreTxt; var ballsTxt; var highScoreTxt; // Initialize game elements function initializeGame() { // Add background image var background = LK.getAsset('backgroundImage', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 }); game.addChild(background); // Start automatic horizontal movement for the launcher startLauncherMovement(); // Play background music LK.playMusic('bg_music'); // Create launcher launcher = new Launcher(); launcher.x = 2048 / 2; launcher.y = 100; game.addChild(launcher); // Create pegs createPegs(); // Create cups createCups(); // Removed wall creation logic // Create UI createUI(); } function createPegs() { // Create grid of pegs var pegSpacingX = 130; var pegSpacingY = 130; var startX = 300; var startY = 350; var rows = 8; var cols = 12; for (var row = 0; row < rows; row++) { for (var col = 0; col < cols; col++) { // Offset odd rows var offsetX = row % 2 === 0 ? 0 : pegSpacingX / 2; var x = startX + col * pegSpacingX + offsetX; var y = startY + row * pegSpacingY; // Ensure peg is within bounds and add some randomness to layout if (x >= 150 && x <= 2048 - 150) { // Randomly make some pegs multiplier pegs (more valuable) var isMultiplier = Math.random() < 0.15; var peg = new Peg(isMultiplier); peg.x = x; peg.y = y; pegs.push(peg); game.addChild(peg); } } } } function createCups() { var cupSpacingX = 180; var startX = 200; var y = 2400; var numCups = 10; for (var i = 0; i < numCups; i++) { var x = startX + i * cupSpacingX; // Make some cups jackpot cups var isJackpot = i === 2 || i === 7; var value = isJackpot ? 50 : 10; var cup = new Cup(isJackpot, value); cup.x = x; cup.y = y; cups.push(cup); game.addChild(cup); } } // Removed wall creation logic function createUI() { // Score text scoreTxt = new Text2('Score: 0', { size: 60, fill: 0xFFFFFF }); scoreTxt.anchor.set(0, 0); LK.gui.topRight.addChild(scoreTxt); scoreTxt.x = -250; scoreTxt.y = 30; // Balls text ballsTxt = new Text2('Balls: ' + remainingBalls, { size: 60, fill: 0xFFFFFF }); ballsTxt.anchor.set(0.5, 0); LK.gui.top.addChild(ballsTxt); ballsTxt.y = 30; // High score text highScoreTxt = new Text2('High Score: ' + highScore, { size: 40, fill: 0xFFFFFF }); highScoreTxt.anchor.set(0, 0); LK.gui.topRight.addChild(highScoreTxt); highScoreTxt.x = -250; highScoreTxt.y = 100; } function updateUI() { scoreTxt.setText('Score: ' + score); ballsTxt.setText('Balls: ' + remainingBalls); highScoreTxt.setText('High Score: ' + highScore); } function addPoints(value) { score += value; LK.setScore(score); if (score > highScore) { highScore = score; storage.highScore = highScore; } updateUI(); } function checkGameOver() { if (remainingBalls <= 0 && balls.length === 0) { // Game over if no balls left and none in play LK.showGameOver(); } } // Function to start automatic horizontal movement for the launcher function startLauncherMovement() { var direction = 1; // 1 for right, -1 for left var speed = 2; // Speed of movement LK.setInterval(function () { // Move launcher launcher.x += direction * speed; // Check boundaries and change direction if needed if (launcher.x >= 2048 - 100 || launcher.x <= 100) { direction *= -1; // Reverse direction } }, 16); // Approximately 60 FPS } // Initialize the game initializeGame(); // Game update loop game.update = function () { // Process each active ball for (var i = balls.length - 1; i >= 0; i--) { var ball = balls[i]; if (!ball.active) { balls.splice(i, 1); continue; } // Check collisions with pegs var hitMultiplier = false; for (var j = 0; j < pegs.length; j++) { var collided = pegs[j].checkCollision(ball); if (collided && pegs[j].isMultiplier) { hitMultiplier = true; } } // Removed wall collision checks // Check collisions with cups for (var m = 0; m < cups.length; m++) { var scoredInCup = cups[m].checkCollision(ball); if (scoredInCup) { var pointValue = cups[m].value; // Apply multiplier if ball hit a multiplier peg if (hitMultiplier) { pointValue *= 2; LK.effects.flashScreen(0xFFFF00, 300); // Flash for multiplier effect } addPoints(pointValue); break; } } } // Check if game is over checkGameOver(); }; // Handle user clicks on game area game.down = function (x, y, obj) { // If the launcher can launch and there are remaining balls if (launcher.canLaunch && remainingBalls > 0) { // Move launcher to tap position (within limits) launcher.x = Math.max(200, Math.min(2048 - 200, x)); // Launch a ball launcher.launchBall(); } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
highScore: 0,
totalBalls: 10
});
/****
* Classes
****/
var Ball = Container.expand(function () {
var self = Container.call(this);
var ballGraphics = self.attachAsset('ball', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocity = {
x: 0,
y: 0
};
self.gravity = 2.0;
self.friction = 0.98;
self.restitution = 0.7;
self.active = true;
self.update = function () {
if (!self.active) {
return;
}
// Apply gravity
self.velocity.y += self.gravity;
// Apply velocity
self.x += self.velocity.x;
self.y += self.velocity.y;
// Apply friction
self.velocity.x *= self.friction;
self.velocity.y *= self.friction;
// Check boundaries
if (self.x < ballGraphics.width / 2) {
self.x = ballGraphics.width / 2;
self.velocity.x *= -self.restitution;
} else if (self.x > 2048 - ballGraphics.width / 2) {
self.x = 2048 - ballGraphics.width / 2;
self.velocity.x *= -self.restitution;
}
// Check if ball has fallen off screen
if (self.y > 2732 + 100) {
self.active = false;
self.destroy();
}
};
self.applyImpulse = function (x, y) {
self.velocity.x += x;
self.velocity.y += y;
};
return self;
});
var Cup = Container.expand(function (isJackpot, value) {
var self = Container.call(this);
var assetId = isJackpot ? 'jackpotCup' : 'cup';
var cupGraphics = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0
});
self.isJackpot = isJackpot || false;
self.value = value || 10;
var pointsText = new Text2(self.value.toString(), {
size: 30,
fill: 0xFFFFFF
});
pointsText.anchor.set(0.5, 0.5);
pointsText.x = 0;
pointsText.y = cupGraphics.height / 2;
self.addChild(pointsText);
self.width = cupGraphics.width;
self.checkCollision = function (ball) {
var ballRadius = ball.getChildAt(0).width / 2;
// Check if ball is inside cup
if (ball.y + ballRadius > self.y && ball.y - ballRadius < self.y + cupGraphics.height && ball.x > self.x - cupGraphics.width / 2 + ballRadius && ball.x < self.x + cupGraphics.width / 2 - ballRadius) {
// Center the ball in the cup
ball.x = self.x;
ball.y = self.y + ballRadius;
// Stop ball movement
ball.velocity.x = 0;
ball.velocity.y = 0;
ball.active = false;
// Play sound
if (self.isJackpot) {
LK.getSound('jackpot').play();
} else {
LK.getSound('score').play();
}
// Play cup collision sound
LK.getSound('ball_hit').play();
// Visual feedback
LK.effects.flashObject(self, 0xFFFF00, 500);
tween(ball, {
alpha: 0
}, {
duration: 1000,
onFinish: function onFinish() {
ball.destroy();
}
});
return true;
}
return false;
};
return self;
});
var Launcher = Container.expand(function () {
var self = Container.call(this);
var launcherGraphics = self.attachAsset('launcher', {
anchorX: 0.5,
anchorY: 0.5
});
self.canLaunch = true;
self.down = function (x, y, obj) {
if (self.canLaunch && remainingBalls > 0) {
self.launchBall();
}
};
self.launchBall = function () {
if (!self.canLaunch || remainingBalls <= 0) {
return;
}
// Create a new ball
var ball = new Ball();
ball.x = self.x;
ball.y = self.y + 40;
balls.push(ball);
game.addChild(ball);
// Apply initial velocity
ball.applyImpulse(Math.random() * 4 - 2, 2);
// Update UI
remainingBalls--;
updateUI();
// Cooldown period
self.canLaunch = false;
tween(self, {
alpha: 0.5
}, {
duration: 200,
onFinish: function onFinish() {
tween(self, {
alpha: 1
}, {
duration: 200,
onFinish: function onFinish() {
self.canLaunch = true;
}
});
}
});
};
return self;
});
var Peg = Container.expand(function (isMultiplier) {
var self = Container.call(this);
var assetId = isMultiplier ? 'multiplierPeg' : 'peg';
var pegGraphics = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5
});
self.isMultiplier = isMultiplier || false;
self.radius = pegGraphics.width / 2;
self.checkCollision = function (ball) {
var dx = self.x - ball.x;
var dy = self.y - ball.y;
var distance = Math.sqrt(dx * dx + dy * dy);
var ballRadius = ball.getChildAt(0).width / 2;
if (distance < self.radius + ballRadius) {
// Calculate collision response
var angle = Math.atan2(dy, dx);
var speed = Math.sqrt(ball.velocity.x * ball.velocity.x + ball.velocity.y * ball.velocity.y);
// Apply impulse in the opposite direction of collision
ball.velocity.x = -Math.cos(angle) * speed * ball.restitution;
ball.velocity.y = -Math.sin(angle) * speed * ball.restitution;
// Ensure ball is outside the peg
var overlap = self.radius + ballRadius - distance;
ball.x -= Math.cos(angle) * overlap;
ball.y -= Math.sin(angle) * overlap;
// Play sound
LK.getSound('ball_hit').play();
// Visual feedback
tween(self, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 100,
onFinish: function onFinish() {
tween(self, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
}
});
return true;
}
return false;
};
return self;
});
var Wall = Container.expand(function () {
var self = Container.call(this);
var wallGraphics = self.attachAsset('wall', {
anchorX: 0.5,
anchorY: 0.5
});
self.checkCollision = function (ball) {
var ballRadius = ball.getChildAt(0).width / 2;
var halfWidth = wallGraphics.width / 2;
var halfHeight = wallGraphics.height / 2;
// Check if ball is colliding with wall
if (ball.x + ballRadius > self.x - halfWidth && ball.x - ballRadius < self.x + halfWidth && ball.y + ballRadius > self.y - halfHeight && ball.y - ballRadius < self.y + halfHeight) {
// Determine which side the collision occurred on
var dx = (ball.x - self.x) / halfWidth;
var dy = (ball.y - self.y) / halfHeight;
if (Math.abs(dx) > Math.abs(dy)) {
// Horizontal collision
ball.velocity.x *= -ball.restitution;
ball.x = self.x + (halfWidth + ballRadius) * Math.sign(dx);
} else {
// Vertical collision
ball.velocity.y *= -ball.restitution;
ball.y = self.y + (halfHeight + ballRadius) * Math.sign(dy);
}
// Play sound
LK.getSound('ball_hit').play();
return true;
}
return false;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2F4F4F
});
/****
* Game Code
****/
// Game variables
var balls = [];
var pegs = [];
var cups = [];
var walls = [];
var score = 0;
var remainingBalls = 10;
var highScore = storage.highScore || 0;
var launcher;
// UI elements
var scoreTxt;
var ballsTxt;
var highScoreTxt;
// Initialize game elements
function initializeGame() {
// Add background image
var background = LK.getAsset('backgroundImage', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
game.addChild(background);
// Start automatic horizontal movement for the launcher
startLauncherMovement();
// Play background music
LK.playMusic('bg_music');
// Create launcher
launcher = new Launcher();
launcher.x = 2048 / 2;
launcher.y = 100;
game.addChild(launcher);
// Create pegs
createPegs();
// Create cups
createCups();
// Removed wall creation logic
// Create UI
createUI();
}
function createPegs() {
// Create grid of pegs
var pegSpacingX = 130;
var pegSpacingY = 130;
var startX = 300;
var startY = 350;
var rows = 8;
var cols = 12;
for (var row = 0; row < rows; row++) {
for (var col = 0; col < cols; col++) {
// Offset odd rows
var offsetX = row % 2 === 0 ? 0 : pegSpacingX / 2;
var x = startX + col * pegSpacingX + offsetX;
var y = startY + row * pegSpacingY;
// Ensure peg is within bounds and add some randomness to layout
if (x >= 150 && x <= 2048 - 150) {
// Randomly make some pegs multiplier pegs (more valuable)
var isMultiplier = Math.random() < 0.15;
var peg = new Peg(isMultiplier);
peg.x = x;
peg.y = y;
pegs.push(peg);
game.addChild(peg);
}
}
}
}
function createCups() {
var cupSpacingX = 180;
var startX = 200;
var y = 2400;
var numCups = 10;
for (var i = 0; i < numCups; i++) {
var x = startX + i * cupSpacingX;
// Make some cups jackpot cups
var isJackpot = i === 2 || i === 7;
var value = isJackpot ? 50 : 10;
var cup = new Cup(isJackpot, value);
cup.x = x;
cup.y = y;
cups.push(cup);
game.addChild(cup);
}
}
// Removed wall creation logic
function createUI() {
// Score text
scoreTxt = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0, 0);
LK.gui.topRight.addChild(scoreTxt);
scoreTxt.x = -250;
scoreTxt.y = 30;
// Balls text
ballsTxt = new Text2('Balls: ' + remainingBalls, {
size: 60,
fill: 0xFFFFFF
});
ballsTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(ballsTxt);
ballsTxt.y = 30;
// High score text
highScoreTxt = new Text2('High Score: ' + highScore, {
size: 40,
fill: 0xFFFFFF
});
highScoreTxt.anchor.set(0, 0);
LK.gui.topRight.addChild(highScoreTxt);
highScoreTxt.x = -250;
highScoreTxt.y = 100;
}
function updateUI() {
scoreTxt.setText('Score: ' + score);
ballsTxt.setText('Balls: ' + remainingBalls);
highScoreTxt.setText('High Score: ' + highScore);
}
function addPoints(value) {
score += value;
LK.setScore(score);
if (score > highScore) {
highScore = score;
storage.highScore = highScore;
}
updateUI();
}
function checkGameOver() {
if (remainingBalls <= 0 && balls.length === 0) {
// Game over if no balls left and none in play
LK.showGameOver();
}
}
// Function to start automatic horizontal movement for the launcher
function startLauncherMovement() {
var direction = 1; // 1 for right, -1 for left
var speed = 2; // Speed of movement
LK.setInterval(function () {
// Move launcher
launcher.x += direction * speed;
// Check boundaries and change direction if needed
if (launcher.x >= 2048 - 100 || launcher.x <= 100) {
direction *= -1; // Reverse direction
}
}, 16); // Approximately 60 FPS
}
// Initialize the game
initializeGame();
// Game update loop
game.update = function () {
// Process each active ball
for (var i = balls.length - 1; i >= 0; i--) {
var ball = balls[i];
if (!ball.active) {
balls.splice(i, 1);
continue;
}
// Check collisions with pegs
var hitMultiplier = false;
for (var j = 0; j < pegs.length; j++) {
var collided = pegs[j].checkCollision(ball);
if (collided && pegs[j].isMultiplier) {
hitMultiplier = true;
}
}
// Removed wall collision checks
// Check collisions with cups
for (var m = 0; m < cups.length; m++) {
var scoredInCup = cups[m].checkCollision(ball);
if (scoredInCup) {
var pointValue = cups[m].value;
// Apply multiplier if ball hit a multiplier peg
if (hitMultiplier) {
pointValue *= 2;
LK.effects.flashScreen(0xFFFF00, 300); // Flash for multiplier effect
}
addPoints(pointValue);
break;
}
}
}
// Check if game is over
checkGameOver();
};
// Handle user clicks on game area
game.down = function (x, y, obj) {
// If the launcher can launch and there are remaining balls
if (launcher.canLaunch && remainingBalls > 0) {
// Move launcher to tap position (within limits)
launcher.x = Math.max(200, Math.min(2048 - 200, x));
// Launch a ball
launcher.launchBall();
}
};
clown face. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
circus ball. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
silver coin with clown image. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
circus tent png image. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
8 bit colorfull image about anime image of circus tent at city field. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
8 bit anime image delecious burger. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
wraped candy classic. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows