Code edit (3 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
si isMiniGameRunning == 1 et heavyRain est vrai, le CakeRainManager appelle spawnCake 20 fois
User prompt
Si le Bonus Cake est clickeÌ pendant le main game passe heavyRain aÌ vrai
User prompt
quand on bascule de mini jeu 2 vers le main Game, met heavyRain aÌ faux
User prompt
ajoute un nouveau flag global heavyRain = false
Code edit (1 edits merged)
Please save this source code
User prompt
quand le upgradeLevel change, appelle disableButton si upgradeLevvel >= 9
Code edit (3 edits merged)
Please save this source code
User prompt
dans la classe Upgrade, ajouter une fonction disableButton qui le rend non interactif et met le upgradeText aÌ vide
User prompt
Quand upgradeLevel == 9, desactive le bouton Upgrade et cache son prix
Code edit (5 edits merged)
Please save this source code
User prompt
Please fix the bug: 'switchButtonThird.scale.activate is not a function' in or related to this line: 'switchButtonThird.scale.activate();' Line Number: 2259
Code edit (1 edits merged)
Please save this source code
User prompt
ajoute une fonction activate dans SwitchButton qui met le interactive aÌ vrai
Code edit (1 edits merged)
Please save this source code
User prompt
anime leÌgerement la taille du switchButton en boucle tant que hasUsedSwitchButton est faux âȘđĄ Consider importing and using the following plugins: @upit/tween.v1
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
score: 0,
autoClickerCount: 0,
upgradeMultiplier: 1,
isMiniGameRunning: 0,
hasUsedSwitchButton: false
});
/****
* 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
}
if (self.autoClickerCount > 1 && self.autoClickerCount < autoClicksPerSecond.length) {
bigCake.emit('down'); // Trigger the 'down' event on bigCake to simulate a click
currentScore += upgradeMultiplier[upgradeLevel] * autoClicksPerSecond[self.autoClickerCount]; // 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
}
}, 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 toque image on top of the auto clicker button
var toqueGraphics = self.attachAsset('toque', {
anchorX: 0.5,
anchorY: 0.5
});
toqueGraphics.y = 0; // 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.initStars = function () {
// Clear existing stars
self.stars.forEach(function (star) {
star.destroy();
});
self.stars = [];
// Create new stars based on autoClickerCount
for (var i = 0; i < self.autoClickerCount; i++) {
var star = self.attachAsset('etoile', {
anchorX: 0.5,
anchorY: 0.5
});
star.y = toqueGraphics.y + toqueGraphics.height / 2 + star.height / 2;
self.stars.push(star);
}
self.displayStars(); // Update positions of all stars based on the current count
};
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;
} else if (self.autoClickerCount > 3) {
var angle = index * (Math.PI * 2 / self.autoClickerCount);
star.x = Math.cos(angle) * 100; // x varies between -100 and 100
star.y = Math.sin(angle) * 100; // y varies between -100 and 100
}
});
};
self.onClick = function () {
if (currentScore >= self.cost && self.autoClickerCount < 9) {
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 <= 9) {
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
// 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);
if (isMiniGameRunning === 0) {
LK.getSound('clickSound').play();
}
currentScore += upgradeMultiplier[upgradeLevel]; // Increment score by the upgrade multiplier per click
cakesGeneratedInMainGame = true; // Set flag to true when a cake is generated manually
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);
});
// BonusCake class
var BonusCake = Container.expand(function () {
var self = Container.call(this);
self.speedY = -10; // Initial upward speed
self.gravity = isMiniGameRunning === 2 ? 0.4 : 0.2; // Increase gravity when isMiniGameRunning is 2
self.speedX = (Math.random() - 0.5) * 10; // Random horizontal speed
var bonusCakeGraphics = self.attachAsset('bonusCake', {
anchorX: 0.5,
anchorY: 0.5
});
self.on('down', function (x, y, obj) {
if (isMiniGameRunning === 2 || self.hasBeenClicked) {
return;
}
self.hasBeenClicked = true;
self.interactive = false; // Disable interaction after click
LK.setTimeout(function () {
LK.getSound('cheers').play(); // Play cheers sound after 1 second
}, 1000);
// Flash screen white for 500ms when bonus cake is clicked
LK.effects.flashScreen(0xffffff, 500);
LK.getSound('bonusSound').play(); // Play bonus sound
// Define what happens when the bonus cake is clicked
var clickCount = 0;
var clickInterval = LK.setInterval(function () {
if (clickCount < 100) {
bigCake.emit('down'); // Trigger the 'down' event on bigCake to simulate a click
clickCount++;
} else {
LK.clearInterval(clickInterval);
}
}, 100); // 100ms delay between each click
LK.getSound('clickSound').play(); // Play click sound
tween(self, {
scaleX: 20,
scaleY: 20,
alpha: 0
}, {
duration: 3000,
easing: tween.easeOut,
onFinish: function onFinish() {
self.destroy(); // Remove the bonus cake after animation
}
});
});
self.update = function () {
self.rotation += 0.1; // Rotate the bonus cake while it falls
// VĂ©rifier la collision avec le thirdGameCakePipe en mode mini-jeu 2
if (isMiniGameRunning === 2) {
// Calculer les dimensions pour la détection de collision
var bonusCakeRadius = self.width / 2;
var pipeWidth = thirdGameCakePipe.width * 0.6;
var pipeHeight = thirdGameCakePipe.height * 0.9;
// VĂ©rifier si le bonusCake est en collision avec le thirdGameCakePipe
var dx = Math.abs(self.x - thirdGameCakePipe.x);
var dy = Math.abs(self.y - thirdGameCakePipe.y);
if (dx < pipeWidth / 2 + bonusCakeRadius && dy < pipeHeight / 2 + bonusCakeRadius) {
// Collision détectée - aspirer le bonusCake vers le haut
self.speedY = -30; // Forte vitesse vers le haut
self.speedX = (thirdGameCakePipe.x - self.x) * 0.1;
self.gravity = 0; // Désactiver la gravité
// Jouer un son pour l'aspiration
if (!self.hasPlayedYeahh) {
LK.getSound('yeahh').play();
self.hasPlayedYeahh = true;
bonusCakesReachedPipeCount++; // Increment the global counter for bonus cakes reaching the CakePipe
}
// Animation de rétrécissement
tween(self, {
scaleX: 0.5,
scaleY: 0.5
}, {
duration: 500,
easing: tween.easeOut
});
// Si le bonusCake atteint le haut de l'écran, le détruire
if (self.y < -bonusCakeRadius) {
self.destroy();
return;
}
} else if (!self.hasPlayedNooo && self.speedY > 0 && self.y > thirdGameCakePipe.y) {
LK.getSound('nooo').play();
self.hasPlayedNooo = true;
}
}
// Comportement normal si pas de collision
self.y += self.speedY;
self.x += self.speedX;
self.speedY += self.gravity; // Apply gravity
// DĂ©truire le bonusCake s'il sort de l'Ă©cran par le bas
if (self.y > 2732 + self.height / 2) {
self.destroy(); // Remove the bonus cake if it goes off-screen
}
};
});
var BonusCakeManager = Container.expand(function () {
var self = Container.call(this);
self.popBonus = function () {
console.log("popBonus:", bigCake.x);
LK.getSound('ohoh').play(); // Play 'ohoh' sound when BonusCake appears
var bonusCake = new BonusCake();
bonusCake.x = bigCake.x;
bonusCake.y = bigCake.y;
foregroundContainer.addChild(bonusCake);
};
self.start = function () {
function triggerPopBonus() {
if (isMiniGameRunning === 0) {
self.popBonus();
}
var randomInterval = 120000 + Math.random() * 60000; // Random interval between 3min (180000ms) and 6min (360000ms)
LK.setTimeout(triggerPopBonus, randomInterval);
}
triggerPopBonus();
};
});
// CakeMachine class
var CakeMachine = Container.expand(function () {
var self = Container.call(this);
self.canonCake = self.attachAsset('cakePipe', {
anchorX: 0.5,
anchorY: 1,
rotation: 0
});
self.canonCake.x = 10;
self.canonCake.y = -680;
self.addChild(self.canonCake);
// Attacher l'asset de la machine Ă gĂąteaux
var cakeMachineGraphics = self.attachAsset('cakeMachine', {
anchorX: 0.5,
anchorY: 0.5
});
// Attach lightCentral asset
var lightCentralGraphics = self.attachAsset('lightCentral', {
anchorX: 0.5,
anchorY: 0.5
});
lightCentralGraphics.x = -5;
lightCentralGraphics.y = 495;
self.addChild(lightCentralGraphics);
var bonusPreviewraphics = self.attachAsset('bonusCake', {
anchorX: 0.5,
anchorY: 0.5,
width: 80,
height: 70,
rotation: 0
});
bonusPreviewraphics.x = -3;
bonusPreviewraphics.y = -222;
self.addChild(bonusPreviewraphics);
var lightUpperGraphics = self.attachAsset('lightCentral', {
anchorX: 0.5,
anchorY: 0.5,
width: 100,
height: 100
});
lightUpperGraphics.x = -3;
lightUpperGraphics.y = -222;
self.addChild(lightUpperGraphics);
// Attach lightSide asset
var lightSideGraphics1 = self.attachAsset('lightSide', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: -1
});
lightSideGraphics1.x = 438;
lightSideGraphics1.y = 388;
self.addChild(lightSideGraphics1);
self.canonAngle = 0;
self.canonDir = 1;
var maxAngle = Math.PI * 0.33;
self.update = function () {
self.canonAngle += self.canonDir * Math.PI * 0.01;
self.canonCake.rotation = self.canonAngle;
if (self.canonAngle > maxAngle || self.canonAngle < -maxAngle) {
self.canonDir *= -1;
}
};
// Animate lightUpperGraphics transparency and rotation
function animateLightUpper() {
lightUpperGraphics.tint = preparedBonusCakesCount > 0 ? 0xFFFFFF : 0xFF0000;
tween(lightUpperGraphics, {
alpha: 0.2,
rotation: preparedBonusCakesCount > 0 ? -Math.PI * 4 : 0
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
lightUpperGraphics.tint = preparedBonusCakesCount > 0 ? 0xFFFFFF : 0xFF0000;
tween(lightUpperGraphics, {
alpha: 1,
rotation: 0 // Reset rotation
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: animateLightUpper // Restart the animation loop
});
}
});
}
animateLightUpper();
// Animate lightUpperGraphics transparency and rotation
function animateBonusPreview() {
bonusPreviewraphics.alpha = preparedBonusCakesCount > 0;
tween(bonusPreviewraphics, {
rotation: Math.PI * 2 // Full rotation
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(bonusPreviewraphics, {
rotation: 0 // Reset rotation
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: animateBonusPreview // Restart the animation loop
});
}
});
}
animateBonusPreview();
var lightSideGraphics2 = self.attachAsset('lightSide', {
anchorX: 0.5,
anchorY: 0.5
});
lightSideGraphics2.x = -440;
lightSideGraphics2.y = 390;
self.addChild(lightSideGraphics2);
// Ătat de la machine
self.isActive = false;
// MĂ©thode pour activer la machine
self.activate = function () {
self.isActive = true;
};
// Méthode pour désactiver la machine
self.deactivate = function () {
self.isActive = false;
};
// Animate lightCentral transparency and rotation
function animateLightCentral() {
tween(lightCentralGraphics, {
alpha: 0.2,
rotation: Math.PI * 2 // Full rotation
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(lightCentralGraphics, {
alpha: 1,
rotation: 0 // Reset rotation
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: animateLightCentral // Restart the animation loop
});
}
});
}
animateLightCentral();
// Animate lightSide1 transparency
function animateLightSide1() {
tween(lightSideGraphics1, {
alpha: 0.2
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(lightSideGraphics1, {
alpha: 1
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: animateLightSide1 // Restart the animation loop
});
}
});
}
animateLightSide1();
// Animate lightSide2 transparency
function animateLightSide2() {
tween(lightSideGraphics2, {
alpha: 0.2
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(lightSideGraphics2, {
alpha: 1
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: animateLightSide2 // Restart the animation loop
});
}
});
}
animateLightSide2();
// Ajouter un gestionnaire d'événement pour le clic/tap sur la machine
self.on('down', function (x, y, obj) {
if (preparedBonusCakesCount <= 0) {
LK.getSound('machineError').play(); // Play error sound if no bonus cakes are prepared
return; // Exit if no bonus cakes are prepared
}
preparedBonusCakesCount--; // Decrement the count of prepared bonus cakes
// Créer un bonusCake
var bonusCake = new BonusCake();
// Calculer la position initiale du bonusCake (à l'extrémité du canon)
var canonLength = 350; // Longueur approximative du canon
var canonEndX = self.x + self.canonCake.x + Math.sin(self.canonAngle) * canonLength;
var canonEndY = self.y + self.canonCake.y - Math.cos(self.canonAngle) * canonLength;
bonusCake.x = canonEndX;
bonusCake.y = canonEndY;
// DĂ©finir la vitesse initiale dans la direction du canon
var speed = 25;
bonusCake.speedX = Math.sin(self.canonAngle) * speed;
bonusCake.speedY = -Math.cos(self.canonAngle) * speed;
// Ajouter le bonusCake au conteneur approprié
if (isMiniGameRunning === 2) {
thirdGameMiddlegroundContainer.addChild(bonusCake);
}
// Jouer un son
LK.getSound('canonSound').play();
});
return self;
});
var CakePipe = Container.expand(function () {
var self = Container.call(this);
var cakePipeGraphics = self.attachAsset('cakePipe', {
anchorX: 0.5,
anchorY: 0,
scaleY: -1
});
self.addChild(cakePipeGraphics);
// Direction de mouvement (1 = droite, -1 = gauche)
self.direction = 1;
// Vitesse de déplacement
self.speed = 7;
// MĂ©thode update pour le mouvement horizontal
self.update = function () {
// DĂ©placement horizontal
self.x += self.speed * self.direction;
// Changement de direction aux limites
if (self.x >= 1848) {
self.direction = -1;
} else if (self.x <= 200) {
self.direction = 1;
}
};
return self;
});
var CakeRainManager = Container.expand(function () {
var self = Container.call(this);
self.cakes = [];
self.spawnCake = function () {
if (isMiniGameRunning !== 1 || !cakesGeneratedInMainGame) {
return; // Stop updating if not in mini-game mode 1
}
var cake = self.attachAsset('cake_' + upgradeLevel, {
anchorX: 0.5,
anchorY: 0.5
});
cake.scaleX = 1.2;
cake.scaleY = 1.2;
cake.x = Math.random() * 2048;
cake.y = -cake.height / 2;
cake.speedY = 5 + Math.random() * 5;
cake.assetId = 'cake_' + upgradeLevel; // Store asset ID for mini cakes
cake.on('down', function (x, y, obj) {
var cutEffect = new CutEffect();
cutEffect.show(cake.x, cake.y);
miniGameMiddlegroundContainer.addChild(cutEffect);
var miniCake1 = new MiniCake(cake);
var miniCake2 = new MiniCake(cake);
miniCake1.x = cake.x - 20;
miniCake1.y = cake.y;
miniCake2.x = cake.x + 20;
miniCake2.y = cake.y;
miniGameMiniCakes.push(miniCake1, miniCake2);
miniGameMiddlegroundContainer.addChild(miniCake1);
miniGameMiddlegroundContainer.addChild(miniCake2);
LK.getSound('CutSound').play(); // Play cut sound when a cake is cut
var index = miniGameCurrentCakes.indexOf(cake);
if (index !== -1) {
miniGameCurrentCakes.splice(index, 1);
}
cake.destroy();
});
var boundingBox = self.attachAsset('boundingBox', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0
});
cake.borderBox = boundingBox;
cake.addChild(boundingBox);
self.cakes.push(cake);
miniGameCurrentCakes.push(cake);
miniGameMiddlegroundContainer.addChild(cake);
};
self.update = function () {
if (isMiniGameRunning !== 1) {
return; // Stop updating if not in mini-game mode 1
}
for (var i = self.cakes.length - 1; i >= 0; i--) {
var cake = self.cakes[i];
cake.y += cake.speedY;
if (cake.y > 2732 + cake.height / 2) {
// Trouver et retirer le gĂąteau du tableau miniGameCurrentCakes
var index = miniGameCurrentCakes.indexOf(cake);
if (index !== -1) {
miniGameCurrentCakes.splice(index, 1);
}
cake.destroy();
self.cakes.splice(i, 1);
}
}
};
self.start = function () {
LK.setInterval(self.spawnCake, 1000);
};
});
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
});
self.assetId = 'cake_' + Math.max(0, Math.min(cakeIndex, 9)); // Store asset ID for mini cakes
self.speedY = -15; // Initial upward speed
self.speedX = (Math.random() - 0.5) * 10; // Random horizontal speed
self.gravity = 0.2;
self.update = function () {
self.speedY += self.gravity;
self.y += self.speedY;
self.x += self.speedX;
self.rotation += (Math.random() - 0.5) * 0.1;
if (self.y > 2732 + self.height / 2) {
self.destroy();
}
};
// Add click/tap event to cut the confetti cake
self.on('down', function (x, y, obj) {
// Create cut effect
var cutEffect = new CutEffect();
cutEffect.show(self.x, self.y);
middleContainer.addChild(cutEffect);
// Create two mini cakes
var miniCake1 = new MiniCake(self);
var miniCake2 = new MiniCake(self);
miniCake1.x = self.x - 20;
miniCake1.y = self.y;
miniCake2.x = self.x + 20;
miniCake2.y = self.y;
middleContainer.addChild(miniCake1);
middleContainer.addChild(miniCake2);
// Play cut sound
LK.getSound('CutSound').play();
// Remove the original confetti
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;
}
};
});
var CutEffect = Container.expand(function () {
var self = Container.call(this);
var cutEffectGraphics = self.attachAsset('cutEffect', {
anchorX: 0.5,
anchorY: 0.5
});
cutEffectGraphics.alpha = 0; // Start with the effect invisible
self.show = function (x, y) {
self.x = x;
self.y = y;
cutEffectGraphics.alpha = 1; // Make the effect visible
cutEffectGraphics.scaleX = 1.5; // Enlarge the effect horizontally
cutEffectGraphics.scaleY = 1.5; // Enlarge the effect vertically
cutEffectGraphics.rotation = (Math.random() - 0.5) * Math.PI / 2; // Randomize rotation within +/- 45 degrees
tween(cutEffectGraphics, {
alpha: 0
}, {
duration: 500,
// Fade out over 500ms
easing: tween.easeOut,
onFinish: function onFinish() {
self.destroy(); // Remove the effect after fading out
}
});
};
});
var Dwarf = Container.expand(function (dwarfIndex) {
var self = Container.call(this);
// Stocker l'index du nain
self.dwarfIndex = dwarfIndex || 0;
// Propriété pour identifier le mini-jeu auquel appartient le nain
self.miniGame = 1; // Par défaut, appartient au mini-jeu 1
// Index du gùteau ciblé actuellement (-1 signifie aucun gùteau ciblé)
self.targetCakeIndex = -1;
// Attach assets for full and empty states
var dwarfFullFrame1 = self.attachAsset('dwarf_full_frame_1', {
anchorX: 0.5,
anchorY: 1.0
});
var dwarfFullFrame2 = self.attachAsset('dwarf_full_frame_2', {
anchorX: 0.5,
anchorY: 1.0
});
var dwarfEmptyFrame1 = self.attachAsset('dwarf_empty_frame_1', {
anchorX: 0.5,
anchorY: 1.0
});
var dwarfEmptyFrame2 = self.attachAsset('dwarf_empty_frame_2', {
anchorX: 0.5,
anchorY: 1.0
});
// Initial visibility
dwarfEmptyFrame1.visible = false;
dwarfEmptyFrame2.visible = true;
dwarfFullFrame1.visible = false;
dwarfFullFrame2.visible = false;
// State and animation properties
self.state = 'empty'; // Initial state
self.jumpPlayed = false; // Flag to ensure jump animation is played only once
self.currentFrame = dwarfFullFrame1;
self.animationCounter = 0;
self.animationDelay = 3;
// Movement properties
var threshold = 50;
var baseSpeed = 7; // Reduced base speed for smoother movement
var edgeMargin = 100; // Margin from the edges to prevent trembling
self.x = 1024;
self.speedX = 7;
self.targetX = self.x;
self.lastX = self.x;
self.targetCooldown = 0; // Cooldown counter for changing targets
self.maxTargetCooldown = 60; // 60 frames = 1 seconde Ă 60 FPS
self.idleTime = 0; // Compteur pour le temps d'inactivité
self.maxIdleTime = 30; // Temps maximum d'inactivité avant de chercher activement une cible
self.waitingAtCenter = false;
// Update function for movement and animation
self.update = function () {
if (isMiniGameRunning !== 1 && isMiniGameRunning !== 2 || self.isSquashing) {
return;
} // Only update if the mini-game or third game is active and not being squashed
if (isMiniGameRunning == 2 && !cakesCutInMiniGame1) {
return; // Exit if cakes have not been cut in mini-game 1
}
// Comportement spécifique au troisiÚme jeu
if (isMiniGameRunning === 2 && self.miniGame === 2) {
self.speedX = 10;
// Animation du nain seulement s'il n'est pas en attente
if (!self.waitingAtCenter) {
self.animationCounter++;
if (self.animationCounter >= self.animationDelay) {
self.animationCounter = 0;
if (self.state === 'full') {
dwarfFullFrame1.visible = !dwarfFullFrame1.visible;
dwarfFullFrame2.visible = !dwarfFullFrame2.visible;
dwarfEmptyFrame1.visible = false;
dwarfEmptyFrame2.visible = false;
} else {
dwarfEmptyFrame1.visible = !dwarfEmptyFrame1.visible;
dwarfEmptyFrame2.visible = !dwarfEmptyFrame2.visible;
dwarfFullFrame1.visible = false;
dwarfFullFrame2.visible = false;
}
}
}
self.currentFrame = dwarfFullFrame1.visible ? dwarfFullFrame1 : dwarfFullFrame2.visible ? dwarfFullFrame2 : dwarfEmptyFrame1.visible ? dwarfEmptyFrame1 : dwarfEmptyFrame2;
self.currentFrame.scaleX = -1;
// Gestion du comportement du nain dans le troisiĂšme jeu
if (self.state === 'full') {
// Le nain se déplace vers x=1024
if (self.x > 950) {
self.x -= self.speedX;
} else if (!self.waitingAtCenter) {
// Arrivé au centre, attendre 1 seconde
self.waitingAtCenter = true;
// Create a miniCake at the dwarf's position
var miniCake = new MiniCake(self);
miniCake.x = self.x + 70;
miniCake.y = self.y - 70;
thirdGameMiddlegroundContainer.addChild(miniCake);
preparedBonusCakesCount++; // Increment the global counter for prepared bonus cakes
// Activate the cake machine when a mini cake is placed
thirdGameCakeMachine.activate();
// Animate the miniCake upwards and remove it
tween(miniCake, {
y: miniCake.y - 400
}, {
duration: 1000,
easing: tween.easeOut,
onFinish: function onFinish() {
LK.getSound('aspire').play(); // Play 'aspire' sound when miniCake disappears
tween(miniCake, {
scaleX: 0,
// Reduce size to 0
scaleY: 0,
// Reduce size to 0
alpha: 0
}, {
duration: 1000,
easing: tween.easeOut,
onFinish: function onFinish() {
miniCake.destroy();
}
});
}
});
LK.setTimeout(function () {
// AprĂšs 1 seconde, passer en mode empty et continuer
self.state = 'empty';
dwarfFullFrame1.visible = false;
dwarfFullFrame2.visible = false;
dwarfEmptyFrame1.visible = true;
dwarfEmptyFrame2.visible = false;
self.waitingAtCenter = false;
}, 1000);
}
} else {
// En mode empty, continuer jusqu'Ă x=-300
if (self.x > -300) {
self.x -= self.speedX;
} else {
// RĂ©initialiser le nain Ă droite en mode full
self.x = 2300;
self.state = 'full';
dwarfFullFrame1.visible = true;
dwarfFullFrame2.visible = false;
dwarfEmptyFrame1.visible = false;
dwarfEmptyFrame2.visible = false;
}
}
return; // Ne pas exécuter le reste du code pour le mini-jeu
}
// Comportement original du mini-jeu (isMiniGameRunning === 1)
if (isMiniGameRunning === 1 && self.miniGame === 1) {
// Check if the dwarf reaches x = -300 and switch mode from full to empty
if (self.x <= -300 && self.state === 'full') {
self.state = 'empty';
self.x = 2348;
self.y = 2732 - 180; // RĂ©initialiser la position Y
dwarfEmptyFrame1.visible = true;
dwarfEmptyFrame2.visible = false;
dwarfFullFrame1.visible = false;
dwarfFullFrame2.visible = false;
self.jumpPlayed = false; // Reset jump animation flag
self.targetCooldown = 0; // Forcer la recherche d'une nouvelle cible immédiatement
self.speedX = 7; // RĂ©initialiser la vitesse
}
// Decrement cooldown if active
if (self.targetCooldown > 0) {
self.targetCooldown--;
}
// Si le nain est immobile, incrémenter le compteur d'inactivité
if (Math.abs(self.speedX) < 0.1) {
self.idleTime++;
} else {
self.idleTime = 0;
}
// Si le nain est inactif depuis trop longtemps, forcer la recherche d'une nouvelle cible
if (self.idleTime >= self.maxIdleTime) {
self.targetCooldown = 0;
self.idleTime = 0;
}
// Move the dwarf towards the closest falling cake on the x-axis
if (self.state === 'full') {
self.searchForCakeInFullMode();
} else {
self.searchForCakeInEmptyMode();
}
// Calculate distance to target
var distanceToTarget = self.targetX - self.x;
var absDistance = Math.abs(distanceToTarget);
if (absDistance > threshold) {
// Gradually adjust speed based on distance for smoother movement
var direction = distanceToTarget > 0 ? 1 : -1;
var speedFactor = Math.min(1, absDistance / 200); // Scale speed based on distance
self.speedX = direction * baseSpeed * speedFactor;
self.x += self.speedX;
} else if (absDistance > 0) {
// Slow down as we approach the target
var slowSpeed = baseSpeed * 0.5;
self.speedX = distanceToTarget > 0 ? Math.min(slowSpeed, distanceToTarget) : Math.max(-slowSpeed, distanceToTarget);
self.x += self.speedX;
} else {
// Si le nain est exactement à la position cible, réinitialiser le cooldown
// pour qu'il cherche une nouvelle cible au prochain cycle
self.targetCooldown = 0;
}
// Check for intersection with miniCakes
miniGameMiniCakes.forEach(function (miniCake, index) {
if (self.intersects(miniCake)) {
LK.getSound('youpi').play(); // Play 'youpi' sound when a dwarf catches a minicake
// Enter 'full' mode
self.state = 'full';
dwarfEmptyFrame1.visible = false;
dwarfEmptyFrame2.visible = false;
dwarfFullFrame1.visible = true;
dwarfFullFrame2.visible = false;
// Set cakesCutInMiniGame1 to true when a dwarf catches a mini cake
cakesCutInMiniGame1 = true;
// Remove the miniCake
miniCake.destroy();
miniGameMiniCakes.splice(index, 1);
}
});
// Check for intersection with non-miniCakes
if (self.state === 'empty' && !self.isSquashing) {
miniGameCurrentCakes.forEach(function (cake, index) {
//self.x >= cake.borderBox.x - cake.borderBox.width / 2 && self.x <= cake.borderBox.x + cake.borderBox.width / 2
if (cake && cake.y < 2500 && !cake.hasSquashed && self.intersects(cake.borderBox)) {
cake.hasSquashed = true; // Marquer le gùteau comme ayant déjà écrasé un nain
self.squashAnimation(cake);
return;
}
});
}
// Animate frames
self.animateFrames();
// Update lastX
self.lastX = self.x;
}
};
self.searchForCakeInEmptyMode = function () {
// Chercher une nouvelle cible si le cooldown est terminé ou si la cible actuelle est invalide
if (self.targetCooldown === 0 || !self.currentTarget || self.currentTarget.y > 2732 + self.currentTarget.height / 2) {
if (self.currentTarget && Math.abs(self.x - self.currentTarget.x) < threshold) {
self.performImpatienceAnimation();
}
self.currentTarget = self.findClosestMiniCake() || self.findClosestFallingCake();
if (self.currentTarget) {
self.targetCooldown = self.maxTargetCooldown; // Reset cooldown
self.targetX = self.currentTarget.x;
} else if (miniGameCurrentCakes.length > 0) {
// S'il y a des gùteaux mais que findClosestFallingCake n'en a pas trouvé,
// prendre le premier gĂąteau disponible comme cible de secours
self.currentTarget = miniGameCurrentCakes[0];
self.targetX = self.currentTarget.x;
self.targetCooldown = self.maxTargetCooldown;
} else {
// S'il n'y a vraiment aucun gùteau, faire bouger le nain aléatoirement
// pour Ă©viter qu'il ne reste immobile
if (self.idleTime > self.maxIdleTime / 2) {
self.targetX = Math.random() * (2048 - 2 * edgeMargin) + edgeMargin;
}
}
}
};
self.searchForCakeInFullMode = function () {
if (!self.jumpPlayed) {
tween(self, {
y: baseDwarfY - 150
}, {
duration: 50,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(self, {
y: baseDwarfY
}, {
duration: 50,
easing: tween.easeInOut,
onFinish: function onFinish() {
self.speedX = 14; // Increase speed to 10 when in full mode
self.targetX = -300;
self.jumpPlayed = true; // Mark the jump animation as played
}
});
}
});
}
};
self.findClosestFallingCake = function () {
// Vérifier si le gùteau actuellement ciblé existe toujours
if (self.targetCakeIndex !== -1) {
// Parcourir le tableau pour trouver si le gĂąteau avec cet index existe encore
var cakeStillExists = false;
for (var i = 0; i < miniGameCurrentCakes.length; i++) {
if (miniGameCurrentCakes[i].cakeIndex === self.targetCakeIndex) {
cakeStillExists = true;
return miniGameCurrentCakes[i]; // Continuer Ă cibler le mĂȘme gĂąteau
}
}
if (!cakeStillExists) {
self.targetCakeIndex = -1; // Le gùteau n'existe plus, réinitialiser la cible
}
}
// Chercher un nouveau gĂąteau Ă cibler
var availableCakeIndices = [];
// Parcourir tous les gĂąteaux disponibles
for (var i = 0; i < miniGameCurrentCakes.length; i++) {
var cake = miniGameCurrentCakes[i];
// Si le gĂąteau n'a pas d'index, lui en attribuer un
if (cake.cakeIndex === undefined) {
cake.cakeIndex = Math.floor(Math.random() * 10000); // Générer un index unique
}
// Vérifier si ce gùteau est déjà ciblé par un autre nain
var isTargeted = false;
var isTooCrowded = false;
for (var j = 0; j < miniGameDwarfs.length; j++) {
var otherDwarf = miniGameDwarfs[j];
// Ne pas vérifier le nain actuel
if (otherDwarf.dwarfIndex !== self.dwarfIndex) {
// Vérifier si le gùteau est déjà ciblé
if (otherDwarf.targetCakeIndex === cake.cakeIndex) {
isTargeted = true;
break;
}
// Vérifier si un autre nain est déjà trop proche de ce gùteau
if (otherDwarf.targetCakeIndex !== -1 && Math.abs(otherDwarf.x - cake.x) < 300) {
isTooCrowded = true;
break;
}
}
}
// Si le gùteau n'est pas ciblé et n'est pas trop proche d'un autre nain, l'ajouter aux gùteaux disponibles
if (!isTargeted && !isTooCrowded) {
availableCakeIndices.push(i); // Stocker l'index dans le tableau miniGameCurrentCakes
}
}
// S'il y a des gĂąteaux disponibles, en choisir un AU HASARD
if (availableCakeIndices.length > 0) {
// SĂ©lectionner un gĂąteau au hasard parmi les disponibles
var randomIndex = Math.floor(Math.random() * availableCakeIndices.length);
var selectedCakeIndex = availableCakeIndices[randomIndex];
var selectedCake = miniGameCurrentCakes[selectedCakeIndex];
self.targetCakeIndex = selectedCake.cakeIndex;
return selectedCake;
}
// Si tous les gùteaux sont déjà ciblés ou trop proches d'autres nains,
// essayer de trouver un gĂąteau qui n'est pas ciblĂ©, mĂȘme s'il est proche d'un autre nain
availableCakeIndices = [];
for (var i = 0; i < miniGameCurrentCakes.length; i++) {
var cake = miniGameCurrentCakes[i];
var isTargeted = false;
for (var j = 0; j < miniGameDwarfs.length; j++) {
if (miniGameDwarfs[j].dwarfIndex !== self.dwarfIndex && miniGameDwarfs[j].targetCakeIndex === cake.cakeIndex) {
isTargeted = true;
break;
}
}
if (!isTargeted) {
availableCakeIndices.push(i);
}
}
// S'il y a des gùteaux non ciblés, en choisir un au hasard
if (availableCakeIndices.length > 0) {
var randomIndex = Math.floor(Math.random() * availableCakeIndices.length);
var selectedCakeIndex = availableCakeIndices[randomIndex];
var selectedCake = miniGameCurrentCakes[selectedCakeIndex];
self.targetCakeIndex = selectedCake.cakeIndex;
return selectedCake;
}
// Si tous les gùteaux sont déjà ciblés, choisir le plus proche
var closestCake = null;
var minDistance = Infinity;
miniGameCurrentCakes.forEach(function (cake) {
var dx = self.x - cake.x;
var dy = self.y - cake.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < minDistance) {
minDistance = distance;
closestCake = cake;
}
});
if (closestCake) {
// Si le gĂąteau n'a pas d'index, lui en attribuer un
if (closestCake.cakeIndex === undefined) {
closestCake.cakeIndex = Math.floor(Math.random() * 10000);
}
self.targetCakeIndex = closestCake.cakeIndex;
} else {
self.targetCakeIndex = -1;
}
return closestCake;
};
self.findClosestMiniCake = function () {
var closestMiniCake = null;
var minDistance = Infinity;
miniGameMiniCakes.forEach(function (miniCake, index) {
// Ignore mini cakes that are within 50px of the screen edges
if (miniCake.x < 50 || miniCake.x > 2048 - 50) {
return;
}
var dx = self.x - miniCake.x;
var dy = self.y - miniCake.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < minDistance) {
minDistance = distance;
closestMiniCake = miniCake;
}
});
return closestMiniCake;
};
// Function to alternate frames for animation
self.animateFrames = function () {
if (self.x !== self.lastX && !self.isSquashing) {
self.animationCounter++;
if (self.animationCounter >= self.animationDelay) {
if (self.state === 'full') {
if (dwarfFullFrame1.visible) {
dwarfFullFrame1.visible = false;
dwarfFullFrame2.visible = true;
} else {
dwarfFullFrame2.visible = false;
dwarfFullFrame1.visible = true;
}
} else {
if (dwarfEmptyFrame1.visible) {
dwarfEmptyFrame1.visible = false;
dwarfEmptyFrame2.visible = true;
} else {
dwarfEmptyFrame2.visible = false;
dwarfEmptyFrame1.visible = true;
}
}
self.animationCounter = 0;
}
}
self.currentFrame = dwarfFullFrame1.visible ? dwarfFullFrame1 : dwarfFullFrame2.visible ? dwarfFullFrame2 : dwarfEmptyFrame1.visible ? dwarfEmptyFrame1 : dwarfEmptyFrame2;
self.currentFrame.scaleX = self.speedX ? Math.sign(self.speedX) : 1;
};
self.squashAnimation = function (cake) {
if (self.isSquashing) {
return;
} // Prevent re-triggering if already squashing
self.isSquashing = true; // Set flag to indicate squash is in progress
LK.getSound('squashingSound').play(); // Play squashing sound when a dwarf gets squashed
tween(self.currentFrame, {
scaleY: 0
}, {
duration: 400,
easing: tween.easeInOut,
onFinish: function onFinish() {
// Repositionner le nain Ă droite de l'Ă©cran
self.x = 2300 + Math.floor(Math.random() * 100);
// ArrĂȘter et faire disparaĂźtre le gĂąteau
cake.speedY = 0;
tween(cake, {
alpha: 0
}, {
duration: 600,
easing: tween.easeOut,
onFinish: function onFinish() {
var index = miniGameCurrentCakes.indexOf(cake);
if (index !== -1) {
miniGameCurrentCakes.splice(index, 1);
}
cake.destroy(); // Remove the cake after it fades out
// RĂ©initialiser l'Ă©tat du nain
self.state = 'empty';
self.targetCakeIndex = -1;
self.targetCooldown = 0;
self.animationCounter = 0;
self.speedX = 7;
// RĂ©initialiser les frames d'animation
dwarfFullFrame1.visible = false;
dwarfFullFrame2.visible = false;
dwarfEmptyFrame1.visible = true;
dwarfEmptyFrame2.visible = false;
// RĂ©initialiser l'Ă©chelle du nain
tween(self.currentFrame, {
scaleY: 1
}, {
duration: 10,
easing: tween.easeInOut,
onFinish: function onFinish() {
// Réinitialiser le flag d'écrasement seulement aprÚs que l'animation soit complÚtement terminée
self.isSquashing = false;
}
});
}
});
}
});
};
self.performImpatienceAnimation = function () {
// Randomly set the direction of the Dwarf
if (!self.isImpatient) {
self.isImpatient = true;
var baseScaleX = self.scaleX;
var changeScale = Math.random() < 0.1 ? -1 : 1;
tween(self, {
y: baseDwarfY - 20,
scaleX: changeScale * baseScaleX
}, {
duration: 100,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(self, {
y: baseDwarfY
}, {
duration: 100,
easing: tween.easeInOut,
onFinish: function onFinish() {
self.isImpatient = false;
self.scaleX = baseScaleX;
}
});
}
});
}
};
});
var MiniCake = Container.expand(function (originalCake) {
var self = Container.call(this);
var assetId = originalCake.assetId || 'cake_0'; // Default to 'cake_0' if assetId is undefined
var miniCakeGraphics = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5
});
miniCakeGraphics.scaleX = 0.5;
miniCakeGraphics.scaleY = 0.5;
self.speedY = -5;
self.speedX = (Math.random() - 0.5) * 10;
self.isInMiniGame = typeof isMiniGameRunning !== 'undefined' && isMiniGameRunning == 1;
self.update = function () {
if (isMiniGameRunning === 2) {
return;
}
if (self.lastY === undefined) {
self.lastY = self.y;
}
self.y += self.speedY;
self.x += self.speedX;
self.rotation += (Math.random() - 0.5) * 0.1; // Add random rotation to mini cakes
self.speedY += 0.2; // Apply gravity
if (self.lastY <= self.y - 20 && self.y > self.lastY - 20) {
tween(self, {
y: self.y - 20
}, {
duration: 500,
easing: tween.easeOut
});
}
if (self.y > 2732 + self.height / 2) {
if (self.isInMiniGame) {
var index = miniGameMiniCakes.indexOf(self);
if (index !== -1) {
miniGameMiniCakes.splice(index, 1);
}
}
self.destroy();
}
self.lastY = self.y;
};
});
// 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 (x, y, obj) {
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);
autoClicker.cost = 100; // Reset auto clicker cost to initial value
autoClicker.autoClickerCount = 0; // Reset auto clicker count
autoClicker.updatePriceText(); // Update the price text to reflect the new cost
autoClicker.initStars(); // Update stars when the game is reset
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());
};
});
// SwitchButton class
var SwitchButton = Container.expand(function () {
var self = Container.call(this);
var switchButtonGraphics = self.attachAsset('buttonSwitch', {
anchorX: 0.5,
anchorY: 0.5
});
// Add any additional properties or methods for the switch button here
self.on('down', function (x, y, obj) {
toggleMiniGame();
hasUsedSwitchButton = true; // Set the flag to true when the SwitchButton is used
storage.hasUsedSwitchButton = hasUsedSwitchButton; // Save the updated flag to storage
});
});
// ThirdDwarfManager class for the third game
var ThirdDwarfManager = Container.expand(function () {
var self = Container.call(this);
self.spawnDwarf = function (dwarfIndex) {
var dwarf = new Dwarf(dwarfIndex);
dwarf.miniGame = 2; // DĂ©finir que ce nain appartient au mini-jeu 2
dwarf.x = 2300 + dwarfIndex * 1024; // Position initiale décalée selon l'index
dwarf.y = 2732 - 180; // Base y position
dwarf.speedX = 5; // Vitesse fixe pour un mouvement uniforme
dwarf.state = 'full'; // Commencer en mode full
// Configurer explicitement les frames pour le mode full
dwarf.children[0].visible = true; // dwarfFullFrame1
dwarf.children[1].visible = false; // dwarfFullFrame2
dwarf.children[2].visible = false; // dwarfEmptyFrame1
dwarf.children[3].visible = false; // dwarfEmptyFrame2
thirdGameDwarfs.push(dwarf); // Ajouter au tableau global thirdGameDwarfs
thirdGameMiddlegroundContainer.addChild(dwarf);
};
self.start = function () {
// Vider le tableau des nains du troisiĂšme jeu
thirdGameDwarfs = [];
// Spawn exactly 3 dwarfs with unique indices
for (var i = 0; i < 3; i++) {
self.spawnDwarf(i);
}
};
return self;
});
// 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
storage.upgradeLevel = upgradeLevel; // Save the updated upgrade level
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
];
// Global array for the number of auto clicks per second
var autoClicksPerSecond = [1,
// 0
10,
// 1
50,
// 2
150,
// 3
500,
// 4
1500,
// 5
5000,
// 6
20000,
// 7
100000,
// 8
500000 // 9
];
// Global array for upgrade multipliers
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
];
/****
* Game Code
* Main game logic and event handling
****/
/****
* Assets
* Initialize all game assets including images, sounds, and music
****/
// Declare game variables
var hasUsedSwitchButton = false; // Flag to track if the player has used the SwitchButton
var hasUsedSwitchButton = storage.hasUsedSwitchButton || false; // Load saved flag or default to false
var cakesGeneratedInMainGame = false; // Global flag to track if cakes have been generated in the main game
var cakesCutInMiniGame1 = false; // Global flag to track if cakes have been cut in mini-game 1
var preparedBonusCakesCount = 0; // Global counter for prepared bonus cakes
var bonusCakesReachedPipeCount = 0; // Global counter for bonus cakes reaching the CakePipe in mini-game 2
var bonusCakeManager; // Declare bonusCakeManager globally
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 = storage.upgradeLevel || 0; // Load saved upgrade level or default to 0
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 mainGameContainer;
var backgroundContainer;
var middleContainer;
var foregroundContainer;
var currentScore;
var score;
var lastTimestamp;
var timeElapsed;
var clicksSinceLastSession;
var autoClicker;
var upgrade;
var bigCake;
var resetButton;
var switchButton;
var board;
var thirdGameCakeMachine; // Variable globale pour la machine Ă gĂąteaux du troisiĂšme jeu
var thirdGameCakePipe;
////////////////////////////////////////////////////////////////////////
////////////////////////// MINI GAME CODE /////////////////////////////
////////////////////////////////////////////////////////////////////////
var isMiniGameRunning = 0;
var miniGameContainer;
var miniGameBackgroundContainer;
var miniGameMiddlegroundContainer;
var miniGameForegroundContainer;
var miniGamebackground;
var switchButtonMini;
var chef;
var miniGameDwarfs = []; // Variable globale pour stocker les nains
var miniGameDwarfCount = 7; // Nombre de nains à créer
var miniGameCurrentCakes = []; // Global array to store falling cakes
var miniGameMiniCakes = []; // Global array to track mini cakes
var baseDwarfY = 2732 - 180;
// Variables pour le thirdGame
var thirdGameContainer;
var thirdGameBackgroundContainer;
var thirdGameMiddlegroundContainer;
var thirdGameForegroundContainer;
var thirdGameBackground;
var switchButtonThird;
var isTransitioning = false; // Flag to prevent multiple calls during transitions
var thirdDwarfManager; // Variable globale pour le ThirdDwarfManager
var thirdGameDwarfs = []; // Variable globale pour stocker les nains du troisiĂšme jeu
function toggleMiniGame() {
if (isTransitioning) {
return;
} // Exit if a transition is already in progress
isTransitioning = true; // Set flag to indicate a transition is starting
// Gestion des transitions entre les différents jeux
if (isMiniGameRunning === 0) {
// Passage du jeu principal au minijeu (slide vers le bas)
isMiniGameRunning = 1;
storage.isMiniGameRunning = 1; // Update storage
miniGameContainer.x = 0;
cakesCutInMiniGame1 = false;
miniGameContainer.y = 2732; // Positionner au-dessus pour l'animation
miniGameContainer.visible = true;
// Animation du jeu principal vers le bas
tween(mainGameContainer, {
y: -2732
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
mainGameContainer.visible = false;
isTransitioning = false; // Reset flag after transition
}
});
// Animation du minijeu vers le bas
tween(miniGameContainer, {
y: 0
}, {
duration: 1000,
easing: tween.easeInOut
});
} else if (isMiniGameRunning === 1) {
thirdGameCakeMachine.deactivate(); // Set the cake machine to inactive when entering mini game 2
// Passage du minijeu au thirdGame (slide vers la gauche)
isMiniGameRunning = 2;
storage.isMiniGameRunning = 2; // Update storage
thirdGameContainer.x = -2048; // Positionner Ă droite pour l'animation
thirdGameContainer.y = 0;
thirdGameDwarfs.forEach(function (dwarf) {
dwarf.destroy(); // Destroy each Dwarf instance
});
thirdGameDwarfs = []; // Clear the thirdGameDwarfs array when exiting mini-game 2
thirdGameContainer.visible = true;
// Animation du minijeu vers la gauche
tween(miniGameContainer, {
x: 2048
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
miniGameContainer.visible = false;
isTransitioning = false; // Reset flag after transition
}
});
// Animation du thirdGame vers la gauche
tween(thirdGameContainer, {
x: 0
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
thirdDwarfManager.start();
}
});
} else if (isMiniGameRunning === 2) {
// Retour au jeu principal depuis le thirdGame (slide vers le haut)
isMiniGameRunning = 0;
thirdGameDwarfs.forEach(function (dwarf) {
dwarf.destroy(); // Destroy each Dwarf instance
});
thirdGameDwarfs = []; // Clear the thirdGameDwarfs array when exiting mini-game 2
cakesGeneratedInMainGame = false;
storage.isMiniGameRunning = 0; // Update storage
mainGameContainer.x = 0; // Positionner en bas pour l'animation
mainGameContainer.y = -2732; // Positionner en bas pour l'animation
mainGameContainer.visible = true;
// Animation du thirdGame vers le haut
tween(thirdGameContainer, {
y: 2732
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
thirdGameContainer.visible = false;
isTransitioning = false; // Reset flag after transition
}
});
// Animation du jeu principal vers le haut
tween(mainGameContainer, {
y: 0
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
console.log("Toggle. bonus:", bonusCakesReachedPipeCount);
for (var i = 0; i < bonusCakesReachedPipeCount; i++) {
bonusCakeManager.popBonus();
}
bonusCakesReachedPipeCount = 0; // Reset the counter after popping bonus cakes
}
});
}
}
game.down = function (x, y, obj) {
if (isMiniGameRunning === 1) {
// Code spécifique au minijeu
} else if (isMiniGameRunning === 2) {
// Code spécifique au thirdGame
}
};
////////////////////////////////////////////////////////////////////////
// Initialize game variables
function initializeGameVariables() {
mainGameContainer = new Container();
game.addChild(mainGameContainer);
backgroundContainer = new Container();
mainGameContainer.addChild(backgroundContainer);
// Initialize middleContainer
middleContainer = new Container();
mainGameContainer.addChild(middleContainer);
// Initialize foregroundContainer
foregroundContainer = new Container();
mainGameContainer.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 = foregroundContainer.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
autoClicker.initStars(); // Initialize and update the display of stars based on the current autoClickerCount
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.updateCakeGraphics(); // Update cake graphics based on new upgrade level
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();
// Initialize bonus cake manager
bonusCakeManager = new BonusCakeManager();
LK.setTimeout(function () {
bonusCakeManager.start(); // Start the bonus cake manager after 1 minute
}, 60000);
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
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();
});
switchButton = new SwitchButton();
switchButton.x = 1024;
switchButton.y = 2732 - switchButton.height * 0.5;
foregroundContainer.addChild(switchButton);
// Animate the switchButton if hasUsedSwitchButton is false
if (!hasUsedSwitchButton) {
var _animateSwitchButton = function animateSwitchButton() {
tween(switchButton, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 500,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(switchButton, {
scaleX: 1,
scaleY: 1
}, {
duration: 500,
easing: tween.easeInOut,
onFinish: _animateSwitchButton // Restart the animation loop
});
}
});
};
_animateSwitchButton();
}
// Play bakery music in a loop throughout the game
LK.playMusic('musiqueclicker', {
loop: true
});
isMiniGameRunning = 0;
storage.isMiniGameRunning = 0;
}
function initializeminiGameVariables() {
miniGameContainer = new Container();
miniGameContainer.x = 0;
miniGameContainer.y = 2732; // Position initiale hors Ă©cran
game.addChild(miniGameContainer);
miniGameContainer.visible = false;
miniGameBackgroundContainer = new Container();
miniGameContainer.addChild(miniGameBackgroundContainer);
miniGameMiddlegroundContainer = new Container();
miniGameContainer.addChild(miniGameMiddlegroundContainer);
miniGameForegroundContainer = new Container();
miniGameContainer.addChild(miniGameForegroundContainer);
miniGamebackground = miniGameBackgroundContainer.addChild(LK.getAsset('miniGameBackground', {
anchorX: 0.5,
anchorY: 0.5
}));
miniGamebackground.x = 2048 / 2;
miniGamebackground.y = 2732 / 2;
miniGamebackground.scaleX = 2048 / miniGamebackground.width; // Scale background to fit the game width
miniGamebackground.scaleY = 2732 / miniGamebackground.height; // Scale background to fit the game height
switchButtonMini = new SwitchButton();
switchButtonMini.x = switchButtonMini.width * 0.25;
switchButtonMini.y = 1366;
switchButtonMini.rotation = -Math.PI / 2;
switchButtonMini.scale.y = -1;
miniGameForegroundContainer.addChild(switchButtonMini);
// Dwarfs
miniGameDwarfs = []; // RĂ©initialiser le tableau des nains
for (var i = 0; i < miniGameDwarfCount; i++) {
var dwarf = new Dwarf(i);
// RĂ©partir les nains sur toute la largeur de l'Ă©cran
dwarf.x = 500 + Math.floor((2048 - 1000) * (i / (miniGameDwarfCount - 1 || 1)));
dwarf.y = 2732 - 180;
miniGameMiddlegroundContainer.addChild(dwarf);
miniGameDwarfs.push(dwarf);
}
var cakeRainManager = new CakeRainManager();
miniGameMiddlegroundContainer.addChild(cakeRainManager);
cakeRainManager.start();
}
function initializeThirdGameVariables() {
thirdGameContainer = new Container();
thirdGameContainer.x = -2048; // Position initiale hors Ă©cran (Ă droite)
thirdGameContainer.y = 0;
game.addChild(thirdGameContainer);
thirdGameContainer.visible = false;
thirdGameBackgroundContainer = new Container();
thirdGameContainer.addChild(thirdGameBackgroundContainer);
thirdGameMiddlegroundContainer = new Container();
thirdGameContainer.addChild(thirdGameMiddlegroundContainer);
thirdGameForegroundContainer = new Container();
thirdGameContainer.addChild(thirdGameForegroundContainer);
// Utiliser le mĂȘme fond que le miniGame pour le moment
thirdGameBackground = thirdGameBackgroundContainer.addChild(LK.getAsset('miniGameBackground', {
anchorX: 0.5,
anchorY: 0.5
}));
thirdGameBackground.x = 2048 / 2;
thirdGameBackground.y = 2732 / 2;
thirdGameBackground.scaleX = -2048 / thirdGameBackground.width; // Scale background to fit the game width
thirdGameBackground.scaleY = 2732 / thirdGameBackground.height; // Scale background to fit the game height
// Ajouter uniquement le bouton de changement de jeu
switchButtonThird = new SwitchButton();
switchButtonThird.x = 1024;
switchButtonThird.y = switchButtonThird.height * 0.5;
switchButtonThird.scale.y = -1;
thirdGameForegroundContainer.addChild(switchButtonThird);
// Initialize thirdGameCakeMachine
thirdGameCakeMachine = new CakeMachine();
thirdGameMiddlegroundContainer.addChild(thirdGameCakeMachine);
thirdGameCakeMachine.x = 1024;
thirdGameCakeMachine.y = 1600;
thirdGameCakePipe = new CakePipe();
thirdGameForegroundContainer.addChild(thirdGameCakePipe);
thirdGameCakePipe.x = 512;
thirdGameCakePipe.y = 250;
// Create and start the ThirdDwarfManager
thirdDwarfManager = new ThirdDwarfManager();
thirdGameMiddlegroundContainer.addChild(thirdDwarfManager);
thirdDwarfManager.start();
}
// Call the function to initialize game variables
initializeGameVariables();
initializeminiGameVariables();
initializeThirdGameVariables();
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.
gaÌteau ( pas reÌaliste ). Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
sparkles
gaÌteau. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
gaÌteau. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
gaÌteau. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
dessin de toque de chef
eÌtoile doreÌe toute simple comme dans les commentaires d'un site web
une patisserie (gaÌ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 centreÌe d'une machine magique en forme de pieÌce monteÌe arc-en-ciel avec une petite entreÌe d'alimentation en bas au milieu, un treÌs grand hublot central et un tube transparent dirigeÌ 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