User prompt
dans le update de BonusCake fait le tomber jusqu'en bas de l'écran
Code edit (2 edits merged)
Please save this source code
User prompt
dans BonusCakeManager popBouns tu dois créer une instance de la classe BonusCake
User prompt
crée la fonction popBonus BonusCakeManager et pas dans BonusCake
User prompt
crée une classe BonusCakeManager qui va s'occuper de faire apparaitre les BonusCake pendant le jeu mais ne l'instancie pas
Code edit (10 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'popBonus')' in or related to this line: 'self.popBonus = function () {' Line Number: 931
User prompt
dans classe bonusCake ajoute une fonction popBonus() qui crée un asset bonusCake
User prompt
ajoute une classe BonusCake
User prompt
il faut également charger le upgradeLevel au démarrage
User prompt
il faut sauvegarder le upgradeLevel
User prompt
de la meme facon il faut appeler updateCakeGraphics au chargement
User prompt
pour l'autoclicker il faut ajouter une fonction initStars() pour re-creer les étoiles en fonction du nombre d'autoclicker
User prompt
quand on lance le jeu il faut également mettre à jour l'affichage des étoiles
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
adapte displayStars pour gérer jusqu'à 9 étoiles (ne change pas le traitement actuel pour les index 1 2 et 3); les étoiles doivent être disposée en cercle sur le bouton x peut varier entre -100 et 100 y peut varirier entre -100 et 100
User prompt
utilise le tableat upgradeMultiplier
User prompt
ajout un nouveau tableau upgradeMultiplier: var upgradeMultiplier = [ 1, // Niveau 0 2, // Niveau 1 5, // Niveau 2 10, // Niveau 3 20, // Niveau 4 50, // Niveau 5 100, // Niveau 6 200, // Niveau 7 500, // Niveau 8 1000 // Niveau 9 ];
Code edit (1 edits merged)
Please save this source code
User prompt
dans startAutoClicking, utilise autoClicksPerSecond :
User prompt
limite le nombre d'autoclickers à 9 maximum
Code edit (1 edits merged)
Please save this source code
User prompt
ajoute un nouveau tableau pour le nombre d'autoclick par seconde: 0 1 1 10 2 50 3 150 4 500 5 1500 6 5000 7 15000 8 50000 9 150000
User prompt
maintenant utilise autoClickerPrices
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1", { score: 0, autoClickerCount: 0, upgradeMultiplier: 1 }); /**** * Classes ****/ // AutoClicker class var AutoClicker = Container.expand(function () { var self = Container.call(this); self.startAutoClicking = function () { self.autoClickerInterval = LK.setInterval(function () { if (self.autoClickerCount > 0) { bigCake.emit('down'); // Trigger the 'down' event on bigCake to simulate a click } }, 1000); }; // Create a shadow effect by adding a black tinted, semi-transparent duplicate of autoClickerGraphics var shadowGraphics = self.attachAsset('autoClicker', { anchorX: 0.5, anchorY: 0.5 }); shadowGraphics.tint = 0x000000; // Tint the shadow black shadowGraphics.alpha = 0.5; // Make the shadow semi-transparent shadowGraphics.y = 10; // Position the shadow slightly below the autoClicker button self.addChild(shadowGraphics); var autoClickerGraphics = self.attachAsset('autoClicker', { anchorX: 0.5, anchorY: 0.5 }); // Add 'Worker' text above the auto clicker image var workerLabel = new Text2('Worker', { size: 60, fill: 0x1E90FF, // Match price text color fontWeight: '900', dropShadow: true, dropShadowColor: 0x000000, dropShadowBlur: 5, dropShadowDistance: 5 }); workerLabel.anchor.set(0.5, 1); // Center the text horizontally and align it to the bottom workerLabel.fill = 0x0000FF; // Change text color to blue workerLabel.y = autoClickerGraphics.y - autoClickerGraphics.height / 2 - 10; // Adjust text position to -10 above the auto clicker image self.addChild(workerLabel); // Attach the chef's toque image on top of the auto clicker button var toqueGraphics = self.attachAsset('toque', { anchorX: 0.5, anchorY: 0.5 }); toqueGraphics.y = -10; // Move the toque slightly higher on the auto clicker self.addChild(toqueGraphics); self.cost = 100; // Initial cost of the auto clicker self.autoClickerCount = 0; self.stars = []; // Array to store the list of stars var priceText = new Text2('$' + self.cost, { size: 80, fill: 0x1E90FF, fontWeight: '900', // Make the text bolder dropShadow: true, // Enable drop shadow dropShadowColor: 0x000000, // Set drop shadow color to black dropShadowBlur: 5, // Set drop shadow blur dropShadowDistance: 5 // Set drop shadow distance }); priceText.setText('$' + self.cost); // Update the price text to reflect the current cost priceText.anchor.set(0.5, 0); priceText.x = 0; priceText.y = autoClickerGraphics.height / 2 + 0; // Position text below the auto clicker button self.addChild(priceText); self.updatePriceText = function () { priceText.setText(formatPrice(self.cost)); // Update the price text to reflect the current cost }; self.displayStars = function () { // Update positions of all stars based on the current count self.stars.forEach(function (star, index) { if (self.autoClickerCount === 1) { star.x = 0; // Position the first star at x = 0 } else if (self.autoClickerCount === 2) { star.x = index === 0 ? -30 : 30; // Position the second star at x = -60 and the third at x = 60 } else if (self.autoClickerCount === 3) { star.x = index === 0 ? -70 : index === 1 ? 0 : 70; star.y = index === 0 ? 70 : index === 1 ? 100 : 70; } }); }; self.onClick = function () { if (currentScore >= self.cost) { currentScore -= self.cost; // Deduct the cost from the current score score.updateScore(currentScore); // Update the score display self.autoClickerCount += 1; // Increase the number of auto clickers // Add a star under the toque for each upgrade, up to 3 stars if (self.autoClickerCount <= 3) { var star = self.attachAsset('etoile', { anchorX: 0.5, anchorY: 0.5 }); star.y = toqueGraphics.y + toqueGraphics.height / 2 + star.height / 2; // Position the star under the toque self.stars.push(star); // Add the star to the stars array self.displayStars(); // Update positions of all stars based on the current count } storage.autoClickerCount = self.autoClickerCount; // Save the updated auto clicker count if (self.autoClickerCount === 1) { self.startAutoClicking(); // Start auto clicking only when the first auto clicker is purchased } self.cost = autoClickerPrices[Math.min(self.autoClickerCount, autoClickerPrices.length - 1)]; // Update the cost using the autoClickerPrices array storage.autoClickerCost = self.cost; // Save the updated auto clicker cost self.updatePriceText(); // Update the price text to reflect the new cost LK.getSound('buyAutoclickerSound').play(); // Play buyAutoclickerSound when an autoclicker is purchased autoClickerText.fill = currentScore >= self.cost ? 0x00FF00 : 0xFF0000; // Update text color based on affordability // Animate the autoClicker button tween(autoClickerGraphics, { scaleX: 0.9, scaleY: 0.9 }, { duration: 100, easing: tween.easeInOut, onFinish: function onFinish() { tween(autoClickerGraphics, { scaleX: 1, scaleY: 1 }, { duration: 100, easing: tween.easeInOut }); } }); // Animate the shadowGraphics in the same way tween(shadowGraphics, { scaleX: 0.9, scaleY: 0.9 }, { duration: 100, easing: tween.easeInOut, onFinish: function onFinish() { tween(shadowGraphics, { scaleX: 1, scaleY: 1 }, { duration: 100, easing: tween.easeInOut }); } }); // Animate the toqueGraphics in the same way tween(toqueGraphics, { scaleX: 0.9, scaleY: 0.9 }, { duration: 100, easing: tween.easeInOut, onFinish: function onFinish() { tween(toqueGraphics, { scaleX: 1, scaleY: 1 }, { duration: 100, easing: tween.easeInOut }); } }); } else { tween(self, { alpha: 0.2 }, { duration: 100, easing: tween.easeInOut, onFinish: function onFinish() { tween(self, { alpha: 1 }, { duration: 100, easing: tween.easeInOut, onFinish: function onFinish() { tween(self, { alpha: 0.2 }, { duration: 100, easing: tween.easeInOut, onFinish: function onFinish() { tween(self, { alpha: 1 }, { duration: 100, easing: tween.easeInOut }); } }); } }); } }); LK.getSound('errorsond').play(); // Play error sound } }; }); // BigCake class var BigCake = Container.expand(function () { var self = Container.call(this); var bigCakeGraphics = self.attachAsset('bigCake', { anchorX: 0.5, anchorY: 0.5 }); self.on('down', function (x, y, obj) { // Use ConfettiManager to create confetti effect confettiManager.popCakes(self.x, self.y, 5); LK.getSound('clickSound').play(); currentScore += upgrade.multiplier; // Increment score by the upgrade multiplier per click score.updateScore(currentScore); storage.score = currentScore; // Save the updated score storage.timestamp = Date.now(); // Save the current timestamp // Add a bump animation tween(self, { scaleX: 1.2, scaleY: 1.2 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { tween(self, { scaleX: 1, scaleY: 1 }, { duration: 200, easing: tween.easeIn }); } }); // Removed the creation of falling cakes }); }); // Board class var Board = Container.expand(function () { var self = Container.call(this); self.boardGraphics = self.attachAsset('board', { anchorX: 0.5, anchorY: 0.5 }); self.boardGraphics.alpha = 1; // Make the board fully opaque self.addChild(self.boardGraphics); }); var Confetti = Container.expand(function (cakeIndex) { var self = Container.call(this); cakeIndex = cakeIndex ? cakeIndex : 0; var confettiGraphics = self.attachAsset('cake_' + Math.max(0, Math.min(cakeIndex, 9)), { anchorX: 0.5, anchorY: 0.5 }); confettiGraphics.visible = true; self.speedY = -10; // Initial upward speed self.gravity = 0.2; // Gravity effect self.speedX = (Math.random() - 0.5) * 10; // Random horizontal speed self.update = function () { if (self.lastY === undefined) { self.lastY = self.y; } self.y += self.speedY; self.x += self.speedX; self.speedY += self.gravity; // Apply gravity if (confettiGraphics && self.y > 2732 + confettiGraphics.height / 2) { self.destroy(); } }; }); var ConfettiManager = Container.expand(function () { var self = Container.call(this); self.popCakes = function (x, y, numConfetti) { for (var i = 0; i < numConfetti; i++) { var confetti = middleContainer.addChild(new Confetti(upgradeLevel)); confetti.x = x; confetti.y = y; confetti.speedY = -15; // Initial upward speed } }; }); // ResetButton class var ResetButton = Container.expand(function () { var self = Container.call(this); var resetButtonGraphics = self.attachAsset('resetButton', { anchorX: 0.5, anchorY: 0.5 }); self.on('down', function () { if (isResetConfirmationDisplayed) { return; } // Prevent re-clicking if confirmation is already displayed LK.getSound('resetSound').play(); // Play reset sound isResetConfirmationDisplayed = true; // Set to true when reset confirmation is shown // Create a mask to prevent clicking elsewhere during confirmation var mask = foregroundContainer.addChild(LK.getAsset('masque', { anchorX: 0.5, anchorY: 0.5 })); mask.x = 2048 / 2; mask.y = 2732 / 2; mask.alpha = 0.5; // Make the mask semi-transparent // Create a new board behind the yes and no buttons for confirmation var confirmationBoard = foregroundContainer.addChild(new Board()); confirmationBoard.x = 2048 / 2 - 80; confirmationBoard.y = 2732 / 2 - 100; confirmationBoard.scaleX = -1.5; // Mirror the board horizontally and make it wider confirmationBoard.alpha = 1; // Make the board opaque // Add a text above the yes and no buttons var restartText = new Text2('Restart from Zero?', { size: 120, // Increase the size of the text fill: 0xFF0000, // Change color to red fontWeight: 'bold', dropShadow: true, dropShadowColor: 0x000000, dropShadowBlur: 10, // Increase shadow blur for more pronounced effect dropShadowDistance: 5 }); restartText.anchor.set(0.5, 1); // Center the text horizontally and align it to the bottom restartText.x = 2048 / 2; // Center horizontally restartText.y = 2732 / 2 - 500; // Position above the buttons foregroundContainer.addChild(restartText); // Create yes and no buttons for confirmation var yesButton = foregroundContainer.addChild(LK.getAsset('yesButton', { anchorX: 0.5, anchorY: 0.5 })); yesButton.x = 2048 / 3; // Position yes button one-third from the left yesButton.y = 2732 / 2; // Center vertically var noButton = foregroundContainer.addChild(LK.getAsset('noButton', { anchorX: 0.5, anchorY: 0.5 })); noButton.x = 2048 * 2 / 3; // Position no button two-thirds from the left noButton.y = 2732 / 2; // Center vertically // Event listener for yes button yesButton.on('down', function () { LK.getSound('clearedSound').play(); // Play cleared sound when yes is pressed currentScore = 0; // Reset the score to zero upgradeLevel = 0; // Reset the upgrade level to zero score.updateScore(currentScore); // Update the score display autoClicker.cost = 100; // Reset auto clicker cost to initial value autoClicker.autoClickerCount = 0; // Reset auto clicker count autoClicker.updatePriceText(); // Update the auto clicker price text upgrade.cost = 10; // Reset upgrade cost to initial value upgrade.multiplier = 1; // Reset upgrade multiplier upgrade.updateUpgradeText(); // Update the upgrade price text upgrade.updateCakeGraphics(); // Update cake graphics based on new upgrade level storage.score = currentScore; // Save the reset score storage.autoClickerCount = autoClicker.autoClickerCount; // Save the reset auto clicker count storage.autoClickerCost = autoClicker.cost; // Save the reset auto clicker cost storage.upgradeMultiplier = upgrade.multiplier; // Save the reset upgrade multiplier storage.upgradeCost = upgrade.cost; // Save the reset upgrade cost // Remove confirmation buttons yesButton.destroy(); mask.destroy(); // Remove the mask noButton.destroy(); confirmationBoard.destroy(); // Hide the confirmation board restartText.destroy(); // Remove the 'Restart from Zero?' text isResetConfirmationDisplayed = false; // Set to false when reset confirmation is dismissed }); // Event listener for no button noButton.on('down', function () { LK.getSound('resetSound').play(); // Play reset sound // Remove confirmation buttons without resetting yesButton.destroy(); mask.destroy(); // Remove the mask noButton.destroy(); confirmationBoard.destroy(); // Hide the confirmation board restartText.destroy(); // Remove the 'Restart from Zero?' text isResetConfirmationDisplayed = false; // Set to false when reset confirmation is dismissed }); }); }); // Score class var Score = Container.expand(function () { var self = Container.call(this); var scoreText = new Text2('0', { size: 200, fill: 0xFFFDD0, dropShadow: true, // Enable drop shadow dropShadowColor: 0x000000, // Set drop shadow color to black dropShadowBlur: 5, // Set drop shadow blur dropShadowDistance: 5 // Set drop shadow distance }); scoreText.anchor.set(0.5, 0); self.addChild(scoreText); self.updateScore = function (newScore) { scoreText.setText('$' + newScore.toString()); }; }); // Upgrade class var Upgrade = Container.expand(function () { var self = Container.call(this); // Create a shadow effect by adding a black tinted, semi-transparent duplicate of upgradeGraphics var shadowGraphics = self.attachAsset('upgrade', { anchorX: 0.5, anchorY: 0.5 }); shadowGraphics.tint = 0x000000; // Tint the shadow black shadowGraphics.alpha = 0.5; // Make the shadow semi-transparent shadowGraphics.y = 10; // Position the shadow slightly below the upgrade button self.addChild(shadowGraphics); var upgradeGraphics = self.attachAsset('upgrade', { anchorX: 0.5, anchorY: 0.5 }); // Attach the cake_1 image on top of the upgrade button self.cakeGraphics = self.attachAsset('cake_1', { anchorX: 0.5, anchorY: 0.5 }); self.cakeGraphics.y = -10; // Move the cake slightly higher on the upgrade button self.addChild(self.cakeGraphics); var upgradesLabel = new Text2('Upgrades', { size: 60, fill: 0x808080, // Gray color fontWeight: '900' }); upgradesLabel.anchor.set(0.5, 1); // Center the text horizontally and align it to the bottom upgradesLabel.y = self.cakeGraphics.y - self.cakeGraphics.height / 2 - 160; // Move text slightly higher above the cake image upgradesLabel.fill = 0x808080; // Change text color to gray self.addChild(upgradesLabel); var upgradeLabel = new Text2('Cake', { size: 60, fill: 0xFF8C00, // Dark orange color fontWeight: '900', dropShadow: true, dropShadowColor: 0x000000, dropShadowBlur: 5, dropShadowDistance: 5 }); upgradeLabel.anchor.set(0.5, 1); // Center the text horizontally and align it to the bottom upgradeLabel.y = self.cakeGraphics.y - self.cakeGraphics.height / 2 - 50; // Position text even higher above the cake image self.addChild(upgradeLabel); self.cost = 10; // Initial cost of the upgrade self.multiplier = 1; // Score multiplier self.updateCost = function () { self.cost = upgradePrices[Math.min(upgradeLevel + 1, upgradePrices.length - 1)]; // Update the cost using the upgradePrices array storage.upgradeCost = self.cost; // Save the updated upgrade cost }; self.increaseMultiplier = function () { self.multiplier += 1; // Increase the multiplier by 1 }; var upgradeText = new Text2('$' + self.cost, { size: 80, fill: 0xFFA500, // Orange color fontWeight: '900', dropShadow: true, dropShadowColor: 0x000000, dropShadowBlur: 5, dropShadowDistance: 5 }); upgradeText.anchor.set(0.5, 0); upgradeText.x = 0; upgradeText.y = upgradeGraphics.height / 2 + 20; // Position text below the upgrade button self.addChild(upgradeText); self.updateUpgradeText = function () { upgradeText.setText(formatPrice(self.cost)); }; self.updateCakeGraphics = function () { var cakeIndex = Math.min(upgradeLevel + 1, 9); tween(self.cakeGraphics, { alpha: 0 }, { duration: 500, easing: tween.easeOut, onFinish: function onFinish() { self.removeChild(self.cakeGraphics); self.cakeGraphics = self.attachAsset('cake_' + cakeIndex, { anchorX: 0.5, anchorY: 0.5 }); self.cakeGraphics.y = -10; self.cakeGraphics.alpha = 0; self.addChild(self.cakeGraphics); tween(self.cakeGraphics, { alpha: 1 }, { duration: 500, easing: tween.easeIn }); } }); }; self.onClick = function () { if (currentScore >= self.cost) { currentScore -= self.cost; // Deduct the cost from the current score score.updateScore(currentScore); // Update the score display self.updateCost(); // Update the cost for the next upgrade storage.upgradeMultiplier = self.multiplier; // Save the updated multiplier self.increaseMultiplier(); // Increase the score multiplier self.updateUpgradeText(); // Update the upgrade text upgradeLevel = Math.min(upgradeLevel + 1, 9); // Increment upgrade level, max 9 self.updateCakeGraphics(); // Update cake graphics based on new upgrade level confettiManager.popCakes(bigCake.x, bigCake.y, 5); // Call popCakes using bigCake's coordinates LK.getSound('buySound').play(); // Play buy sound when upgrade is purchased // Animate the upgrade button tween(upgradeGraphics, { scaleX: 0.9, scaleY: 0.9 }, { duration: 100, easing: tween.easeInOut, onFinish: function onFinish() { tween(upgradeGraphics, { scaleX: 1, scaleY: 1 }, { duration: 100, easing: tween.easeInOut }); } }); // Animate the shadowGraphics in the same way tween(shadowGraphics, { scaleX: 0.9, scaleY: 0.9 }, { duration: 100, easing: tween.easeInOut, onFinish: function onFinish() { tween(shadowGraphics, { scaleX: 1, scaleY: 1 }, { duration: 100, easing: tween.easeInOut }); } }); // Animate the cakeGraphics in the same way tween(self.cakeGraphics, { scaleX: 0.9, scaleY: 0.9 }, { duration: 100, easing: tween.easeInOut, onFinish: function onFinish() { tween(self.cakeGraphics, { scaleX: 1, scaleY: 1 }, { duration: 100, easing: tween.easeInOut }); } }); } else { tween(self, { alpha: 0.2 }, { duration: 100, easing: tween.easeInOut, onFinish: function onFinish() { tween(self, { alpha: 1 }, { duration: 100, easing: tween.easeInOut, onFinish: function onFinish() { tween(self, { alpha: 0.2 }, { duration: 100, easing: tween.easeInOut, onFinish: function onFinish() { tween(self, { alpha: 1 }, { duration: 100, easing: tween.easeInOut }); } }); } }); } }); LK.getSound('errorsond').play(); // Play error sound } }; }); /**** * Initialize Game ****/ /**** * Initialize Game * Set up the game environment and initial configurations ****/ var game = new LK.Game({ // No title, no description // Always backgroundColor is black backgroundColor: 0x000000 }); /**** * Game Code ****/ // Global array for upgrade prices var upgradePrices = [10, // $10 100, // $100 1000, // $1,000 10000, // $10,000 100000, // $100,000 1000000, // $1,000,000 10000000, // $10,000,000 100000000, // $100,000,000 1000000000, // $1,000,000,000 10000000000 // $10,000,000,000 ]; // Global array for auto clicker prices var autoClickerPrices = [100, // $100 1000, // $1,000 20000, // $10,000 300000, // $100,000 4000000, // $1,000,000 50000000, // $10,000,000 600000000, // $100,000,000 7000000000, // $1,000,000,000 80000000000, // $10,000,000,000 900000000000 // $100,000,000,000 ]; /**** * Game Code * Main game logic and event handling ****/ /**** * Assets * Initialize all game assets including images, sounds, and music ****/ // Declare game variables var cakeList = ['cake_0', 'cake_1', 'cake_2', 'cake_3', 'cake_4', 'cake_5', 'cake_6', 'cake_8', 'cake_9']; var isResetConfirmationDisplayed = false; // Track if reset confirmation is displayed var upgradeLevel = 0; // Track the upgrade level from 0 to 9 var confettiManager; // Declare confettiManager globally // Sounds // Music /**** * Plugins * Import necessary plugins for tweening animations and storage management ****/ // Function to format prices function formatPrice(value) { if (value >= 1e18) { // Quintillion return '$' + (value / 1e18).toFixed(1) + 'Q'; } else if (value >= 1e15) { // Quadrillion return '$' + (value / 1e15).toFixed(1) + 'Qa'; } else if (value >= 1e12) { // Trillion return '$' + (value / 1e12).toFixed(1) + 'T'; } else if (value >= 1e9) { // Billion return '$' + (value / 1e9).toFixed(1) + 'B'; } else if (value >= 1e6) { // Million return '$' + (value / 1e6).toFixed(1) + 'M'; } else { return '$' + value; } } if (typeof newCakeButton !== 'undefined' && newCakeButton.newCake) { newCakeButton.newCake.on('down', function (x, y, obj) { newCakeButton.newCake.onClick(); }); } // Declare game variables var backgroundContainer; var middleContainer; var foregroundContainer; var currentScore; var score; var lastTimestamp; var timeElapsed; var clicksSinceLastSession; var autoClicker; var upgrade; var autoClickerText; var bigCake; var resetButton; var board; // Initialize game variables function initializeGameVariables() { backgroundContainer = new Container(); game.addChild(backgroundContainer); // Initialize middleContainer middleContainer = new Container(); game.addChild(middleContainer); // Initialize foregroundContainer foregroundContainer = new Container(); game.addChild(foregroundContainer); background = backgroundContainer.addChild(LK.getAsset('background', { anchorX: 0.5, anchorY: 0.5 })); background.x = 2048 / 2; background.y = 2732 / 2; background.scaleX = 2048 / background.width; // Scale background to fit the game width background.scaleY = 2732 / background.height; // Scale background to fit the game height // Initialize board board = foregroundContainer.addChild(new Board()); board.x = 2240; board.y = 1230; // Center board vertically board.boardGraphics.alpha = 0.8; // Set transparency of the right board to 0.8 // Initialize bigCake bigCake = middleContainer.addChild(new BigCake()); bigCake.x = 2048 / 2; bigCake.y = 2732 / 2; // Initialize score score = game.addChild(new Score()); score.x = 2048 / 2; score.y = 30; // Position score even higher at the top center currentScore = storage.score || 0; // Load saved score or default to 0 score.updateScore(currentScore); // Refresh the score display with the loaded score // Calculate the number of clicks since the last session lastTimestamp = storage.timestamp || Date.now(); timeElapsed = Date.now() - lastTimestamp; clicksSinceLastSession = Math.floor(timeElapsed / 1000); // Assuming 1 click per second as a baseline console.log("Clicks since last session: ", clicksSinceLastSession); currentScore += clicksSinceLastSession; // Add clicks since last session to the current score score.updateScore(currentScore); // Update the score display with the new score storage.score = currentScore; // Save the updated score // Initialize auto clicker autoClicker = foregroundContainer.addChild(new AutoClicker()); autoClicker.autoClickerCount = storage.autoClickerCount || 0; // Load saved auto clicker count or default to 0 autoClicker.cost = storage.autoClickerCost || autoClickerPrices[0]; // Load saved auto clicker cost or default to initial cost from autoClickerPrices array autoClicker.updatePriceText(); // Update the price text to reflect the loaded cost if (autoClicker.autoClickerCount > 0) { autoClicker.startAutoClicking(); // Start auto-clicking if there are saved auto-clickers } // Initialize upgrade upgrade = foregroundContainer.addChild(new Upgrade()); upgrade.multiplier = storage.upgradeMultiplier || 1; // Load saved upgrade multiplier or default to 1 upgrade.cost = storage.upgradeCost || upgradePrices[0]; // Load saved upgrade cost or default to initial cost from upgradePrices array upgrade.updateUpgradeText(); // Update the upgrade price text to reflect the loaded cost upgrade.x = 2048 - upgrade.width / 2 - 10; // Position upgrade button on the right side of the screen upgrade.y = 2732 / 2 - upgrade.height + 140; // Position upgrade button slightly lower on the screen // Event listener for upgrade button clicks upgrade.on('down', function (x, y, obj) { upgrade.onClick(); }); // Initialize reset button resetButton = backgroundContainer.addChild(new ResetButton()); // Initialize confetti manager confettiManager = new ConfettiManager(); resetButton.x = 2048 - resetButton.width / 2 - 40; // Add margin to the right edge resetButton.y = score.y + score.height / 2 + 10; // Adjust reset button position to be slightly higher // Initialize auto clicker text autoClickerText = new Text2('Auto Clicker: $' + autoClicker.cost, { size: 100, fill: currentScore >= autoClicker.cost ? 0x00FF00 : 0xFF0000 }); autoClickerText.anchor.set(0.5, 0); autoClickerText.x = autoClicker.x; autoClickerText.y = autoClicker.y - autoClicker.height / 2 - 50; // Position text above the auto clicker button game.addChild(autoClickerText); // Update autoClickerText immediately after loading the game autoClicker.x = 2048 - autoClicker.width / 2 - 10; // Position auto clicker button on the right side of the screen autoClicker.y = 2732 / 2 + 160; // Position auto clicker button slightly lower on the screen // Event listener for auto clicker clicks autoClicker.on('down', function (x, y, obj) { autoClicker.onClick(); }); // Play bakery music in a loop throughout the game LK.playMusic('musiqueclicker', { loop: true }); } // Call the function to initialize game variables initializeGameVariables();
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
score: 0,
autoClickerCount: 0,
upgradeMultiplier: 1
});
/****
* Classes
****/
// AutoClicker class
var AutoClicker = Container.expand(function () {
var self = Container.call(this);
self.startAutoClicking = function () {
self.autoClickerInterval = LK.setInterval(function () {
if (self.autoClickerCount > 0) {
bigCake.emit('down'); // Trigger the 'down' event on bigCake to simulate a click
}
}, 1000);
};
// Create a shadow effect by adding a black tinted, semi-transparent duplicate of autoClickerGraphics
var shadowGraphics = self.attachAsset('autoClicker', {
anchorX: 0.5,
anchorY: 0.5
});
shadowGraphics.tint = 0x000000; // Tint the shadow black
shadowGraphics.alpha = 0.5; // Make the shadow semi-transparent
shadowGraphics.y = 10; // Position the shadow slightly below the autoClicker button
self.addChild(shadowGraphics);
var autoClickerGraphics = self.attachAsset('autoClicker', {
anchorX: 0.5,
anchorY: 0.5
});
// Add 'Worker' text above the auto clicker image
var workerLabel = new Text2('Worker', {
size: 60,
fill: 0x1E90FF,
// Match price text color
fontWeight: '900',
dropShadow: true,
dropShadowColor: 0x000000,
dropShadowBlur: 5,
dropShadowDistance: 5
});
workerLabel.anchor.set(0.5, 1); // Center the text horizontally and align it to the bottom
workerLabel.fill = 0x0000FF; // Change text color to blue
workerLabel.y = autoClickerGraphics.y - autoClickerGraphics.height / 2 - 10; // Adjust text position to -10 above the auto clicker image
self.addChild(workerLabel);
// Attach the chef's toque image on top of the auto clicker button
var toqueGraphics = self.attachAsset('toque', {
anchorX: 0.5,
anchorY: 0.5
});
toqueGraphics.y = -10; // Move the toque slightly higher on the auto clicker
self.addChild(toqueGraphics);
self.cost = 100; // Initial cost of the auto clicker
self.autoClickerCount = 0;
self.stars = []; // Array to store the list of stars
var priceText = new Text2('$' + self.cost, {
size: 80,
fill: 0x1E90FF,
fontWeight: '900',
// Make the text bolder
dropShadow: true,
// Enable drop shadow
dropShadowColor: 0x000000,
// Set drop shadow color to black
dropShadowBlur: 5,
// Set drop shadow blur
dropShadowDistance: 5 // Set drop shadow distance
});
priceText.setText('$' + self.cost); // Update the price text to reflect the current cost
priceText.anchor.set(0.5, 0);
priceText.x = 0;
priceText.y = autoClickerGraphics.height / 2 + 0; // Position text below the auto clicker button
self.addChild(priceText);
self.updatePriceText = function () {
priceText.setText(formatPrice(self.cost)); // Update the price text to reflect the current cost
};
self.displayStars = function () {
// Update positions of all stars based on the current count
self.stars.forEach(function (star, index) {
if (self.autoClickerCount === 1) {
star.x = 0; // Position the first star at x = 0
} else if (self.autoClickerCount === 2) {
star.x = index === 0 ? -30 : 30; // Position the second star at x = -60 and the third at x = 60
} else if (self.autoClickerCount === 3) {
star.x = index === 0 ? -70 : index === 1 ? 0 : 70;
star.y = index === 0 ? 70 : index === 1 ? 100 : 70;
}
});
};
self.onClick = function () {
if (currentScore >= self.cost) {
currentScore -= self.cost; // Deduct the cost from the current score
score.updateScore(currentScore); // Update the score display
self.autoClickerCount += 1; // Increase the number of auto clickers
// Add a star under the toque for each upgrade, up to 3 stars
if (self.autoClickerCount <= 3) {
var star = self.attachAsset('etoile', {
anchorX: 0.5,
anchorY: 0.5
});
star.y = toqueGraphics.y + toqueGraphics.height / 2 + star.height / 2; // Position the star under the toque
self.stars.push(star); // Add the star to the stars array
self.displayStars(); // Update positions of all stars based on the current count
}
storage.autoClickerCount = self.autoClickerCount; // Save the updated auto clicker count
if (self.autoClickerCount === 1) {
self.startAutoClicking(); // Start auto clicking only when the first auto clicker is purchased
}
self.cost = autoClickerPrices[Math.min(self.autoClickerCount, autoClickerPrices.length - 1)]; // Update the cost using the autoClickerPrices array
storage.autoClickerCost = self.cost; // Save the updated auto clicker cost
self.updatePriceText(); // Update the price text to reflect the new cost
LK.getSound('buyAutoclickerSound').play(); // Play buyAutoclickerSound when an autoclicker is purchased
autoClickerText.fill = currentScore >= self.cost ? 0x00FF00 : 0xFF0000; // Update text color based on affordability
// Animate the autoClicker button
tween(autoClickerGraphics, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(autoClickerGraphics, {
scaleX: 1,
scaleY: 1
}, {
duration: 100,
easing: tween.easeInOut
});
}
});
// Animate the shadowGraphics in the same way
tween(shadowGraphics, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(shadowGraphics, {
scaleX: 1,
scaleY: 1
}, {
duration: 100,
easing: tween.easeInOut
});
}
});
// Animate the toqueGraphics in the same way
tween(toqueGraphics, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(toqueGraphics, {
scaleX: 1,
scaleY: 1
}, {
duration: 100,
easing: tween.easeInOut
});
}
});
} else {
tween(self, {
alpha: 0.2
}, {
duration: 100,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(self, {
alpha: 1
}, {
duration: 100,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(self, {
alpha: 0.2
}, {
duration: 100,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(self, {
alpha: 1
}, {
duration: 100,
easing: tween.easeInOut
});
}
});
}
});
}
});
LK.getSound('errorsond').play(); // Play error sound
}
};
});
// BigCake class
var BigCake = Container.expand(function () {
var self = Container.call(this);
var bigCakeGraphics = self.attachAsset('bigCake', {
anchorX: 0.5,
anchorY: 0.5
});
self.on('down', function (x, y, obj) {
// Use ConfettiManager to create confetti effect
confettiManager.popCakes(self.x, self.y, 5);
LK.getSound('clickSound').play();
currentScore += upgrade.multiplier; // Increment score by the upgrade multiplier per click
score.updateScore(currentScore);
storage.score = currentScore; // Save the updated score
storage.timestamp = Date.now(); // Save the current timestamp
// Add a bump animation
tween(self, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self, {
scaleX: 1,
scaleY: 1
}, {
duration: 200,
easing: tween.easeIn
});
}
});
// Removed the creation of falling cakes
});
});
// Board class
var Board = Container.expand(function () {
var self = Container.call(this);
self.boardGraphics = self.attachAsset('board', {
anchorX: 0.5,
anchorY: 0.5
});
self.boardGraphics.alpha = 1; // Make the board fully opaque
self.addChild(self.boardGraphics);
});
var Confetti = Container.expand(function (cakeIndex) {
var self = Container.call(this);
cakeIndex = cakeIndex ? cakeIndex : 0;
var confettiGraphics = self.attachAsset('cake_' + Math.max(0, Math.min(cakeIndex, 9)), {
anchorX: 0.5,
anchorY: 0.5
});
confettiGraphics.visible = true;
self.speedY = -10; // Initial upward speed
self.gravity = 0.2; // Gravity effect
self.speedX = (Math.random() - 0.5) * 10; // Random horizontal speed
self.update = function () {
if (self.lastY === undefined) {
self.lastY = self.y;
}
self.y += self.speedY;
self.x += self.speedX;
self.speedY += self.gravity; // Apply gravity
if (confettiGraphics && self.y > 2732 + confettiGraphics.height / 2) {
self.destroy();
}
};
});
var ConfettiManager = Container.expand(function () {
var self = Container.call(this);
self.popCakes = function (x, y, numConfetti) {
for (var i = 0; i < numConfetti; i++) {
var confetti = middleContainer.addChild(new Confetti(upgradeLevel));
confetti.x = x;
confetti.y = y;
confetti.speedY = -15; // Initial upward speed
}
};
});
// ResetButton class
var ResetButton = Container.expand(function () {
var self = Container.call(this);
var resetButtonGraphics = self.attachAsset('resetButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.on('down', function () {
if (isResetConfirmationDisplayed) {
return;
} // Prevent re-clicking if confirmation is already displayed
LK.getSound('resetSound').play(); // Play reset sound
isResetConfirmationDisplayed = true; // Set to true when reset confirmation is shown
// Create a mask to prevent clicking elsewhere during confirmation
var mask = foregroundContainer.addChild(LK.getAsset('masque', {
anchorX: 0.5,
anchorY: 0.5
}));
mask.x = 2048 / 2;
mask.y = 2732 / 2;
mask.alpha = 0.5; // Make the mask semi-transparent
// Create a new board behind the yes and no buttons for confirmation
var confirmationBoard = foregroundContainer.addChild(new Board());
confirmationBoard.x = 2048 / 2 - 80;
confirmationBoard.y = 2732 / 2 - 100;
confirmationBoard.scaleX = -1.5; // Mirror the board horizontally and make it wider
confirmationBoard.alpha = 1; // Make the board opaque
// Add a text above the yes and no buttons
var restartText = new Text2('Restart from Zero?', {
size: 120,
// Increase the size of the text
fill: 0xFF0000,
// Change color to red
fontWeight: 'bold',
dropShadow: true,
dropShadowColor: 0x000000,
dropShadowBlur: 10,
// Increase shadow blur for more pronounced effect
dropShadowDistance: 5
});
restartText.anchor.set(0.5, 1); // Center the text horizontally and align it to the bottom
restartText.x = 2048 / 2; // Center horizontally
restartText.y = 2732 / 2 - 500; // Position above the buttons
foregroundContainer.addChild(restartText);
// Create yes and no buttons for confirmation
var yesButton = foregroundContainer.addChild(LK.getAsset('yesButton', {
anchorX: 0.5,
anchorY: 0.5
}));
yesButton.x = 2048 / 3; // Position yes button one-third from the left
yesButton.y = 2732 / 2; // Center vertically
var noButton = foregroundContainer.addChild(LK.getAsset('noButton', {
anchorX: 0.5,
anchorY: 0.5
}));
noButton.x = 2048 * 2 / 3; // Position no button two-thirds from the left
noButton.y = 2732 / 2; // Center vertically
// Event listener for yes button
yesButton.on('down', function () {
LK.getSound('clearedSound').play(); // Play cleared sound when yes is pressed
currentScore = 0; // Reset the score to zero
upgradeLevel = 0; // Reset the upgrade level to zero
score.updateScore(currentScore); // Update the score display
autoClicker.cost = 100; // Reset auto clicker cost to initial value
autoClicker.autoClickerCount = 0; // Reset auto clicker count
autoClicker.updatePriceText(); // Update the auto clicker price text
upgrade.cost = 10; // Reset upgrade cost to initial value
upgrade.multiplier = 1; // Reset upgrade multiplier
upgrade.updateUpgradeText(); // Update the upgrade price text
upgrade.updateCakeGraphics(); // Update cake graphics based on new upgrade level
storage.score = currentScore; // Save the reset score
storage.autoClickerCount = autoClicker.autoClickerCount; // Save the reset auto clicker count
storage.autoClickerCost = autoClicker.cost; // Save the reset auto clicker cost
storage.upgradeMultiplier = upgrade.multiplier; // Save the reset upgrade multiplier
storage.upgradeCost = upgrade.cost; // Save the reset upgrade cost
// Remove confirmation buttons
yesButton.destroy();
mask.destroy(); // Remove the mask
noButton.destroy();
confirmationBoard.destroy(); // Hide the confirmation board
restartText.destroy(); // Remove the 'Restart from Zero?' text
isResetConfirmationDisplayed = false; // Set to false when reset confirmation is dismissed
});
// Event listener for no button
noButton.on('down', function () {
LK.getSound('resetSound').play(); // Play reset sound
// Remove confirmation buttons without resetting
yesButton.destroy();
mask.destroy(); // Remove the mask
noButton.destroy();
confirmationBoard.destroy(); // Hide the confirmation board
restartText.destroy(); // Remove the 'Restart from Zero?' text
isResetConfirmationDisplayed = false; // Set to false when reset confirmation is dismissed
});
});
});
// Score class
var Score = Container.expand(function () {
var self = Container.call(this);
var scoreText = new Text2('0', {
size: 200,
fill: 0xFFFDD0,
dropShadow: true,
// Enable drop shadow
dropShadowColor: 0x000000,
// Set drop shadow color to black
dropShadowBlur: 5,
// Set drop shadow blur
dropShadowDistance: 5 // Set drop shadow distance
});
scoreText.anchor.set(0.5, 0);
self.addChild(scoreText);
self.updateScore = function (newScore) {
scoreText.setText('$' + newScore.toString());
};
});
// Upgrade class
var Upgrade = Container.expand(function () {
var self = Container.call(this);
// Create a shadow effect by adding a black tinted, semi-transparent duplicate of upgradeGraphics
var shadowGraphics = self.attachAsset('upgrade', {
anchorX: 0.5,
anchorY: 0.5
});
shadowGraphics.tint = 0x000000; // Tint the shadow black
shadowGraphics.alpha = 0.5; // Make the shadow semi-transparent
shadowGraphics.y = 10; // Position the shadow slightly below the upgrade button
self.addChild(shadowGraphics);
var upgradeGraphics = self.attachAsset('upgrade', {
anchorX: 0.5,
anchorY: 0.5
});
// Attach the cake_1 image on top of the upgrade button
self.cakeGraphics = self.attachAsset('cake_1', {
anchorX: 0.5,
anchorY: 0.5
});
self.cakeGraphics.y = -10; // Move the cake slightly higher on the upgrade button
self.addChild(self.cakeGraphics);
var upgradesLabel = new Text2('Upgrades', {
size: 60,
fill: 0x808080,
// Gray color
fontWeight: '900'
});
upgradesLabel.anchor.set(0.5, 1); // Center the text horizontally and align it to the bottom
upgradesLabel.y = self.cakeGraphics.y - self.cakeGraphics.height / 2 - 160; // Move text slightly higher above the cake image
upgradesLabel.fill = 0x808080; // Change text color to gray
self.addChild(upgradesLabel);
var upgradeLabel = new Text2('Cake', {
size: 60,
fill: 0xFF8C00,
// Dark orange color
fontWeight: '900',
dropShadow: true,
dropShadowColor: 0x000000,
dropShadowBlur: 5,
dropShadowDistance: 5
});
upgradeLabel.anchor.set(0.5, 1); // Center the text horizontally and align it to the bottom
upgradeLabel.y = self.cakeGraphics.y - self.cakeGraphics.height / 2 - 50; // Position text even higher above the cake image
self.addChild(upgradeLabel);
self.cost = 10; // Initial cost of the upgrade
self.multiplier = 1; // Score multiplier
self.updateCost = function () {
self.cost = upgradePrices[Math.min(upgradeLevel + 1, upgradePrices.length - 1)]; // Update the cost using the upgradePrices array
storage.upgradeCost = self.cost; // Save the updated upgrade cost
};
self.increaseMultiplier = function () {
self.multiplier += 1; // Increase the multiplier by 1
};
var upgradeText = new Text2('$' + self.cost, {
size: 80,
fill: 0xFFA500,
// Orange color
fontWeight: '900',
dropShadow: true,
dropShadowColor: 0x000000,
dropShadowBlur: 5,
dropShadowDistance: 5
});
upgradeText.anchor.set(0.5, 0);
upgradeText.x = 0;
upgradeText.y = upgradeGraphics.height / 2 + 20; // Position text below the upgrade button
self.addChild(upgradeText);
self.updateUpgradeText = function () {
upgradeText.setText(formatPrice(self.cost));
};
self.updateCakeGraphics = function () {
var cakeIndex = Math.min(upgradeLevel + 1, 9);
tween(self.cakeGraphics, {
alpha: 0
}, {
duration: 500,
easing: tween.easeOut,
onFinish: function onFinish() {
self.removeChild(self.cakeGraphics);
self.cakeGraphics = self.attachAsset('cake_' + cakeIndex, {
anchorX: 0.5,
anchorY: 0.5
});
self.cakeGraphics.y = -10;
self.cakeGraphics.alpha = 0;
self.addChild(self.cakeGraphics);
tween(self.cakeGraphics, {
alpha: 1
}, {
duration: 500,
easing: tween.easeIn
});
}
});
};
self.onClick = function () {
if (currentScore >= self.cost) {
currentScore -= self.cost; // Deduct the cost from the current score
score.updateScore(currentScore); // Update the score display
self.updateCost(); // Update the cost for the next upgrade
storage.upgradeMultiplier = self.multiplier; // Save the updated multiplier
self.increaseMultiplier(); // Increase the score multiplier
self.updateUpgradeText(); // Update the upgrade text
upgradeLevel = Math.min(upgradeLevel + 1, 9); // Increment upgrade level, max 9
self.updateCakeGraphics(); // Update cake graphics based on new upgrade level
confettiManager.popCakes(bigCake.x, bigCake.y, 5); // Call popCakes using bigCake's coordinates
LK.getSound('buySound').play(); // Play buy sound when upgrade is purchased
// Animate the upgrade button
tween(upgradeGraphics, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(upgradeGraphics, {
scaleX: 1,
scaleY: 1
}, {
duration: 100,
easing: tween.easeInOut
});
}
});
// Animate the shadowGraphics in the same way
tween(shadowGraphics, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(shadowGraphics, {
scaleX: 1,
scaleY: 1
}, {
duration: 100,
easing: tween.easeInOut
});
}
});
// Animate the cakeGraphics in the same way
tween(self.cakeGraphics, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(self.cakeGraphics, {
scaleX: 1,
scaleY: 1
}, {
duration: 100,
easing: tween.easeInOut
});
}
});
} else {
tween(self, {
alpha: 0.2
}, {
duration: 100,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(self, {
alpha: 1
}, {
duration: 100,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(self, {
alpha: 0.2
}, {
duration: 100,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(self, {
alpha: 1
}, {
duration: 100,
easing: tween.easeInOut
});
}
});
}
});
}
});
LK.getSound('errorsond').play(); // Play error sound
}
};
});
/****
* Initialize Game
****/
/****
* Initialize Game
* Set up the game environment and initial configurations
****/
var game = new LK.Game({
// No title, no description
// Always backgroundColor is black
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Global array for upgrade prices
var upgradePrices = [10,
// $10
100,
// $100
1000,
// $1,000
10000,
// $10,000
100000,
// $100,000
1000000,
// $1,000,000
10000000,
// $10,000,000
100000000,
// $100,000,000
1000000000,
// $1,000,000,000
10000000000 // $10,000,000,000
];
// Global array for auto clicker prices
var autoClickerPrices = [100,
// $100
1000,
// $1,000
20000,
// $10,000
300000,
// $100,000
4000000,
// $1,000,000
50000000,
// $10,000,000
600000000,
// $100,000,000
7000000000,
// $1,000,000,000
80000000000,
// $10,000,000,000
900000000000 // $100,000,000,000
];
/****
* Game Code
* Main game logic and event handling
****/
/****
* Assets
* Initialize all game assets including images, sounds, and music
****/
// Declare game variables
var cakeList = ['cake_0', 'cake_1', 'cake_2', 'cake_3', 'cake_4', 'cake_5', 'cake_6', 'cake_8', 'cake_9'];
var isResetConfirmationDisplayed = false; // Track if reset confirmation is displayed
var upgradeLevel = 0; // Track the upgrade level from 0 to 9
var confettiManager; // Declare confettiManager globally
// Sounds
// Music
/****
* Plugins
* Import necessary plugins for tweening animations and storage management
****/
// Function to format prices
function formatPrice(value) {
if (value >= 1e18) {
// Quintillion
return '$' + (value / 1e18).toFixed(1) + 'Q';
} else if (value >= 1e15) {
// Quadrillion
return '$' + (value / 1e15).toFixed(1) + 'Qa';
} else if (value >= 1e12) {
// Trillion
return '$' + (value / 1e12).toFixed(1) + 'T';
} else if (value >= 1e9) {
// Billion
return '$' + (value / 1e9).toFixed(1) + 'B';
} else if (value >= 1e6) {
// Million
return '$' + (value / 1e6).toFixed(1) + 'M';
} else {
return '$' + value;
}
}
if (typeof newCakeButton !== 'undefined' && newCakeButton.newCake) {
newCakeButton.newCake.on('down', function (x, y, obj) {
newCakeButton.newCake.onClick();
});
}
// Declare game variables
var backgroundContainer;
var middleContainer;
var foregroundContainer;
var currentScore;
var score;
var lastTimestamp;
var timeElapsed;
var clicksSinceLastSession;
var autoClicker;
var upgrade;
var autoClickerText;
var bigCake;
var resetButton;
var board;
// Initialize game variables
function initializeGameVariables() {
backgroundContainer = new Container();
game.addChild(backgroundContainer);
// Initialize middleContainer
middleContainer = new Container();
game.addChild(middleContainer);
// Initialize foregroundContainer
foregroundContainer = new Container();
game.addChild(foregroundContainer);
background = backgroundContainer.addChild(LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5
}));
background.x = 2048 / 2;
background.y = 2732 / 2;
background.scaleX = 2048 / background.width; // Scale background to fit the game width
background.scaleY = 2732 / background.height; // Scale background to fit the game height
// Initialize board
board = foregroundContainer.addChild(new Board());
board.x = 2240;
board.y = 1230; // Center board vertically
board.boardGraphics.alpha = 0.8; // Set transparency of the right board to 0.8
// Initialize bigCake
bigCake = middleContainer.addChild(new BigCake());
bigCake.x = 2048 / 2;
bigCake.y = 2732 / 2;
// Initialize score
score = game.addChild(new Score());
score.x = 2048 / 2;
score.y = 30; // Position score even higher at the top center
currentScore = storage.score || 0; // Load saved score or default to 0
score.updateScore(currentScore); // Refresh the score display with the loaded score
// Calculate the number of clicks since the last session
lastTimestamp = storage.timestamp || Date.now();
timeElapsed = Date.now() - lastTimestamp;
clicksSinceLastSession = Math.floor(timeElapsed / 1000); // Assuming 1 click per second as a baseline
console.log("Clicks since last session: ", clicksSinceLastSession);
currentScore += clicksSinceLastSession; // Add clicks since last session to the current score
score.updateScore(currentScore); // Update the score display with the new score
storage.score = currentScore; // Save the updated score
// Initialize auto clicker
autoClicker = foregroundContainer.addChild(new AutoClicker());
autoClicker.autoClickerCount = storage.autoClickerCount || 0; // Load saved auto clicker count or default to 0
autoClicker.cost = storage.autoClickerCost || autoClickerPrices[0]; // Load saved auto clicker cost or default to initial cost from autoClickerPrices array
autoClicker.updatePriceText(); // Update the price text to reflect the loaded cost
if (autoClicker.autoClickerCount > 0) {
autoClicker.startAutoClicking(); // Start auto-clicking if there are saved auto-clickers
}
// Initialize upgrade
upgrade = foregroundContainer.addChild(new Upgrade());
upgrade.multiplier = storage.upgradeMultiplier || 1; // Load saved upgrade multiplier or default to 1
upgrade.cost = storage.upgradeCost || upgradePrices[0]; // Load saved upgrade cost or default to initial cost from upgradePrices array
upgrade.updateUpgradeText(); // Update the upgrade price text to reflect the loaded cost
upgrade.x = 2048 - upgrade.width / 2 - 10; // Position upgrade button on the right side of the screen
upgrade.y = 2732 / 2 - upgrade.height + 140; // Position upgrade button slightly lower on the screen
// Event listener for upgrade button clicks
upgrade.on('down', function (x, y, obj) {
upgrade.onClick();
});
// Initialize reset button
resetButton = backgroundContainer.addChild(new ResetButton());
// Initialize confetti manager
confettiManager = new ConfettiManager();
resetButton.x = 2048 - resetButton.width / 2 - 40; // Add margin to the right edge
resetButton.y = score.y + score.height / 2 + 10; // Adjust reset button position to be slightly higher
// Initialize auto clicker text
autoClickerText = new Text2('Auto Clicker: $' + autoClicker.cost, {
size: 100,
fill: currentScore >= autoClicker.cost ? 0x00FF00 : 0xFF0000
});
autoClickerText.anchor.set(0.5, 0);
autoClickerText.x = autoClicker.x;
autoClickerText.y = autoClicker.y - autoClicker.height / 2 - 50; // Position text above the auto clicker button
game.addChild(autoClickerText);
// Update autoClickerText immediately after loading the game
autoClicker.x = 2048 - autoClicker.width / 2 - 10; // Position auto clicker button on the right side of the screen
autoClicker.y = 2732 / 2 + 160; // Position auto clicker button slightly lower on the screen
// Event listener for auto clicker clicks
autoClicker.on('down', function (x, y, obj) {
autoClicker.onClick();
});
// Play bakery music in a loop throughout the game
LK.playMusic('musiqueclicker', {
loop: true
});
}
// Call the function to initialize game variables
initializeGameVariables();
a button saying 'reset'. In-Game asset. 2d. Blank background. High contrast.
enlève ça
interieure de patiserie. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
gâteau ( pas réaliste ). Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
sparkles
gâteau. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
gâteau. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
gâteau. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
dessin de toque de chef
étoile dorée toute simple comme dans les commentaires d'un site web
une patisserie (gâteau) simple. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
interieure de patiserie vide avec uniquement le sol et les murs. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
trace blanche verticale d'un effet de coup de ninja
Vue de face centrée d'une machine magique en forme de pièce montée arc-en-ciel avec une petite entrée d'alimentation en bas au milieu, un très grand hublot central et un tube transparent dirigé vers le haut.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
errorsond
Sound effect
relaxsond
Sound effect
clickSound
Sound effect
musiqueclicker
Music
buySound
Sound effect
resetSound
Sound effect
buyAutoclickerSound
Sound effect
clearedSound
Sound effect
bonusSound
Sound effect
ohoh
Sound effect
cheers
Sound effect
squashingSound
Sound effect
CutSound
Sound effect
youpi
Sound effect
canonSound
Sound effect
yeahh
Sound effect
nooo
Sound effect
machineError
Sound effect
aspire
Sound effect