User prompt
LET ANIMALS COME OUT ON THE GRASS
User prompt
LET'S TAKE THE EGGS AND PUT THEM SOMEWHERE, AND THE EGGS AND THE ANIMALS ARE COMING TOGETHER. FIX THAT TOO.
Code edit (1 edits merged)
Please save this source code
User prompt
Egg Farm Tycoon
Initial prompt
ADD A TUS, LET'S BUY AN ANIMAL FROM THERE, LET THERE BE 5 EGGS AND LET 1 ANIMAL COME FROM EACH EGG FROM 4 RANDOM ANIMALS AND LET EACH ANIMAL GIVE 1 MONEY EVERY 4 SECONDS, BUT NOT EVERY ANIMAL GIVE 1 MONEY EVERY 4 SECONDS. SOME ARE 2, SOME ARE 3,4,5,6,9,15 RANDOMLY.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var Animal = Container.expand(function (type) { var self = Container.call(this); self.type = type; self.lastEarningTime = LK.ticks; self.isMoving = false; // Track if animal is currently moving // Animal types: 0=chicken, 1=cow, 2=pig, 3=sheep, 4=horse, 5=goat, 6=duck, 7=rabbit, 8=bear, 9=fox, 10=turkey, 11=iceDragon, 12=darkDragon, 13=goldenDragon, 14=elephant, 15=lion, 16=tiger, 17=giraffe, 18=zebra, 19=hippo, 20=rhino, 21=panda, 22=trex, 23=triceratops, 24=stegosaurus, 25=brontosaurus, 26=velociraptor, 27=pteranodon, 28=fireDragon var assetNames = ['chicken', 'cow', 'pig', 'sheep', 'horse', 'goat', 'duck', 'rabbit', 'bear', 'fox', 'turkey', 'iceDragon', 'darkDragon', 'goldenDragon', 'elephant', 'lion', 'tiger', 'giraffe', 'zebra', 'hippo', 'rhino', 'panda', 'trex', 'triceratops', 'stegosaurus', 'brontosaurus', 'velociraptor', 'pteranodon', 'fireDragon']; var earningRates = [1, 2, 4, 6, 7, 8, 9, 9, 10, 11, 1, 13, 15, 12, 14, 16, 18, 15, 17, 19, 20, 22, 30, 20, 25, 23, 21, 20, 30]; // coins per cycle - added dinosaurs and fire dragon var earningCycles = [5.26, 5.13, 4.44, 6, 6, 6, 6, 5, 4.5, 5.73, 7.75, 2.96, 2.73, 1.25, 4, 5, 4.5, 5.5, 5, 4, 3.5, 3, 3, 3.5, 4, 2.5, 3.8, 3.2, 2]; // seconds between earnings - added dinosaur cycles var animalGraphics = self.attachAsset(assetNames[type], { anchorX: 0.5, anchorY: 0.5 }); self.earningRate = earningRates[type]; self.earningCycle = earningCycles[type] * 60; // Convert seconds to ticks (60fps) // Special turkey variants (10% chance for golden turkey, 5% chance for golden fox) if (type === 10) { // Turkey var turkeyRandom = Math.random(); if (turkeyRandom < 0.1) { // 10% chance for golden turkey (17 coins) self.earningRate = 17; // Tint golden animalGraphics.tint = 0xFFD700; } } else if (type === 9) { // Fox var foxRandom = Math.random(); if (foxRandom < 0.05) { // 5% chance for golden fox (15 coins) self.earningRate = 15; self.earningCycle = 5.73 * 60; // 5.73 seconds converted to ticks // Tint golden animalGraphics.tint = 0xFFD700; } } self.update = function () { // Generate coins based on animal-specific cycle if (LK.ticks - self.lastEarningTime >= self.earningCycle) { self.generateCoins(); self.lastEarningTime = LK.ticks; } ; if (!self.isMoving && Math.random() < 0.01) { // 1% chance per frame to start moving self.startWandering(); } }; self.generateCoins = function () { coins += self.earningRate; updateCoinDisplay(); // Visual feedback - coin animation var coinEffect = new CoinEffect(); coinEffect.x = self.x; coinEffect.y = self.y - 50; game.addChild(coinEffect); LK.getSound('coinCollect').play(); }; self.startWandering = function () { self.isMoving = true; // Calculate random target position within grass bounds // Grass is positioned at x=1024, y=1400 with width=2048, height=800 // So grass bounds are: left=0, right=2048, top=1400, bottom=2200 var grassLeft = 50; // Small margin from edges var grassRight = 1998; // Small margin from edges var grassTop = 1450; // Small margin from top var grassBottom = 2150; // Small margin from bottom var targetX = grassLeft + Math.random() * (grassRight - grassLeft); var targetY = grassTop + Math.random() * (grassBottom - grassTop); // Calculate distance for duration (further = longer time) var distance = Math.sqrt((targetX - self.x) * (targetX - self.x) + (targetY - self.y) * (targetY - self.y)); var duration = Math.max(1000, distance * 3); // Minimum 1 second, scaled by distance tween(self, { x: targetX, y: targetY }, { duration: duration, easing: tween.easeInOut, onFinish: function onFinish() { self.isMoving = false; } }); }; return self; }); var CoinEffect = Container.expand(function () { var self = Container.call(this); var coinGraphics = self.attachAsset('coin', { anchorX: 0.5, anchorY: 0.5 }); // Animate coin floating up and fading out tween(self, { y: self.y - 100, alpha: 0 }, { duration: 1000, easing: tween.easeOut, onFinish: function onFinish() { self.destroy(); } }); return self; }); var DinosaurEgg = Container.expand(function () { var self = Container.call(this); var eggGraphics = self.attachAsset('dinosaurEgg', { anchorX: 0.5, anchorY: 0.5 }); // Tint dinosaur egg with green color eggGraphics.tint = 0x228B22; self.isHatched = false; self.isHatching = false; self.hatchCountdown = 0; // Create countdown text (initially hidden) var countdownText = new Text2('20', { size: 60, fill: 0x000000 }); countdownText.anchor.set(0.5, 0.5); countdownText.y = 0; countdownText.visible = false; self.addChild(countdownText); self.down = function (x, y, obj) { if (!self.isHatched && !self.isHatching) { self.startHatching(); } }; self.update = function () { if (self.isHatching && self.hatchCountdown > 0) { self.hatchCountdown--; var secondsLeft = Math.ceil(self.hatchCountdown / 60); countdownText.setText(secondsLeft.toString()); if (self.hatchCountdown <= 0) { self.hatch(); } } }; self.startHatching = function () { if (self.isHatching || self.isHatched) { return; } self.isHatching = true; self.hatchCountdown = 1200; // 20 seconds at 60fps countdownText.visible = true; countdownText.setText('20'); // Animate countdown text appearance tween(countdownText, { scaleX: 1.5, scaleY: 1.5 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { tween(countdownText, { scaleX: 1, scaleY: 1 }, { duration: 200, easing: tween.easeIn }); } }); }; self.hatch = function () { if (self.isHatched) { return; } self.isHatched = true; self.isHatching = false; countdownText.visible = false; LK.getSound('hatch').play(); // Dinosaur egg hatches into one of 6 dinosaur types (22-27) var animalType = 22 + Math.floor(Math.random() * 6); var animal = new Animal(animalType); // Position animal randomly on grass animal.x = 200 + Math.random() * 1600; // Random X position across grass width animal.y = 1450 + Math.random() * 700; // Random Y position on grass area // Add animal to game and animals array game.addChild(animal); animals.push(animal); // Remove dinosaur egg from game and eggs array var eggIndex = eggs.indexOf(self); if (eggIndex !== -1) { eggs.splice(eggIndex, 1); } self.destroy(); }; return self; }); var DinosaurShopButton = Container.expand(function () { var self = Container.call(this); var buttonGraphics = self.attachAsset('shopButton', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.5, scaleY: 1.5 }); buttonGraphics.tint = 0x228B22; // Green color for dinosaur button var buttonText = new Text2('Buy Dinosaur Egg (' + dinosaurEggPrice + ' coins)', { size: 20, fill: 0xFFFFFF }); buttonText.anchor.set(0.5, 0.5); self.addChild(buttonText); self.down = function (x, y, obj) { if (coins >= dinosaurEggPrice) { self.purchaseDinosaurEgg(); } }; self.purchaseDinosaurEgg = function () { coins -= dinosaurEggPrice; if (progressivePriceIncreaseActive) { eggsPurchased++; dinosaurEggPrice = baseDinosaurEggPrice + eggsPurchased * 55; } else { dinosaurEggPrice += 25; } updateCoinDisplay(); // Update button text with new price buttonText.setText('Buy Dinosaur Egg (' + dinosaurEggPrice + ' coins)'); LK.getSound('purchase').play(); // Create new dinosaur egg and add to game var newDinosaurEgg = new DinosaurEgg(); // Position dinosaur egg in egg area grid layout var gridX = eggs.length % 5; var gridY = Math.floor(eggs.length / 5); newDinosaurEgg.x = 200 + gridX * 120; newDinosaurEgg.y = 600 + gridY * 180; game.addChild(newDinosaurEgg); eggs.push(newDinosaurEgg); // Flash button green LK.effects.flashObject(self, 0x00FF00, 500); }; return self; }); var DragonEgg = Container.expand(function () { var self = Container.call(this); var eggGraphics = self.attachAsset('dragonEgg', { anchorX: 0.5, anchorY: 0.5 }); self.isHatched = false; self.isHatching = false; self.hatchCountdown = 0; // Create countdown text (initially hidden) var countdownText = new Text2('15', { size: 60, fill: 0x000000 }); countdownText.anchor.set(0.5, 0.5); countdownText.y = 0; countdownText.visible = false; self.addChild(countdownText); self.down = function (x, y, obj) { if (!self.isHatched && !self.isHatching) { self.startHatching(); } }; self.update = function () { if (self.isHatching && self.hatchCountdown > 0) { self.hatchCountdown--; var secondsLeft = Math.ceil(self.hatchCountdown / 60); countdownText.setText(secondsLeft.toString()); if (self.hatchCountdown <= 0) { self.hatch(); } } }; self.startHatching = function () { if (self.isHatching || self.isHatched) { return; } self.isHatching = true; self.hatchCountdown = 900; // 15 seconds at 60fps countdownText.visible = true; countdownText.setText('15'); // Animate countdown text appearance tween(countdownText, { scaleX: 1.5, scaleY: 1.5 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { tween(countdownText, { scaleX: 1, scaleY: 1 }, { duration: 200, easing: tween.easeIn }); } }); }; self.hatch = function () { if (self.isHatched) { return; } self.isHatched = true; self.isHatching = false; countdownText.visible = false; LK.getSound('hatch').play(); // Dragon type selection with golden dragon rare spawn var dragonType; var randomValue = Math.random(); if (randomValue < 0.009) { // 0.9% chance for golden dragon dragonType = 13; // Golden dragon } else if (randomValue < 0.35) { // 35% chance for ice dragon dragonType = 11; // Ice dragon } else if (randomValue < 0.7) { // 35% chance for dark dragon dragonType = 12; // Dark dragon } else { // 30% chance for fire dragon dragonType = 28; // Fire dragon } var dragon = new Animal(dragonType); // Position dragon randomly on grass dragon.x = 200 + Math.random() * 1600; // Random X position across grass width dragon.y = 1450 + Math.random() * 700; // Random Y position on grass area // Add dragon to game and animals array game.addChild(dragon); animals.push(dragon); // Remove dragon egg from game and eggs array var eggIndex = eggs.indexOf(self); if (eggIndex !== -1) { eggs.splice(eggIndex, 1); } self.destroy(); }; return self; }); var DragonShopButton = Container.expand(function () { var self = Container.call(this); var buttonGraphics = self.attachAsset('shopButton', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.5, scaleY: 1.5 }); buttonGraphics.tint = 0x8B008B; // Purple color for dragon button var buttonText = new Text2('Buy Dragon Egg (' + dragonEggPrice + ' coins)', { size: 22, fill: 0xFFFFFF }); buttonText.anchor.set(0.5, 0.5); self.addChild(buttonText); self.down = function (x, y, obj) { if (coins >= dragonEggPrice) { self.purchaseDragonEgg(); } }; self.purchaseDragonEgg = function () { coins -= dragonEggPrice; if (progressivePriceIncreaseActive) { eggsPurchased++; dragonEggPrice = baseDragonEggPrice + eggsPurchased * 55; } else { dragonEggPrice += 20; } updateCoinDisplay(); // Update button text with new price buttonText.setText('Buy Dragon Egg (' + dragonEggPrice + ' coins)'); LK.getSound('purchase').play(); // Create new dragon egg and add to game var newDragonEgg = new DragonEgg(); // Position dragon egg in egg area grid layout var gridX = eggs.length % 5; var gridY = Math.floor(eggs.length / 5); newDragonEgg.x = 200 + gridX * 120; newDragonEgg.y = 600 + gridY * 180; game.addChild(newDragonEgg); eggs.push(newDragonEgg); // Flash button purple LK.effects.flashObject(self, 0xFF00FF, 500); }; return self; }); var Egg = Container.expand(function () { var self = Container.call(this); var eggGraphics = self.attachAsset('egg', { anchorX: 0.5, anchorY: 0.5 }); self.isHatched = false; self.isHatching = false; self.hatchCountdown = 0; // Create countdown text (initially hidden) var countdownText = new Text2('6', { size: 60, fill: 0x000000 }); countdownText.anchor.set(0.5, 0.5); countdownText.y = 0; countdownText.visible = false; self.addChild(countdownText); self.down = function (x, y, obj) { if (!self.isHatched && !self.isHatching) { self.startHatching(); } }; self.update = function () { if (self.isHatching && self.hatchCountdown > 0) { self.hatchCountdown--; var secondsLeft = Math.ceil(self.hatchCountdown / 60); countdownText.setText(secondsLeft.toString()); if (self.hatchCountdown <= 0) { self.hatch(); } } }; self.startHatching = function () { if (self.isHatching || self.isHatched) { return; } self.isHatching = true; self.hatchCountdown = 360; // 6 seconds at 60fps countdownText.visible = true; countdownText.setText('6'); // Animate countdown text appearance tween(countdownText, { scaleX: 1.5, scaleY: 1.5 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { tween(countdownText, { scaleX: 1, scaleY: 1 }, { duration: 200, easing: tween.easeIn }); } }); }; self.hatch = function () { if (self.isHatched) { return; } self.isHatched = true; self.isHatching = false; countdownText.visible = false; LK.getSound('hatch').play(); // Random animal type (0-10) - now includes bear, fox, and turkey var animalType = Math.floor(Math.random() * 11); var animal = new Animal(animalType); // Position animal randomly on grass animal.x = 200 + Math.random() * 1600; // Random X position across grass width animal.y = 1450 + Math.random() * 700; // Random Y position on grass area // Add animal to game and animals array game.addChild(animal); animals.push(animal); // Remove egg from game and eggs array var eggIndex = eggs.indexOf(self); if (eggIndex !== -1) { eggs.splice(eggIndex, 1); } self.destroy(); }; return self; }); var MysteryEgg = Container.expand(function () { var self = Container.call(this); var eggGraphics = self.attachAsset('mysteryEgg', { anchorX: 0.5, anchorY: 0.5 }); // Tint mystery egg with purple color eggGraphics.tint = 0x9932CC; self.isHatched = false; self.isHatching = false; self.hatchCountdown = 0; // Create countdown text (initially hidden) var countdownText = new Text2('10', { size: 60, fill: 0x000000 }); countdownText.anchor.set(0.5, 0.5); countdownText.y = 0; countdownText.visible = false; self.addChild(countdownText); self.down = function (x, y, obj) { if (!self.isHatched && !self.isHatching) { self.startHatching(); } }; self.update = function () { if (self.isHatching && self.hatchCountdown > 0) { self.hatchCountdown--; var secondsLeft = Math.ceil(self.hatchCountdown / 60); countdownText.setText(secondsLeft.toString()); if (self.hatchCountdown <= 0) { self.hatch(); } } }; self.startHatching = function () { if (self.isHatching || self.isHatched) { return; } self.isHatching = true; self.hatchCountdown = 600; // 10 seconds at 60fps countdownText.visible = true; countdownText.setText('10'); // Animate countdown text appearance tween(countdownText, { scaleX: 1.5, scaleY: 1.5 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { tween(countdownText, { scaleX: 1, scaleY: 1 }, { duration: 200, easing: tween.easeIn }); } }); }; self.hatch = function () { if (self.isHatched) { return; } self.isHatched = true; self.isHatching = false; countdownText.visible = false; LK.getSound('hatch').play(); // Mystery egg hatches into one of 8 new animals (14-21) var animalType = 14 + Math.floor(Math.random() * 8); var animal = new Animal(animalType); // Position animal randomly on grass animal.x = 200 + Math.random() * 1600; // Random X position across grass width animal.y = 1450 + Math.random() * 700; // Random Y position on grass area // Add animal to game and animals array game.addChild(animal); animals.push(animal); // Remove mystery egg from game and eggs array var eggIndex = eggs.indexOf(self); if (eggIndex !== -1) { eggs.splice(eggIndex, 1); } self.destroy(); }; return self; }); var MysteryShopButton = Container.expand(function () { var self = Container.call(this); var buttonGraphics = self.attachAsset('shopButton', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.5, scaleY: 1.5 }); buttonGraphics.tint = 0x9932CC; // Purple color for mystery button var buttonText = new Text2('Buy Mystery Egg (' + mysteryEggPrice + ' coins)', { size: 20, fill: 0xFFFFFF }); buttonText.anchor.set(0.5, 0.5); self.addChild(buttonText); self.down = function (x, y, obj) { if (coins >= mysteryEggPrice) { self.purchaseMysteryEgg(); } }; self.purchaseMysteryEgg = function () { coins -= mysteryEggPrice; if (progressivePriceIncreaseActive) { eggsPurchased++; mysteryEggPrice = baseMysteryEggPrice + eggsPurchased * 55; } else { mysteryEggPrice += 15; } updateCoinDisplay(); // Update button text with new price buttonText.setText('Buy Mystery Egg (' + mysteryEggPrice + ' coins)'); LK.getSound('purchase').play(); // Create new mystery egg and add to game var newMysteryEgg = new MysteryEgg(); // Position mystery egg in egg area grid layout var gridX = eggs.length % 5; var gridY = Math.floor(eggs.length / 5); newMysteryEgg.x = 200 + gridX * 120; newMysteryEgg.y = 600 + gridY * 180; game.addChild(newMysteryEgg); eggs.push(newMysteryEgg); // Flash button purple LK.effects.flashObject(self, 0xFF00FF, 500); }; return self; }); var ShopButton = Container.expand(function () { var self = Container.call(this); var buttonGraphics = self.attachAsset('shopButton', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.5, scaleY: 1.5 }); var buttonText = new Text2('Buy Egg (' + eggPrice + ' coins)', { size: 24, fill: 0xFFFFFF }); buttonText.anchor.set(0.5, 0.5); self.addChild(buttonText); self.down = function (x, y, obj) { if (coins >= eggPrice) { self.purchaseEgg(); } }; self.purchaseEgg = function () { coins -= eggPrice; if (progressivePriceIncreaseActive) { eggsPurchased++; eggPrice = baseEggPrice + eggsPurchased * 55; } else { eggPrice += 10; } updateCoinDisplay(); // Update button text with new price buttonText.setText('Buy Egg (' + eggPrice + ' coins)'); LK.getSound('purchase').play(); // Create new egg and add to game var newEgg = new Egg(); // Position egg in egg area grid layout var gridX = eggs.length % 5; var gridY = Math.floor(eggs.length / 5); newEgg.x = 200 + gridX * 120; newEgg.y = 600 + gridY * 180; game.addChild(newEgg); eggs.push(newEgg); // Flash button green LK.effects.flashObject(self, 0x00FF00, 500); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x006400 }); /**** * Game Code ****/ // Game variables var coins = 0; var eggs = []; var animals = []; var eggPrice = 25; var dragonEggPrice = 65; var mysteryEggPrice = 45; var dinosaurEggPrice = 85; // UI elements var coinDisplay = new Text2('Coins: 0', { size: 60, fill: 0xFFD700 }); coinDisplay.anchor.set(0.5, 0); LK.gui.top.addChild(coinDisplay); // Shop button var shopButton = new ShopButton(); shopButton.x = 1348; shopButton.y = 2450; shopButton.scaleX = 1.5; shopButton.scaleY = 1.5; game.addChild(shopButton); // Dragon shop button var dragonShopButton = new DragonShopButton(); dragonShopButton.x = 700; dragonShopButton.y = 2650; dragonShopButton.scaleX = 1.5; dragonShopButton.scaleY = 1.5; game.addChild(dragonShopButton); // Mystery shop button var mysteryShopButton = new MysteryShopButton(); mysteryShopButton.x = 700; mysteryShopButton.y = 2450; mysteryShopButton.scaleX = 1.5; mysteryShopButton.scaleY = 1.5; game.addChild(mysteryShopButton); // Dinosaur shop button var dinosaurShopButton = new DinosaurShopButton(); dinosaurShopButton.x = 1348; dinosaurShopButton.y = 2650; dinosaurShopButton.scaleX = 1.5; dinosaurShopButton.scaleY = 1.5; game.addChild(dinosaurShopButton); // Add grass background for egg hatching area var eggHatchingBackground = LK.getAsset('eggHatchingBackground', { anchorX: 0.5, anchorY: 0, scaleY: 0.7 }); eggHatchingBackground.x = 500; eggHatchingBackground.y = 540; game.addChild(eggHatchingBackground); // Egg area now uses grass background from eggHatchingBackground // Egg area label var eggAreaLabel = new Text2('EGGS', { size: 50, fill: 0xFFFFFF }); eggAreaLabel.anchor.set(0.5, 0); eggAreaLabel.x = 500; eggAreaLabel.y = 500; game.addChild(eggAreaLabel); // Add grass background for animals var grassBackground = LK.getAsset('grass', { anchorX: 0.5, anchorY: 0 }); grassBackground.x = 1024; grassBackground.y = 1400; game.addChild(grassBackground); // Animal area label var animalAreaLabel = new Text2('ANIMALS ON GRASS', { size: 50, fill: 0xFFFFFF }); animalAreaLabel.anchor.set(0.5, 0); animalAreaLabel.x = 1024; animalAreaLabel.y = 1300; game.addChild(animalAreaLabel); // Create initial 2 eggs in egg area for (var i = 0; i < 2; i++) { var egg = new Egg(); egg.x = 200 + i % 5 * 120; egg.y = 600 + Math.floor(i / 5) * 180; game.addChild(egg); eggs.push(egg); } function updateCoinDisplay() { coinDisplay.setText('Coins: ' + coins); storage.coins = coins; } // Initialize coin display updateCoinDisplay(); // Start background music LK.playMusic('farmMusic'); // Track if we've already increased prices at 100 coins var hasIncreasedPrices = false; // Track progressive price increases at 150 coins var progressivePriceIncreaseActive = false; // Track if we've already increased prices at 450 coins var hasPriceIncrease450 = false; var baseEggPrice = 25; var baseDragonEggPrice = 65; var baseMysteryEggPrice = 45; var baseDinosaurEggPrice = 85; var eggsPurchased = 0; game.update = function () { // Check if we reached 100 coins and haven't increased prices yet if (coins >= 100 && !hasIncreasedPrices) { // Increase all egg prices by 35% eggPrice = Math.floor(eggPrice * 1.35); dragonEggPrice = Math.floor(dragonEggPrice * 1.35); mysteryEggPrice = Math.floor(mysteryEggPrice * 1.35); dinosaurEggPrice = Math.floor(dinosaurEggPrice * 1.35); // Update base prices for progressive increase calculation baseEggPrice = eggPrice; baseDragonEggPrice = dragonEggPrice; baseMysteryEggPrice = mysteryEggPrice; baseDinosaurEggPrice = dinosaurEggPrice; hasIncreasedPrices = true; // Update all shop button texts with new prices shopButton.children[1].setText('Buy Egg (' + eggPrice + ' coins)'); dragonShopButton.children[1].setText('Buy Dragon Egg (' + dragonEggPrice + ' coins)'); mysteryShopButton.children[1].setText('Buy Mystery Egg (' + mysteryEggPrice + ' coins)'); dinosaurShopButton.children[1].setText('Buy Dinosaur Egg (' + dinosaurEggPrice + ' coins)'); } // Activate progressive price increase when money reaches 150 if (coins >= 150) { progressivePriceIncreaseActive = true; } // Check if we reached 450 coins and increase all egg prices by 150 if (coins >= 450 && !hasPriceIncrease450) { // Increase all egg prices by 150 eggPrice += 150; dragonEggPrice += 150; mysteryEggPrice += 150; dinosaurEggPrice += 150; // Update base prices for progressive increase calculation baseEggPrice += 150; baseDragonEggPrice += 150; baseMysteryEggPrice += 150; baseDinosaurEggPrice += 150; hasPriceIncrease450 = true; // Update all shop button texts with new prices shopButton.children[1].setText('Buy Egg (' + eggPrice + ' coins)'); dragonShopButton.children[1].setText('Buy Dragon Egg (' + dragonEggPrice + ' coins)'); mysteryShopButton.children[1].setText('Buy Mystery Egg (' + mysteryEggPrice + ' coins)'); dinosaurShopButton.children[1].setText('Buy Dinosaur Egg (' + dinosaurEggPrice + ' coins)'); } // Update shop button affordability if (coins >= eggPrice) { shopButton.alpha = 1.0; } else { shopButton.alpha = 0.6; } // Update dragon shop button affordability if (coins >= dragonEggPrice) { dragonShopButton.alpha = 1.0; } else { dragonShopButton.alpha = 0.6; } // Update mystery shop button affordability if (coins >= mysteryEggPrice) { mysteryShopButton.alpha = 1.0; } else { mysteryShopButton.alpha = 0.6; } // Update dinosaur shop button affordability if (coins >= dinosaurEggPrice) { dinosaurShopButton.alpha = 1.0; } else { dinosaurShopButton.alpha = 0.6; } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Animal = Container.expand(function (type) {
var self = Container.call(this);
self.type = type;
self.lastEarningTime = LK.ticks;
self.isMoving = false; // Track if animal is currently moving
// Animal types: 0=chicken, 1=cow, 2=pig, 3=sheep, 4=horse, 5=goat, 6=duck, 7=rabbit, 8=bear, 9=fox, 10=turkey, 11=iceDragon, 12=darkDragon, 13=goldenDragon, 14=elephant, 15=lion, 16=tiger, 17=giraffe, 18=zebra, 19=hippo, 20=rhino, 21=panda, 22=trex, 23=triceratops, 24=stegosaurus, 25=brontosaurus, 26=velociraptor, 27=pteranodon, 28=fireDragon
var assetNames = ['chicken', 'cow', 'pig', 'sheep', 'horse', 'goat', 'duck', 'rabbit', 'bear', 'fox', 'turkey', 'iceDragon', 'darkDragon', 'goldenDragon', 'elephant', 'lion', 'tiger', 'giraffe', 'zebra', 'hippo', 'rhino', 'panda', 'trex', 'triceratops', 'stegosaurus', 'brontosaurus', 'velociraptor', 'pteranodon', 'fireDragon'];
var earningRates = [1, 2, 4, 6, 7, 8, 9, 9, 10, 11, 1, 13, 15, 12, 14, 16, 18, 15, 17, 19, 20, 22, 30, 20, 25, 23, 21, 20, 30]; // coins per cycle - added dinosaurs and fire dragon
var earningCycles = [5.26, 5.13, 4.44, 6, 6, 6, 6, 5, 4.5, 5.73, 7.75, 2.96, 2.73, 1.25, 4, 5, 4.5, 5.5, 5, 4, 3.5, 3, 3, 3.5, 4, 2.5, 3.8, 3.2, 2]; // seconds between earnings - added dinosaur cycles
var animalGraphics = self.attachAsset(assetNames[type], {
anchorX: 0.5,
anchorY: 0.5
});
self.earningRate = earningRates[type];
self.earningCycle = earningCycles[type] * 60; // Convert seconds to ticks (60fps)
// Special turkey variants (10% chance for golden turkey, 5% chance for golden fox)
if (type === 10) {
// Turkey
var turkeyRandom = Math.random();
if (turkeyRandom < 0.1) {
// 10% chance for golden turkey (17 coins)
self.earningRate = 17;
// Tint golden
animalGraphics.tint = 0xFFD700;
}
} else if (type === 9) {
// Fox
var foxRandom = Math.random();
if (foxRandom < 0.05) {
// 5% chance for golden fox (15 coins)
self.earningRate = 15;
self.earningCycle = 5.73 * 60; // 5.73 seconds converted to ticks
// Tint golden
animalGraphics.tint = 0xFFD700;
}
}
self.update = function () {
// Generate coins based on animal-specific cycle
if (LK.ticks - self.lastEarningTime >= self.earningCycle) {
self.generateCoins();
self.lastEarningTime = LK.ticks;
}
;
if (!self.isMoving && Math.random() < 0.01) {
// 1% chance per frame to start moving
self.startWandering();
}
};
self.generateCoins = function () {
coins += self.earningRate;
updateCoinDisplay();
// Visual feedback - coin animation
var coinEffect = new CoinEffect();
coinEffect.x = self.x;
coinEffect.y = self.y - 50;
game.addChild(coinEffect);
LK.getSound('coinCollect').play();
};
self.startWandering = function () {
self.isMoving = true;
// Calculate random target position within grass bounds
// Grass is positioned at x=1024, y=1400 with width=2048, height=800
// So grass bounds are: left=0, right=2048, top=1400, bottom=2200
var grassLeft = 50; // Small margin from edges
var grassRight = 1998; // Small margin from edges
var grassTop = 1450; // Small margin from top
var grassBottom = 2150; // Small margin from bottom
var targetX = grassLeft + Math.random() * (grassRight - grassLeft);
var targetY = grassTop + Math.random() * (grassBottom - grassTop);
// Calculate distance for duration (further = longer time)
var distance = Math.sqrt((targetX - self.x) * (targetX - self.x) + (targetY - self.y) * (targetY - self.y));
var duration = Math.max(1000, distance * 3); // Minimum 1 second, scaled by distance
tween(self, {
x: targetX,
y: targetY
}, {
duration: duration,
easing: tween.easeInOut,
onFinish: function onFinish() {
self.isMoving = false;
}
});
};
return self;
});
var CoinEffect = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
// Animate coin floating up and fading out
tween(self, {
y: self.y - 100,
alpha: 0
}, {
duration: 1000,
easing: tween.easeOut,
onFinish: function onFinish() {
self.destroy();
}
});
return self;
});
var DinosaurEgg = Container.expand(function () {
var self = Container.call(this);
var eggGraphics = self.attachAsset('dinosaurEgg', {
anchorX: 0.5,
anchorY: 0.5
});
// Tint dinosaur egg with green color
eggGraphics.tint = 0x228B22;
self.isHatched = false;
self.isHatching = false;
self.hatchCountdown = 0;
// Create countdown text (initially hidden)
var countdownText = new Text2('20', {
size: 60,
fill: 0x000000
});
countdownText.anchor.set(0.5, 0.5);
countdownText.y = 0;
countdownText.visible = false;
self.addChild(countdownText);
self.down = function (x, y, obj) {
if (!self.isHatched && !self.isHatching) {
self.startHatching();
}
};
self.update = function () {
if (self.isHatching && self.hatchCountdown > 0) {
self.hatchCountdown--;
var secondsLeft = Math.ceil(self.hatchCountdown / 60);
countdownText.setText(secondsLeft.toString());
if (self.hatchCountdown <= 0) {
self.hatch();
}
}
};
self.startHatching = function () {
if (self.isHatching || self.isHatched) {
return;
}
self.isHatching = true;
self.hatchCountdown = 1200; // 20 seconds at 60fps
countdownText.visible = true;
countdownText.setText('20');
// Animate countdown text appearance
tween(countdownText, {
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(countdownText, {
scaleX: 1,
scaleY: 1
}, {
duration: 200,
easing: tween.easeIn
});
}
});
};
self.hatch = function () {
if (self.isHatched) {
return;
}
self.isHatched = true;
self.isHatching = false;
countdownText.visible = false;
LK.getSound('hatch').play();
// Dinosaur egg hatches into one of 6 dinosaur types (22-27)
var animalType = 22 + Math.floor(Math.random() * 6);
var animal = new Animal(animalType);
// Position animal randomly on grass
animal.x = 200 + Math.random() * 1600; // Random X position across grass width
animal.y = 1450 + Math.random() * 700; // Random Y position on grass area
// Add animal to game and animals array
game.addChild(animal);
animals.push(animal);
// Remove dinosaur egg from game and eggs array
var eggIndex = eggs.indexOf(self);
if (eggIndex !== -1) {
eggs.splice(eggIndex, 1);
}
self.destroy();
};
return self;
});
var DinosaurShopButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('shopButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1.5
});
buttonGraphics.tint = 0x228B22; // Green color for dinosaur button
var buttonText = new Text2('Buy Dinosaur Egg (' + dinosaurEggPrice + ' coins)', {
size: 20,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.down = function (x, y, obj) {
if (coins >= dinosaurEggPrice) {
self.purchaseDinosaurEgg();
}
};
self.purchaseDinosaurEgg = function () {
coins -= dinosaurEggPrice;
if (progressivePriceIncreaseActive) {
eggsPurchased++;
dinosaurEggPrice = baseDinosaurEggPrice + eggsPurchased * 55;
} else {
dinosaurEggPrice += 25;
}
updateCoinDisplay();
// Update button text with new price
buttonText.setText('Buy Dinosaur Egg (' + dinosaurEggPrice + ' coins)');
LK.getSound('purchase').play();
// Create new dinosaur egg and add to game
var newDinosaurEgg = new DinosaurEgg();
// Position dinosaur egg in egg area grid layout
var gridX = eggs.length % 5;
var gridY = Math.floor(eggs.length / 5);
newDinosaurEgg.x = 200 + gridX * 120;
newDinosaurEgg.y = 600 + gridY * 180;
game.addChild(newDinosaurEgg);
eggs.push(newDinosaurEgg);
// Flash button green
LK.effects.flashObject(self, 0x00FF00, 500);
};
return self;
});
var DragonEgg = Container.expand(function () {
var self = Container.call(this);
var eggGraphics = self.attachAsset('dragonEgg', {
anchorX: 0.5,
anchorY: 0.5
});
self.isHatched = false;
self.isHatching = false;
self.hatchCountdown = 0;
// Create countdown text (initially hidden)
var countdownText = new Text2('15', {
size: 60,
fill: 0x000000
});
countdownText.anchor.set(0.5, 0.5);
countdownText.y = 0;
countdownText.visible = false;
self.addChild(countdownText);
self.down = function (x, y, obj) {
if (!self.isHatched && !self.isHatching) {
self.startHatching();
}
};
self.update = function () {
if (self.isHatching && self.hatchCountdown > 0) {
self.hatchCountdown--;
var secondsLeft = Math.ceil(self.hatchCountdown / 60);
countdownText.setText(secondsLeft.toString());
if (self.hatchCountdown <= 0) {
self.hatch();
}
}
};
self.startHatching = function () {
if (self.isHatching || self.isHatched) {
return;
}
self.isHatching = true;
self.hatchCountdown = 900; // 15 seconds at 60fps
countdownText.visible = true;
countdownText.setText('15');
// Animate countdown text appearance
tween(countdownText, {
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(countdownText, {
scaleX: 1,
scaleY: 1
}, {
duration: 200,
easing: tween.easeIn
});
}
});
};
self.hatch = function () {
if (self.isHatched) {
return;
}
self.isHatched = true;
self.isHatching = false;
countdownText.visible = false;
LK.getSound('hatch').play();
// Dragon type selection with golden dragon rare spawn
var dragonType;
var randomValue = Math.random();
if (randomValue < 0.009) {
// 0.9% chance for golden dragon
dragonType = 13; // Golden dragon
} else if (randomValue < 0.35) {
// 35% chance for ice dragon
dragonType = 11; // Ice dragon
} else if (randomValue < 0.7) {
// 35% chance for dark dragon
dragonType = 12; // Dark dragon
} else {
// 30% chance for fire dragon
dragonType = 28; // Fire dragon
}
var dragon = new Animal(dragonType);
// Position dragon randomly on grass
dragon.x = 200 + Math.random() * 1600; // Random X position across grass width
dragon.y = 1450 + Math.random() * 700; // Random Y position on grass area
// Add dragon to game and animals array
game.addChild(dragon);
animals.push(dragon);
// Remove dragon egg from game and eggs array
var eggIndex = eggs.indexOf(self);
if (eggIndex !== -1) {
eggs.splice(eggIndex, 1);
}
self.destroy();
};
return self;
});
var DragonShopButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('shopButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1.5
});
buttonGraphics.tint = 0x8B008B; // Purple color for dragon button
var buttonText = new Text2('Buy Dragon Egg (' + dragonEggPrice + ' coins)', {
size: 22,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.down = function (x, y, obj) {
if (coins >= dragonEggPrice) {
self.purchaseDragonEgg();
}
};
self.purchaseDragonEgg = function () {
coins -= dragonEggPrice;
if (progressivePriceIncreaseActive) {
eggsPurchased++;
dragonEggPrice = baseDragonEggPrice + eggsPurchased * 55;
} else {
dragonEggPrice += 20;
}
updateCoinDisplay();
// Update button text with new price
buttonText.setText('Buy Dragon Egg (' + dragonEggPrice + ' coins)');
LK.getSound('purchase').play();
// Create new dragon egg and add to game
var newDragonEgg = new DragonEgg();
// Position dragon egg in egg area grid layout
var gridX = eggs.length % 5;
var gridY = Math.floor(eggs.length / 5);
newDragonEgg.x = 200 + gridX * 120;
newDragonEgg.y = 600 + gridY * 180;
game.addChild(newDragonEgg);
eggs.push(newDragonEgg);
// Flash button purple
LK.effects.flashObject(self, 0xFF00FF, 500);
};
return self;
});
var Egg = Container.expand(function () {
var self = Container.call(this);
var eggGraphics = self.attachAsset('egg', {
anchorX: 0.5,
anchorY: 0.5
});
self.isHatched = false;
self.isHatching = false;
self.hatchCountdown = 0;
// Create countdown text (initially hidden)
var countdownText = new Text2('6', {
size: 60,
fill: 0x000000
});
countdownText.anchor.set(0.5, 0.5);
countdownText.y = 0;
countdownText.visible = false;
self.addChild(countdownText);
self.down = function (x, y, obj) {
if (!self.isHatched && !self.isHatching) {
self.startHatching();
}
};
self.update = function () {
if (self.isHatching && self.hatchCountdown > 0) {
self.hatchCountdown--;
var secondsLeft = Math.ceil(self.hatchCountdown / 60);
countdownText.setText(secondsLeft.toString());
if (self.hatchCountdown <= 0) {
self.hatch();
}
}
};
self.startHatching = function () {
if (self.isHatching || self.isHatched) {
return;
}
self.isHatching = true;
self.hatchCountdown = 360; // 6 seconds at 60fps
countdownText.visible = true;
countdownText.setText('6');
// Animate countdown text appearance
tween(countdownText, {
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(countdownText, {
scaleX: 1,
scaleY: 1
}, {
duration: 200,
easing: tween.easeIn
});
}
});
};
self.hatch = function () {
if (self.isHatched) {
return;
}
self.isHatched = true;
self.isHatching = false;
countdownText.visible = false;
LK.getSound('hatch').play();
// Random animal type (0-10) - now includes bear, fox, and turkey
var animalType = Math.floor(Math.random() * 11);
var animal = new Animal(animalType);
// Position animal randomly on grass
animal.x = 200 + Math.random() * 1600; // Random X position across grass width
animal.y = 1450 + Math.random() * 700; // Random Y position on grass area
// Add animal to game and animals array
game.addChild(animal);
animals.push(animal);
// Remove egg from game and eggs array
var eggIndex = eggs.indexOf(self);
if (eggIndex !== -1) {
eggs.splice(eggIndex, 1);
}
self.destroy();
};
return self;
});
var MysteryEgg = Container.expand(function () {
var self = Container.call(this);
var eggGraphics = self.attachAsset('mysteryEgg', {
anchorX: 0.5,
anchorY: 0.5
});
// Tint mystery egg with purple color
eggGraphics.tint = 0x9932CC;
self.isHatched = false;
self.isHatching = false;
self.hatchCountdown = 0;
// Create countdown text (initially hidden)
var countdownText = new Text2('10', {
size: 60,
fill: 0x000000
});
countdownText.anchor.set(0.5, 0.5);
countdownText.y = 0;
countdownText.visible = false;
self.addChild(countdownText);
self.down = function (x, y, obj) {
if (!self.isHatched && !self.isHatching) {
self.startHatching();
}
};
self.update = function () {
if (self.isHatching && self.hatchCountdown > 0) {
self.hatchCountdown--;
var secondsLeft = Math.ceil(self.hatchCountdown / 60);
countdownText.setText(secondsLeft.toString());
if (self.hatchCountdown <= 0) {
self.hatch();
}
}
};
self.startHatching = function () {
if (self.isHatching || self.isHatched) {
return;
}
self.isHatching = true;
self.hatchCountdown = 600; // 10 seconds at 60fps
countdownText.visible = true;
countdownText.setText('10');
// Animate countdown text appearance
tween(countdownText, {
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(countdownText, {
scaleX: 1,
scaleY: 1
}, {
duration: 200,
easing: tween.easeIn
});
}
});
};
self.hatch = function () {
if (self.isHatched) {
return;
}
self.isHatched = true;
self.isHatching = false;
countdownText.visible = false;
LK.getSound('hatch').play();
// Mystery egg hatches into one of 8 new animals (14-21)
var animalType = 14 + Math.floor(Math.random() * 8);
var animal = new Animal(animalType);
// Position animal randomly on grass
animal.x = 200 + Math.random() * 1600; // Random X position across grass width
animal.y = 1450 + Math.random() * 700; // Random Y position on grass area
// Add animal to game and animals array
game.addChild(animal);
animals.push(animal);
// Remove mystery egg from game and eggs array
var eggIndex = eggs.indexOf(self);
if (eggIndex !== -1) {
eggs.splice(eggIndex, 1);
}
self.destroy();
};
return self;
});
var MysteryShopButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('shopButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1.5
});
buttonGraphics.tint = 0x9932CC; // Purple color for mystery button
var buttonText = new Text2('Buy Mystery Egg (' + mysteryEggPrice + ' coins)', {
size: 20,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.down = function (x, y, obj) {
if (coins >= mysteryEggPrice) {
self.purchaseMysteryEgg();
}
};
self.purchaseMysteryEgg = function () {
coins -= mysteryEggPrice;
if (progressivePriceIncreaseActive) {
eggsPurchased++;
mysteryEggPrice = baseMysteryEggPrice + eggsPurchased * 55;
} else {
mysteryEggPrice += 15;
}
updateCoinDisplay();
// Update button text with new price
buttonText.setText('Buy Mystery Egg (' + mysteryEggPrice + ' coins)');
LK.getSound('purchase').play();
// Create new mystery egg and add to game
var newMysteryEgg = new MysteryEgg();
// Position mystery egg in egg area grid layout
var gridX = eggs.length % 5;
var gridY = Math.floor(eggs.length / 5);
newMysteryEgg.x = 200 + gridX * 120;
newMysteryEgg.y = 600 + gridY * 180;
game.addChild(newMysteryEgg);
eggs.push(newMysteryEgg);
// Flash button purple
LK.effects.flashObject(self, 0xFF00FF, 500);
};
return self;
});
var ShopButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('shopButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1.5
});
var buttonText = new Text2('Buy Egg (' + eggPrice + ' coins)', {
size: 24,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.down = function (x, y, obj) {
if (coins >= eggPrice) {
self.purchaseEgg();
}
};
self.purchaseEgg = function () {
coins -= eggPrice;
if (progressivePriceIncreaseActive) {
eggsPurchased++;
eggPrice = baseEggPrice + eggsPurchased * 55;
} else {
eggPrice += 10;
}
updateCoinDisplay();
// Update button text with new price
buttonText.setText('Buy Egg (' + eggPrice + ' coins)');
LK.getSound('purchase').play();
// Create new egg and add to game
var newEgg = new Egg();
// Position egg in egg area grid layout
var gridX = eggs.length % 5;
var gridY = Math.floor(eggs.length / 5);
newEgg.x = 200 + gridX * 120;
newEgg.y = 600 + gridY * 180;
game.addChild(newEgg);
eggs.push(newEgg);
// Flash button green
LK.effects.flashObject(self, 0x00FF00, 500);
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x006400
});
/****
* Game Code
****/
// Game variables
var coins = 0;
var eggs = [];
var animals = [];
var eggPrice = 25;
var dragonEggPrice = 65;
var mysteryEggPrice = 45;
var dinosaurEggPrice = 85;
// UI elements
var coinDisplay = new Text2('Coins: 0', {
size: 60,
fill: 0xFFD700
});
coinDisplay.anchor.set(0.5, 0);
LK.gui.top.addChild(coinDisplay);
// Shop button
var shopButton = new ShopButton();
shopButton.x = 1348;
shopButton.y = 2450;
shopButton.scaleX = 1.5;
shopButton.scaleY = 1.5;
game.addChild(shopButton);
// Dragon shop button
var dragonShopButton = new DragonShopButton();
dragonShopButton.x = 700;
dragonShopButton.y = 2650;
dragonShopButton.scaleX = 1.5;
dragonShopButton.scaleY = 1.5;
game.addChild(dragonShopButton);
// Mystery shop button
var mysteryShopButton = new MysteryShopButton();
mysteryShopButton.x = 700;
mysteryShopButton.y = 2450;
mysteryShopButton.scaleX = 1.5;
mysteryShopButton.scaleY = 1.5;
game.addChild(mysteryShopButton);
// Dinosaur shop button
var dinosaurShopButton = new DinosaurShopButton();
dinosaurShopButton.x = 1348;
dinosaurShopButton.y = 2650;
dinosaurShopButton.scaleX = 1.5;
dinosaurShopButton.scaleY = 1.5;
game.addChild(dinosaurShopButton);
// Add grass background for egg hatching area
var eggHatchingBackground = LK.getAsset('eggHatchingBackground', {
anchorX: 0.5,
anchorY: 0,
scaleY: 0.7
});
eggHatchingBackground.x = 500;
eggHatchingBackground.y = 540;
game.addChild(eggHatchingBackground);
// Egg area now uses grass background from eggHatchingBackground
// Egg area label
var eggAreaLabel = new Text2('EGGS', {
size: 50,
fill: 0xFFFFFF
});
eggAreaLabel.anchor.set(0.5, 0);
eggAreaLabel.x = 500;
eggAreaLabel.y = 500;
game.addChild(eggAreaLabel);
// Add grass background for animals
var grassBackground = LK.getAsset('grass', {
anchorX: 0.5,
anchorY: 0
});
grassBackground.x = 1024;
grassBackground.y = 1400;
game.addChild(grassBackground);
// Animal area label
var animalAreaLabel = new Text2('ANIMALS ON GRASS', {
size: 50,
fill: 0xFFFFFF
});
animalAreaLabel.anchor.set(0.5, 0);
animalAreaLabel.x = 1024;
animalAreaLabel.y = 1300;
game.addChild(animalAreaLabel);
// Create initial 2 eggs in egg area
for (var i = 0; i < 2; i++) {
var egg = new Egg();
egg.x = 200 + i % 5 * 120;
egg.y = 600 + Math.floor(i / 5) * 180;
game.addChild(egg);
eggs.push(egg);
}
function updateCoinDisplay() {
coinDisplay.setText('Coins: ' + coins);
storage.coins = coins;
}
// Initialize coin display
updateCoinDisplay();
// Start background music
LK.playMusic('farmMusic');
// Track if we've already increased prices at 100 coins
var hasIncreasedPrices = false;
// Track progressive price increases at 150 coins
var progressivePriceIncreaseActive = false;
// Track if we've already increased prices at 450 coins
var hasPriceIncrease450 = false;
var baseEggPrice = 25;
var baseDragonEggPrice = 65;
var baseMysteryEggPrice = 45;
var baseDinosaurEggPrice = 85;
var eggsPurchased = 0;
game.update = function () {
// Check if we reached 100 coins and haven't increased prices yet
if (coins >= 100 && !hasIncreasedPrices) {
// Increase all egg prices by 35%
eggPrice = Math.floor(eggPrice * 1.35);
dragonEggPrice = Math.floor(dragonEggPrice * 1.35);
mysteryEggPrice = Math.floor(mysteryEggPrice * 1.35);
dinosaurEggPrice = Math.floor(dinosaurEggPrice * 1.35);
// Update base prices for progressive increase calculation
baseEggPrice = eggPrice;
baseDragonEggPrice = dragonEggPrice;
baseMysteryEggPrice = mysteryEggPrice;
baseDinosaurEggPrice = dinosaurEggPrice;
hasIncreasedPrices = true;
// Update all shop button texts with new prices
shopButton.children[1].setText('Buy Egg (' + eggPrice + ' coins)');
dragonShopButton.children[1].setText('Buy Dragon Egg (' + dragonEggPrice + ' coins)');
mysteryShopButton.children[1].setText('Buy Mystery Egg (' + mysteryEggPrice + ' coins)');
dinosaurShopButton.children[1].setText('Buy Dinosaur Egg (' + dinosaurEggPrice + ' coins)');
}
// Activate progressive price increase when money reaches 150
if (coins >= 150) {
progressivePriceIncreaseActive = true;
}
// Check if we reached 450 coins and increase all egg prices by 150
if (coins >= 450 && !hasPriceIncrease450) {
// Increase all egg prices by 150
eggPrice += 150;
dragonEggPrice += 150;
mysteryEggPrice += 150;
dinosaurEggPrice += 150;
// Update base prices for progressive increase calculation
baseEggPrice += 150;
baseDragonEggPrice += 150;
baseMysteryEggPrice += 150;
baseDinosaurEggPrice += 150;
hasPriceIncrease450 = true;
// Update all shop button texts with new prices
shopButton.children[1].setText('Buy Egg (' + eggPrice + ' coins)');
dragonShopButton.children[1].setText('Buy Dragon Egg (' + dragonEggPrice + ' coins)');
mysteryShopButton.children[1].setText('Buy Mystery Egg (' + mysteryEggPrice + ' coins)');
dinosaurShopButton.children[1].setText('Buy Dinosaur Egg (' + dinosaurEggPrice + ' coins)');
}
// Update shop button affordability
if (coins >= eggPrice) {
shopButton.alpha = 1.0;
} else {
shopButton.alpha = 0.6;
}
// Update dragon shop button affordability
if (coins >= dragonEggPrice) {
dragonShopButton.alpha = 1.0;
} else {
dragonShopButton.alpha = 0.6;
}
// Update mystery shop button affordability
if (coins >= mysteryEggPrice) {
mysteryShopButton.alpha = 1.0;
} else {
mysteryShopButton.alpha = 0.6;
}
// Update dinosaur shop button affordability
if (coins >= dinosaurEggPrice) {
dinosaurShopButton.alpha = 1.0;
} else {
dinosaurShopButton.alpha = 0.6;
}
};
Tavuk pixel. In-Game asset. 2d. High contrast. No shadows
Inek pixel. In-Game asset. 2d. High contrast. No shadows
Domuz pixel. In-Game asset. 2d. High contrast. No shadows
Koyun pixel. In-Game asset. 2d. High contrast. No shadows
Egg pixel. In-Game asset. 2d. High contrast. No shadows
rabbit pixel. In-Game asset. 2d. High contrast. No shadows
Ordek pixel. In-Game asset. 2d. High contrast. No shadows
Dragon egg pixel. In-Game asset. 2d. High contrast. No shadows
Goat pixel. In-Game asset. 2d. High contrast. No shadows
Horse pixel. In-Game asset. 2d. High contrast. No shadows
DARK DRAGON PIXEL. In-Game asset. 2d. High contrast. No shadows
Ice dragon pixel. In-Game asset. 2d. High contrast. No shadows
Pixel
Turkey Pixel. In-Game asset. 2d. High contrast. No shadows
Bear pixel. In-Game asset. 2d. High contrast. No shadows
Fox pixel. In-Game asset. 2d. High contrast. No shadows
Coin pixel. In-Game asset. 2d. High contrast. No shadows
Elephant 8 bit. In-Game asset. 2d. High contrast. No shadows
Lion 8 bit. In-Game asset. 2d. High contrast. No shadows
Giraffe 8 bit. In-Game asset. 2d. High contrast. No shadows
Tiger 8 bit. In-Game asset. 2d. High contrast. No shadows
Zebra 8bit. In-Game asset. 2d. High contrast. No shadows
Panda 8bit. In-Game asset. 2d. High contrast. No shadows
Rhino 8bit. In-Game asset. 2d. High contrast. No shadows
T rex pixel. In-Game asset. 2d. High contrast. No shadows
Triceraptos pixel. In-Game asset. 2d. High contrast. No shadows
Stegosaurus pixel. In-Game asset. 2d. High contrast. No shadows
Brontosaurus pixel. In-Game asset. 2d. High contrast. No shadows
Veliciraptor pixel. In-Game asset. 2d. High contrast. No shadows
Pteranodon pixel. In-Game asset. 2d. High contrast. No shadows
Hippo 8 bit. In-Game asset. 2d. High contrast. No shadows