/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var AutoClickerFinger = Container.expand(function () {
var self = Container.call(this);
var fingerGraphics = self.attachAsset('autoClickerFinger', {
anchorX: 0.5,
anchorY: 1
});
self.clickTimer = 0;
self.clickInterval = 600; // 10 seconds at 60fps
self.update = function () {
self.clickTimer++;
if (self.clickTimer >= self.clickInterval) {
self.clickTimer = 0;
// Trigger auto click
if (typeof autoClickBall === 'function') {
autoClickBall();
}
}
};
return self;
});
var Basket = Container.expand(function () {
var self = Container.call(this);
var basketGraphics = self.attachAsset('basket', {
anchorX: 0.5,
anchorY: 0.5
});
self.direction = 1;
self.baseSpeed = 5;
self.speedMultiplier = 1;
self.update = function () {
self.x += self.direction * self.baseSpeed * self.speedMultiplier;
if (self.x <= 90 || self.x >= 2048 - 90) {
self.direction *= -1;
}
};
return self;
});
var Capsule = Container.expand(function () {
var self = Container.call(this);
var capsuleGraphics = self.attachAsset('capsule', {
anchorX: 0.5,
anchorY: 1
});
var capsuleBottom = self.attachAsset('capsuleBottom', {
anchorX: 0.5,
anchorY: 0
});
capsuleBottom.y = 0;
self.addChild(capsuleBottom);
self.maxCoins = 10;
self.currentCoins = 0;
self.isOpening = false;
self.collectTimer = 0;
self.addCoin = function () {
if (self.currentCoins < self.maxCoins && !self.isOpening) {
self.currentCoins++;
// Visual feedback for coin collection
tween(capsuleGraphics, {
scaleX: 1.1,
scaleY: 1.05
}, {
duration: 150,
onFinish: function onFinish() {
tween(capsuleGraphics, {
scaleX: 1,
scaleY: 1
}, {
duration: 150
});
}
});
if (self.currentCoins >= self.maxCoins) {
self.emptyCapsule();
}
return true;
}
return false;
};
self.emptyCapsule = function () {
if (self.isOpening) return;
self.isOpening = true;
// Animate bottom opening
tween(capsuleBottom, {
y: 30,
alpha: 0.3
}, {
duration: 300,
onFinish: function onFinish() {
// Reset after emptying
self.currentCoins = 0;
self.isOpening = false;
// Increase basket speed
basket.speedMultiplier += 0.3;
tween(capsuleBottom, {
y: 0,
alpha: 1
}, {
duration: 200
});
}
});
// Add breaking effect
tween(capsuleGraphics, {
scaleX: 1.2,
scaleY: 0.9
}, {
duration: 200,
onFinish: function onFinish() {
tween(capsuleGraphics, {
scaleX: 1,
scaleY: 1
}, {
duration: 200
});
}
});
};
return self;
});
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.fallSpeed = 8 + Math.random() * 4;
self.collected = false;
self.swayDirection = Math.random() > 0.5 ? 1 : -1;
self.swaySpeed = 0.5 + Math.random() * 1;
self.swayAmount = 20 + Math.random() * 30;
self.rotationSpeed = (Math.random() - 0.5) * 0.1;
self.startX = 0;
self.swayTime = 0;
self.update = function () {
if (!self.collected) {
self.y += self.fallSpeed;
}
};
return self;
});
var UpgradeButton = Container.expand(function (text, cost) {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('upgradeButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.buttonText = new Text2(text + '\n' + cost + ' coins', {
size: 24,
fill: 0xFFFFFF
});
self.buttonText.anchor.set(0.5, 0.5);
self.addChild(self.buttonText);
self.cost = cost;
self.upgradeText = text;
self.updateButton = function (newCost) {
self.cost = newCost;
self.buttonText.setText(self.upgradeText + '\n' + self.cost + ' coins');
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb
});
/****
* Game Code
****/
// Game variables
var clickCount = 0;
var coinCount = 0;
var autoClickerLevel = 0;
var basketSpeedLevel = 0;
var coins = [];
var autoClickerFingers = [];
// Create central ball
var centralBall = game.addChild(LK.getAsset('centralBall', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 3
}));
// Create counter text above basket
var counterText = new Text2('0', {
size: 48,
fill: 0x000000
});
counterText.anchor.set(0.5, 1);
game.addChild(counterText);
// Create basket
var basket = game.addChild(new Basket());
basket.x = 2048 / 2;
basket.y = 2732 - 150;
basket.speedMultiplier = 1 + basketSpeedLevel * 0.5;
// Create capsule above basket
var capsule = game.addChild(new Capsule());
capsule.x = basket.x;
capsule.y = basket.y - 120;
// Position counter text above basket
counterText.x = basket.x;
counterText.y = basket.y - 50;
// Create coin counter display below basket
var coinDisplay = new Text2('Coins: ' + coinCount, {
size: 36,
fill: 0x000000
});
coinDisplay.anchor.set(0.5, 0);
coinDisplay.x = basket.x;
coinDisplay.y = basket.y + 50;
game.addChild(coinDisplay);
// Upgrade buttons removed
// Create auto-clicker fingers based on saved level
for (var i = 0; i < autoClickerLevel; i++) {
var finger = game.addChild(new AutoClickerFinger());
// Position fingers in a circle around the central ball
var angle = i / Math.max(1, autoClickerLevel) * 2 * Math.PI;
var radius = 150;
finger.x = centralBall.x + Math.cos(angle) * radius;
finger.y = centralBall.y + Math.sin(angle) * radius;
autoClickerFingers.push(finger);
}
// Auto click function
function autoClickBall() {
clickCount++;
counterText.setText(clickCount.toString());
// Create coin drop
createCoinDrop();
// Play sound
LK.getSound('ballClick').play();
// Visual feedback
tween(centralBall, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 100,
onFinish: function onFinish() {
tween(centralBall, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
}
});
// Animate all auto-clicker fingers
for (var f = 0; f < autoClickerFingers.length; f++) {
var finger = autoClickerFingers[f];
tween(finger, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 150,
onFinish: function onFinish() {
tween(finger, {
scaleX: 1,
scaleY: 1
}, {
duration: 150
});
}
});
}
}
// Create falling coin
function createCoinDrop() {
var coin = new Coin();
coin.x = Math.random() * (2048 - 100) + 50;
coin.startX = coin.x; // Store starting position for sway physics
coin.y = -50;
coins.push(coin);
game.addChild(coin);
}
// Ball click handler
centralBall.down = function (x, y, obj) {
clickCount++;
counterText.setText(clickCount.toString());
// Create coin drop
createCoinDrop();
// Play sound
LK.getSound('ballClick').play();
// Visual feedback
tween(centralBall, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 100,
onFinish: function onFinish() {
tween(centralBall, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
}
});
};
// Main game update loop
game.update = function () {
// Update coins
for (var i = coins.length - 1; i >= 0; i--) {
var coin = coins[i];
if (coin.lastY === undefined) coin.lastY = coin.y;
// Check if coin fell off screen
if (coin.lastY <= 2732 && coin.y > 2732) {
coin.destroy();
coins.splice(i, 1);
continue;
}
// Check collision with capsule first
if (!coin.collected && coin.intersects(capsule)) {
coin.collected = true;
if (capsule.addCoin()) {
// Play sound
LK.getSound('coinCollect').play();
// If capsule is full, add coins to count
if (capsule.currentCoins >= capsule.maxCoins || capsule.isOpening) {
coinCount += capsule.maxCoins;
coinDisplay.setText('Coins: ' + coinCount);
}
}
// Remove coin
coin.destroy();
coins.splice(i, 1);
continue;
}
// Check collision with basket (fallback)
if (!coin.collected && coin.intersects(basket)) {
coin.collected = true;
coinCount++;
coinDisplay.setText('Coins: ' + coinCount);
// Play sound
LK.getSound('coinCollect').play();
// Remove coin
coin.destroy();
coins.splice(i, 1);
continue;
}
coin.lastY = coin.y;
}
// Update capsule position to follow basket
capsule.x = basket.x;
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var AutoClickerFinger = Container.expand(function () {
var self = Container.call(this);
var fingerGraphics = self.attachAsset('autoClickerFinger', {
anchorX: 0.5,
anchorY: 1
});
self.clickTimer = 0;
self.clickInterval = 600; // 10 seconds at 60fps
self.update = function () {
self.clickTimer++;
if (self.clickTimer >= self.clickInterval) {
self.clickTimer = 0;
// Trigger auto click
if (typeof autoClickBall === 'function') {
autoClickBall();
}
}
};
return self;
});
var Basket = Container.expand(function () {
var self = Container.call(this);
var basketGraphics = self.attachAsset('basket', {
anchorX: 0.5,
anchorY: 0.5
});
self.direction = 1;
self.baseSpeed = 5;
self.speedMultiplier = 1;
self.update = function () {
self.x += self.direction * self.baseSpeed * self.speedMultiplier;
if (self.x <= 90 || self.x >= 2048 - 90) {
self.direction *= -1;
}
};
return self;
});
var Capsule = Container.expand(function () {
var self = Container.call(this);
var capsuleGraphics = self.attachAsset('capsule', {
anchorX: 0.5,
anchorY: 1
});
var capsuleBottom = self.attachAsset('capsuleBottom', {
anchorX: 0.5,
anchorY: 0
});
capsuleBottom.y = 0;
self.addChild(capsuleBottom);
self.maxCoins = 10;
self.currentCoins = 0;
self.isOpening = false;
self.collectTimer = 0;
self.addCoin = function () {
if (self.currentCoins < self.maxCoins && !self.isOpening) {
self.currentCoins++;
// Visual feedback for coin collection
tween(capsuleGraphics, {
scaleX: 1.1,
scaleY: 1.05
}, {
duration: 150,
onFinish: function onFinish() {
tween(capsuleGraphics, {
scaleX: 1,
scaleY: 1
}, {
duration: 150
});
}
});
if (self.currentCoins >= self.maxCoins) {
self.emptyCapsule();
}
return true;
}
return false;
};
self.emptyCapsule = function () {
if (self.isOpening) return;
self.isOpening = true;
// Animate bottom opening
tween(capsuleBottom, {
y: 30,
alpha: 0.3
}, {
duration: 300,
onFinish: function onFinish() {
// Reset after emptying
self.currentCoins = 0;
self.isOpening = false;
// Increase basket speed
basket.speedMultiplier += 0.3;
tween(capsuleBottom, {
y: 0,
alpha: 1
}, {
duration: 200
});
}
});
// Add breaking effect
tween(capsuleGraphics, {
scaleX: 1.2,
scaleY: 0.9
}, {
duration: 200,
onFinish: function onFinish() {
tween(capsuleGraphics, {
scaleX: 1,
scaleY: 1
}, {
duration: 200
});
}
});
};
return self;
});
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.fallSpeed = 8 + Math.random() * 4;
self.collected = false;
self.swayDirection = Math.random() > 0.5 ? 1 : -1;
self.swaySpeed = 0.5 + Math.random() * 1;
self.swayAmount = 20 + Math.random() * 30;
self.rotationSpeed = (Math.random() - 0.5) * 0.1;
self.startX = 0;
self.swayTime = 0;
self.update = function () {
if (!self.collected) {
self.y += self.fallSpeed;
}
};
return self;
});
var UpgradeButton = Container.expand(function (text, cost) {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('upgradeButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.buttonText = new Text2(text + '\n' + cost + ' coins', {
size: 24,
fill: 0xFFFFFF
});
self.buttonText.anchor.set(0.5, 0.5);
self.addChild(self.buttonText);
self.cost = cost;
self.upgradeText = text;
self.updateButton = function (newCost) {
self.cost = newCost;
self.buttonText.setText(self.upgradeText + '\n' + self.cost + ' coins');
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb
});
/****
* Game Code
****/
// Game variables
var clickCount = 0;
var coinCount = 0;
var autoClickerLevel = 0;
var basketSpeedLevel = 0;
var coins = [];
var autoClickerFingers = [];
// Create central ball
var centralBall = game.addChild(LK.getAsset('centralBall', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 3
}));
// Create counter text above basket
var counterText = new Text2('0', {
size: 48,
fill: 0x000000
});
counterText.anchor.set(0.5, 1);
game.addChild(counterText);
// Create basket
var basket = game.addChild(new Basket());
basket.x = 2048 / 2;
basket.y = 2732 - 150;
basket.speedMultiplier = 1 + basketSpeedLevel * 0.5;
// Create capsule above basket
var capsule = game.addChild(new Capsule());
capsule.x = basket.x;
capsule.y = basket.y - 120;
// Position counter text above basket
counterText.x = basket.x;
counterText.y = basket.y - 50;
// Create coin counter display below basket
var coinDisplay = new Text2('Coins: ' + coinCount, {
size: 36,
fill: 0x000000
});
coinDisplay.anchor.set(0.5, 0);
coinDisplay.x = basket.x;
coinDisplay.y = basket.y + 50;
game.addChild(coinDisplay);
// Upgrade buttons removed
// Create auto-clicker fingers based on saved level
for (var i = 0; i < autoClickerLevel; i++) {
var finger = game.addChild(new AutoClickerFinger());
// Position fingers in a circle around the central ball
var angle = i / Math.max(1, autoClickerLevel) * 2 * Math.PI;
var radius = 150;
finger.x = centralBall.x + Math.cos(angle) * radius;
finger.y = centralBall.y + Math.sin(angle) * radius;
autoClickerFingers.push(finger);
}
// Auto click function
function autoClickBall() {
clickCount++;
counterText.setText(clickCount.toString());
// Create coin drop
createCoinDrop();
// Play sound
LK.getSound('ballClick').play();
// Visual feedback
tween(centralBall, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 100,
onFinish: function onFinish() {
tween(centralBall, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
}
});
// Animate all auto-clicker fingers
for (var f = 0; f < autoClickerFingers.length; f++) {
var finger = autoClickerFingers[f];
tween(finger, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 150,
onFinish: function onFinish() {
tween(finger, {
scaleX: 1,
scaleY: 1
}, {
duration: 150
});
}
});
}
}
// Create falling coin
function createCoinDrop() {
var coin = new Coin();
coin.x = Math.random() * (2048 - 100) + 50;
coin.startX = coin.x; // Store starting position for sway physics
coin.y = -50;
coins.push(coin);
game.addChild(coin);
}
// Ball click handler
centralBall.down = function (x, y, obj) {
clickCount++;
counterText.setText(clickCount.toString());
// Create coin drop
createCoinDrop();
// Play sound
LK.getSound('ballClick').play();
// Visual feedback
tween(centralBall, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 100,
onFinish: function onFinish() {
tween(centralBall, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
}
});
};
// Main game update loop
game.update = function () {
// Update coins
for (var i = coins.length - 1; i >= 0; i--) {
var coin = coins[i];
if (coin.lastY === undefined) coin.lastY = coin.y;
// Check if coin fell off screen
if (coin.lastY <= 2732 && coin.y > 2732) {
coin.destroy();
coins.splice(i, 1);
continue;
}
// Check collision with capsule first
if (!coin.collected && coin.intersects(capsule)) {
coin.collected = true;
if (capsule.addCoin()) {
// Play sound
LK.getSound('coinCollect').play();
// If capsule is full, add coins to count
if (capsule.currentCoins >= capsule.maxCoins || capsule.isOpening) {
coinCount += capsule.maxCoins;
coinDisplay.setText('Coins: ' + coinCount);
}
}
// Remove coin
coin.destroy();
coins.splice(i, 1);
continue;
}
// Check collision with basket (fallback)
if (!coin.collected && coin.intersects(basket)) {
coin.collected = true;
coinCount++;
coinDisplay.setText('Coins: ' + coinCount);
// Play sound
LK.getSound('coinCollect').play();
// Remove coin
coin.destroy();
coins.splice(i, 1);
continue;
}
coin.lastY = coin.y;
}
// Update capsule position to follow basket
capsule.x = basket.x;
};