/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
clicks: 0,
clickPower: 1,
autoClickersOwned: 0,
clickMultiplierOwned: 0,
superClickerOwned: 0,
megaClickerOwned: 0,
clickingEmpireOwned: 0
});
/****
* Classes
****/
var ClickSquare = Container.expand(function () {
var self = Container.call(this);
var square = self.attachAsset('clickSquare', {
anchorX: 0.5,
anchorY: 0.5
});
self.originalScale = 1;
square.scale.set(self.originalScale);
self.down = function (x, y, obj) {
// Shrink the square when pressed
tween(square.scale, {
x: 0.9,
y: 0.9
}, {
duration: 100
});
// Add clicks based on click power
gameState.clicks += gameState.clickPower;
updateDisplays();
// Play click sound
LK.getSound('click').play();
// Create and animate "+clickPower" text
var clickText = new Text2("+" + gameState.clickPower, {
size: 60,
fill: 0xFFFFFF
});
clickText.anchor.set(0.5, 0.5);
clickText.x = x;
clickText.y = y;
self.addChild(clickText);
// Animate the text floating upward and fading
tween(clickText, {
y: y - 100,
alpha: 0
}, {
duration: 800,
easing: tween.easeOut,
onFinish: function onFinish() {
clickText.destroy();
}
});
};
self.up = function (x, y, obj) {
// Return to original size when released
tween(square.scale, {
x: self.originalScale,
y: self.originalScale
}, {
duration: 100
});
};
// Pulse animation function
self.pulse = function () {
tween(square.scale, {
x: self.originalScale * 1.05,
y: self.originalScale * 1.05
}, {
duration: 500,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(square.scale, {
x: self.originalScale,
y: self.originalScale
}, {
duration: 500,
easing: tween.easeInOut,
onFinish: self.pulse
});
}
});
};
// Start pulsing animation
self.pulse();
return self;
});
var NotificationsTab = Container.expand(function () {
var self = Container.call(this);
var background = self.attachAsset('shopBackground', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.9
});
var titleText = new Text2("Notifications", {
size: 80,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0);
titleText.y = -background.height / 2 + 100;
self.addChild(titleText);
// Close button
var closeBtn = self.attachAsset('closeButton', {
anchorX: 0.5,
anchorY: 0.5,
x: background.width / 2 - 80,
y: -background.height / 2 + 80
});
var closeX = new Text2("X", {
size: 50,
fill: 0xFFFFFF
});
closeX.anchor.set(0.5, 0.5);
closeX.x = closeBtn.x;
closeX.y = closeBtn.y;
self.addChild(closeX);
// Notifications display
self.notificationsText = new Text2("", {
size: 35,
fill: 0xFFFFFF,
wordWrap: true,
wordWrapWidth: 1400
});
self.notificationsText.anchor.set(0.5, 0);
self.notificationsText.y = 0;
self.addChild(self.notificationsText);
// Click handlers for close button
closeBtn.interactive = true;
closeBtn.down = function () {
toggleNotifications(false);
};
self.updateNotifications = function (notifications) {
self.notificationsText.setText(notifications.join("\n"));
};
return self;
});
var ShopButton = Container.expand(function () {
var self = Container.call(this);
var button = self.attachAsset('shopButton', {
anchorX: 0.5,
anchorY: 0.5
});
var buttonText = new Text2("SHOP", {
size: 60,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.down = function (x, y, obj) {
tween(button.scale, {
x: 0.95,
y: 0.95
}, {
duration: 100
});
toggleShop(true);
};
self.up = function (x, y, obj) {
tween(button.scale, {
x: 1,
y: 1
}, {
duration: 100
});
};
return self;
});
var ShopPanel = Container.expand(function () {
var self = Container.call(this);
var background = self.attachAsset('shopBackground', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.9
});
var titleText = new Text2("UPGRADE SHOP", {
size: 80,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0);
titleText.y = -background.height / 2 + 100;
self.addChild(titleText);
// Close button
var closeBtn = self.attachAsset('closeButton', {
anchorX: 0.5,
anchorY: 0.5,
x: background.width / 2 - 80,
y: -background.height / 2 + 80
});
var closeX = new Text2("X", {
size: 50,
fill: 0xFFFFFF
});
closeX.anchor.set(0.5, 0.5);
closeX.x = closeBtn.x;
closeX.y = closeBtn.y;
self.addChild(closeX);
// Create upgrade buttons
self.autoClicker = new UpgradeButton("Auto Clicker", 50, "Automatically clicks once per second");
self.autoClicker.y = -400;
self.addChild(self.autoClicker);
self.clickMultiplier = new UpgradeButton("Click Multiplier", 100, "Increases click power by 1");
self.clickMultiplier.y = -200;
self.addChild(self.clickMultiplier);
self.superClicker = new UpgradeButton("Super Clicker", 500, "Multiplies your click power by 2");
self.superClicker.y = 0;
self.addChild(self.superClicker);
self.megaClicker = new UpgradeButton("Mega Clicker", 20000, "Multiplies your click power by 5");
self.megaClicker.y = 200;
self.addChild(self.megaClicker);
self.clickingEmpire = new UpgradeButton("Clicking Empire", 100000, "The ultimate upgrade - win the game!");
self.clickingEmpire.y = 400;
self.addChild(self.clickingEmpire);
// Description text
self.descriptionText = new Text2("", {
size: 30,
fill: 0xFFFFFF,
wordWrap: true,
wordWrapWidth: 1400
});
self.descriptionText.anchor.set(0.5, 0);
self.descriptionText.y = 400;
self.addChild(self.descriptionText);
// Stats display
self.statsText = new Text2("", {
size: 35,
fill: 0xFFFFFF
});
self.statsText.anchor.set(0.5, 1);
self.statsText.y = background.height / 2 - 100;
self.addChild(self.statsText);
self.updateStats = function () {
var stats = "Auto Clickers: " + gameState.autoClickersOwned;
stats += " | Click Multiplier: " + gameState.clickMultiplierOwned;
stats += " | Super Clicker: " + gameState.superClickerOwned;
self.statsText.setText(stats);
// Update button appearances
self.autoClicker.updateAppearance();
self.clickMultiplier.updateAppearance();
self.superClicker.updateAppearance();
self.clickingEmpire.updateAppearance();
// Update costs if needed from saved state
self.autoClicker.cost = 50 * Math.pow(2, gameState.autoClickersOwned);
self.autoClicker.getChildAt(2).setText(Math.floor(self.autoClicker.cost) + " clicks");
self.clickMultiplier.cost = 100 * Math.pow(3, gameState.clickMultiplierOwned);
self.clickMultiplier.getChildAt(2).setText(Math.floor(self.clickMultiplier.cost) + " clicks");
self.superClicker.cost = 500 * Math.pow(4, gameState.superClickerOwned);
self.superClicker.getChildAt(2).setText(Math.floor(self.superClicker.cost) + " clicks");
};
// Click handlers for close button
closeBtn.interactive = true;
closeBtn.down = function () {
toggleShop(false);
};
// Mouse over handlers for description
self.autoClicker.move = function () {
self.descriptionText.setText(self.autoClicker.description);
};
self.clickMultiplier.move = function () {
self.descriptionText.setText(self.clickMultiplier.description);
};
self.superClicker.move = function () {
self.descriptionText.setText(self.superClicker.description);
};
self.clickingEmpire.move = function () {
self.descriptionText.setText(self.clickingEmpire.description);
};
return self;
});
var StartOverButton = Container.expand(function () {
var self = Container.call(this);
var button = self.attachAsset('shopButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
// Increase button width
scaleY: 1.5 // Increase button height
});
var buttonText = new Text2("START OVER", {
size: 80,
//{1P} // Increase text size
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.down = function (x, y, obj) {
tween(button.scale, {
x: 0.95,
y: 0.95
}, {
duration: 100
});
confirmStartOver();
};
self.up = function (x, y, obj) {
tween(button.scale, {
x: 1,
y: 1
}, {
duration: 100
});
};
return self;
});
var UpgradeButton = Container.expand(function (type, cost, description) {
var self = Container.call(this);
self.type = type;
self.cost = cost;
self.description = description;
var button = self.attachAsset('upgradeButton', {
anchorX: 0.5,
anchorY: 0.5
});
var titleText = new Text2(type, {
size: 40,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0);
titleText.y = -35;
self.addChild(titleText);
var costText = new Text2(cost + " clicks", {
size: 30,
fill: 0xFFFFFF
});
costText.anchor.set(0.5, 1);
costText.y = 35;
self.addChild(costText);
self.updateAppearance = function () {
// Change appearance based on affordability
if (gameState.clicks >= self.cost) {
button.alpha = 1;
titleText.alpha = 1;
costText.alpha = 1;
} else {
button.alpha = 0.6;
titleText.alpha = 0.6;
costText.alpha = 0.6;
}
};
self.down = function (x, y, obj) {
tween(button.scale, {
x: 0.95,
y: 0.95
}, {
duration: 100
});
if (gameState.clicks >= self.cost) {
gameState.clicks -= self.cost;
// Apply upgrade effect
switch (self.type) {
case "Auto Clicker":
gameState.autoClickersOwned++;
self.cost = Math.floor(self.cost * 1.5); // Increase cost for next purchase
startAutoClicker();
break;
case "Click Multiplier":
gameState.clickMultiplierOwned++;
if (gameState.megaClickerOwned === undefined) {
gameState.megaClickerOwned = 0;
}
gameState.clickPower = (1 + gameState.clickMultiplierOwned) * (1 + gameState.superClickerOwned * 2) * (1 + gameState.megaClickerOwned * 4);
self.cost = Math.floor(self.cost * 2); // Increase cost for next purchase
break;
case "Super Clicker":
gameState.superClickerOwned++;
if (gameState.megaClickerOwned === undefined) {
gameState.megaClickerOwned = 0;
}
gameState.clickPower = (1 + gameState.clickMultiplierOwned) * (1 + gameState.superClickerOwned * 2) * (1 + gameState.megaClickerOwned * 4);
self.cost = Math.floor(self.cost * 3); // Increase cost for next purchase
break;
case "Mega Clicker":
gameState.megaClickerOwned = 1;
gameState.clickPower = (1 + gameState.clickMultiplierOwned) * (1 + gameState.superClickerOwned * 2) * 5;
self.cost = Math.floor(self.cost * 5); // Increase cost for next purchase
break;
case "Clicking Empire":
gameState.clickingEmpireOwned = 1;
// Victory condition!
LK.showYouWin();
break;
}
// Update cost text
costText.setText(self.cost + " clicks");
// Play purchase sound
LK.getSound('purchase').play();
// Save game state
saveGameState();
// Update all displays
updateDisplays();
} else {
// Play error sound
LK.getSound('error').play();
}
};
self.up = function (x, y, obj) {
tween(button.scale, {
x: 1,
y: 1
}, {
duration: 100
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2c3e50
});
/****
* Game Code
****/
var notificationsTab = new NotificationsTab();
notificationsTab.x = 2048 / 2;
notificationsTab.y = 2732 - 300;
notificationsTab.visible = false;
notificationsTab.alpha = 0;
game.addChild(notificationsTab);
function toggleNotifications(visible) {
if (visible) {
notificationsTab.visible = true;
notificationsTab.updateNotifications(unlockedAchievements);
tween(notificationsTab, {
alpha: 1
}, {
duration: 300
});
} else {
tween(notificationsTab, {
alpha: 0
}, {
duration: 300,
onFinish: function onFinish() {
notificationsTab.visible = false;
}
});
}
}
function confirmStartOver() {
var confirmPanel = new Container();
var background = confirmPanel.attachAsset('shopBackground', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.9
});
var confirmText = new Text2("Are you sure you want to start over?", {
size: 50,
fill: 0xFFFFFF,
wordWrap: true,
wordWrapWidth: 1400
});
confirmText.anchor.set(0.5, 0.5);
confirmText.y = -100;
confirmPanel.addChild(confirmText);
var yesButton = new Container();
var yesButtonBackground = yesButton.attachAsset('upgradeButton', {
anchorX: 0.5,
anchorY: 0.5
});
var yesText = new Text2("YES", {
size: 40,
fill: 0xFFFFFF
});
yesText.anchor.set(0.5, 0.5);
yesButton.addChild(yesText);
yesButton.y = 100;
yesButton.down = function () {
resetGame();
confirmPanel.destroy();
};
confirmPanel.addChild(yesButton);
var noButton = new Container();
var noButtonBackground = noButton.attachAsset('upgradeButton', {
anchorX: 0.5,
anchorY: 0.5
});
var noText = new Text2("NO", {
size: 40,
fill: 0xFFFFFF
});
noText.anchor.set(0.5, 0.5);
noButton.addChild(noText);
noButton.y = 200;
noButton.down = function () {
confirmPanel.destroy();
};
confirmPanel.addChild(noButton);
confirmPanel.x = 2048 / 2;
confirmPanel.y = 2732 / 2;
game.addChild(confirmPanel);
}
function resetGame() {
gameState.clicks = 0;
gameState.clickPower = 1;
gameState.autoClickersOwned = 0;
gameState.clickMultiplierOwned = 0;
gameState.superClickerOwned = 0;
gameState.megaClickerOwned = 0;
gameState.clickingEmpireOwned = 0;
saveGameState();
updateDisplays();
startAutoClicker();
}
// Game state
var gameState = {
clicks: storage.clicks || 0,
clickPower: storage.clickPower || 1,
autoClickersOwned: storage.autoClickersOwned || 0,
clickMultiplierOwned: storage.clickMultiplierOwned || 0,
superClickerOwned: storage.superClickerOwned || 0,
megaClickerOwned: storage.megaClickerOwned || 0,
clickingEmpireOwned: storage.clickingEmpireOwned || 0,
shopOpen: false
};
// Create main click square
var clickSquare = new ClickSquare();
clickSquare.x = 2048 / 2;
clickSquare.y = 2732 / 2 - 300;
game.addChild(clickSquare);
// Create shop button
var shopButton = new ShopButton();
shopButton.x = 2048 / 2;
shopButton.y = 2732 / 2 + 400;
game.addChild(shopButton);
// Create start over button
var startOverButton = new StartOverButton();
startOverButton.x = 2048 / 2;
startOverButton.y = 2732 / 2 + 600;
game.addChild(startOverButton);
// Create shop panel (initially hidden)
var shopPanel = new ShopPanel();
shopPanel.x = 2048 / 2;
shopPanel.y = 2732 / 2;
shopPanel.visible = false;
shopPanel.alpha = 0;
game.addChild(shopPanel);
// Create click counter display
var clicksDisplay = new Text2("0", {
size: 100,
fill: 0xFFFFFF
});
clicksDisplay.anchor.set(0.5, 0.5);
clicksDisplay.x = 2048 / 2;
clicksDisplay.y = 2732 / 2 + 150;
game.addChild(clicksDisplay);
// Create click power display
var powerDisplay = new Text2("Click Power: 1", {
size: 50,
fill: 0xFFFFFF
});
powerDisplay.anchor.set(0.5, 0.5);
powerDisplay.x = 2048 / 2;
powerDisplay.y = 2732 / 2 + 250;
game.addChild(powerDisplay);
// Auto clicker timer
var autoClickTimer = null;
// Function to toggle shop visibility
function toggleShop(visible) {
gameState.shopOpen = visible;
if (visible) {
shopPanel.visible = true;
shopPanel.updateStats();
tween(shopPanel, {
alpha: 1
}, {
duration: 300
});
} else {
tween(shopPanel, {
alpha: 0
}, {
duration: 300,
onFinish: function onFinish() {
shopPanel.visible = false;
}
});
}
}
// Achievements tracking
var achievements = [{
clicks: 100,
message: "Achievement Unlocked: 100 Clicks!"
}, {
clicks: 500,
message: "Achievement Unlocked: 500 Clicks!"
}, {
clicks: 1000,
message: "Achievement Unlocked: 1000 Clicks!"
}, {
clicks: 5000,
message: "Achievement Unlocked: 5000 Clicks!"
}, {
clicks: 10000,
message: "Achievement Unlocked: 10000 Clicks!"
}, {
clicks: 50000,
message: "Achievement Unlocked: 50000 Clicks!"
}];
var unlockedAchievements = [];
// Function to check and display achievements
function checkAchievements() {
achievements.forEach(function (achievement) {
if ((gameState.autoClickersOwned > 0 || gameState.clickMultiplierOwned > 0 || gameState.superClickerOwned > 0) && !unlockedAchievements.includes('firstUpgrade')) {
unlockedAchievements.push('firstUpgrade');
displayAchievement("Achievement Unlocked: First Upgrade Purchased!");
}
if (gameState.clickingEmpireOwned === 1 && !unlockedAchievements.includes('win')) {
unlockedAchievements.push('win');
displayAchievement("Achievement Unlocked: You Won the Game!");
}
if (gameState.clicks >= achievement.clicks && !unlockedAchievements.includes(achievement.clicks)) {
unlockedAchievements.push(achievement.clicks);
displayAchievement(achievement.message);
}
});
}
// Function to display achievement message
function displayAchievement(message) {
var achievementText = new Text2(message, {
size: 80,
fill: 0xFFD700 // Gold color for achievements
});
achievementText.anchor.set(0.5, 0.5);
achievementText.x = 2048 / 2;
achievementText.y = 2732 / 2 - 500;
game.addChild(achievementText);
// Animate the text fading out
tween(achievementText, {
alpha: 0
}, {
duration: 3000,
onFinish: function onFinish() {
achievementText.destroy();
}
});
}
// Function to update all displays
function updateDisplays() {
checkAchievements();
// Format large numbers for better readability
var formattedClicks;
if (gameState.clicks >= 1000000) {
formattedClicks = (gameState.clicks / 1000000).toFixed(1) + "M";
} else if (gameState.clicks >= 1000) {
formattedClicks = (gameState.clicks / 1000).toFixed(1) + "K";
} else {
formattedClicks = Math.floor(gameState.clicks);
}
clicksDisplay.setText(formattedClicks);
powerDisplay.setText("Click Power: " + gameState.clickPower);
if (shopPanel.visible) {
shopPanel.updateStats();
}
}
// Function to save game state
function saveGameState() {
storage.clicks = gameState.clicks;
storage.clickPower = gameState.clickPower;
storage.autoClickersOwned = gameState.autoClickersOwned;
storage.clickMultiplierOwned = gameState.clickMultiplierOwned;
storage.superClickerOwned = gameState.superClickerOwned;
storage.megaClickerOwned = gameState.megaClickerOwned;
storage.clickingEmpireOwned = gameState.clickingEmpireOwned;
}
// Auto-save timer
var saveTimer = LK.setInterval(function () {
saveGameState();
}, 10000); // Save every 10 seconds
// Start auto clicker if player has purchased any
function startAutoClicker() {
if (autoClickTimer) {
LK.clearInterval(autoClickTimer);
}
if (gameState.autoClickersOwned > 0) {
autoClickTimer = LK.setInterval(function () {
for (var i = 0; i < gameState.autoClickersOwned; i++) {
gameState.clicks += 1;
}
updateDisplays();
}, 1000); // Every second
}
}
// Initialize auto clicker
startAutoClicker();
// Initialize displays with saved state
updateDisplays();
// Play background music
LK.playMusic('bgMusic', {
fade: {
start: 0,
end: 0.3,
duration: 1000
}
});
// Game update function
game.update = function () {
// Auto-clicking logic is handled by the timer
saveGameState();
};
// Game move handler
game.move = function (x, y, obj) {
// Currently no global move handling needed
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
clicks: 0,
clickPower: 1,
autoClickersOwned: 0,
clickMultiplierOwned: 0,
superClickerOwned: 0,
megaClickerOwned: 0,
clickingEmpireOwned: 0
});
/****
* Classes
****/
var ClickSquare = Container.expand(function () {
var self = Container.call(this);
var square = self.attachAsset('clickSquare', {
anchorX: 0.5,
anchorY: 0.5
});
self.originalScale = 1;
square.scale.set(self.originalScale);
self.down = function (x, y, obj) {
// Shrink the square when pressed
tween(square.scale, {
x: 0.9,
y: 0.9
}, {
duration: 100
});
// Add clicks based on click power
gameState.clicks += gameState.clickPower;
updateDisplays();
// Play click sound
LK.getSound('click').play();
// Create and animate "+clickPower" text
var clickText = new Text2("+" + gameState.clickPower, {
size: 60,
fill: 0xFFFFFF
});
clickText.anchor.set(0.5, 0.5);
clickText.x = x;
clickText.y = y;
self.addChild(clickText);
// Animate the text floating upward and fading
tween(clickText, {
y: y - 100,
alpha: 0
}, {
duration: 800,
easing: tween.easeOut,
onFinish: function onFinish() {
clickText.destroy();
}
});
};
self.up = function (x, y, obj) {
// Return to original size when released
tween(square.scale, {
x: self.originalScale,
y: self.originalScale
}, {
duration: 100
});
};
// Pulse animation function
self.pulse = function () {
tween(square.scale, {
x: self.originalScale * 1.05,
y: self.originalScale * 1.05
}, {
duration: 500,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(square.scale, {
x: self.originalScale,
y: self.originalScale
}, {
duration: 500,
easing: tween.easeInOut,
onFinish: self.pulse
});
}
});
};
// Start pulsing animation
self.pulse();
return self;
});
var NotificationsTab = Container.expand(function () {
var self = Container.call(this);
var background = self.attachAsset('shopBackground', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.9
});
var titleText = new Text2("Notifications", {
size: 80,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0);
titleText.y = -background.height / 2 + 100;
self.addChild(titleText);
// Close button
var closeBtn = self.attachAsset('closeButton', {
anchorX: 0.5,
anchorY: 0.5,
x: background.width / 2 - 80,
y: -background.height / 2 + 80
});
var closeX = new Text2("X", {
size: 50,
fill: 0xFFFFFF
});
closeX.anchor.set(0.5, 0.5);
closeX.x = closeBtn.x;
closeX.y = closeBtn.y;
self.addChild(closeX);
// Notifications display
self.notificationsText = new Text2("", {
size: 35,
fill: 0xFFFFFF,
wordWrap: true,
wordWrapWidth: 1400
});
self.notificationsText.anchor.set(0.5, 0);
self.notificationsText.y = 0;
self.addChild(self.notificationsText);
// Click handlers for close button
closeBtn.interactive = true;
closeBtn.down = function () {
toggleNotifications(false);
};
self.updateNotifications = function (notifications) {
self.notificationsText.setText(notifications.join("\n"));
};
return self;
});
var ShopButton = Container.expand(function () {
var self = Container.call(this);
var button = self.attachAsset('shopButton', {
anchorX: 0.5,
anchorY: 0.5
});
var buttonText = new Text2("SHOP", {
size: 60,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.down = function (x, y, obj) {
tween(button.scale, {
x: 0.95,
y: 0.95
}, {
duration: 100
});
toggleShop(true);
};
self.up = function (x, y, obj) {
tween(button.scale, {
x: 1,
y: 1
}, {
duration: 100
});
};
return self;
});
var ShopPanel = Container.expand(function () {
var self = Container.call(this);
var background = self.attachAsset('shopBackground', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.9
});
var titleText = new Text2("UPGRADE SHOP", {
size: 80,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0);
titleText.y = -background.height / 2 + 100;
self.addChild(titleText);
// Close button
var closeBtn = self.attachAsset('closeButton', {
anchorX: 0.5,
anchorY: 0.5,
x: background.width / 2 - 80,
y: -background.height / 2 + 80
});
var closeX = new Text2("X", {
size: 50,
fill: 0xFFFFFF
});
closeX.anchor.set(0.5, 0.5);
closeX.x = closeBtn.x;
closeX.y = closeBtn.y;
self.addChild(closeX);
// Create upgrade buttons
self.autoClicker = new UpgradeButton("Auto Clicker", 50, "Automatically clicks once per second");
self.autoClicker.y = -400;
self.addChild(self.autoClicker);
self.clickMultiplier = new UpgradeButton("Click Multiplier", 100, "Increases click power by 1");
self.clickMultiplier.y = -200;
self.addChild(self.clickMultiplier);
self.superClicker = new UpgradeButton("Super Clicker", 500, "Multiplies your click power by 2");
self.superClicker.y = 0;
self.addChild(self.superClicker);
self.megaClicker = new UpgradeButton("Mega Clicker", 20000, "Multiplies your click power by 5");
self.megaClicker.y = 200;
self.addChild(self.megaClicker);
self.clickingEmpire = new UpgradeButton("Clicking Empire", 100000, "The ultimate upgrade - win the game!");
self.clickingEmpire.y = 400;
self.addChild(self.clickingEmpire);
// Description text
self.descriptionText = new Text2("", {
size: 30,
fill: 0xFFFFFF,
wordWrap: true,
wordWrapWidth: 1400
});
self.descriptionText.anchor.set(0.5, 0);
self.descriptionText.y = 400;
self.addChild(self.descriptionText);
// Stats display
self.statsText = new Text2("", {
size: 35,
fill: 0xFFFFFF
});
self.statsText.anchor.set(0.5, 1);
self.statsText.y = background.height / 2 - 100;
self.addChild(self.statsText);
self.updateStats = function () {
var stats = "Auto Clickers: " + gameState.autoClickersOwned;
stats += " | Click Multiplier: " + gameState.clickMultiplierOwned;
stats += " | Super Clicker: " + gameState.superClickerOwned;
self.statsText.setText(stats);
// Update button appearances
self.autoClicker.updateAppearance();
self.clickMultiplier.updateAppearance();
self.superClicker.updateAppearance();
self.clickingEmpire.updateAppearance();
// Update costs if needed from saved state
self.autoClicker.cost = 50 * Math.pow(2, gameState.autoClickersOwned);
self.autoClicker.getChildAt(2).setText(Math.floor(self.autoClicker.cost) + " clicks");
self.clickMultiplier.cost = 100 * Math.pow(3, gameState.clickMultiplierOwned);
self.clickMultiplier.getChildAt(2).setText(Math.floor(self.clickMultiplier.cost) + " clicks");
self.superClicker.cost = 500 * Math.pow(4, gameState.superClickerOwned);
self.superClicker.getChildAt(2).setText(Math.floor(self.superClicker.cost) + " clicks");
};
// Click handlers for close button
closeBtn.interactive = true;
closeBtn.down = function () {
toggleShop(false);
};
// Mouse over handlers for description
self.autoClicker.move = function () {
self.descriptionText.setText(self.autoClicker.description);
};
self.clickMultiplier.move = function () {
self.descriptionText.setText(self.clickMultiplier.description);
};
self.superClicker.move = function () {
self.descriptionText.setText(self.superClicker.description);
};
self.clickingEmpire.move = function () {
self.descriptionText.setText(self.clickingEmpire.description);
};
return self;
});
var StartOverButton = Container.expand(function () {
var self = Container.call(this);
var button = self.attachAsset('shopButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
// Increase button width
scaleY: 1.5 // Increase button height
});
var buttonText = new Text2("START OVER", {
size: 80,
//{1P} // Increase text size
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.down = function (x, y, obj) {
tween(button.scale, {
x: 0.95,
y: 0.95
}, {
duration: 100
});
confirmStartOver();
};
self.up = function (x, y, obj) {
tween(button.scale, {
x: 1,
y: 1
}, {
duration: 100
});
};
return self;
});
var UpgradeButton = Container.expand(function (type, cost, description) {
var self = Container.call(this);
self.type = type;
self.cost = cost;
self.description = description;
var button = self.attachAsset('upgradeButton', {
anchorX: 0.5,
anchorY: 0.5
});
var titleText = new Text2(type, {
size: 40,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0);
titleText.y = -35;
self.addChild(titleText);
var costText = new Text2(cost + " clicks", {
size: 30,
fill: 0xFFFFFF
});
costText.anchor.set(0.5, 1);
costText.y = 35;
self.addChild(costText);
self.updateAppearance = function () {
// Change appearance based on affordability
if (gameState.clicks >= self.cost) {
button.alpha = 1;
titleText.alpha = 1;
costText.alpha = 1;
} else {
button.alpha = 0.6;
titleText.alpha = 0.6;
costText.alpha = 0.6;
}
};
self.down = function (x, y, obj) {
tween(button.scale, {
x: 0.95,
y: 0.95
}, {
duration: 100
});
if (gameState.clicks >= self.cost) {
gameState.clicks -= self.cost;
// Apply upgrade effect
switch (self.type) {
case "Auto Clicker":
gameState.autoClickersOwned++;
self.cost = Math.floor(self.cost * 1.5); // Increase cost for next purchase
startAutoClicker();
break;
case "Click Multiplier":
gameState.clickMultiplierOwned++;
if (gameState.megaClickerOwned === undefined) {
gameState.megaClickerOwned = 0;
}
gameState.clickPower = (1 + gameState.clickMultiplierOwned) * (1 + gameState.superClickerOwned * 2) * (1 + gameState.megaClickerOwned * 4);
self.cost = Math.floor(self.cost * 2); // Increase cost for next purchase
break;
case "Super Clicker":
gameState.superClickerOwned++;
if (gameState.megaClickerOwned === undefined) {
gameState.megaClickerOwned = 0;
}
gameState.clickPower = (1 + gameState.clickMultiplierOwned) * (1 + gameState.superClickerOwned * 2) * (1 + gameState.megaClickerOwned * 4);
self.cost = Math.floor(self.cost * 3); // Increase cost for next purchase
break;
case "Mega Clicker":
gameState.megaClickerOwned = 1;
gameState.clickPower = (1 + gameState.clickMultiplierOwned) * (1 + gameState.superClickerOwned * 2) * 5;
self.cost = Math.floor(self.cost * 5); // Increase cost for next purchase
break;
case "Clicking Empire":
gameState.clickingEmpireOwned = 1;
// Victory condition!
LK.showYouWin();
break;
}
// Update cost text
costText.setText(self.cost + " clicks");
// Play purchase sound
LK.getSound('purchase').play();
// Save game state
saveGameState();
// Update all displays
updateDisplays();
} else {
// Play error sound
LK.getSound('error').play();
}
};
self.up = function (x, y, obj) {
tween(button.scale, {
x: 1,
y: 1
}, {
duration: 100
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2c3e50
});
/****
* Game Code
****/
var notificationsTab = new NotificationsTab();
notificationsTab.x = 2048 / 2;
notificationsTab.y = 2732 - 300;
notificationsTab.visible = false;
notificationsTab.alpha = 0;
game.addChild(notificationsTab);
function toggleNotifications(visible) {
if (visible) {
notificationsTab.visible = true;
notificationsTab.updateNotifications(unlockedAchievements);
tween(notificationsTab, {
alpha: 1
}, {
duration: 300
});
} else {
tween(notificationsTab, {
alpha: 0
}, {
duration: 300,
onFinish: function onFinish() {
notificationsTab.visible = false;
}
});
}
}
function confirmStartOver() {
var confirmPanel = new Container();
var background = confirmPanel.attachAsset('shopBackground', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.9
});
var confirmText = new Text2("Are you sure you want to start over?", {
size: 50,
fill: 0xFFFFFF,
wordWrap: true,
wordWrapWidth: 1400
});
confirmText.anchor.set(0.5, 0.5);
confirmText.y = -100;
confirmPanel.addChild(confirmText);
var yesButton = new Container();
var yesButtonBackground = yesButton.attachAsset('upgradeButton', {
anchorX: 0.5,
anchorY: 0.5
});
var yesText = new Text2("YES", {
size: 40,
fill: 0xFFFFFF
});
yesText.anchor.set(0.5, 0.5);
yesButton.addChild(yesText);
yesButton.y = 100;
yesButton.down = function () {
resetGame();
confirmPanel.destroy();
};
confirmPanel.addChild(yesButton);
var noButton = new Container();
var noButtonBackground = noButton.attachAsset('upgradeButton', {
anchorX: 0.5,
anchorY: 0.5
});
var noText = new Text2("NO", {
size: 40,
fill: 0xFFFFFF
});
noText.anchor.set(0.5, 0.5);
noButton.addChild(noText);
noButton.y = 200;
noButton.down = function () {
confirmPanel.destroy();
};
confirmPanel.addChild(noButton);
confirmPanel.x = 2048 / 2;
confirmPanel.y = 2732 / 2;
game.addChild(confirmPanel);
}
function resetGame() {
gameState.clicks = 0;
gameState.clickPower = 1;
gameState.autoClickersOwned = 0;
gameState.clickMultiplierOwned = 0;
gameState.superClickerOwned = 0;
gameState.megaClickerOwned = 0;
gameState.clickingEmpireOwned = 0;
saveGameState();
updateDisplays();
startAutoClicker();
}
// Game state
var gameState = {
clicks: storage.clicks || 0,
clickPower: storage.clickPower || 1,
autoClickersOwned: storage.autoClickersOwned || 0,
clickMultiplierOwned: storage.clickMultiplierOwned || 0,
superClickerOwned: storage.superClickerOwned || 0,
megaClickerOwned: storage.megaClickerOwned || 0,
clickingEmpireOwned: storage.clickingEmpireOwned || 0,
shopOpen: false
};
// Create main click square
var clickSquare = new ClickSquare();
clickSquare.x = 2048 / 2;
clickSquare.y = 2732 / 2 - 300;
game.addChild(clickSquare);
// Create shop button
var shopButton = new ShopButton();
shopButton.x = 2048 / 2;
shopButton.y = 2732 / 2 + 400;
game.addChild(shopButton);
// Create start over button
var startOverButton = new StartOverButton();
startOverButton.x = 2048 / 2;
startOverButton.y = 2732 / 2 + 600;
game.addChild(startOverButton);
// Create shop panel (initially hidden)
var shopPanel = new ShopPanel();
shopPanel.x = 2048 / 2;
shopPanel.y = 2732 / 2;
shopPanel.visible = false;
shopPanel.alpha = 0;
game.addChild(shopPanel);
// Create click counter display
var clicksDisplay = new Text2("0", {
size: 100,
fill: 0xFFFFFF
});
clicksDisplay.anchor.set(0.5, 0.5);
clicksDisplay.x = 2048 / 2;
clicksDisplay.y = 2732 / 2 + 150;
game.addChild(clicksDisplay);
// Create click power display
var powerDisplay = new Text2("Click Power: 1", {
size: 50,
fill: 0xFFFFFF
});
powerDisplay.anchor.set(0.5, 0.5);
powerDisplay.x = 2048 / 2;
powerDisplay.y = 2732 / 2 + 250;
game.addChild(powerDisplay);
// Auto clicker timer
var autoClickTimer = null;
// Function to toggle shop visibility
function toggleShop(visible) {
gameState.shopOpen = visible;
if (visible) {
shopPanel.visible = true;
shopPanel.updateStats();
tween(shopPanel, {
alpha: 1
}, {
duration: 300
});
} else {
tween(shopPanel, {
alpha: 0
}, {
duration: 300,
onFinish: function onFinish() {
shopPanel.visible = false;
}
});
}
}
// Achievements tracking
var achievements = [{
clicks: 100,
message: "Achievement Unlocked: 100 Clicks!"
}, {
clicks: 500,
message: "Achievement Unlocked: 500 Clicks!"
}, {
clicks: 1000,
message: "Achievement Unlocked: 1000 Clicks!"
}, {
clicks: 5000,
message: "Achievement Unlocked: 5000 Clicks!"
}, {
clicks: 10000,
message: "Achievement Unlocked: 10000 Clicks!"
}, {
clicks: 50000,
message: "Achievement Unlocked: 50000 Clicks!"
}];
var unlockedAchievements = [];
// Function to check and display achievements
function checkAchievements() {
achievements.forEach(function (achievement) {
if ((gameState.autoClickersOwned > 0 || gameState.clickMultiplierOwned > 0 || gameState.superClickerOwned > 0) && !unlockedAchievements.includes('firstUpgrade')) {
unlockedAchievements.push('firstUpgrade');
displayAchievement("Achievement Unlocked: First Upgrade Purchased!");
}
if (gameState.clickingEmpireOwned === 1 && !unlockedAchievements.includes('win')) {
unlockedAchievements.push('win');
displayAchievement("Achievement Unlocked: You Won the Game!");
}
if (gameState.clicks >= achievement.clicks && !unlockedAchievements.includes(achievement.clicks)) {
unlockedAchievements.push(achievement.clicks);
displayAchievement(achievement.message);
}
});
}
// Function to display achievement message
function displayAchievement(message) {
var achievementText = new Text2(message, {
size: 80,
fill: 0xFFD700 // Gold color for achievements
});
achievementText.anchor.set(0.5, 0.5);
achievementText.x = 2048 / 2;
achievementText.y = 2732 / 2 - 500;
game.addChild(achievementText);
// Animate the text fading out
tween(achievementText, {
alpha: 0
}, {
duration: 3000,
onFinish: function onFinish() {
achievementText.destroy();
}
});
}
// Function to update all displays
function updateDisplays() {
checkAchievements();
// Format large numbers for better readability
var formattedClicks;
if (gameState.clicks >= 1000000) {
formattedClicks = (gameState.clicks / 1000000).toFixed(1) + "M";
} else if (gameState.clicks >= 1000) {
formattedClicks = (gameState.clicks / 1000).toFixed(1) + "K";
} else {
formattedClicks = Math.floor(gameState.clicks);
}
clicksDisplay.setText(formattedClicks);
powerDisplay.setText("Click Power: " + gameState.clickPower);
if (shopPanel.visible) {
shopPanel.updateStats();
}
}
// Function to save game state
function saveGameState() {
storage.clicks = gameState.clicks;
storage.clickPower = gameState.clickPower;
storage.autoClickersOwned = gameState.autoClickersOwned;
storage.clickMultiplierOwned = gameState.clickMultiplierOwned;
storage.superClickerOwned = gameState.superClickerOwned;
storage.megaClickerOwned = gameState.megaClickerOwned;
storage.clickingEmpireOwned = gameState.clickingEmpireOwned;
}
// Auto-save timer
var saveTimer = LK.setInterval(function () {
saveGameState();
}, 10000); // Save every 10 seconds
// Start auto clicker if player has purchased any
function startAutoClicker() {
if (autoClickTimer) {
LK.clearInterval(autoClickTimer);
}
if (gameState.autoClickersOwned > 0) {
autoClickTimer = LK.setInterval(function () {
for (var i = 0; i < gameState.autoClickersOwned; i++) {
gameState.clicks += 1;
}
updateDisplays();
}, 1000); // Every second
}
}
// Initialize auto clicker
startAutoClicker();
// Initialize displays with saved state
updateDisplays();
// Play background music
LK.playMusic('bgMusic', {
fade: {
start: 0,
end: 0.3,
duration: 1000
}
});
// Game update function
game.update = function () {
// Auto-clicking logic is handled by the timer
saveGameState();
};
// Game move handler
game.move = function (x, y, obj) {
// Currently no global move handling needed
};