/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var AquaticPlantSpot = Container.expand(function (x, y) { var self = Container.call(this); self.x = x; self.y = y; self.planted = false; self.plantType = null; self.plantTime = 0; self.grown = false; self.regrowTime = 0; self.isAquatic = true; var sandGraphics = self.attachAsset('sand', { anchorX: 0.5, anchorY: 0.5, tint: 0xF4A460 }); // Move sand graphics to the back layer self.setChildIndex(sandGraphics, 0); var plantGraphics = null; self.plantSeed = function (seedType) { if (self.planted) return false; self.planted = true; // Handle cactus planting if (seedType === 'cactus' || seedType === 'atlas_cactus') { self.plantType = seedType; self.plantTime = LK.ticks; self.grown = false; self.isColorful = false; // 5% chance for colorful cactus (3x price) if (Math.random() < 0.05) { self.isColorful = true; self.plantType = 'colorful_' + seedType; } var finalScale = 1.0; var assetName = seedType === 'atlas_cactus' ? self.isColorful ? 'colorful_atlas_cactus' : 'atlas_cactus_icon' : self.plantType; } else { // Handle fish planting self.plantType = seedType === 'fish2' ? 'fish2' : 'fish'; // Support both fish types self.plantTime = LK.ticks; self.grown = false; self.isColorful = false; // 5% chance for colorful fish (3x price) if (Math.random() < 0.05) { self.isColorful = true; } var finalScale = 1.0; var assetName; if (self.plantType === 'fish2') { assetName = self.isColorful ? 'colorful_Fish2' : 'Fish2'; } else { assetName = self.isColorful ? 'colorful_fish' : 'fish'; } } plantGraphics = self.attachAsset(assetName, { anchorX: 0.5, anchorY: 0.5, alpha: 0.5, scaleX: 0.3, scaleY: 0.3 }); // Add colorful tint for special fish if (self.isColorful) { plantGraphics.tint = 0xFFD700; // Golden fish } // Ensure fish graphics appear above water self.setChildIndex(plantGraphics, self.children.length - 1); // Animate fish growth over 3 seconds (faster than plants) tween(plantGraphics, { scaleX: finalScale, scaleY: finalScale }, { duration: 3000, easing: tween.easeOut }); // Add swimming animation for colorful fish if (self.isColorful) { var swimmingAnimation = function swimmingAnimation() { if (plantGraphics) { tween(plantGraphics, { x: 20 }, { duration: 1000, easing: tween.easeInOut, onFinish: function onFinish() { tween(plantGraphics, { x: -20 }, { duration: 1000, easing: tween.easeInOut, onFinish: function onFinish() { tween(plantGraphics, { x: 0 }, { duration: 1000, easing: tween.easeInOut, onFinish: swimmingAnimation }); } }); } }); } }; // Start swimming animation after growth completes LK.setTimeout(swimmingAnimation, 3000); } LK.getSound('plant').play(); return true; }; self.harvest = function () { if (!self.grown) return null; var harvestedType = self.plantType; // Use the actual planted type (fish, fish2, or cactus) var isColorfulHarvest = self.isColorful; // All plants (including cactus) now regrow if (plantGraphics) { tween(plantGraphics, { alpha: 0.3, scaleX: 0.5, scaleY: 0.5 }, { duration: 500, easing: tween.easeIn }); } self.grown = false; self.regrowTime = LK.ticks; LK.getSound('harvest').play(); return { type: harvestedType, colorful: isColorfulHarvest, chocolate: self.isChocolate || false, fromSeedPack: self.isFromSeedPack || false }; }; self.update = function () { if (self.planted && !self.grown) { // Check if this spot is affected by a sprinkler var speedMultiplier = 1; for (var i = 0; i < sprinklers.length; i++) { var sprinkler = sprinklers[i]; var distanceX = Math.abs(self.x - sprinkler.x); var distanceY = Math.abs(self.y - sprinkler.y); // Regular sprinkler: 5x speed in 3x3 area if (distanceX <= 660 && distanceY <= 660) { speedMultiplier = 5; break; } } // Check if it's time to regrow after harvest if (self.regrowTime > 0) { var regrowTime; var isCactus = self.plantType === 'cactus' || self.plantType === 'colorful_cactus'; var isAtlasCactus = self.plantType === 'atlas_cactus' || self.plantType === 'colorful_atlas_cactus'; if (isCactus) { regrowTime = 1200; // 20 seconds for cactus regrow } else if (isAtlasCactus) { regrowTime = 1560; // 26 seconds for atlas cactus regrow (2x growth time) } else if (self.plantType === 'fish2') { regrowTime = 2700; // 45 seconds for fish2 } else { regrowTime = 3300; // 55 seconds for fish } if (LK.ticks - self.regrowTime > regrowTime / speedMultiplier) { self.grown = true; self.regrowTime = 0; if (plantGraphics) { var regrowScale = 1.0; tween(plantGraphics, { alpha: 1.0, scaleX: regrowScale, scaleY: regrowScale }, { duration: 1000, easing: tween.easeOut }); } } } else if (self.regrowTime === 0) { var isCactus = self.plantType === 'cactus' || self.plantType === 'colorful_cactus'; var isAtlasCactus = self.plantType === 'atlas_cactus' || self.plantType === 'colorful_atlas_cactus'; var growthTime; if (isCactus) { growthTime = 300; // 5 seconds for cactus (same as other plants) } else if (isAtlasCactus) { growthTime = 600; // 10 seconds for atlas cactus } else if (self.plantType === 'fish2') { growthTime = 2700; // 45 seconds for fish2 } else { growthTime = 3300; // 55 seconds for fish } if (LK.ticks - self.plantTime > growthTime / speedMultiplier) { self.grown = true; if (plantGraphics) { plantGraphics.alpha = 1.0; } } } } }; self.down = function () { if (self.grown) { var harvested = self.harvest(); if (harvested) { if (!harvested.fromSeedPack) { var harvestType = harvested.type; if (harvested.chocolate) { var baseType = harvestType === 'fish2' ? 'fish2' : 'fish'; inventory['choco_' + baseType] = (inventory['choco_' + baseType] || 0) + 1; } else if (harvested.colorful) { var baseType = harvestType === 'fish2' ? 'fish2' : 'fish'; inventory['colorful_' + baseType] = (inventory['colorful_' + baseType] || 0) + 1; } else { inventory[harvestType] = (inventory[harvestType] || 0) + 1; } updateInventoryDisplay(); } } } else if (!self.planted && selectedSprinkler) { // Place sprinkler var sprinklerCost = 35; if (money >= sprinklerCost) { var sprinkler = new Sprinkler(self.x, self.y); sprinklers.push(sprinkler); game.addChild(sprinkler); money -= sprinklerCost; updateMoneyDisplay(); selectedSprinkler = false; gearShop.visible = false; } } else if (!self.planted && selectedFish && money >= 100) { // Plant fish in aquatic spots if (self.plantSeed('fish')) { money -= 100; updateMoneyDisplay(); selectedFish = false; fishShop.visible = false; } } else if (!self.planted && selectedFish2 && money >= 150) { // Plant fish2 in aquatic spots if (self.plantSeed('fish2')) { money -= 150; updateMoneyDisplay(); selectedFish2 = false; fishShop.visible = false; } } else if (!self.planted && (selectedSeed === 'cactus' || selectedSeed === 'atlas_cactus') && money >= seedPrices[selectedSeed]) { // Plant cactus in sand spots only if (self.plantSeed(selectedSeed)) { money -= seedPrices[selectedSeed]; updateMoneyDisplay(); selectedSeed = null; seedShop.visible = false; } } else if (!self.planted && selectedSeed && selectedSeed !== 'cactus' && selectedSeed !== 'atlas_cactus' && money >= seedPrices[selectedSeed]) { // Don't plant other fruit seeds in sand - this is for cactus only // No planting action will occur, but we can provide feedback selectedSeed = null; seedShop.visible = false; } }; return self; }); var Button = Container.expand(function (text, onClick) { var self = Container.call(this); var buttonBg = self.attachAsset('button', { anchorX: 0.5, anchorY: 0.5 }); var buttonText = new Text2(text, { size: 30, fill: 0xFFFFFF }); buttonText.anchor.set(0.5, 0.5); self.addChild(buttonText); self.down = function () { if (onClick) onClick(); }; return self; }); var DesertShop = Container.expand(function () { var self = Container.call(this); var background = self.attachAsset('seedShopBg', { anchorX: 0.5, anchorY: 0.5 }); var titleText = new Text2('DESERT SHOP', { size: 80, fill: 0x000000 }); titleText.anchor.set(0.5, 0.5); titleText.y = -600; self.addChild(titleText); // Cactus item var cactusButton = new Container(); cactusButton.x = 0; cactusButton.y = -300; var cactusIcon = cactusButton.attachAsset('cactus', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.5, scaleY: 1.5 }); cactusIcon.x = -300; var cactusNameText = new Text2('Cactus', { size: 70, fill: 0x000000 }); cactusNameText.anchor.set(0, 0.5); cactusNameText.x = -200; cactusButton.addChild(cactusNameText); var cactusPriceText = new Text2('$100', { size: 70, fill: 0xFFFF00 }); cactusPriceText.anchor.set(1, 0.5); cactusPriceText.x = 300; cactusButton.addChild(cactusPriceText); var cactusDescText = new Text2('Sells for $150, 0.3% chance for $450', { size: 40, fill: 0x666666 }); cactusDescText.anchor.set(0.5, 0); cactusDescText.y = 50; cactusButton.addChild(cactusDescText); cactusButton.down = function () { if (money >= 100) { selectedSeed = 'cactus'; self.visible = false; LK.getSound('Buy').play(); } }; self.addChild(cactusButton); // Atlas Cactus item var atlasCactusButton = new Container(); atlasCactusButton.x = 0; atlasCactusButton.y = -150; var atlasCactusIcon = atlasCactusButton.attachAsset('atlas_cactus_icon', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.5, scaleY: 1.5 }); atlasCactusIcon.x = -300; var atlasCactusNameText = new Text2('Atlas Cactus', { size: 70, fill: 0x000000 }); atlasCactusNameText.anchor.set(0, 0.5); atlasCactusNameText.x = -200; atlasCactusButton.addChild(atlasCactusNameText); var atlasCactusPriceText = new Text2('$250', { size: 70, fill: 0xFFFF00 }); atlasCactusPriceText.anchor.set(1, 0.5); atlasCactusPriceText.x = 300; atlasCactusButton.addChild(atlasCactusPriceText); var atlasCactusDescText = new Text2('Sells for $265, 0.5% chance for $500', { size: 40, fill: 0x666666 }); atlasCactusDescText.anchor.set(0.5, 0); atlasCactusDescText.y = 50; atlasCactusButton.addChild(atlasCactusDescText); atlasCactusButton.down = function () { if (money >= 250) { selectedSeed = 'atlas_cactus'; self.visible = false; LK.getSound('Buy').play(); } }; self.addChild(atlasCactusButton); var closeButton = new Button('CLOSE', function () { self.visible = false; }); closeButton.y = 200; self.addChild(closeButton); return self; }); var GearShop = Container.expand(function () { var self = Container.call(this); var background = self.attachAsset('seedShopBg', { anchorX: 0.5, anchorY: 0.5 }); var titleText = new Text2('GEAR SHOP', { size: 80, fill: 0x000000 }); titleText.anchor.set(0.5, 0.5); titleText.y = -600; self.addChild(titleText); // Sprinkler item var sprinklerButton = new Container(); sprinklerButton.x = 0; sprinklerButton.y = -200; var sprinklerIcon = LK.getAsset('sprinkler', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.5, scaleY: 1.5 }); sprinklerIcon.x = -300; sprinklerButton.addChild(sprinklerIcon); var nameText = new Text2('Sprinkler', { size: 70, fill: 0x000000 }); nameText.anchor.set(0, 0.5); nameText.x = -200; sprinklerButton.addChild(nameText); var priceText = new Text2('$35', { size: 70, fill: 0xFFFF00 }); priceText.anchor.set(1, 0.5); priceText.x = 300; sprinklerButton.addChild(priceText); var descText = new Text2('5x growth speed in 3x3 area', { size: 40, fill: 0x666666 }); descText.anchor.set(0.5, 0); descText.y = 50; sprinklerButton.addChild(descText); sprinklerButton.down = function () { if (money >= 35) { selectedSprinkler = 'regular'; self.visible = false; LK.getSound('Buy').play(); } }; self.addChild(sprinklerButton); var closeButton = new Button('CLOSE', function () { self.visible = false; }); closeButton.y = 200; self.addChild(closeButton); return self; }); var PlantSpot = Container.expand(function (x, y) { var self = Container.call(this); self.x = x; self.y = y; self.planted = false; self.plantType = null; self.plantTime = 0; self.grown = false; self.regrowTime = 0; var dirtGraphics = self.attachAsset('dirt', { anchorX: 0.5, anchorY: 0.5 }); // Move dirt graphics to the back layer self.setChildIndex(dirtGraphics, 0); var plantGraphics = null; self.plantSeed = function (seedType) { if (self.planted) return false; self.planted = true; self.plantType = seedType; self.plantTime = LK.ticks; self.grown = false; self.isColorful = false; // 5% chance for colorful fruit (3x price) if (Math.random() < 0.05) { self.isColorful = true; self.plantType = 'colorful_' + seedType; } var finalScale = 1.0; plantGraphics = self.attachAsset(self.plantType, { anchorX: 0.5, anchorY: 0.5, alpha: 0.5, scaleX: 0.3, scaleY: 0.3 }); // Ensure plant graphics appear above soil, especially for giant fruits self.setChildIndex(plantGraphics, self.children.length - 1); // Animate plant growth over 5 seconds tween(plantGraphics, { scaleX: finalScale, scaleY: finalScale }, { duration: 5000, easing: tween.easeOut }); // Add rainbow tint animation for colorful fruits if (self.isColorful) { var colorfulAnimation = function colorfulAnimation() { var colors = [0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0xff00ff, 0x00ffff]; var currentColor = 0; var _animateColor = function animateColor() { if (plantGraphics) { tween(plantGraphics, { tint: colors[currentColor] }, { duration: 800, easing: tween.easeInOut, onFinish: function onFinish() { currentColor = (currentColor + 1) % colors.length; _animateColor(); } }); } }; _animateColor(); }; // Start colorful animation after growth completes LK.setTimeout(colorfulAnimation, 5000); } LK.getSound('plant').play(); return true; }; self.harvest = function () { if (!self.grown) return null; var harvestedType = self.plantType; var isColorfulHarvest = self.isColorful; // Check if this is a regrowing fruit (banana, dragon fruit, coconut, apple, nectarine, kiwi, cherry, mango, heavenMango) var isBanana = harvestedType === 'banana' || harvestedType === 'colorful_banana'; var isDragonFruit = harvestedType === 'dragonfruit' || harvestedType === 'colorful_dragonfruit'; var isCoconut = harvestedType === 'coconut' || harvestedType === 'colorful_coconut'; var isApple = harvestedType === 'apple' || harvestedType === 'colorful_apple'; var isNectarine = harvestedType === 'nectarine' || harvestedType === 'colorful_nectarine'; var isKiwi = harvestedType === 'kiwi' || harvestedType === 'colorful_kiwi'; var isCherry = harvestedType === 'cherry' || harvestedType === 'colorful_cherry'; var isMango = harvestedType === 'mango' || harvestedType === 'colorful_mango'; var isHeavenMango = harvestedType === 'heavenMango' || harvestedType === 'colorful_heavenMango'; if (isBanana || isDragonFruit || isCoconut || isApple || isNectarine || isKiwi || isCherry || isMango || isHeavenMango) { // Hide the plant graphics with animation for regrowing fruits if (plantGraphics) { tween(plantGraphics, { alpha: 0.3, scaleX: 0.5, scaleY: 0.5 }, { duration: 500, easing: tween.easeIn }); } self.grown = false; self.regrowTime = LK.ticks; } else { // For carrots and strawberries, reset the plant completely if (plantGraphics) { plantGraphics.destroy(); plantGraphics = null; } self.planted = false; self.plantType = null; self.plantTime = 0; self.grown = false; self.isColorful = false; self.regrowTime = 0; } LK.getSound('harvest').play(); return { type: harvestedType, colorful: isColorfulHarvest, chocolate: self.isChocolate || false, fromSeedPack: self.isFromSeedPack || false }; }; self.update = function () { if (self.planted && !self.grown) { // Check if this spot is affected by a sprinkler var speedMultiplier = 1; for (var i = 0; i < sprinklers.length; i++) { var sprinkler = sprinklers[i]; var distanceX = Math.abs(self.x - sprinkler.x); var distanceY = Math.abs(self.y - sprinkler.y); // Regular sprinkler: 5x speed in 3x3 area (660px = 3 * 220px spacing) if (distanceX <= 660 && distanceY <= 660) { speedMultiplier = 5; break; } } // Check if it's time to regrow after harvest (for bananas, dragon fruit, coconut, apple, and the new fruits) if (self.regrowTime > 0) { var isBanana = self.plantType === 'banana' || self.plantType === 'colorful_banana'; var isDragonFruit = self.plantType === 'dragonfruit' || self.plantType === 'colorful_dragonfruit'; var isCoconut = self.plantType === 'coconut' || self.plantType === 'colorful_coconut'; var isApple = self.plantType === 'apple' || self.plantType === 'colorful_apple'; var isNectarine = self.plantType === 'nectarine' || self.plantType === 'colorful_nectarine'; var isKiwi = self.plantType === 'kiwi' || self.plantType === 'colorful_kiwi'; var isCherry = self.plantType === 'cherry' || self.plantType === 'colorful_cherry'; var isMango = self.plantType === 'mango' || self.plantType === 'colorful_mango'; var isHeavenMango = self.plantType === 'heavenMango' || self.plantType === 'colorful_heavenMango'; var regrowReady = false; if (isBanana && LK.ticks - self.regrowTime > 1140 / speedMultiplier) { // 19 seconds at 60fps for banana regrow (halved with sprinkler) regrowReady = true; } else if ((isDragonFruit || isCoconut) && LK.ticks - self.regrowTime > 1320 / speedMultiplier) { // 22 seconds at 60fps for dragon fruit and coconut regrow (halved with sprinkler) regrowReady = true; } else if (isApple && LK.ticks - self.regrowTime > 1200 / speedMultiplier) { // 20 seconds at 60fps for apple regrow (halved with sprinkler) regrowReady = true; } else if (isNectarine && LK.ticks - self.regrowTime > 1500 / speedMultiplier) { // 25 seconds at 60fps for nectarine regrow (halved with sprinkler) regrowReady = true; } else if (isKiwi && LK.ticks - self.regrowTime > 2040 / speedMultiplier) { // 34 seconds at 60fps for kiwi regrow (halved with sprinkler) regrowReady = true; } else if (isCherry && LK.ticks - self.regrowTime > 1800 / speedMultiplier) { // 30 seconds at 60fps for cherry regrow (halved with sprinkler) regrowReady = true; } else if (isMango && LK.ticks - self.regrowTime > 2100 / speedMultiplier) { // 35 seconds at 60fps for mango regrow (halved with sprinkler) regrowReady = true; } else if (isHeavenMango && LK.ticks - self.regrowTime > 2400 / speedMultiplier) { // 40 seconds at 60fps for heaven mango regrow (halved with sprinkler) regrowReady = true; } if (regrowReady) { self.grown = true; self.regrowTime = 0; if (plantGraphics) { var regrowScale = 1.0; tween(plantGraphics, { alpha: 1.0, scaleX: regrowScale, scaleY: regrowScale }, { duration: 1000, easing: tween.easeOut }); } } } else if (self.regrowTime === 0) { // Different growth times for different plants var isNectarine = self.plantType === 'nectarine' || self.plantType === 'colorful_nectarine'; var isPineapple = self.plantType === 'pineapple' || self.plantType === 'colorful_pineapple'; var isCherry = self.plantType === 'cherry' || self.plantType === 'colorful_cherry'; var isKiwi = self.plantType === 'kiwi' || self.plantType === 'colorful_kiwi'; var growthTime; if (isNectarine) { growthTime = 480; // 8 seconds for nectarine } else if (isPineapple) { growthTime = 600; // 10 seconds for pineapple } else if (isCherry) { growthTime = 840; // 14 seconds for cherry } else if (isKiwi) { growthTime = 1020; // 17 seconds for kiwi } else { growthTime = 300; // 5 seconds for other plants } if (LK.ticks - self.plantTime > growthTime / speedMultiplier) { self.grown = true; if (plantGraphics) { plantGraphics.alpha = 1.0; } } } } }; self.down = function () { if (self.grown) { var harvested = self.harvest(); if (harvested) { if (!harvested.fromSeedPack) { var harvestType = harvested.type; if (harvested.chocolate) { // Store chocolate fruits separately for 4x price var baseType = harvestType.replace('colorful_', ''); // Special case for carrots - use Chococarrot asset name if (baseType === 'carrot') { inventory['Chococarrot'] = (inventory['Chococarrot'] || 0) + 1; } else { inventory['choco_' + baseType] = (inventory['choco_' + baseType] || 0) + 1; } } else if (harvested.colorful) { // Store colorful fruits separately for 3x price var baseType = harvestType.replace('colorful_', ''); inventory['colorful_' + baseType] = (inventory['colorful_' + baseType] || 0) + 1; } else { inventory[harvestType] = (inventory[harvestType] || 0) + 1; } updateInventoryDisplay(); } } } else if (!self.planted && selectedSprinkler) { // Place sprinkler var sprinklerCost = 35; if (money >= sprinklerCost) { var sprinkler = new Sprinkler(self.x, self.y); sprinklers.push(sprinkler); game.addChild(sprinkler); money -= sprinklerCost; updateMoneyDisplay(); selectedSprinkler = false; gearShop.visible = false; } } else if (!self.planted && selectedSeed && selectedSeed !== 'cactus' && selectedSeed !== 'atlas_cactus' && money >= seedPrices[selectedSeed]) { // Plant non-cactus seeds in dirt spots only if (self.plantSeed(selectedSeed)) { money -= seedPrices[selectedSeed]; updateMoneyDisplay(); selectedSeed = null; seedShop.visible = false; } } else if (!self.planted && (selectedSeed === 'cactus' || selectedSeed === 'atlas_cactus')) { // Block cactus and atlas cactus planting in dirt spots - these can only be planted in sand selectedSeed = null; seedShop.visible = false; } }; return self; }); var SeedShop = Container.expand(function () { var self = Container.call(this); var background = self.attachAsset('seedShopBg', { anchorX: 0.5, anchorY: 0.5 }); var titleText = new Text2('SEED SHOP', { size: 80, fill: 0x000000 }); titleText.anchor.set(0.5, 0.5); titleText.y = -600; self.addChild(titleText); // Blueberry item var blueberryButton = new Container(); blueberryButton.x = 0; blueberryButton.y = -400; var blueberryIcon = blueberryButton.attachAsset('blueberry_icon', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.2, scaleY: 1.2 }); blueberryIcon.x = -350; var blueberryNameText = new Text2('Blueberry', { size: 50, fill: 0x000000 }); blueberryNameText.anchor.set(0, 0.5); blueberryNameText.x = -250; blueberryButton.addChild(blueberryNameText); var blueberryPriceText = new Text2('$10', { size: 50, fill: 0xFFFF00 }); blueberryPriceText.anchor.set(1, 0.5); blueberryPriceText.x = 300; blueberryButton.addChild(blueberryPriceText); var blueberryDescText = new Text2('Sells: $15 (25% chance for $10)', { size: 30, fill: 0x666666 }); blueberryDescText.anchor.set(0.5, 0); blueberryDescText.y = 30; blueberryButton.addChild(blueberryDescText); blueberryButton.down = function () { if (money >= 10) { selectedSeed = 'blueberry'; self.visible = false; LK.getSound('Buy').play(); } }; self.addChild(blueberryButton); // Nectarine item var nectarineButton = new Container(); nectarineButton.x = 0; nectarineButton.y = -280; var nectarineIcon = nectarineButton.attachAsset('nectarine_icon', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.2, scaleY: 1.2 }); nectarineIcon.x = -350; var nectarineNameText = new Text2('Nectarine', { size: 50, fill: 0x000000 }); nectarineNameText.anchor.set(0, 0.5); nectarineNameText.x = -250; nectarineButton.addChild(nectarineNameText); var nectarinePriceText = new Text2('$55', { size: 50, fill: 0xFFFF00 }); nectarinePriceText.anchor.set(1, 0.5); nectarinePriceText.x = 300; nectarineButton.addChild(nectarinePriceText); var nectarineDescText = new Text2('Sells: $60 (25% chance for $30)', { size: 30, fill: 0x666666 }); nectarineDescText.anchor.set(0.5, 0); nectarineDescText.y = 30; nectarineButton.addChild(nectarineDescText); nectarineButton.down = function () { if (money >= 55) { selectedSeed = 'nectarine'; self.visible = false; LK.getSound('Buy').play(); } }; self.addChild(nectarineButton); // Pineapple item var pineappleButton = new Container(); pineappleButton.x = 0; pineappleButton.y = -160; var pineappleIcon = pineappleButton.attachAsset('pineapple_icon', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.2, scaleY: 1.2 }); pineappleIcon.x = -350; var pineappleNameText = new Text2('Pineapple', { size: 50, fill: 0x000000 }); pineappleNameText.anchor.set(0, 0.5); pineappleNameText.x = -250; pineappleButton.addChild(pineappleNameText); var pineapplePriceText = new Text2('$110', { size: 50, fill: 0xFFFF00 }); pineapplePriceText.anchor.set(1, 0.5); pineapplePriceText.x = 300; pineappleButton.addChild(pineapplePriceText); var pineappleDescText = new Text2('Sells: $115 (25% chance for $65)', { size: 30, fill: 0x666666 }); pineappleDescText.anchor.set(0.5, 0); pineappleDescText.y = 30; pineappleButton.addChild(pineappleDescText); pineappleButton.down = function () { if (money >= 110) { selectedSeed = 'pineapple'; self.visible = false; LK.getSound('Buy').play(); } }; self.addChild(pineappleButton); // Cherry item var cherryButton = new Container(); cherryButton.x = 0; cherryButton.y = -40; var cherryIcon = cherryButton.attachAsset('cherry_icon', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.2, scaleY: 1.2 }); cherryIcon.x = -350; var cherryNameText = new Text2('Cherry', { size: 50, fill: 0x000000 }); cherryNameText.anchor.set(0, 0.5); cherryNameText.x = -250; cherryButton.addChild(cherryNameText); var cherryPriceText = new Text2('$165', { size: 50, fill: 0xFFFF00 }); cherryPriceText.anchor.set(1, 0.5); cherryPriceText.x = 300; cherryButton.addChild(cherryPriceText); var cherryDescText = new Text2('Sells: $170 (25% chance for $115)', { size: 30, fill: 0x666666 }); cherryDescText.anchor.set(0.5, 0); cherryDescText.y = 30; cherryButton.addChild(cherryDescText); cherryButton.down = function () { if (money >= 165) { selectedSeed = 'cherry'; self.visible = false; LK.getSound('Buy').play(); } }; self.addChild(cherryButton); // Kiwi item var kiwiButton = new Container(); kiwiButton.x = 0; kiwiButton.y = 80; var kiwiIcon = kiwiButton.attachAsset('kiwi_icon', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.2, scaleY: 1.2 }); kiwiIcon.x = -350; var kiwiNameText = new Text2('Kiwi', { size: 50, fill: 0x000000 }); kiwiNameText.anchor.set(0, 0.5); kiwiNameText.x = -250; kiwiButton.addChild(kiwiNameText); var kiwiPriceText = new Text2('$225', { size: 50, fill: 0xFFFF00 }); kiwiPriceText.anchor.set(1, 0.5); kiwiPriceText.x = 300; kiwiButton.addChild(kiwiPriceText); var kiwiDescText = new Text2('Sells: $230 (25% chance for $165)', { size: 30, fill: 0x666666 }); kiwiDescText.anchor.set(0.5, 0); kiwiDescText.y = 30; kiwiButton.addChild(kiwiDescText); kiwiButton.down = function () { if (money >= 225) { selectedSeed = 'kiwi'; self.visible = false; LK.getSound('Buy').play(); } }; self.addChild(kiwiButton); // Mango item var mangoButton = new Container(); mangoButton.x = 0; mangoButton.y = 200; var mangoIcon = mangoButton.attachAsset('mango_icon', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.2, scaleY: 1.2 }); mangoIcon.x = -350; var mangoNameText = new Text2('Mango', { size: 50, fill: 0x000000 }); mangoNameText.anchor.set(0, 0.5); mangoNameText.x = -250; mangoButton.addChild(mangoNameText); var mangoPriceText = new Text2('$335', { size: 50, fill: 0xFFFF00 }); mangoPriceText.anchor.set(1, 0.5); mangoPriceText.x = 300; mangoButton.addChild(mangoPriceText); var mangoDescText = new Text2('Sells: $350 (25% chance for $330)', { size: 30, fill: 0x666666 }); mangoDescText.anchor.set(0.5, 0); mangoDescText.y = 30; mangoButton.addChild(mangoDescText); mangoButton.down = function () { if (money >= 335) { selectedSeed = 'mango'; self.visible = false; LK.getSound('Buy').play(); } }; self.addChild(mangoButton); // Heaven Mango item var heavenMangoButton = new Container(); heavenMangoButton.x = 0; heavenMangoButton.y = 320; var heavenMangoIcon = heavenMangoButton.attachAsset('heavenMango_icon', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.2, scaleY: 1.2 }); heavenMangoIcon.x = -350; var heavenMangoNameText = new Text2('Heaven Mango', { size: 50, fill: 0x000000 }); heavenMangoNameText.anchor.set(0, 0.5); heavenMangoNameText.x = -250; heavenMangoButton.addChild(heavenMangoNameText); var heavenMangoPriceText = new Text2('$650', { size: 50, fill: 0xFFFF00 }); heavenMangoPriceText.anchor.set(1, 0.5); heavenMangoPriceText.x = 300; heavenMangoButton.addChild(heavenMangoPriceText); var heavenMangoDescText = new Text2('Sells: $700 (10% chance for $670)', { size: 30, fill: 0x666666 }); heavenMangoDescText.anchor.set(0.5, 0); heavenMangoDescText.y = 30; heavenMangoButton.addChild(heavenMangoDescText); heavenMangoButton.down = function () { if (money >= 650) { selectedSeed = 'heavenMango'; self.visible = false; LK.getSound('Buy').play(); } }; self.addChild(heavenMangoButton); // Mystery item var mysteryButton = new Container(); mysteryButton.x = 0; mysteryButton.y = 440; var mysteryIcon = mysteryButton.attachAsset('mystery_icon', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.2, scaleY: 1.2 }); mysteryIcon.x = -350; var mysteryNameText = new Text2('??? Mystery', { size: 50, fill: 0x000000 }); mysteryNameText.anchor.set(0, 0.5); mysteryNameText.x = -250; mysteryButton.addChild(mysteryNameText); var mysteryPriceText = new Text2('$1000', { size: 50, fill: 0xFFFF00 }); mysteryPriceText.anchor.set(1, 0.5); mysteryPriceText.x = 300; mysteryButton.addChild(mysteryPriceText); var mysteryDescText = new Text2('Sells: $1050 (10% chance for $700)', { size: 30, fill: 0x666666 }); mysteryDescText.anchor.set(0.5, 0); mysteryDescText.y = 30; mysteryButton.addChild(mysteryDescText); mysteryButton.down = function () { if (money >= 1000) { selectedSeed = 'mystery'; self.visible = false; LK.getSound('Buy').play(); } }; self.addChild(mysteryButton); var closeButton = new Button('CLOSE', function () { self.visible = false; }); closeButton.y = 600; closeButton.scaleX = 1.5; closeButton.scaleY = 1.5; self.addChild(closeButton); return self; }); var Sprinkler = Container.expand(function (x, y) { var self = Container.call(this); self.x = x; self.y = y; self.type = 'regular'; var sprinklerGraphics = self.attachAsset('sprinkler', { anchorX: 0.5, anchorY: 0.5 }); // Add pulsing animation to show it's active function animateSprinkler() { tween(sprinklerGraphics, { scaleX: 1.2, scaleY: 1.2, alpha: 0.7 }, { duration: 1000, easing: tween.easeInOut, onFinish: function onFinish() { tween(sprinklerGraphics, { scaleX: 1.0, scaleY: 1.0, alpha: 1.0 }, { duration: 1000, easing: tween.easeInOut, onFinish: animateSprinkler }); } }); } animateSprinkler(); return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x228B22 }); /**** * Game Code ****/ // Add grass background var grassBackground = game.attachAsset('grass_bg', { anchorX: 0, anchorY: 0, x: 0, y: 0 }); var money = 0; var inventory = {}; var selectedSeed = null; var selectedSprinkler = false; var selectedFish = false; var selectedFish2 = false; var sprinklers = []; var seedPrices = { cactus: 100, atlas_cactus: 250, blueberry: 10, nectarine: 55, pineapple: 110, cherry: 165, kiwi: 225, mango: 335, heavenMango: 650, mystery: 1000 }; var sellPrices = { fish: 110, fish2: 75, choco_fish: 440, choco_fish2: 720, cactus: 150, atlas_cactus: 265, colorful_cactus: 450, colorful_atlas_cactus: 795, choco_cactus: 600, choco_atlas_cactus: 1060, blueberry: 15, nectarine: 60, pineapple: 115, cherry: 170, kiwi: 230, mango: 350, heavenMango: 700, mystery: 1050, colorful_blueberry: 45, colorful_nectarine: 180, colorful_pineapple: 345, colorful_cherry: 510, colorful_kiwi: 690, colorful_mango: 1050, colorful_heavenMango: 2100, colorful_mystery: 3150 }; // Create plant spots in a grid - start with 64 lands arranged in a grid (32 top + 32 bottom) var plantSpots = []; var spacing = 220; var landsPerRow = 8; var totalRows = 8; // 4 rows for top + 4 rows for bottom var totalWidth = (landsPerRow - 1) * spacing; var startX = (2048 - totalWidth) / 2; // Center horizontally on screen var startY = 600; // Move starting Y up to accommodate bottom section // Create 32 initial plant spots in 8 columns, 4 rows (top section) for (var i = 0; i < 32; i++) { var col = i % 8; var row = Math.floor(i / 8); var spot = new PlantSpot(startX + col * spacing, startY + row * spacing); plantSpots.push(spot); game.addChild(spot); } // Create another 32 plant spots at the bottom (8 columns, 4 rows) var bottomStartY = startY + 4 * spacing + 100; // Add gap between top and bottom sections for (var i = 0; i < 32; i++) { var col = i % 8; var row = Math.floor(i / 8); var spot; // Make the bottom 16 spots (last 2 rows) aquatic if (i >= 16) { spot = new AquaticPlantSpot(startX + col * spacing, bottomStartY + row * spacing); } else { spot = new PlantSpot(startX + col * spacing, bottomStartY + row * spacing); } plantSpots.push(spot); game.addChild(spot); } // UI Elements var moneyText = new Text2('Money: $0', { size: 50, fill: 0x000000 }); moneyText.anchor.set(0, 0); moneyText.x = 150; moneyText.y = 50; LK.gui.topLeft.addChild(moneyText); var inventoryText = new Text2('Inventory: Empty', { size: 50, fill: 0x000000 }); inventoryText.anchor.set(0, 1); inventoryText.x = 100; inventoryText.y = -200; LK.gui.bottomLeft.addChild(inventoryText); // Make inventory alive with pulsing animation function animateInventory() { tween(inventoryText, { scaleX: 1.1, scaleY: 1.1 }, { duration: 1000, easing: tween.easeInOut, onFinish: function onFinish() { tween(inventoryText, { scaleX: 1.0, scaleY: 1.0 }, { duration: 1000, easing: tween.easeInOut, onFinish: animateInventory }); } }); } animateInventory(); var sellButton = new Button('SELL ALL', function () { var totalSale = 0; // Check if we get the 10% price boost (30% chance) var priceBoost = Math.random() < 0.3 ? 1.1 : 1.0; for (var itemType in inventory) { if (inventory[itemType] > 0) { var basePrice; basePrice = sellPrices[itemType]; // 35% chance for fish2 to sell for 85 instead of 75 if (itemType === 'fish2' && Math.random() < 0.35) { basePrice = 85; } // 0.3% chance for cactus to sell for 450 instead of 150 if (itemType === 'cactus' && Math.random() < 0.003) { basePrice = 450; } // 0.5% chance for atlas_cactus to sell for 500 instead of 265 if (itemType === 'atlas_cactus' && Math.random() < 0.005) { basePrice = 500; } // 25% chance for fruits to sell at reduced price if (itemType === 'blueberry' && Math.random() < 0.25) { basePrice = 10; } if (itemType === 'nectarine' && Math.random() < 0.25) { basePrice = 30; } if (itemType === 'pineapple' && Math.random() < 0.25) { basePrice = 65; } if (itemType === 'cherry' && Math.random() < 0.25) { basePrice = 115; } if (itemType === 'kiwi' && Math.random() < 0.25) { basePrice = 165; } if (itemType === 'mango' && Math.random() < 0.25) { basePrice = 330; } // 10% chance for special fruits to sell at reduced price if (itemType === 'heavenMango' && Math.random() < 0.1) { basePrice = 670; } if (itemType === 'mystery' && Math.random() < 0.1) { basePrice = 700; } basePrice *= priceBoost; totalSale += inventory[itemType] * basePrice; inventory[itemType] = 0; } } if (totalSale > 0) { money += totalSale; updateMoneyDisplay(); updateInventoryDisplay(); LK.getSound('sell').play(); } }); sellButton.x = 600; sellButton.y = 100; sellButton.scaleX = 1.3; sellButton.scaleY = 1.3; LK.gui.topLeft.addChild(sellButton); var seedButton = new Button('SEEDS', function () { seedShop.visible = true; }); seedButton.x = 900; seedButton.y = 100; seedButton.scaleX = 1.3; seedButton.scaleY = 1.3; LK.gui.topLeft.addChild(seedButton); var freeCoinsButton = new Button('FREE COINS', function () { money += 500; updateMoneyDisplay(); }); freeCoinsButton.x = 1200; freeCoinsButton.y = 100; freeCoinsButton.scaleX = 1.3; freeCoinsButton.scaleY = 1.3; LK.gui.topLeft.addChild(freeCoinsButton); var gearButton = new Button('GEAR SHOP', function () { gearShop.visible = true; }); gearButton.x = 600; gearButton.y = 250; gearButton.scaleX = 1.3; gearButton.scaleY = 1.3; LK.gui.topLeft.addChild(gearButton); var fishButton = new Button('DESERT SHOP', function () { fishShop.visible = true; }); fishButton.x = 900; fishButton.y = 250; fishButton.scaleX = 1.3; fishButton.scaleY = 1.3; LK.gui.topLeft.addChild(fishButton); var seedShop = new SeedShop(); seedShop.x = 1024; seedShop.y = 1366; seedShop.visible = false; game.addChild(seedShop); var gearShop = new GearShop(); gearShop.x = 1024; gearShop.y = 1366; gearShop.visible = false; game.addChild(gearShop); var fishShop = new DesertShop(); fishShop.x = 1024; fishShop.y = 1366; fishShop.visible = false; game.addChild(fishShop); // Button sliding variables var topButtons = [sellButton, seedButton, freeCoinsButton, gearButton, fishButton]; var buttonBasePositions = [600, 900, 1200, 600, 900]; var slideOffset = 0; var maxSlideOffset = 400; // Maximum pixels to slide // Sliding functions function slideButtonsLeft() { slideOffset = Math.min(slideOffset + 100, maxSlideOffset); updateButtonPositions(); } function slideButtonsRight() { slideOffset = Math.max(slideOffset - 100, -maxSlideOffset); updateButtonPositions(); } function updateButtonPositions() { for (var i = 0; i < topButtons.length; i++) { tween(topButtons[i], { x: buttonBasePositions[i] + slideOffset }, { duration: 300, easing: tween.easeOut }); } } function updateMoneyDisplay() { moneyText.setText('Money: $' + money); } function updateInventoryDisplay() { var inventoryStr = 'Inventory: '; var hasItems = false; for (var itemType in inventory) { if (inventory[itemType] > 0) { if (hasItems) inventoryStr += ', '; inventoryStr += itemType + ' x' + inventory[itemType]; hasItems = true; } } if (!hasItems) { inventoryStr += 'Empty'; } inventoryText.setText(inventoryStr); } function expandLands(targetCount) { var currentCount = plantSpots.length; if (targetCount === 12 && currentCount === 6) { // Expand from 6 to 12 lands - add 6 more in 3 columns, 4 rows total for (var i = currentCount; i < targetCount; i++) { var col = i % 3; var row = Math.floor(i / 3); var newSpot = new PlantSpot(startX + col * spacing, startY + row * spacing); plantSpots.push(newSpot); game.addChild(newSpot); } } else if (targetCount === 18 && currentCount === 12) { // Expand from 12 to 18 lands - rearrange to left column and add right column var leftStartY = 800; // First, move existing 12 lands to left side (3 columns, up to 4 rows) for (var i = 0; i < currentCount; i++) { var spot = plantSpots[i]; var newX = startX + i % 3 * spacing; var newY = leftStartY + Math.floor(i / 3) * spacing; tween(spot, { x: newX, y: newY }, { duration: 1000, easing: tween.easeInOut }); } // Add 6 new lands to the right side var rightStartX = startX + 4 * spacing; for (var i = currentCount; i < targetCount; i++) { var rightIndex = i - currentCount; var col = rightIndex % 3; var row = Math.floor(rightIndex / 3); var newSpot = new PlantSpot(rightStartX + col * spacing, leftStartY + row * spacing); plantSpots.push(newSpot); game.addChild(newSpot); } } } function expandLandsForDragonFruit() { var currentCount = plantSpots.length; // Calculate center positioning for all lands var totalLands = currentCount + 12; // Current lands + 12 new lands var landsPerRow = 6; // 6 lands per row for better centering var totalRows = Math.ceil(totalLands / landsPerRow); var totalWidth = (landsPerRow - 1) * spacing; var totalHeight = (totalRows - 1) * spacing; var centerStartX = (2048 - totalWidth) / 2; // Center horizontally on screen var centerStartY = 800; // Move all existing lands to center positions for (var i = 0; i < currentCount; i++) { var spot = plantSpots[i]; var col = i % landsPerRow; var row = Math.floor(i / landsPerRow); var newX = centerStartX + col * spacing; var newY = centerStartY + row * spacing; tween(spot, { x: newX, y: newY }, { duration: 1000, easing: tween.easeInOut }); } // Add 12 new lands continuing from center positions for (var i = 0; i < 12; i++) { var landIndex = currentCount + i; var col = landIndex % landsPerRow; var row = Math.floor(landIndex / landsPerRow); var newX = centerStartX + col * spacing; var newY = centerStartY + row * spacing; var newSpot = new PlantSpot(newX, newY); plantSpots.push(newSpot); game.addChild(newSpot); } } // Play background music LK.playMusic('Music'); // Touch controls for sliding buttons var touchStartX = 0; var isDraggingButtons = false; game.down = function (x, y, obj) { // Check if touch is in the top button area if (y < 200) { touchStartX = x; isDraggingButtons = true; } }; game.up = function (x, y, obj) { if (isDraggingButtons) { var deltaX = x - touchStartX; if (Math.abs(deltaX) > 50) { // Minimum swipe distance if (deltaX > 0) { slideButtonsLeft(); } else { slideButtonsRight(); } } isDraggingButtons = false; } }; game.update = function () { // Plant spots update automatically through their update methods };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var AquaticPlantSpot = Container.expand(function (x, y) {
var self = Container.call(this);
self.x = x;
self.y = y;
self.planted = false;
self.plantType = null;
self.plantTime = 0;
self.grown = false;
self.regrowTime = 0;
self.isAquatic = true;
var sandGraphics = self.attachAsset('sand', {
anchorX: 0.5,
anchorY: 0.5,
tint: 0xF4A460
});
// Move sand graphics to the back layer
self.setChildIndex(sandGraphics, 0);
var plantGraphics = null;
self.plantSeed = function (seedType) {
if (self.planted) return false;
self.planted = true;
// Handle cactus planting
if (seedType === 'cactus' || seedType === 'atlas_cactus') {
self.plantType = seedType;
self.plantTime = LK.ticks;
self.grown = false;
self.isColorful = false;
// 5% chance for colorful cactus (3x price)
if (Math.random() < 0.05) {
self.isColorful = true;
self.plantType = 'colorful_' + seedType;
}
var finalScale = 1.0;
var assetName = seedType === 'atlas_cactus' ? self.isColorful ? 'colorful_atlas_cactus' : 'atlas_cactus_icon' : self.plantType;
} else {
// Handle fish planting
self.plantType = seedType === 'fish2' ? 'fish2' : 'fish'; // Support both fish types
self.plantTime = LK.ticks;
self.grown = false;
self.isColorful = false;
// 5% chance for colorful fish (3x price)
if (Math.random() < 0.05) {
self.isColorful = true;
}
var finalScale = 1.0;
var assetName;
if (self.plantType === 'fish2') {
assetName = self.isColorful ? 'colorful_Fish2' : 'Fish2';
} else {
assetName = self.isColorful ? 'colorful_fish' : 'fish';
}
}
plantGraphics = self.attachAsset(assetName, {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.5,
scaleX: 0.3,
scaleY: 0.3
});
// Add colorful tint for special fish
if (self.isColorful) {
plantGraphics.tint = 0xFFD700; // Golden fish
}
// Ensure fish graphics appear above water
self.setChildIndex(plantGraphics, self.children.length - 1);
// Animate fish growth over 3 seconds (faster than plants)
tween(plantGraphics, {
scaleX: finalScale,
scaleY: finalScale
}, {
duration: 3000,
easing: tween.easeOut
});
// Add swimming animation for colorful fish
if (self.isColorful) {
var swimmingAnimation = function swimmingAnimation() {
if (plantGraphics) {
tween(plantGraphics, {
x: 20
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(plantGraphics, {
x: -20
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(plantGraphics, {
x: 0
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: swimmingAnimation
});
}
});
}
});
}
};
// Start swimming animation after growth completes
LK.setTimeout(swimmingAnimation, 3000);
}
LK.getSound('plant').play();
return true;
};
self.harvest = function () {
if (!self.grown) return null;
var harvestedType = self.plantType; // Use the actual planted type (fish, fish2, or cactus)
var isColorfulHarvest = self.isColorful;
// All plants (including cactus) now regrow
if (plantGraphics) {
tween(plantGraphics, {
alpha: 0.3,
scaleX: 0.5,
scaleY: 0.5
}, {
duration: 500,
easing: tween.easeIn
});
}
self.grown = false;
self.regrowTime = LK.ticks;
LK.getSound('harvest').play();
return {
type: harvestedType,
colorful: isColorfulHarvest,
chocolate: self.isChocolate || false,
fromSeedPack: self.isFromSeedPack || false
};
};
self.update = function () {
if (self.planted && !self.grown) {
// Check if this spot is affected by a sprinkler
var speedMultiplier = 1;
for (var i = 0; i < sprinklers.length; i++) {
var sprinkler = sprinklers[i];
var distanceX = Math.abs(self.x - sprinkler.x);
var distanceY = Math.abs(self.y - sprinkler.y);
// Regular sprinkler: 5x speed in 3x3 area
if (distanceX <= 660 && distanceY <= 660) {
speedMultiplier = 5;
break;
}
}
// Check if it's time to regrow after harvest
if (self.regrowTime > 0) {
var regrowTime;
var isCactus = self.plantType === 'cactus' || self.plantType === 'colorful_cactus';
var isAtlasCactus = self.plantType === 'atlas_cactus' || self.plantType === 'colorful_atlas_cactus';
if (isCactus) {
regrowTime = 1200; // 20 seconds for cactus regrow
} else if (isAtlasCactus) {
regrowTime = 1560; // 26 seconds for atlas cactus regrow (2x growth time)
} else if (self.plantType === 'fish2') {
regrowTime = 2700; // 45 seconds for fish2
} else {
regrowTime = 3300; // 55 seconds for fish
}
if (LK.ticks - self.regrowTime > regrowTime / speedMultiplier) {
self.grown = true;
self.regrowTime = 0;
if (plantGraphics) {
var regrowScale = 1.0;
tween(plantGraphics, {
alpha: 1.0,
scaleX: regrowScale,
scaleY: regrowScale
}, {
duration: 1000,
easing: tween.easeOut
});
}
}
} else if (self.regrowTime === 0) {
var isCactus = self.plantType === 'cactus' || self.plantType === 'colorful_cactus';
var isAtlasCactus = self.plantType === 'atlas_cactus' || self.plantType === 'colorful_atlas_cactus';
var growthTime;
if (isCactus) {
growthTime = 300; // 5 seconds for cactus (same as other plants)
} else if (isAtlasCactus) {
growthTime = 600; // 10 seconds for atlas cactus
} else if (self.plantType === 'fish2') {
growthTime = 2700; // 45 seconds for fish2
} else {
growthTime = 3300; // 55 seconds for fish
}
if (LK.ticks - self.plantTime > growthTime / speedMultiplier) {
self.grown = true;
if (plantGraphics) {
plantGraphics.alpha = 1.0;
}
}
}
}
};
self.down = function () {
if (self.grown) {
var harvested = self.harvest();
if (harvested) {
if (!harvested.fromSeedPack) {
var harvestType = harvested.type;
if (harvested.chocolate) {
var baseType = harvestType === 'fish2' ? 'fish2' : 'fish';
inventory['choco_' + baseType] = (inventory['choco_' + baseType] || 0) + 1;
} else if (harvested.colorful) {
var baseType = harvestType === 'fish2' ? 'fish2' : 'fish';
inventory['colorful_' + baseType] = (inventory['colorful_' + baseType] || 0) + 1;
} else {
inventory[harvestType] = (inventory[harvestType] || 0) + 1;
}
updateInventoryDisplay();
}
}
} else if (!self.planted && selectedSprinkler) {
// Place sprinkler
var sprinklerCost = 35;
if (money >= sprinklerCost) {
var sprinkler = new Sprinkler(self.x, self.y);
sprinklers.push(sprinkler);
game.addChild(sprinkler);
money -= sprinklerCost;
updateMoneyDisplay();
selectedSprinkler = false;
gearShop.visible = false;
}
} else if (!self.planted && selectedFish && money >= 100) {
// Plant fish in aquatic spots
if (self.plantSeed('fish')) {
money -= 100;
updateMoneyDisplay();
selectedFish = false;
fishShop.visible = false;
}
} else if (!self.planted && selectedFish2 && money >= 150) {
// Plant fish2 in aquatic spots
if (self.plantSeed('fish2')) {
money -= 150;
updateMoneyDisplay();
selectedFish2 = false;
fishShop.visible = false;
}
} else if (!self.planted && (selectedSeed === 'cactus' || selectedSeed === 'atlas_cactus') && money >= seedPrices[selectedSeed]) {
// Plant cactus in sand spots only
if (self.plantSeed(selectedSeed)) {
money -= seedPrices[selectedSeed];
updateMoneyDisplay();
selectedSeed = null;
seedShop.visible = false;
}
} else if (!self.planted && selectedSeed && selectedSeed !== 'cactus' && selectedSeed !== 'atlas_cactus' && money >= seedPrices[selectedSeed]) {
// Don't plant other fruit seeds in sand - this is for cactus only
// No planting action will occur, but we can provide feedback
selectedSeed = null;
seedShop.visible = false;
}
};
return self;
});
var Button = Container.expand(function (text, onClick) {
var self = Container.call(this);
var buttonBg = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
var buttonText = new Text2(text, {
size: 30,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.down = function () {
if (onClick) onClick();
};
return self;
});
var DesertShop = Container.expand(function () {
var self = Container.call(this);
var background = self.attachAsset('seedShopBg', {
anchorX: 0.5,
anchorY: 0.5
});
var titleText = new Text2('DESERT SHOP', {
size: 80,
fill: 0x000000
});
titleText.anchor.set(0.5, 0.5);
titleText.y = -600;
self.addChild(titleText);
// Cactus item
var cactusButton = new Container();
cactusButton.x = 0;
cactusButton.y = -300;
var cactusIcon = cactusButton.attachAsset('cactus', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1.5
});
cactusIcon.x = -300;
var cactusNameText = new Text2('Cactus', {
size: 70,
fill: 0x000000
});
cactusNameText.anchor.set(0, 0.5);
cactusNameText.x = -200;
cactusButton.addChild(cactusNameText);
var cactusPriceText = new Text2('$100', {
size: 70,
fill: 0xFFFF00
});
cactusPriceText.anchor.set(1, 0.5);
cactusPriceText.x = 300;
cactusButton.addChild(cactusPriceText);
var cactusDescText = new Text2('Sells for $150, 0.3% chance for $450', {
size: 40,
fill: 0x666666
});
cactusDescText.anchor.set(0.5, 0);
cactusDescText.y = 50;
cactusButton.addChild(cactusDescText);
cactusButton.down = function () {
if (money >= 100) {
selectedSeed = 'cactus';
self.visible = false;
LK.getSound('Buy').play();
}
};
self.addChild(cactusButton);
// Atlas Cactus item
var atlasCactusButton = new Container();
atlasCactusButton.x = 0;
atlasCactusButton.y = -150;
var atlasCactusIcon = atlasCactusButton.attachAsset('atlas_cactus_icon', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1.5
});
atlasCactusIcon.x = -300;
var atlasCactusNameText = new Text2('Atlas Cactus', {
size: 70,
fill: 0x000000
});
atlasCactusNameText.anchor.set(0, 0.5);
atlasCactusNameText.x = -200;
atlasCactusButton.addChild(atlasCactusNameText);
var atlasCactusPriceText = new Text2('$250', {
size: 70,
fill: 0xFFFF00
});
atlasCactusPriceText.anchor.set(1, 0.5);
atlasCactusPriceText.x = 300;
atlasCactusButton.addChild(atlasCactusPriceText);
var atlasCactusDescText = new Text2('Sells for $265, 0.5% chance for $500', {
size: 40,
fill: 0x666666
});
atlasCactusDescText.anchor.set(0.5, 0);
atlasCactusDescText.y = 50;
atlasCactusButton.addChild(atlasCactusDescText);
atlasCactusButton.down = function () {
if (money >= 250) {
selectedSeed = 'atlas_cactus';
self.visible = false;
LK.getSound('Buy').play();
}
};
self.addChild(atlasCactusButton);
var closeButton = new Button('CLOSE', function () {
self.visible = false;
});
closeButton.y = 200;
self.addChild(closeButton);
return self;
});
var GearShop = Container.expand(function () {
var self = Container.call(this);
var background = self.attachAsset('seedShopBg', {
anchorX: 0.5,
anchorY: 0.5
});
var titleText = new Text2('GEAR SHOP', {
size: 80,
fill: 0x000000
});
titleText.anchor.set(0.5, 0.5);
titleText.y = -600;
self.addChild(titleText);
// Sprinkler item
var sprinklerButton = new Container();
sprinklerButton.x = 0;
sprinklerButton.y = -200;
var sprinklerIcon = LK.getAsset('sprinkler', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1.5
});
sprinklerIcon.x = -300;
sprinklerButton.addChild(sprinklerIcon);
var nameText = new Text2('Sprinkler', {
size: 70,
fill: 0x000000
});
nameText.anchor.set(0, 0.5);
nameText.x = -200;
sprinklerButton.addChild(nameText);
var priceText = new Text2('$35', {
size: 70,
fill: 0xFFFF00
});
priceText.anchor.set(1, 0.5);
priceText.x = 300;
sprinklerButton.addChild(priceText);
var descText = new Text2('5x growth speed in 3x3 area', {
size: 40,
fill: 0x666666
});
descText.anchor.set(0.5, 0);
descText.y = 50;
sprinklerButton.addChild(descText);
sprinklerButton.down = function () {
if (money >= 35) {
selectedSprinkler = 'regular';
self.visible = false;
LK.getSound('Buy').play();
}
};
self.addChild(sprinklerButton);
var closeButton = new Button('CLOSE', function () {
self.visible = false;
});
closeButton.y = 200;
self.addChild(closeButton);
return self;
});
var PlantSpot = Container.expand(function (x, y) {
var self = Container.call(this);
self.x = x;
self.y = y;
self.planted = false;
self.plantType = null;
self.plantTime = 0;
self.grown = false;
self.regrowTime = 0;
var dirtGraphics = self.attachAsset('dirt', {
anchorX: 0.5,
anchorY: 0.5
});
// Move dirt graphics to the back layer
self.setChildIndex(dirtGraphics, 0);
var plantGraphics = null;
self.plantSeed = function (seedType) {
if (self.planted) return false;
self.planted = true;
self.plantType = seedType;
self.plantTime = LK.ticks;
self.grown = false;
self.isColorful = false;
// 5% chance for colorful fruit (3x price)
if (Math.random() < 0.05) {
self.isColorful = true;
self.plantType = 'colorful_' + seedType;
}
var finalScale = 1.0;
plantGraphics = self.attachAsset(self.plantType, {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.5,
scaleX: 0.3,
scaleY: 0.3
});
// Ensure plant graphics appear above soil, especially for giant fruits
self.setChildIndex(plantGraphics, self.children.length - 1);
// Animate plant growth over 5 seconds
tween(plantGraphics, {
scaleX: finalScale,
scaleY: finalScale
}, {
duration: 5000,
easing: tween.easeOut
});
// Add rainbow tint animation for colorful fruits
if (self.isColorful) {
var colorfulAnimation = function colorfulAnimation() {
var colors = [0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0xff00ff, 0x00ffff];
var currentColor = 0;
var _animateColor = function animateColor() {
if (plantGraphics) {
tween(plantGraphics, {
tint: colors[currentColor]
}, {
duration: 800,
easing: tween.easeInOut,
onFinish: function onFinish() {
currentColor = (currentColor + 1) % colors.length;
_animateColor();
}
});
}
};
_animateColor();
};
// Start colorful animation after growth completes
LK.setTimeout(colorfulAnimation, 5000);
}
LK.getSound('plant').play();
return true;
};
self.harvest = function () {
if (!self.grown) return null;
var harvestedType = self.plantType;
var isColorfulHarvest = self.isColorful;
// Check if this is a regrowing fruit (banana, dragon fruit, coconut, apple, nectarine, kiwi, cherry, mango, heavenMango)
var isBanana = harvestedType === 'banana' || harvestedType === 'colorful_banana';
var isDragonFruit = harvestedType === 'dragonfruit' || harvestedType === 'colorful_dragonfruit';
var isCoconut = harvestedType === 'coconut' || harvestedType === 'colorful_coconut';
var isApple = harvestedType === 'apple' || harvestedType === 'colorful_apple';
var isNectarine = harvestedType === 'nectarine' || harvestedType === 'colorful_nectarine';
var isKiwi = harvestedType === 'kiwi' || harvestedType === 'colorful_kiwi';
var isCherry = harvestedType === 'cherry' || harvestedType === 'colorful_cherry';
var isMango = harvestedType === 'mango' || harvestedType === 'colorful_mango';
var isHeavenMango = harvestedType === 'heavenMango' || harvestedType === 'colorful_heavenMango';
if (isBanana || isDragonFruit || isCoconut || isApple || isNectarine || isKiwi || isCherry || isMango || isHeavenMango) {
// Hide the plant graphics with animation for regrowing fruits
if (plantGraphics) {
tween(plantGraphics, {
alpha: 0.3,
scaleX: 0.5,
scaleY: 0.5
}, {
duration: 500,
easing: tween.easeIn
});
}
self.grown = false;
self.regrowTime = LK.ticks;
} else {
// For carrots and strawberries, reset the plant completely
if (plantGraphics) {
plantGraphics.destroy();
plantGraphics = null;
}
self.planted = false;
self.plantType = null;
self.plantTime = 0;
self.grown = false;
self.isColorful = false;
self.regrowTime = 0;
}
LK.getSound('harvest').play();
return {
type: harvestedType,
colorful: isColorfulHarvest,
chocolate: self.isChocolate || false,
fromSeedPack: self.isFromSeedPack || false
};
};
self.update = function () {
if (self.planted && !self.grown) {
// Check if this spot is affected by a sprinkler
var speedMultiplier = 1;
for (var i = 0; i < sprinklers.length; i++) {
var sprinkler = sprinklers[i];
var distanceX = Math.abs(self.x - sprinkler.x);
var distanceY = Math.abs(self.y - sprinkler.y);
// Regular sprinkler: 5x speed in 3x3 area (660px = 3 * 220px spacing)
if (distanceX <= 660 && distanceY <= 660) {
speedMultiplier = 5;
break;
}
}
// Check if it's time to regrow after harvest (for bananas, dragon fruit, coconut, apple, and the new fruits)
if (self.regrowTime > 0) {
var isBanana = self.plantType === 'banana' || self.plantType === 'colorful_banana';
var isDragonFruit = self.plantType === 'dragonfruit' || self.plantType === 'colorful_dragonfruit';
var isCoconut = self.plantType === 'coconut' || self.plantType === 'colorful_coconut';
var isApple = self.plantType === 'apple' || self.plantType === 'colorful_apple';
var isNectarine = self.plantType === 'nectarine' || self.plantType === 'colorful_nectarine';
var isKiwi = self.plantType === 'kiwi' || self.plantType === 'colorful_kiwi';
var isCherry = self.plantType === 'cherry' || self.plantType === 'colorful_cherry';
var isMango = self.plantType === 'mango' || self.plantType === 'colorful_mango';
var isHeavenMango = self.plantType === 'heavenMango' || self.plantType === 'colorful_heavenMango';
var regrowReady = false;
if (isBanana && LK.ticks - self.regrowTime > 1140 / speedMultiplier) {
// 19 seconds at 60fps for banana regrow (halved with sprinkler)
regrowReady = true;
} else if ((isDragonFruit || isCoconut) && LK.ticks - self.regrowTime > 1320 / speedMultiplier) {
// 22 seconds at 60fps for dragon fruit and coconut regrow (halved with sprinkler)
regrowReady = true;
} else if (isApple && LK.ticks - self.regrowTime > 1200 / speedMultiplier) {
// 20 seconds at 60fps for apple regrow (halved with sprinkler)
regrowReady = true;
} else if (isNectarine && LK.ticks - self.regrowTime > 1500 / speedMultiplier) {
// 25 seconds at 60fps for nectarine regrow (halved with sprinkler)
regrowReady = true;
} else if (isKiwi && LK.ticks - self.regrowTime > 2040 / speedMultiplier) {
// 34 seconds at 60fps for kiwi regrow (halved with sprinkler)
regrowReady = true;
} else if (isCherry && LK.ticks - self.regrowTime > 1800 / speedMultiplier) {
// 30 seconds at 60fps for cherry regrow (halved with sprinkler)
regrowReady = true;
} else if (isMango && LK.ticks - self.regrowTime > 2100 / speedMultiplier) {
// 35 seconds at 60fps for mango regrow (halved with sprinkler)
regrowReady = true;
} else if (isHeavenMango && LK.ticks - self.regrowTime > 2400 / speedMultiplier) {
// 40 seconds at 60fps for heaven mango regrow (halved with sprinkler)
regrowReady = true;
}
if (regrowReady) {
self.grown = true;
self.regrowTime = 0;
if (plantGraphics) {
var regrowScale = 1.0;
tween(plantGraphics, {
alpha: 1.0,
scaleX: regrowScale,
scaleY: regrowScale
}, {
duration: 1000,
easing: tween.easeOut
});
}
}
} else if (self.regrowTime === 0) {
// Different growth times for different plants
var isNectarine = self.plantType === 'nectarine' || self.plantType === 'colorful_nectarine';
var isPineapple = self.plantType === 'pineapple' || self.plantType === 'colorful_pineapple';
var isCherry = self.plantType === 'cherry' || self.plantType === 'colorful_cherry';
var isKiwi = self.plantType === 'kiwi' || self.plantType === 'colorful_kiwi';
var growthTime;
if (isNectarine) {
growthTime = 480; // 8 seconds for nectarine
} else if (isPineapple) {
growthTime = 600; // 10 seconds for pineapple
} else if (isCherry) {
growthTime = 840; // 14 seconds for cherry
} else if (isKiwi) {
growthTime = 1020; // 17 seconds for kiwi
} else {
growthTime = 300; // 5 seconds for other plants
}
if (LK.ticks - self.plantTime > growthTime / speedMultiplier) {
self.grown = true;
if (plantGraphics) {
plantGraphics.alpha = 1.0;
}
}
}
}
};
self.down = function () {
if (self.grown) {
var harvested = self.harvest();
if (harvested) {
if (!harvested.fromSeedPack) {
var harvestType = harvested.type;
if (harvested.chocolate) {
// Store chocolate fruits separately for 4x price
var baseType = harvestType.replace('colorful_', '');
// Special case for carrots - use Chococarrot asset name
if (baseType === 'carrot') {
inventory['Chococarrot'] = (inventory['Chococarrot'] || 0) + 1;
} else {
inventory['choco_' + baseType] = (inventory['choco_' + baseType] || 0) + 1;
}
} else if (harvested.colorful) {
// Store colorful fruits separately for 3x price
var baseType = harvestType.replace('colorful_', '');
inventory['colorful_' + baseType] = (inventory['colorful_' + baseType] || 0) + 1;
} else {
inventory[harvestType] = (inventory[harvestType] || 0) + 1;
}
updateInventoryDisplay();
}
}
} else if (!self.planted && selectedSprinkler) {
// Place sprinkler
var sprinklerCost = 35;
if (money >= sprinklerCost) {
var sprinkler = new Sprinkler(self.x, self.y);
sprinklers.push(sprinkler);
game.addChild(sprinkler);
money -= sprinklerCost;
updateMoneyDisplay();
selectedSprinkler = false;
gearShop.visible = false;
}
} else if (!self.planted && selectedSeed && selectedSeed !== 'cactus' && selectedSeed !== 'atlas_cactus' && money >= seedPrices[selectedSeed]) {
// Plant non-cactus seeds in dirt spots only
if (self.plantSeed(selectedSeed)) {
money -= seedPrices[selectedSeed];
updateMoneyDisplay();
selectedSeed = null;
seedShop.visible = false;
}
} else if (!self.planted && (selectedSeed === 'cactus' || selectedSeed === 'atlas_cactus')) {
// Block cactus and atlas cactus planting in dirt spots - these can only be planted in sand
selectedSeed = null;
seedShop.visible = false;
}
};
return self;
});
var SeedShop = Container.expand(function () {
var self = Container.call(this);
var background = self.attachAsset('seedShopBg', {
anchorX: 0.5,
anchorY: 0.5
});
var titleText = new Text2('SEED SHOP', {
size: 80,
fill: 0x000000
});
titleText.anchor.set(0.5, 0.5);
titleText.y = -600;
self.addChild(titleText);
// Blueberry item
var blueberryButton = new Container();
blueberryButton.x = 0;
blueberryButton.y = -400;
var blueberryIcon = blueberryButton.attachAsset('blueberry_icon', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.2,
scaleY: 1.2
});
blueberryIcon.x = -350;
var blueberryNameText = new Text2('Blueberry', {
size: 50,
fill: 0x000000
});
blueberryNameText.anchor.set(0, 0.5);
blueberryNameText.x = -250;
blueberryButton.addChild(blueberryNameText);
var blueberryPriceText = new Text2('$10', {
size: 50,
fill: 0xFFFF00
});
blueberryPriceText.anchor.set(1, 0.5);
blueberryPriceText.x = 300;
blueberryButton.addChild(blueberryPriceText);
var blueberryDescText = new Text2('Sells: $15 (25% chance for $10)', {
size: 30,
fill: 0x666666
});
blueberryDescText.anchor.set(0.5, 0);
blueberryDescText.y = 30;
blueberryButton.addChild(blueberryDescText);
blueberryButton.down = function () {
if (money >= 10) {
selectedSeed = 'blueberry';
self.visible = false;
LK.getSound('Buy').play();
}
};
self.addChild(blueberryButton);
// Nectarine item
var nectarineButton = new Container();
nectarineButton.x = 0;
nectarineButton.y = -280;
var nectarineIcon = nectarineButton.attachAsset('nectarine_icon', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.2,
scaleY: 1.2
});
nectarineIcon.x = -350;
var nectarineNameText = new Text2('Nectarine', {
size: 50,
fill: 0x000000
});
nectarineNameText.anchor.set(0, 0.5);
nectarineNameText.x = -250;
nectarineButton.addChild(nectarineNameText);
var nectarinePriceText = new Text2('$55', {
size: 50,
fill: 0xFFFF00
});
nectarinePriceText.anchor.set(1, 0.5);
nectarinePriceText.x = 300;
nectarineButton.addChild(nectarinePriceText);
var nectarineDescText = new Text2('Sells: $60 (25% chance for $30)', {
size: 30,
fill: 0x666666
});
nectarineDescText.anchor.set(0.5, 0);
nectarineDescText.y = 30;
nectarineButton.addChild(nectarineDescText);
nectarineButton.down = function () {
if (money >= 55) {
selectedSeed = 'nectarine';
self.visible = false;
LK.getSound('Buy').play();
}
};
self.addChild(nectarineButton);
// Pineapple item
var pineappleButton = new Container();
pineappleButton.x = 0;
pineappleButton.y = -160;
var pineappleIcon = pineappleButton.attachAsset('pineapple_icon', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.2,
scaleY: 1.2
});
pineappleIcon.x = -350;
var pineappleNameText = new Text2('Pineapple', {
size: 50,
fill: 0x000000
});
pineappleNameText.anchor.set(0, 0.5);
pineappleNameText.x = -250;
pineappleButton.addChild(pineappleNameText);
var pineapplePriceText = new Text2('$110', {
size: 50,
fill: 0xFFFF00
});
pineapplePriceText.anchor.set(1, 0.5);
pineapplePriceText.x = 300;
pineappleButton.addChild(pineapplePriceText);
var pineappleDescText = new Text2('Sells: $115 (25% chance for $65)', {
size: 30,
fill: 0x666666
});
pineappleDescText.anchor.set(0.5, 0);
pineappleDescText.y = 30;
pineappleButton.addChild(pineappleDescText);
pineappleButton.down = function () {
if (money >= 110) {
selectedSeed = 'pineapple';
self.visible = false;
LK.getSound('Buy').play();
}
};
self.addChild(pineappleButton);
// Cherry item
var cherryButton = new Container();
cherryButton.x = 0;
cherryButton.y = -40;
var cherryIcon = cherryButton.attachAsset('cherry_icon', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.2,
scaleY: 1.2
});
cherryIcon.x = -350;
var cherryNameText = new Text2('Cherry', {
size: 50,
fill: 0x000000
});
cherryNameText.anchor.set(0, 0.5);
cherryNameText.x = -250;
cherryButton.addChild(cherryNameText);
var cherryPriceText = new Text2('$165', {
size: 50,
fill: 0xFFFF00
});
cherryPriceText.anchor.set(1, 0.5);
cherryPriceText.x = 300;
cherryButton.addChild(cherryPriceText);
var cherryDescText = new Text2('Sells: $170 (25% chance for $115)', {
size: 30,
fill: 0x666666
});
cherryDescText.anchor.set(0.5, 0);
cherryDescText.y = 30;
cherryButton.addChild(cherryDescText);
cherryButton.down = function () {
if (money >= 165) {
selectedSeed = 'cherry';
self.visible = false;
LK.getSound('Buy').play();
}
};
self.addChild(cherryButton);
// Kiwi item
var kiwiButton = new Container();
kiwiButton.x = 0;
kiwiButton.y = 80;
var kiwiIcon = kiwiButton.attachAsset('kiwi_icon', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.2,
scaleY: 1.2
});
kiwiIcon.x = -350;
var kiwiNameText = new Text2('Kiwi', {
size: 50,
fill: 0x000000
});
kiwiNameText.anchor.set(0, 0.5);
kiwiNameText.x = -250;
kiwiButton.addChild(kiwiNameText);
var kiwiPriceText = new Text2('$225', {
size: 50,
fill: 0xFFFF00
});
kiwiPriceText.anchor.set(1, 0.5);
kiwiPriceText.x = 300;
kiwiButton.addChild(kiwiPriceText);
var kiwiDescText = new Text2('Sells: $230 (25% chance for $165)', {
size: 30,
fill: 0x666666
});
kiwiDescText.anchor.set(0.5, 0);
kiwiDescText.y = 30;
kiwiButton.addChild(kiwiDescText);
kiwiButton.down = function () {
if (money >= 225) {
selectedSeed = 'kiwi';
self.visible = false;
LK.getSound('Buy').play();
}
};
self.addChild(kiwiButton);
// Mango item
var mangoButton = new Container();
mangoButton.x = 0;
mangoButton.y = 200;
var mangoIcon = mangoButton.attachAsset('mango_icon', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.2,
scaleY: 1.2
});
mangoIcon.x = -350;
var mangoNameText = new Text2('Mango', {
size: 50,
fill: 0x000000
});
mangoNameText.anchor.set(0, 0.5);
mangoNameText.x = -250;
mangoButton.addChild(mangoNameText);
var mangoPriceText = new Text2('$335', {
size: 50,
fill: 0xFFFF00
});
mangoPriceText.anchor.set(1, 0.5);
mangoPriceText.x = 300;
mangoButton.addChild(mangoPriceText);
var mangoDescText = new Text2('Sells: $350 (25% chance for $330)', {
size: 30,
fill: 0x666666
});
mangoDescText.anchor.set(0.5, 0);
mangoDescText.y = 30;
mangoButton.addChild(mangoDescText);
mangoButton.down = function () {
if (money >= 335) {
selectedSeed = 'mango';
self.visible = false;
LK.getSound('Buy').play();
}
};
self.addChild(mangoButton);
// Heaven Mango item
var heavenMangoButton = new Container();
heavenMangoButton.x = 0;
heavenMangoButton.y = 320;
var heavenMangoIcon = heavenMangoButton.attachAsset('heavenMango_icon', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.2,
scaleY: 1.2
});
heavenMangoIcon.x = -350;
var heavenMangoNameText = new Text2('Heaven Mango', {
size: 50,
fill: 0x000000
});
heavenMangoNameText.anchor.set(0, 0.5);
heavenMangoNameText.x = -250;
heavenMangoButton.addChild(heavenMangoNameText);
var heavenMangoPriceText = new Text2('$650', {
size: 50,
fill: 0xFFFF00
});
heavenMangoPriceText.anchor.set(1, 0.5);
heavenMangoPriceText.x = 300;
heavenMangoButton.addChild(heavenMangoPriceText);
var heavenMangoDescText = new Text2('Sells: $700 (10% chance for $670)', {
size: 30,
fill: 0x666666
});
heavenMangoDescText.anchor.set(0.5, 0);
heavenMangoDescText.y = 30;
heavenMangoButton.addChild(heavenMangoDescText);
heavenMangoButton.down = function () {
if (money >= 650) {
selectedSeed = 'heavenMango';
self.visible = false;
LK.getSound('Buy').play();
}
};
self.addChild(heavenMangoButton);
// Mystery item
var mysteryButton = new Container();
mysteryButton.x = 0;
mysteryButton.y = 440;
var mysteryIcon = mysteryButton.attachAsset('mystery_icon', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.2,
scaleY: 1.2
});
mysteryIcon.x = -350;
var mysteryNameText = new Text2('??? Mystery', {
size: 50,
fill: 0x000000
});
mysteryNameText.anchor.set(0, 0.5);
mysteryNameText.x = -250;
mysteryButton.addChild(mysteryNameText);
var mysteryPriceText = new Text2('$1000', {
size: 50,
fill: 0xFFFF00
});
mysteryPriceText.anchor.set(1, 0.5);
mysteryPriceText.x = 300;
mysteryButton.addChild(mysteryPriceText);
var mysteryDescText = new Text2('Sells: $1050 (10% chance for $700)', {
size: 30,
fill: 0x666666
});
mysteryDescText.anchor.set(0.5, 0);
mysteryDescText.y = 30;
mysteryButton.addChild(mysteryDescText);
mysteryButton.down = function () {
if (money >= 1000) {
selectedSeed = 'mystery';
self.visible = false;
LK.getSound('Buy').play();
}
};
self.addChild(mysteryButton);
var closeButton = new Button('CLOSE', function () {
self.visible = false;
});
closeButton.y = 600;
closeButton.scaleX = 1.5;
closeButton.scaleY = 1.5;
self.addChild(closeButton);
return self;
});
var Sprinkler = Container.expand(function (x, y) {
var self = Container.call(this);
self.x = x;
self.y = y;
self.type = 'regular';
var sprinklerGraphics = self.attachAsset('sprinkler', {
anchorX: 0.5,
anchorY: 0.5
});
// Add pulsing animation to show it's active
function animateSprinkler() {
tween(sprinklerGraphics, {
scaleX: 1.2,
scaleY: 1.2,
alpha: 0.7
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(sprinklerGraphics, {
scaleX: 1.0,
scaleY: 1.0,
alpha: 1.0
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: animateSprinkler
});
}
});
}
animateSprinkler();
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x228B22
});
/****
* Game Code
****/
// Add grass background
var grassBackground = game.attachAsset('grass_bg', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
var money = 0;
var inventory = {};
var selectedSeed = null;
var selectedSprinkler = false;
var selectedFish = false;
var selectedFish2 = false;
var sprinklers = [];
var seedPrices = {
cactus: 100,
atlas_cactus: 250,
blueberry: 10,
nectarine: 55,
pineapple: 110,
cherry: 165,
kiwi: 225,
mango: 335,
heavenMango: 650,
mystery: 1000
};
var sellPrices = {
fish: 110,
fish2: 75,
choco_fish: 440,
choco_fish2: 720,
cactus: 150,
atlas_cactus: 265,
colorful_cactus: 450,
colorful_atlas_cactus: 795,
choco_cactus: 600,
choco_atlas_cactus: 1060,
blueberry: 15,
nectarine: 60,
pineapple: 115,
cherry: 170,
kiwi: 230,
mango: 350,
heavenMango: 700,
mystery: 1050,
colorful_blueberry: 45,
colorful_nectarine: 180,
colorful_pineapple: 345,
colorful_cherry: 510,
colorful_kiwi: 690,
colorful_mango: 1050,
colorful_heavenMango: 2100,
colorful_mystery: 3150
};
// Create plant spots in a grid - start with 64 lands arranged in a grid (32 top + 32 bottom)
var plantSpots = [];
var spacing = 220;
var landsPerRow = 8;
var totalRows = 8; // 4 rows for top + 4 rows for bottom
var totalWidth = (landsPerRow - 1) * spacing;
var startX = (2048 - totalWidth) / 2; // Center horizontally on screen
var startY = 600; // Move starting Y up to accommodate bottom section
// Create 32 initial plant spots in 8 columns, 4 rows (top section)
for (var i = 0; i < 32; i++) {
var col = i % 8;
var row = Math.floor(i / 8);
var spot = new PlantSpot(startX + col * spacing, startY + row * spacing);
plantSpots.push(spot);
game.addChild(spot);
}
// Create another 32 plant spots at the bottom (8 columns, 4 rows)
var bottomStartY = startY + 4 * spacing + 100; // Add gap between top and bottom sections
for (var i = 0; i < 32; i++) {
var col = i % 8;
var row = Math.floor(i / 8);
var spot;
// Make the bottom 16 spots (last 2 rows) aquatic
if (i >= 16) {
spot = new AquaticPlantSpot(startX + col * spacing, bottomStartY + row * spacing);
} else {
spot = new PlantSpot(startX + col * spacing, bottomStartY + row * spacing);
}
plantSpots.push(spot);
game.addChild(spot);
}
// UI Elements
var moneyText = new Text2('Money: $0', {
size: 50,
fill: 0x000000
});
moneyText.anchor.set(0, 0);
moneyText.x = 150;
moneyText.y = 50;
LK.gui.topLeft.addChild(moneyText);
var inventoryText = new Text2('Inventory: Empty', {
size: 50,
fill: 0x000000
});
inventoryText.anchor.set(0, 1);
inventoryText.x = 100;
inventoryText.y = -200;
LK.gui.bottomLeft.addChild(inventoryText);
// Make inventory alive with pulsing animation
function animateInventory() {
tween(inventoryText, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(inventoryText, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: animateInventory
});
}
});
}
animateInventory();
var sellButton = new Button('SELL ALL', function () {
var totalSale = 0;
// Check if we get the 10% price boost (30% chance)
var priceBoost = Math.random() < 0.3 ? 1.1 : 1.0;
for (var itemType in inventory) {
if (inventory[itemType] > 0) {
var basePrice;
basePrice = sellPrices[itemType];
// 35% chance for fish2 to sell for 85 instead of 75
if (itemType === 'fish2' && Math.random() < 0.35) {
basePrice = 85;
}
// 0.3% chance for cactus to sell for 450 instead of 150
if (itemType === 'cactus' && Math.random() < 0.003) {
basePrice = 450;
}
// 0.5% chance for atlas_cactus to sell for 500 instead of 265
if (itemType === 'atlas_cactus' && Math.random() < 0.005) {
basePrice = 500;
}
// 25% chance for fruits to sell at reduced price
if (itemType === 'blueberry' && Math.random() < 0.25) {
basePrice = 10;
}
if (itemType === 'nectarine' && Math.random() < 0.25) {
basePrice = 30;
}
if (itemType === 'pineapple' && Math.random() < 0.25) {
basePrice = 65;
}
if (itemType === 'cherry' && Math.random() < 0.25) {
basePrice = 115;
}
if (itemType === 'kiwi' && Math.random() < 0.25) {
basePrice = 165;
}
if (itemType === 'mango' && Math.random() < 0.25) {
basePrice = 330;
}
// 10% chance for special fruits to sell at reduced price
if (itemType === 'heavenMango' && Math.random() < 0.1) {
basePrice = 670;
}
if (itemType === 'mystery' && Math.random() < 0.1) {
basePrice = 700;
}
basePrice *= priceBoost;
totalSale += inventory[itemType] * basePrice;
inventory[itemType] = 0;
}
}
if (totalSale > 0) {
money += totalSale;
updateMoneyDisplay();
updateInventoryDisplay();
LK.getSound('sell').play();
}
});
sellButton.x = 600;
sellButton.y = 100;
sellButton.scaleX = 1.3;
sellButton.scaleY = 1.3;
LK.gui.topLeft.addChild(sellButton);
var seedButton = new Button('SEEDS', function () {
seedShop.visible = true;
});
seedButton.x = 900;
seedButton.y = 100;
seedButton.scaleX = 1.3;
seedButton.scaleY = 1.3;
LK.gui.topLeft.addChild(seedButton);
var freeCoinsButton = new Button('FREE COINS', function () {
money += 500;
updateMoneyDisplay();
});
freeCoinsButton.x = 1200;
freeCoinsButton.y = 100;
freeCoinsButton.scaleX = 1.3;
freeCoinsButton.scaleY = 1.3;
LK.gui.topLeft.addChild(freeCoinsButton);
var gearButton = new Button('GEAR SHOP', function () {
gearShop.visible = true;
});
gearButton.x = 600;
gearButton.y = 250;
gearButton.scaleX = 1.3;
gearButton.scaleY = 1.3;
LK.gui.topLeft.addChild(gearButton);
var fishButton = new Button('DESERT SHOP', function () {
fishShop.visible = true;
});
fishButton.x = 900;
fishButton.y = 250;
fishButton.scaleX = 1.3;
fishButton.scaleY = 1.3;
LK.gui.topLeft.addChild(fishButton);
var seedShop = new SeedShop();
seedShop.x = 1024;
seedShop.y = 1366;
seedShop.visible = false;
game.addChild(seedShop);
var gearShop = new GearShop();
gearShop.x = 1024;
gearShop.y = 1366;
gearShop.visible = false;
game.addChild(gearShop);
var fishShop = new DesertShop();
fishShop.x = 1024;
fishShop.y = 1366;
fishShop.visible = false;
game.addChild(fishShop);
// Button sliding variables
var topButtons = [sellButton, seedButton, freeCoinsButton, gearButton, fishButton];
var buttonBasePositions = [600, 900, 1200, 600, 900];
var slideOffset = 0;
var maxSlideOffset = 400; // Maximum pixels to slide
// Sliding functions
function slideButtonsLeft() {
slideOffset = Math.min(slideOffset + 100, maxSlideOffset);
updateButtonPositions();
}
function slideButtonsRight() {
slideOffset = Math.max(slideOffset - 100, -maxSlideOffset);
updateButtonPositions();
}
function updateButtonPositions() {
for (var i = 0; i < topButtons.length; i++) {
tween(topButtons[i], {
x: buttonBasePositions[i] + slideOffset
}, {
duration: 300,
easing: tween.easeOut
});
}
}
function updateMoneyDisplay() {
moneyText.setText('Money: $' + money);
}
function updateInventoryDisplay() {
var inventoryStr = 'Inventory: ';
var hasItems = false;
for (var itemType in inventory) {
if (inventory[itemType] > 0) {
if (hasItems) inventoryStr += ', ';
inventoryStr += itemType + ' x' + inventory[itemType];
hasItems = true;
}
}
if (!hasItems) {
inventoryStr += 'Empty';
}
inventoryText.setText(inventoryStr);
}
function expandLands(targetCount) {
var currentCount = plantSpots.length;
if (targetCount === 12 && currentCount === 6) {
// Expand from 6 to 12 lands - add 6 more in 3 columns, 4 rows total
for (var i = currentCount; i < targetCount; i++) {
var col = i % 3;
var row = Math.floor(i / 3);
var newSpot = new PlantSpot(startX + col * spacing, startY + row * spacing);
plantSpots.push(newSpot);
game.addChild(newSpot);
}
} else if (targetCount === 18 && currentCount === 12) {
// Expand from 12 to 18 lands - rearrange to left column and add right column
var leftStartY = 800;
// First, move existing 12 lands to left side (3 columns, up to 4 rows)
for (var i = 0; i < currentCount; i++) {
var spot = plantSpots[i];
var newX = startX + i % 3 * spacing;
var newY = leftStartY + Math.floor(i / 3) * spacing;
tween(spot, {
x: newX,
y: newY
}, {
duration: 1000,
easing: tween.easeInOut
});
}
// Add 6 new lands to the right side
var rightStartX = startX + 4 * spacing;
for (var i = currentCount; i < targetCount; i++) {
var rightIndex = i - currentCount;
var col = rightIndex % 3;
var row = Math.floor(rightIndex / 3);
var newSpot = new PlantSpot(rightStartX + col * spacing, leftStartY + row * spacing);
plantSpots.push(newSpot);
game.addChild(newSpot);
}
}
}
function expandLandsForDragonFruit() {
var currentCount = plantSpots.length;
// Calculate center positioning for all lands
var totalLands = currentCount + 12; // Current lands + 12 new lands
var landsPerRow = 6; // 6 lands per row for better centering
var totalRows = Math.ceil(totalLands / landsPerRow);
var totalWidth = (landsPerRow - 1) * spacing;
var totalHeight = (totalRows - 1) * spacing;
var centerStartX = (2048 - totalWidth) / 2; // Center horizontally on screen
var centerStartY = 800;
// Move all existing lands to center positions
for (var i = 0; i < currentCount; i++) {
var spot = plantSpots[i];
var col = i % landsPerRow;
var row = Math.floor(i / landsPerRow);
var newX = centerStartX + col * spacing;
var newY = centerStartY + row * spacing;
tween(spot, {
x: newX,
y: newY
}, {
duration: 1000,
easing: tween.easeInOut
});
}
// Add 12 new lands continuing from center positions
for (var i = 0; i < 12; i++) {
var landIndex = currentCount + i;
var col = landIndex % landsPerRow;
var row = Math.floor(landIndex / landsPerRow);
var newX = centerStartX + col * spacing;
var newY = centerStartY + row * spacing;
var newSpot = new PlantSpot(newX, newY);
plantSpots.push(newSpot);
game.addChild(newSpot);
}
}
// Play background music
LK.playMusic('Music');
// Touch controls for sliding buttons
var touchStartX = 0;
var isDraggingButtons = false;
game.down = function (x, y, obj) {
// Check if touch is in the top button area
if (y < 200) {
touchStartX = x;
isDraggingButtons = true;
}
};
game.up = function (x, y, obj) {
if (isDraggingButtons) {
var deltaX = x - touchStartX;
if (Math.abs(deltaX) > 50) {
// Minimum swipe distance
if (deltaX > 0) {
slideButtonsLeft();
} else {
slideButtonsRight();
}
}
isDraggingButtons = false;
}
};
game.update = function () {
// Plant spots update automatically through their update methods
};
background grass 8 bit. In-Game asset. 2d. High contrast. No shadows
Stone 8 bit. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
Neon
Choco
Choco but all parts of the carrot are visible and only the carrot is painted brown
Blueberry 8 bit. In-Game asset. 2d. High contrast. No shadows
Delete stones, 2d
Cactus 8 bit. In-Game asset. 2d. High contrast. No shadows
8 bit nectarine tree. In-Game asset. 2d. High contrast. No shadows
Cherry tree 8 bit. In-Game asset. 2d. High contrast. No shadows
8 bit pineapple. In-Game asset. 2d. High contrast. No shadows
Kiwi tree 8bit. In-Game asset. 2d. High contrast. No shadows
make trees leaves orange
fruits are black with purple leaves and particles around them
8 bit cherry seed. In-Game asset. 2d. High contrast. No shadows
8bit kiwi seed. In-Game asset. 2d. High contrast. No shadows
Mango seed 8bit. In-Game asset. 2d. High contrast. No shadows
winged and white
make the leaves of the tree white
8 bit pineapple seed. In-Game asset. 2d. High contrast. No shadows
purple black mysterious unknown fruit seed 8bit. In-Game asset. 2d. High contrast. No shadows
8 bit blueberry seed. In-Game asset. 2d. High contrast. No shadows
cactus with pink spines and a small pink flower on top 8bit. In-Game asset. 2d. High contrast. No shadows
Neon
Neon
Neon