User prompt
Update with: First, let's modify the patterns in BudSpawner: ```javascript self.patterns = { single: [[[0,0]]], pairs: [ [[0,0], [0,1]], // horizontal [[0,0], [1,0]], // vertical [[0,0], [1,1]] // diagonal ], triples: [ [[0,0], [0,1], [0,2]], // horizontal [[0,0], [1,0], [2,0]], // vertical [[0,0], [1,1], [2,2]], // diagonal [[0,0], [0,1], [1,0]] // L shape ] };
User prompt
Put this into the budspawner class directly: 3. Add this warning creation method: ```javascript self.createWarning = function(x, y) { let warning = new Container(); let crack = LK.getAsset('soil', { anchorX: 0.5, anchorY: 0.5, alpha: 0.5, tint: 0xFF0000 }); warning.addChild(crack); warning.x = x; warning.y = y; warning.scale.set(0.3); self.garden.addChild(warning); return warning; };
User prompt
Put this code in the BudSpawner class: 3. Add this warning creation method: ```javascript self.createWarning = function(x, y) { let warning = new Container(); let crack = LK.getAsset('soil', { anchorX: 0.5, anchorY: 0.5, alpha: 0.5, tint: 0xFF0000 }); warning.addChild(crack); warning.x = x; warning.y = y; warning.scale.set(0.3); self.garden.addChild(warning); return warning; };
User prompt
Put this in the budspawner class: 3. Add this warning creation method: ```javascript self.createWarning = function(x, y) { let warning = new Container(); let crack = LK.getAsset('soil', { anchorX: 0.5, anchorY: 0.5, alpha: 0.5, tint: 0xFF0000 }); warning.addChild(crack); warning.x = x; warning.y = y; warning.scale.set(0.3); self.garden.addChild(warning); return warning; };
User prompt
3. Add this warning creation method: ```javascript self.createWarning = function(x, y) { let warning = new Container(); let crack = LK.getAsset('soil', { anchorX: 0.5, anchorY: 0.5, alpha: 0.5, tint: 0xFF0000 }); warning.addChild(crack); warning.x = x; warning.y = y; warning.scale.set(0.3); self.garden.addChild(warning); return warning; };
User prompt
Put this in bud spawner class: 2. Add this new method to BudSpawner: ```javascript self.selectSpawnPosition = function() { // Find all valid spawn positions that can fit the pattern let validPositions = []; for(let y = 0; y < self.garden.rows; y++) { for(let x = 0; x < self.garden.cols; x++) { // For each pattern patternCheck: for(let pattern of self.patterns) { // Check if pattern fits at this position for(let [dy, dx] of pattern) { let ny = y + dy; let nx = x + dx; // If any part is out of bounds or occupied, skip this pattern if(ny >= self.garden.rows || nx >= self.garden.cols || self.garden.grid[ny][nx] !== null) { continue patternCheck; } } // If we get here, pattern fits at [x,y] validPositions.push({x, y, pattern}); } } } if(validPositions.length > 0) { // Select random valid position and pattern return validPositions[Math.floor(Math.random() * validPositions.length)]; } return null; };
User prompt
2. Add this new method to BudSpawner: ```javascript self.selectSpawnPosition = function() { // Find all valid spawn positions that can fit the pattern let validPositions = []; for(let y = 0; y < self.garden.rows; y++) { for(let x = 0; x < self.garden.cols; x++) { // For each pattern patternCheck: for(let pattern of self.patterns) { // Check if pattern fits at this position for(let [dy, dx] of pattern) { let ny = y + dy; let nx = x + dx; // If any part is out of bounds or occupied, skip this pattern if(ny >= self.garden.rows || nx >= self.garden.cols || self.garden.grid[ny][nx] !== null) { continue patternCheck; } } // If we get here, pattern fits at [x,y] validPositions.push({x, y, pattern}); } } } if(validPositions.length > 0) { // Select random valid position and pattern return validPositions[Math.floor(Math.random() * validPositions.length)]; } return null; };
User prompt
1. Add these properties near the start of the BudSpawner class definition: ```javascript self.patterns = [ // 2-bud patterns [[0,0], [0,1]], // horizontal pair [[0,0], [1,0]], // vertical pair [[0,0], [1,1]], // diagonal pair // 3-bud patterns [[0,0], [0,1], [0,2]], // horizontal line [[0,0], [1,0], [2,0]], // vertical line [[0,0], [1,1], [2,2]], // diagonal line [[0,0], [0,1], [1,0]], // L shape ]; self.warningTime = 180; // 3 seconds at 60fps self.currentPattern = null; self.warningSprites = []; self.nextSpawnPosition = null;
User prompt
// In Bee's collectPollen method, find: var collectAmount = 25; // Change to: var collectAmount = 14;
User prompt
Update as needed with: // In Bee's collectPollen method, find: var collectAmount = 25; // Replace with better max checking: if (self.currentPollen >= self.maxPollen) { return; // Don't collect if we're at max } var collectAmount = Math.min(25, self.maxPollen - self.currentPollen);
User prompt
Update using: // In Bee's usePollen method, find this block: self.currentPollen -= pollenUsed; // Update pollen types properly var pType = self.pollenTypes[0]; var color = pType.color; // New line to store color pType.amount -= pollenUsed; // Add after that: if (self.currentPollen <= 0) { self.pollenTypes = []; // Clear all pollen types when empty }
User prompt
Update as needed: // In Bee class constructor, find: self.maxPollen = 50; // Change to: self.maxPollen = 14; // Exactly enough for 2 buds (2 * 7 = 14)
User prompt
Update as needed: // In Bee's collectPollen method, find: flower.pollenCollected = true; flower.hasActivePollen = false; // Change to: if (!flower.isSourceFlower) { flower.pollenCollected = true; flower.hasActivePollen = false; } else { // Source flowers reset immediately flower.hasActivePollen = true; flower.pollenCollected = false; }
User prompt
Update as needed: // In SourceFlower class, after collecting, it needs to reset itself // Add this method to SourceFlower: self.collectPollen = function() { // Reset immediately to allow continuous collection self.hasActivePollen = true; self.pollenCollected = false; };
User prompt
Update with: // In BasicFlower constructor, find: self.pollenCollected = false; // Change to: self.pollenCollected = true; // Set to true so pollen can't be collected
User prompt
Update as needed: // In BasicFlower's bloom method, remove both of these timer blocks: // Remove this one in onFinish: LK.setTimeout(function() { self.hasActivePollen = true; // Create fairy particles after delay for (var i = 0; i < self.FAIRY_COUNT; i++) { var fairy = new PollenParticle().init('fairy'); fairy.scale.set(0.3 + Math.random() * 0.2); fairy.x += (Math.random() - 0.5) * 60; fairy.y += (Math.random() - 0.5) * 60; fairy.rotation = Math.random() * Math.PI * 2; fairy.rotationSpeed = (Math.random() - 0.5) * 0.2; self.addChild(fairy); self.fairyParticles.push(fairy); } }, 1000); // And in BudSpawner's update method where it auto-blooms, find and remove: LK.setTimeout(function() { newFlower.hasActivePollen = true; }, 1000);
User prompt
So in BasicFlower: 1. Keep `self.hasActivePollen = false;` at the start to ensure flowers spawn without pollen 2. Keep `self.fairyParticles = [];` and `self.FAIRY_COUNT = 3;` as they're referenced elsewhere 3. In the bloom() function, remove the entire `LK.setTimeout()` block that adds fairy particles Only source flowers should set `hasActivePollen = true` in their constructor.
User prompt
// In Bee class collectPollen method, find this line: flower.removeFairyParticles(); // Replace with: if (!flower.isSourceFlower) { flower.removeFairyParticles(); }
User prompt
Update as needed: // In Bee class, find this in checkFlowerCollision method: self.checkFlowerCollision = function() { // Convert bee position to garden's local space var localPos = garden.toLocal({x: self.x, y: self.y}, game); // Add these lines right after the localPos definition: // Check source flowers first if (garden.sourceFlowers) { garden.sourceFlowers.children.forEach(function(flower) { var dx = localPos.x - flower.x; var dy = localPos.y - flower.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < garden.cellSize/2) { self.collectPollen(flower); } }); }
User prompt
Update as needed with: self.collectPollen = function(flower) { if (self.currentPollen < self.maxPollen && flower.hasActivePollen && !flower.pollenCollected) { var collectAmount = 25; // Add to pollen types first var existingType = self.pollenTypes.find(function(p) { return p.color === flower.color; }); if (existingType) { existingType.amount += collectAmount; } else { self.pollenTypes.push({ color: flower.color, amount: collectAmount }); } // Set currentPollen to match total of all types self.currentPollen = self.pollenTypes.reduce(function(total, type) { return total + type.amount; }, 0); self.currentColor = flower.color; self.pollenTrail.currentColor = flower.color; flower.pollenCollected = true; flower.hasActivePollen = false; // Only remove fairy particles if it's not a source flower if (!flower.isSourceFlower && flower.removeFairyParticles) { flower.removeFairyParticles(); } // Update UI game.beeUI.updatePollen(flower.color, self.currentPollen, self.maxPollen); // Update meter self.pollenMeter.updateMeter(self.currentPollen, self.maxPollen); // Find exact position of this flower in grid... // Rest of the existing code...
User prompt
Please fix the bug: 'undefined is not an object (evaluating 'self.removeFairyParticles = function () { __$(735); self.fairyParticles.forEach(function (fairy) { __$(736); self.removeChild(fairy); }); __$(737); self.fairyParticles = []; }')' in or related to this line: 'self.removeFairyParticles = function () {' Line Number: 1313
User prompt
Please fix the bug: 'TypeError: flower.removeFairyParticles is not a function. (In 'flower.removeFairyParticles()', 'flower.removeFairyParticles' is undefined)' in or related to this line: 'flower.removeFairyParticles();' Line Number: 166
User prompt
Make update as needed with: self.checkFlowerCollision = function() { // Convert bee position to garden's local space var localPos = garden.toLocal({x: self.x, y: self.y}, game); // First check source flowers if (garden.sourceFlowers) { garden.sourceFlowers.children.forEach(function(flower) { var dx = localPos.x - flower.x; var dy = localPos.y - flower.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < garden.cellSize/2) { self.collectPollen(flower); } }); } // Then check grid flowers (existing code) var gridX = Math.floor(localPos.x / garden.cellSize); var gridY = Math.floor(localPos.y / garden.cellSize); if (gridX >= 0 && gridX < garden.cols && gridY >= 0 && gridY < garden.rows) { var gridItem = garden.grid[gridY][gridX]; if (gridItem) { if (gridItem.isFlower && gridItem.hasActivePollen) { self.collectPollen(gridItem); } else if (gridItem && gridItem.isBud && self.currentPollen > 0) { // Rest of the existing bud collision code...
User prompt
Update as needed: // Blue flower at top center var blueFlower = new SourceFlower('blue'); blueFlower.x = centerX; blueFlower.y = -75; // Just above top row // Red flower under bottom left bud var redFlower = new SourceFlower('red'); redFlower.x = self.cellSize/2; // Align with first column's center redFlower.y = (self.rows * self.cellSize) + self.cellSize/2; // Below last row // Yellow flower under bottom right bud var yellowFlower = new SourceFlower('yellow'); yellowFlower.x = (self.cols * self.cellSize) - self.cellSize/2; // Align with last column's center yellowFlower.y = (self.rows * self.cellSize) + self.cellSize/2; // Below last row
User prompt
Update as needed: // Blue flower at top center var blueFlower = new SourceFlower('blue'); blueFlower.x = centerX; blueFlower.y = -75; // Moved closer to top row // Red flower at bottom left corner (under the garden) var redFlower = new SourceFlower('red'); redFlower.x = 0; redFlower.y = (self.rows + 1) * self.cellSize; // Yellow flower at bottom right corner (under the garden) var yellowFlower = new SourceFlower('yellow'); yellowFlower.x = (self.cols - 1) * self.cellSize; yellowFlower.y = (self.rows + 1) * self.cellSize;
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var BasicFlower = Container.expand(function (color) { var self = Container.call(this); // Store flower color self.color = color || 'red'; // Default to red if no color specified // Map color to asset name var assetMap = { 'red': 'RedFlower', 'blue': 'BlueFlower', 'yellow': 'YellowFlower' }; // Attach bud asset first var budGraphics = self.attachAsset('Bud', { anchorX: 0.5, anchorY: 0.5 }); // Use correct asset based on color var flowerGraphics = self.attachAsset(assetMap[self.color], { anchorX: 0.5, anchorY: 0.5 }); self.hasActivePollen = false; self.fairyParticles = []; self.FAIRY_COUNT = 3; self.update = function () { var scaleFactor = 1 + Math.sin(LK.ticks * 0.1) * 0.05; flowerGraphics.scale.x = scaleFactor; flowerGraphics.scale.y = scaleFactor; flowerGraphics.rotation = Math.sin(LK.ticks * 0.1) * 0.05; }; self.bloom = function () { // Scale animation self.scale.set(0.3, 0.3); tween(self.scale, { x: 1, y: 1 }, { duration: 1000, onFinish: function onFinish() { // After bloom animation, delay before activating pollen LK.setTimeout(function () { self.hasActivePollen = true; // Create fairy particles after delay for (var i = 0; i < self.FAIRY_COUNT; i++) { var fairy = new PollenParticle().init('fairy'); fairy.scale.set(0.3 + Math.random() * 0.2); fairy.x += (Math.random() - 0.5) * 60; fairy.y += (Math.random() - 0.5) * 60; fairy.rotation = Math.random() * Math.PI * 2; fairy.rotationSpeed = (Math.random() - 0.5) * 0.2; self.addChild(fairy); self.fairyParticles.push(fairy); } }, 1000); // 1 second delay after bloom before pollen activates } }); // Create initial burst particles self.createPollenBurst(self.x, self.y); self.removeFairyParticles = function () { self.fairyParticles.forEach(function (fairy) { self.removeChild(fairy); }); self.fairyParticles = []; }; }; self.createPollenBurst = function (x, y) { for (var i = 0; i < 12; i++) { var particle = new PollenParticle().init('burst'); var angle = i / 12 * Math.PI * 2; particle.x = x; particle.y = y; particle.vx = Math.cos(angle) * 3; particle.vy = Math.sin(angle) * 3; if (self.parent) { self.parent.addChild(particle); } } }; // Initialize pollen status self.pollenCollected = false; // New flag to track if we've collected from it }); var Bee = Container.expand(function () { var self = Container.call(this); self.currentColor = null; // Add this back // Movement properties var beeSprite = self.attachAsset('Bee', { anchorX: 0.5, anchorY: 0.5 }); // Movement properties self.targetX = self.x; self.targetY = self.y; self.moveSpeed = 0.1; // Adjust this for faster/slower following self.isMoving = false; // New pollen properties self.maxPollen = 50; // Cap pollen amount self.currentPollen = 0; // Current amount being carried self.pollenTypes = []; // Array to track different pollen colors // Format: [{color: 'red', amount: 30}, ...] self.pollenMeter = new PollenMeter(); self.pollenMeter.y = -50; // Position above bee self.addChild(self.pollenMeter); // Add trail property self.pollenTrail = new PollenTrail(); game.addChild(self.pollenTrail); // Add to game so it renders behind bee // Pollen collection method self.collectPollen = function (flower) { if (self.currentPollen < self.maxPollen && flower.hasActivePollen && !flower.pollenCollected) { var collectAmount = 25; // Add to pollen types first var existingType = self.pollenTypes.find(function (p) { return p.color === flower.color; }); if (existingType) { existingType.amount += collectAmount; } else { self.pollenTypes.push({ color: flower.color, amount: collectAmount }); } // Restart trail with current color if (self.pollenTrail) { self.pollenTrail.active = false; // Force restart self.pollenTrail.startTrail(self.x, self.y, garden, self); } // Set currentPollen to match total of all types self.currentPollen = self.pollenTypes.reduce(function (total, type) { return total + type.amount; }, 0); self.currentColor = flower.color; // Add this back self.pollenTrail.currentColor = flower.color; flower.pollenCollected = true; flower.hasActivePollen = false; flower.removeFairyParticles(); // Update UI game.beeUI.updatePollen(flower.color, self.currentPollen, self.maxPollen); // Update UI using game.beeUI // Update meter self.pollenMeter.updateMeter(self.currentPollen, self.maxPollen); // Find exact position of this flower in grid var foundGridPos = false; var gridX = 0; var gridY = 0; for (var y = 0; y < garden.rows; y++) { for (var x = 0; x < garden.cols; x++) { if (garden.grid[y][x] === flower) { gridX = x; gridY = y; foundGridPos = true; break; } } if (foundGridPos) { break; } } if (foundGridPos && game.flowerMatcher) { game.flowerMatcher.checkForMatches(garden, gridX, gridY); } } }; self.checkFlowerCollision = function () { // Convert bee position to garden's local space var localPos = garden.toLocal({ x: self.x, y: self.y }, game); // Calculate grid position var gridX = Math.floor(localPos.x / garden.cellSize); var gridY = Math.floor(localPos.y / garden.cellSize); // Check if position is within grid bounds if (gridX >= 0 && gridX < garden.cols && gridY >= 0 && gridY < garden.rows) { var gridItem = garden.grid[gridY][gridX]; if (gridItem) { if (gridItem.isFlower && gridItem.hasActivePollen) { // Collect pollen from flower self.collectPollen(gridItem); } else if (gridItem && gridItem.isBud && self.currentPollen > 0) { if (gridItem.isBeingPollinated) { return; } gridItem.isBeingPollinated = true; var pollenColor = self.usePollen(gridItem); if (!pollenColor) { gridItem.isBeingPollinated = false; return; } // Double-check the bud is still there if (garden.grid[gridY][gridX] === gridItem && gridItem.isBud) { // Force remove the bud and clear grid position garden.removeChild(gridItem); garden.grid[gridY][gridX] = null; gridItem.destroy(); // Fully destroy the bud // Only create flower if position is clear if (!garden.grid[gridY][gridX]) { var newFlower = new BasicFlower(pollenColor); newFlower.x = gridItem.x; newFlower.y = gridItem.y; newFlower.isFlower = true; garden.grid[gridY][gridX] = newFlower; garden.addChild(newFlower); newFlower.bloom(); } } else { gridItem.isBeingPollinated = false; } } } } }; self.update = function () { if (self.isMoving) { // Smooth movement towards target self.x += (self.targetX - self.x) * self.moveSpeed; self.y += (self.targetY - self.y) * self.moveSpeed; // Calculate rotation based on movement direction var dx = self.targetX - self.x; var dy = self.targetY - self.y; var angle = Math.atan2(dy, dx); self.rotation = angle + Math.PI / 2; // Update trail when carrying pollen if (self.currentPollen > 0) { // Make sure trail starts if not already active if (!self.pollenTrail.active) { self.pollenTrail.startTrail(self.x, self.y, garden); } self.pollenTrail.updateTrail(self.x, self.y); } // Add collision check self.checkFlowerCollision(); } }; // Pollen usage method self.usePollen = function (bud) { // Add debug logs var pollenUsed = 7; if (self.currentPollen > 0 && self.pollenTypes.length > 0) { // If we have less than pollenUsed, use remaining pollen if (self.currentPollen < pollenUsed) { pollenUsed = self.currentPollen; } // Reduce pollen instead of zeroing it self.currentPollen -= pollenUsed; // Update pollen types properly var pType = self.pollenTypes[0]; var color = pType.color; // New line to store color pType.amount -= pollenUsed; // Update UI game.beeUI.updatePollen(color, self.currentPollen, self.maxPollen); // Update UI using game.beeUI // Only clear type if it's empty if (pType.amount <= 0) { self.pollenTypes.shift(); } // Only end trail if we're actually out of pollen if (self.currentPollen <= 0 || self.pollenTypes.length === 0) { self.pollenTrail.active = false; self.pollenTrail.points = []; } return color; // Updated to return color } return null; }; return self; }); // Bud class var Bud = Container.expand(function () { var self = Container.call(this); var budGraphics = self.attachAsset('Bud', { anchorX: 0.5, anchorY: 0.5 }); // Timer properties self.bloomTimer = 5 * 60; // 5 seconds (assuming 60fps) self.isBud = true; self.isFlower = false; self.isBeingReplaced = false; // Add this flag // Update now handles timer and auto-bloom self.update = function () { // Basic animation self.rotation = Math.sin(LK.ticks * 0.05) * 0.1; }; self.autoBloom = function () { if (!self.isBud || self.isBeingReplaced) { return; // Prevent double-blooming or if already being replaced } self.isBeingReplaced = true; // Get grid position var localPos = garden.toLocal({ x: self.x, y: self.y }, game); var gridX = Math.floor(localPos.x / garden.cellSize); var gridY = Math.floor(localPos.y / garden.cellSize); // Create random color flower var flowerColors = ['red', 'blue', 'yellow']; var randomColor = flowerColors[Math.floor(Math.random() * flowerColors.length)]; var newFlower = new BasicFlower(randomColor); newFlower.x = self.x; newFlower.y = self.y; newFlower.isFlower = true; newFlower.hasActivePollen = false; // Auto-bloomed flowers start dead // Update grid if (garden.grid[gridY] && garden.grid[gridY][gridX] === self) { garden.removeChild(self); garden.grid[gridY][gridX] = newFlower; garden.addChild(newFlower); newFlower.bloom(); } self.isBud = false; }; return self; }); // Add BudSpawner to handle progressive difficulty var BudSpawner = Container.expand(function () { var self = Container.call(this); self.garden = null; self.gameTime = 0; self.init = function (garden) { self.garden = garden; self.gameTime = 0; self.firstBloom = false; // Just set the first bloom timer self.nextBloomTime = 90; // 1.5 seconds for first bloom }; self.findEmptySpot = function () { var validSpots = []; // Match flower removal coordinate system [gridY][gridX] for (var gridY = 0; gridY < self.garden.rows; gridY++) { for (var gridX = 0; gridX < self.garden.cols; gridX++) { if (!self.garden.grid[gridY][gridX]) { validSpots.push({ x: gridX, y: gridY }); } } } if (validSpots.length > 0) { return validSpots[Math.floor(Math.random() * validSpots.length)]; } return null; }; self.getSpawnRate = function () { // Keep original timing logic return 16; // Spawn every frame for immediate filling }; self.update = function () { self.gameTime = LK.ticks / 60; // Count down to next bloom if (self.nextBloomTime > 0) { self.nextBloomTime--; if (self.nextBloomTime <= 0) { // Find a random bud to bloom var validBuds = []; for (var i = 0; i < self.garden.rows; i++) { for (var j = 0; j < self.garden.cols; j++) { var gridItem = self.garden.grid[i][j]; if (gridItem && gridItem.isBud) { validBuds.push({ item: gridItem, x: j, y: i }); } } } if (validBuds.length > 0) { // Pick a random bud var randomIndex = Math.floor(Math.random() * validBuds.length); var selectedBud = validBuds[randomIndex]; // Create the flower var flowerColors = ['red', 'blue', 'yellow']; var randomColor = flowerColors[Math.floor(Math.random() * flowerColors.length)]; var newFlower = new BasicFlower(randomColor); newFlower.x = selectedBud.item.x; newFlower.y = selectedBud.item.y; newFlower.isFlower = true; newFlower.hasActivePollen = false; // Auto-bloomed flowers start without pollen // Update grid self.garden.removeChild(selectedBud.item); self.garden.grid[selectedBud.y][selectedBud.x] = newFlower; self.garden.addChild(newFlower); newFlower.bloom(); // Set timer for next bloom (15-20 seconds) self.nextBloomTime = (15 + Math.random() * 5) * 60; } } } }; }); // Simplified FlowerManager - mainly for flower conversion and management var FlowerManager = Container.expand(function () { var self = Container.call(this); // Convert a bud to a flower self.convertBudToFlower = function (bud, garden) { var gridPos = { x: Math.floor((bud.y - garden.y) / garden.cellSize), y: Math.floor((bud.x - garden.x) / garden.cellSize) }; var newFlower = new BasicFlower(); newFlower.x = bud.x; newFlower.y = bud.y; newFlower.isFlower = true; garden.removeChild(bud); garden.grid[gridPos.x][gridPos.y] = newFlower; garden.addChild(newFlower); // When a flower blooms: createPollenBurst(newFlower.x, newFlower.y); return newFlower; }; // Empty touch handler as we're using the new trail system self.handleTouch = function () {}; }); var FlowerMatcher = Container.expand(function () { var self = Container.call(this); self.checkForMatches = function (garden, x, y) { var matches = self.findMatches(garden, x, y); if (matches.length >= 3) { self.clearMatches(garden, matches); return true; } return false; }; self.findMatches = function (garden, startX, startY) { if (startY < 0 || startY >= garden.rows || startX < 0 || startX >= garden.cols) { return []; } var startFlower = garden.grid[startY][startX]; if (!startFlower || !startFlower.isFlower) { return []; } var flowerColor = startFlower.color; var matches = []; var visited = {}; var _checkFlower = function checkFlower(x, y) { if (x < 0 || x >= garden.cols || y < 0 || y >= garden.rows) { return; } var key = x + ',' + y; if (visited[key]) { return; } visited[key] = true; var flower = garden.grid[y][x]; if (flower && flower.isFlower && !flower.hasActivePollen && flower.scale.x >= 1 && flower.pollenCollected && flower.color === flowerColor) { matches.push({ x: x, y: y, flower: flower }); _checkFlower(x + 1, y); _checkFlower(x - 1, y); _checkFlower(x, y + 1); _checkFlower(x, y - 1); } }; _checkFlower(startX, startY); return matches.length >= 3 ? matches : []; }; self.clearMatches = function (garden, matches) { matches.forEach(function (match) { var flower = match.flower; // Expand and pop animation tween(flower.scale, { x: 1.3, // Expand to 1.5 times the size y: 1.3 // Expand to 1.5 times the size }, { duration: 500, onFinish: function onFinish() { // Check if flower is still in expected position if (garden.grid[match.y][match.x] === flower) { // Create petal burst after animation self.createPetalBurst(match.x, match.y, flower.color); garden.grid[match.y][match.x] = null; garden.removeChild(flower); // Only create new bud if position is still empty if (!garden.grid[match.y][match.x]) { var newBud = new Bud(); newBud.x = flower.x; newBud.y = flower.y; newBud.scale.set(0, 0); garden.grid[match.y][match.x] = newBud; garden.addChild(newBud); tween(newBud.scale, { x: 1, y: 1 }, { duration: 1000, ease: 'elasticOut' }); } } } }); }); }; self.createPetalBurst = function (x, y, color) { var colorTints = { 'red': 0xFF0000, 'blue': 0x0000FF, 'yellow': 0xFFFF00, 'purple': 0x800080, 'orange': 0xFFA500, 'green': 0x00FF00 }; var worldPos = garden.gridToWorld(x, y); for (var i = 0; i < 12; i++) { var particle = new PollenParticle().init('burst'); var angle = i / 12 * Math.PI * 2; particle.x = worldPos.x; particle.y = worldPos.y; particle.vx = Math.cos(angle) * 8; particle.vy = Math.sin(angle) * 8; particle.scale.set(0.8); particle.tint = colorTints[color]; game.addChild(particle); } }; return self; }); //<Assets used in the game will automatically appear here> // Garden class to manage the grid of soil var Garden = Container.expand(function () { var self = Container.call(this); // Add new helper method for safe grid updates self.updateGridPosition = function (row, col, item) { if (row >= 0 && row < self.rows && col >= 0 && col < self.cols) { // First clear any existing item var existingItem = self.grid[row][col]; if (existingItem && existingItem.parent) { existingItem.parent.removeChild(existingItem); } // Then set new item self.grid[row][col] = item; return true; } return false; }; self.grid = []; self.rows = 8; self.cols = 8; self.cellSize = 210; self.init = function () { var _this = this; // Add source flowers this.sourceFlowers = new Container(); this.addChild(this.sourceFlowers); // Calculate positions var centerX = this.cols * this.cellSize / 2; // Blue flower at top center var blueFlower = new SourceFlower('blue'); blueFlower.x = centerX; blueFlower.y = -75; // Moved closer to top row this.sourceFlowers.addChild(blueFlower); // Red flower at bottom left corner (under the garden) var redFlower = new SourceFlower('red'); redFlower.x = 0; redFlower.y = (this.rows + 1) * this.cellSize; this.sourceFlowers.addChild(redFlower); // Yellow flower at bottom right corner (under the garden) var yellowFlower = new SourceFlower('yellow'); yellowFlower.x = (this.cols - 1) * this.cellSize; yellowFlower.y = (this.rows + 1) * this.cellSize; this.sourceFlowers.addChild(yellowFlower); // Center the grid on screen self.x = (2048 - self.cols * self.cellSize) / 2; self.y = (2732 - self.rows * self.cellSize) / 2 + 2732 * 0.12 - 400; // Initialize grid and fill with buds for (var i = 0; i < self.rows; i++) { self.grid[i] = []; for (var j = 0; j < self.cols; j++) { var bud = new Bud(); bud.x = j * self.cellSize + self.cellSize / 2; bud.y = i * self.cellSize + self.cellSize / 2; bud.isBud = true; bud.isFlower = false; self.grid[i][j] = bud; self.addChild(bud); } } }; // Helper method to convert grid position to world position self.gridToWorld = function (gridX, gridY) { return { x: self.x + gridX * self.cellSize + self.cellSize / 2, y: self.y + gridY * self.cellSize + self.cellSize / 2 }; }; // Helper method to convert world position to grid position self.worldToGrid = function (worldX, worldY) { var localX = worldX - self.x; var localY = worldY - self.y; return { x: Math.floor(localX / self.cellSize), y: Math.floor(localY / self.cellSize) }; }; }); // GardenBackground class var GardenBackground = Container.expand(function () { var self = Container.call(this); var gardenBackground = LK.getAsset('GardenBackground', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.02, scaleY: 1.02, x: 2048 / 2, y: 2732 / 2 }); self.addChild(gardenBackground); }); var Hive = Container.expand(function () { var self = Container.call(this); var hiveSprite = self.attachAsset('Hive', { anchorX: 0.5, anchorY: 0.5 }); self.storedPollen = { 'red': 0, 'blue': 0, 'yellow': 0 }; // Add meter above hive self.pollenMeter = new PollenMeter(); self.pollenMeter.y = -200; self.addChild(self.pollenMeter); // Collection method self.collectFromBee = function (bee) { if (bee.currentPollen > 0) { // Transfer each type of pollen bee.pollenTypes.forEach(function (type) { // Initialize hive's stored pollen for this color if needed if (!self.storedPollen) { self.storedPollen = {}; } if (!self.storedPollen[type.color]) { self.storedPollen[type.color] = 0; } // Add to hive's storage self.storedPollen[type.color] += type.amount; // Update hive UI game.hiveUI.updatePollen(type.color, self.storedPollen[type.color], 1000); // Update UI using game.hiveUI }); // Create particles spread across the hive's width var particleCount = 20; var hiveWidth = 300; for (var i = 0; i < particleCount; i++) { var particle = new PollenParticle().init('transfer'); particle.x = -hiveWidth / 2 + Math.random() * hiveWidth; particle.y = -200; particle.vx = (Math.random() - 0.5) * 0.5; particle.vy = 1 + Math.random(); particle.twinkleOffset = Math.random() * Math.PI * 2; particle.twinkleSpeed = 0.1 + Math.random() * 0.1; particle.scale.set(0.5); self.addChild(particle); } // Clear bee's pollen bee.currentPollen = 0; bee.pollenTypes = []; // Update bee UI to show empty ['red', 'blue', 'yellow'].forEach(function (color) { game.beeUI.updatePollen(color, 0, bee.maxPollen); // Clear bee's pollen using game.beeUI }); // End bee's trail bee.pollenTrail.active = false; bee.pollenTrail.points = []; } }; return self; }); var PollenMeter = Container.expand(function () { var self = Container.call(this); // Create background bar var background = LK.getAsset('marker', { anchorX: 0.5, anchorY: 0.5, scaleX: 1, scaleY: 0.1 }); self.addChild(background); // Create fill bar var fill = LK.getAsset('marker', { anchorX: 0.5, anchorY: 0.5, scaleX: 0, scaleY: 0.1 }); fill.tint = 0xFFFF00; // Yellow for pollen self.fillBar = fill; self.addChild(fill); // Update method to show current pollen self.updateMeter = function (current, max) { fill.scale.x = current / max; }; return self; }); // PollenParticle class var PollenParticle = Container.expand(function () { var self = Container.call(this); // Particle properties self.velocity = { x: 0, y: 0 }; self.lifespan = 1; // Goes from 1 to 0 self.decayRate = 0.02; // How fast the particle fades self.type = 'trail'; // Can be 'trail' or 'burst' // Create the visual element var assetMap = { 'trail': 'PollenSparkle', 'burst': 'Petal', 'fairy': 'PollenSparkle', 'transfer': 'PollenSparkle' }; var pollenGraphics; // Initialize with random properties for more organic feel self.init = function (type) { self.type = type || 'trail'; if (!pollenGraphics) { pollenGraphics = self.attachAsset(assetMap[self.type], { anchorX: 0.5, anchorY: 0.5 }); } // Set initial scale based on type if (self.type === 'trail') { self.scale.set(0.7 + Math.random() * 0.3); // Larger for trail self.decayRate = 0.03; // Faster decay for trail // Slight random velocity for trail movement self.velocity = { x: (Math.random() - 0.5) * 2, y: (Math.random() - 0.5) * 2 }; } else if (self.type === 'burst') { self.scale.set(0.5 + Math.random() * 0.3); // Smaller initial size for bursts self.decayRate = 0.01; // Slower decay for longer travel // Radial burst velocity var angle = Math.random() * Math.PI * 2; var speed = 3 + Math.random() * 5; // Increased speed for further travel self.velocity = { x: Math.cos(angle) * speed, y: Math.sin(angle) * speed }; } else if (self.type === 'fairy') { self.lifespan = undefined; // Don't fade out self.startAngle = Math.random() * Math.PI * 2; // Random start position self.orbitRadius = 20 + Math.random() * 40; // Increase orbit radius variation self.orbitSpeed = 0.005 + Math.random() * 0.03; // Increase orbit speed variation self.update = function () { var time = LK.ticks * self.orbitSpeed; // Orbit motion self.x = Math.cos(time + self.startAngle) * self.orbitRadius; self.y = Math.sin(time + self.startAngle) * self.orbitRadius; // Add bobbing self.y += Math.sin(time * 2 + self.startAngle) * 10; }; } // Random rotation speed self.rotationSpeed = (Math.random() - 0.5) * 0.2; // Random starting rotation self.rotation = Math.random() * Math.PI * 2; // Add random rotation speed for dynamic movement self.rotationSpeed = (Math.random() - 0.5) * 0.2; // Full opacity to start self.alpha = 1; if (self.type === 'transfer') { self.scale.set(0.5); self.alpha = 1; self.twinkleOffset = 0; // Initialize twinkle offset self.twinkleSpeed = 0.1; // Initialize twinkle speed self.update = function () { // Gentle drift down self.x += self.vx; self.y += self.vy; // Individual twinkle effect self.alpha = 0.6 + Math.sin(LK.ticks * self.twinkleSpeed + self.twinkleOffset) * 0.4; // Remove when below hive if (self.y > 100) { self.destroy(); } }; } return self; }; self.update = function () { // Update position based on velocity self.x += self.velocity.x; self.y += self.velocity.y; // Add rotation self.rotation += self.rotationSpeed; // Slow down velocity over time self.velocity.x *= 0.95; self.velocity.y *= 0.95; // Update lifespan and alpha self.lifespan -= self.decayRate; self.alpha = self.lifespan; // Scale slightly varies with life var scalePulse = 1 + Math.sin(LK.ticks * 0.2) * 0.1; pollenGraphics.scale.set(scalePulse * self.scale.x); // Remove when lifecycle complete if (self.lifespan <= 0) { self.destroy(); } }; }); // First, let's add a PollenTrail class to handle the dragging mechanic var PollenTrail = Container.expand(function () { var self = Container.call(this); self.points = []; self.active = false; self.currentGarden = null; // Store reference to garden self.MAX_SPEED = 15; // Adjust this value for proper feel self.startTrail = function (x, y, garden, bee) { self.active = true; self.points = [{ x: x, y: y, time: Date.now() }]; self.startTime = Date.now(); self.trailStartTime = Date.now(); self.currentGarden = garden; self.bee = bee; // Store bee reference self.lastPoint = { x: x, y: y }; // Initialize lastPoint // Force red on first particle to verify bee storage var particle = new PollenParticle().init('trail'); particle.children[0].tint = 0xFF0000; particle.x = x; particle.y = y; game.addChild(particle); }; self.updateTrail = function (x, y) { if (!self.active) { return; } // Enforce maximum speed var dx = x - self.lastPoint.x; var dy = y - self.lastPoint.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > self.MAX_SPEED) { var ratio = self.MAX_SPEED / distance; x = self.lastPoint.x + dx * ratio; y = self.lastPoint.y + dy * ratio; } self.points.push({ x: x, y: y, time: Date.now() }); self.lastPoint = { x: x, y: y }; // Create particle effect along trail var particle = new PollenParticle().init('trail'); if (self.bee && self.bee.pollenTypes && self.bee.pollenTypes[0]) { if (self.bee.pollenTypes[0].color === 'red') { particle.children[0].tint = 0xFF0000; } else if (self.bee.pollenTypes[0].color === 'blue') { particle.children[0].tint = 0x0000FF; } else if (self.bee.pollenTypes[0].color === 'yellow') { particle.children[0].tint = 0xFFFF00; } } particle.x = x; particle.y = y; game.addChild(particle); }; // Add the burst effect function self.createPollenBurst = function (x, y) { for (var i = 0; i < 12; i++) { var particle = new PollenParticle().init('burst'); var angle = i / 12 * Math.PI * 2; var distance = 30; particle.x = x + Math.cos(angle) * distance; particle.y = y + Math.sin(angle) * distance; // Give particles outward velocity particle.vx = Math.cos(angle) * 3; particle.vy = Math.sin(angle) * 3; game.addChild(particle); } }; self.endTrail = function () { if (!self.active) { return; } var affectedBuds = []; var checkedPositions = {}; self.points.forEach(function (point) { var localPos = self.currentGarden.toLocal({ x: point.x, y: point.y }, game); var gridX = Math.floor(localPos.x / self.currentGarden.cellSize); var gridY = Math.floor(localPos.y / self.currentGarden.cellSize); var posKey = gridX + ',' + gridY; if (!checkedPositions[posKey] && gridX >= 0 && gridX < self.currentGarden.cols && gridY >= 0 && gridY < self.currentGarden.rows) { checkedPositions[posKey] = true; var gridItem = self.currentGarden.grid[gridY][gridX]; // Verify it's a valid bud if (gridItem && gridItem.isBud === true && gridItem.isFlower === false) { affectedBuds.push({ bud: gridItem, gridX: gridX, gridY: gridY }); } } }); if (affectedBuds.length >= 2) { affectedBuds.forEach(function (budInfo) { // IMPORTANT: Clear the grid position first self.currentGarden.grid[budInfo.gridY][budInfo.gridX] = null; // Remove the bud from display list self.currentGarden.removeChild(budInfo.bud); // Create new flower var newFlower = new BasicFlower(); newFlower.x = budInfo.bud.x; newFlower.y = budInfo.bud.y; newFlower.isFlower = true; // Update grid position and add to display list self.currentGarden.grid[budInfo.gridY][budInfo.gridX] = newFlower; self.currentGarden.addChild(newFlower); // Start bloom animation newFlower.bloom(); }); } self.active = false; self.points = []; }; self.update = function () { // Just update particles, no time checks // Update all children particles for (var i = self.children.length - 1; i >= 0; i--) { var particle = self.children[i]; if (particle && particle.update) { particle.update(); } } }; }); var PollenUI = Container.expand(function () { var self = Container.call(this); // Create cells with their fill indicators // Red cell and fill // Red cell initialization and position var redCell = LK.getAsset('pollenCellBase', { anchorX: 0.5, anchorY: 0.5, x: -300 // Set position in initialization }); redCell.tint = 0xFF0000; redCell.alpha = 0.4; self.addChild(redCell); self.redFill = LK.getAsset('pollenCellBase', { anchorX: 0.5, anchorY: 0, x: -300 // Set position in initialization }); self.redFill.tint = 0xFF0000; self.redFill.alpha = 0.7; self.redFill.y = 90; self.redFill.scale.y = 0; self.addChild(self.redFill); // Blue cell initialization and position var blueCell = LK.getAsset('pollenCellBase', { anchorX: 0.5, anchorY: 0.5, x: 0 // Set position in initialization }); blueCell.tint = 0x0000FF; blueCell.alpha = 0.4; self.addChild(blueCell); self.blueFill = LK.getAsset('pollenCellBase', { anchorX: 0.5, anchorY: 0, x: 0 // Set position in initialization }); self.blueFill.tint = 0x0000FF; self.blueFill.alpha = 0.7; self.blueFill.y = 90; self.blueFill.scale.y = 0; self.addChild(self.blueFill); // Yellow cell initialization and position var yellowCell = LK.getAsset('pollenCellBase', { anchorX: 0.5, anchorY: 0.5, x: 300 // Set position in initialization }); yellowCell.tint = 0xFFFF00; yellowCell.alpha = 0.4; self.addChild(yellowCell); self.yellowFill = LK.getAsset('pollenCellBase', { anchorX: 0.5, anchorY: 0, x: 300 // Set position in initialization }); self.yellowFill.tint = 0xFFFF00; self.yellowFill.alpha = 0.7; self.yellowFill.y = 90; self.yellowFill.scale.y = 0; self.addChild(self.yellowFill); // Add update method self.updatePollen = function (color, amount, max) { var fillAmount = Math.min(amount / max, 1); if (color === 'red') { self.redFill.scale.y = fillAmount; self.redFill.y = 90 - 180 * fillAmount; // Start at 90, move up as it fills } else if (color === 'blue') { self.blueFill.scale.y = fillAmount; self.blueFill.y = 90 - 180 * fillAmount; } else if (color === 'yellow') { self.yellowFill.scale.y = fillAmount; self.yellowFill.y = 90 - 180 * fillAmount; } }; return self; }); // Add ScoreManager to handle chain reactions and scoring var ScoreManager = Container.expand(function () { var self = Container.call(this); self.currentScore = 0; self.currentChain = 0; self.chainMultiplier = 1; self.addToChain = function () { self.currentChain++; self.chainMultiplier = Math.min(1 + self.currentChain * 0.5, 5); // Cap at 5x self.addScore(100 * self.chainMultiplier); }; self.resetChain = function () { self.currentChain = 0; self.chainMultiplier = 1; }; self.addScore = function (points) { self.currentScore += Math.floor(points); // Update score display if (game.scoreDisplay) { game.scoreDisplay.text = self.currentScore.toString(); } }; }); var SourceFlower = Container.expand(function (color) { var self = Container.call(this); // Store flower color self.color = color; self.isSourceFlower = true; // Flag to identify source flowers // Map color to asset name var assetMap = { 'red': 'RedFlower', 'blue': 'BlueFlower', 'yellow': 'YellowFlower' }; // Create flower sprite var flowerGraphics = self.attachAsset(assetMap[self.color], { anchorX: 0.5, anchorY: 0.5 }); // Source flowers always have pollen self.hasActivePollen = true; self.fairyParticles = []; self.FAIRY_COUNT = 3; // Initialize fairy particles for (var i = 0; i < self.FAIRY_COUNT; i++) { var fairy = new PollenParticle().init('fairy'); fairy.scale.set(0.3 + Math.random() * 0.2); fairy.x += (Math.random() - 0.5) * 60; fairy.y += (Math.random() - 0.5) * 60; fairy.rotation = Math.random() * Math.PI * 2; fairy.rotationSpeed = (Math.random() - 0.5) * 0.2; self.addChild(fairy); self.fairyParticles.push(fairy); } // Gentle animation self.update = function () { var scaleFactor = 1 + Math.sin(LK.ticks * 0.1) * 0.05; flowerGraphics.scale.x = scaleFactor; flowerGraphics.scale.y = scaleFactor; flowerGraphics.rotation = Math.sin(LK.ticks * 0.1) * 0.05; // Update fairy particles self.fairyParticles.forEach(function (fairy) { if (fairy && fairy.update) { fairy.update(); } }); }; // Override collection behavior - source flowers regenerate pollen immediately self.pollenCollected = false; self.resetPollen = function () { self.hasActivePollen = true; self.pollenCollected = false; }; return self; }); // Level display class var LevelDisplay = Text2.expand(function () { var self = Text2.call(this, 'Level 1', { size: 150, fill: 0xFFFFFF }); }); // Score display class var ScoreDisplay = Text2.expand(function () { var self = Text2.call(this, '0', { size: 150, fill: 0xFFFFFF }); }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Declare and initialize flowerManager in global scope var flowerManager = new FlowerManager(); var titleScreen = new Container(); var background = LK.getAsset('titlebackground', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 }); titleScreen.addChild(background); var logo = LK.getAsset('logo', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 }); titleScreen.addChild(logo); var playButton = LK.getAsset('playButton', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 + 200 }); titleScreen.addChild(playButton); var tutorialButton = LK.getAsset('tutorialButton', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 + 400 }); titleScreen.addChild(tutorialButton); game.addChild(titleScreen); playButton.down = function (x, y, obj) { game.removeChild(titleScreen); var gardenBackground = new GardenBackground(); game.addChild(gardenBackground); garden = new Garden(); garden.init(); game.addChild(garden); var flowerManager = new FlowerManager(); game.flowerMatcher = new FlowerMatcher(); game.addChild(game.flowerMatcher); var pollenTrail = new PollenTrail(); game.addChild(pollenTrail); // Create and position hive var hive = new Hive(); hive.x = 2048 / 2; hive.y = 2732 * 0.97 - 200; // Create bee and position above hive var bee = new Bee(); bee.x = hive.x; bee.y = hive.y - 150; // Create UI and attach to game object so it's globally accessible game.beeUI = new PollenUI(); game.beeUI.position.set(hive.x - 600, hive.y + 100); game.beeUI.scale.set(0.8); game.addChild(game.beeUI); game.hiveUI = new PollenUI(); game.hiveUI.position.set(hive.x + 600, hive.y + 100); game.addChild(game.hiveUI); // Add objects to game game.addChild(hive); game.addChild(bee); // Ensure pollen particles are rendered on top by adding them last game.setChildIndex(pollenTrail, game.children.length - 1); // Initialize bud spawner garden.budSpawner = new BudSpawner(); garden.budSpawner.init(garden); game.addChild(garden.budSpawner); // Touch handlers game.down = function (x, y, obj) { bee.isMoving = true; bee.targetX = x; bee.targetY = y; }; game.move = function (x, y, obj) { if (bee.isMoving) { bee.targetX = x; bee.targetY = y - 200; } }; game.up = function (x, y, obj) { bee.isMoving = false; }; // Initialize score display var scoreDisplay = new ScoreDisplay(); scoreDisplay.anchor.set(0.5, 0); LK.gui.top.addChild(scoreDisplay); game.scoreDisplay = scoreDisplay; // Add the main update loop game.update = function () { // Update spawning system if (game.budSpawner) { game.budSpawner.update(); } // Update trail system if (pollenTrail) { pollenTrail.update(); } // Update garden elements if (garden) { // Update all flowers and buds in the grid for (var i = 0; i < garden.rows; i++) { for (var j = 0; j < garden.cols; j++) { var gridItem = garden.grid[i][j]; if (gridItem && gridItem.update) { gridItem.update(); } } } } // Update all children that have update methods for (var i = 0; i < game.children.length; i++) { var child = game.children[i]; if (child && child.update) { child.update(); } } // Update all particles if (game.particlesToUpdate) { for (var i = game.particlesToUpdate.length - 1; i >= 0; i--) { var particle = game.particlesToUpdate[i]; if (particle && particle.update) { particle.update(); } } } // Update bee if (bee && bee.update) { bee.update(); // Collision detection between bee and hive if (hive) { var dx = bee.x - hive.x; var dy = bee.y - hive.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < 100) { // Adjust collection radius as needed hive.collectFromBee(bee); } } } }; }; tutorialButton.down = function (x, y, obj) { // Open tutorial }; // Removed duplicate playPollenPatternAnimation method
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var BasicFlower = Container.expand(function (color) {
var self = Container.call(this);
// Store flower color
self.color = color || 'red'; // Default to red if no color specified
// Map color to asset name
var assetMap = {
'red': 'RedFlower',
'blue': 'BlueFlower',
'yellow': 'YellowFlower'
};
// Attach bud asset first
var budGraphics = self.attachAsset('Bud', {
anchorX: 0.5,
anchorY: 0.5
});
// Use correct asset based on color
var flowerGraphics = self.attachAsset(assetMap[self.color], {
anchorX: 0.5,
anchorY: 0.5
});
self.hasActivePollen = false;
self.fairyParticles = [];
self.FAIRY_COUNT = 3;
self.update = function () {
var scaleFactor = 1 + Math.sin(LK.ticks * 0.1) * 0.05;
flowerGraphics.scale.x = scaleFactor;
flowerGraphics.scale.y = scaleFactor;
flowerGraphics.rotation = Math.sin(LK.ticks * 0.1) * 0.05;
};
self.bloom = function () {
// Scale animation
self.scale.set(0.3, 0.3);
tween(self.scale, {
x: 1,
y: 1
}, {
duration: 1000,
onFinish: function onFinish() {
// After bloom animation, delay before activating pollen
LK.setTimeout(function () {
self.hasActivePollen = true;
// Create fairy particles after delay
for (var i = 0; i < self.FAIRY_COUNT; i++) {
var fairy = new PollenParticle().init('fairy');
fairy.scale.set(0.3 + Math.random() * 0.2);
fairy.x += (Math.random() - 0.5) * 60;
fairy.y += (Math.random() - 0.5) * 60;
fairy.rotation = Math.random() * Math.PI * 2;
fairy.rotationSpeed = (Math.random() - 0.5) * 0.2;
self.addChild(fairy);
self.fairyParticles.push(fairy);
}
}, 1000); // 1 second delay after bloom before pollen activates
}
});
// Create initial burst particles
self.createPollenBurst(self.x, self.y);
self.removeFairyParticles = function () {
self.fairyParticles.forEach(function (fairy) {
self.removeChild(fairy);
});
self.fairyParticles = [];
};
};
self.createPollenBurst = function (x, y) {
for (var i = 0; i < 12; i++) {
var particle = new PollenParticle().init('burst');
var angle = i / 12 * Math.PI * 2;
particle.x = x;
particle.y = y;
particle.vx = Math.cos(angle) * 3;
particle.vy = Math.sin(angle) * 3;
if (self.parent) {
self.parent.addChild(particle);
}
}
};
// Initialize pollen status
self.pollenCollected = false; // New flag to track if we've collected from it
});
var Bee = Container.expand(function () {
var self = Container.call(this);
self.currentColor = null; // Add this back
// Movement properties
var beeSprite = self.attachAsset('Bee', {
anchorX: 0.5,
anchorY: 0.5
});
// Movement properties
self.targetX = self.x;
self.targetY = self.y;
self.moveSpeed = 0.1; // Adjust this for faster/slower following
self.isMoving = false;
// New pollen properties
self.maxPollen = 50; // Cap pollen amount
self.currentPollen = 0; // Current amount being carried
self.pollenTypes = []; // Array to track different pollen colors
// Format: [{color: 'red', amount: 30}, ...]
self.pollenMeter = new PollenMeter();
self.pollenMeter.y = -50; // Position above bee
self.addChild(self.pollenMeter);
// Add trail property
self.pollenTrail = new PollenTrail();
game.addChild(self.pollenTrail); // Add to game so it renders behind bee
// Pollen collection method
self.collectPollen = function (flower) {
if (self.currentPollen < self.maxPollen && flower.hasActivePollen && !flower.pollenCollected) {
var collectAmount = 25;
// Add to pollen types first
var existingType = self.pollenTypes.find(function (p) {
return p.color === flower.color;
});
if (existingType) {
existingType.amount += collectAmount;
} else {
self.pollenTypes.push({
color: flower.color,
amount: collectAmount
});
}
// Restart trail with current color
if (self.pollenTrail) {
self.pollenTrail.active = false; // Force restart
self.pollenTrail.startTrail(self.x, self.y, garden, self);
}
// Set currentPollen to match total of all types
self.currentPollen = self.pollenTypes.reduce(function (total, type) {
return total + type.amount;
}, 0);
self.currentColor = flower.color; // Add this back
self.pollenTrail.currentColor = flower.color;
flower.pollenCollected = true;
flower.hasActivePollen = false;
flower.removeFairyParticles();
// Update UI
game.beeUI.updatePollen(flower.color, self.currentPollen, self.maxPollen); // Update UI using game.beeUI
// Update meter
self.pollenMeter.updateMeter(self.currentPollen, self.maxPollen);
// Find exact position of this flower in grid
var foundGridPos = false;
var gridX = 0;
var gridY = 0;
for (var y = 0; y < garden.rows; y++) {
for (var x = 0; x < garden.cols; x++) {
if (garden.grid[y][x] === flower) {
gridX = x;
gridY = y;
foundGridPos = true;
break;
}
}
if (foundGridPos) {
break;
}
}
if (foundGridPos && game.flowerMatcher) {
game.flowerMatcher.checkForMatches(garden, gridX, gridY);
}
}
};
self.checkFlowerCollision = function () {
// Convert bee position to garden's local space
var localPos = garden.toLocal({
x: self.x,
y: self.y
}, game);
// Calculate grid position
var gridX = Math.floor(localPos.x / garden.cellSize);
var gridY = Math.floor(localPos.y / garden.cellSize);
// Check if position is within grid bounds
if (gridX >= 0 && gridX < garden.cols && gridY >= 0 && gridY < garden.rows) {
var gridItem = garden.grid[gridY][gridX];
if (gridItem) {
if (gridItem.isFlower && gridItem.hasActivePollen) {
// Collect pollen from flower
self.collectPollen(gridItem);
} else if (gridItem && gridItem.isBud && self.currentPollen > 0) {
if (gridItem.isBeingPollinated) {
return;
}
gridItem.isBeingPollinated = true;
var pollenColor = self.usePollen(gridItem);
if (!pollenColor) {
gridItem.isBeingPollinated = false;
return;
}
// Double-check the bud is still there
if (garden.grid[gridY][gridX] === gridItem && gridItem.isBud) {
// Force remove the bud and clear grid position
garden.removeChild(gridItem);
garden.grid[gridY][gridX] = null;
gridItem.destroy(); // Fully destroy the bud
// Only create flower if position is clear
if (!garden.grid[gridY][gridX]) {
var newFlower = new BasicFlower(pollenColor);
newFlower.x = gridItem.x;
newFlower.y = gridItem.y;
newFlower.isFlower = true;
garden.grid[gridY][gridX] = newFlower;
garden.addChild(newFlower);
newFlower.bloom();
}
} else {
gridItem.isBeingPollinated = false;
}
}
}
}
};
self.update = function () {
if (self.isMoving) {
// Smooth movement towards target
self.x += (self.targetX - self.x) * self.moveSpeed;
self.y += (self.targetY - self.y) * self.moveSpeed;
// Calculate rotation based on movement direction
var dx = self.targetX - self.x;
var dy = self.targetY - self.y;
var angle = Math.atan2(dy, dx);
self.rotation = angle + Math.PI / 2;
// Update trail when carrying pollen
if (self.currentPollen > 0) {
// Make sure trail starts if not already active
if (!self.pollenTrail.active) {
self.pollenTrail.startTrail(self.x, self.y, garden);
}
self.pollenTrail.updateTrail(self.x, self.y);
}
// Add collision check
self.checkFlowerCollision();
}
};
// Pollen usage method
self.usePollen = function (bud) {
// Add debug logs
var pollenUsed = 7;
if (self.currentPollen > 0 && self.pollenTypes.length > 0) {
// If we have less than pollenUsed, use remaining pollen
if (self.currentPollen < pollenUsed) {
pollenUsed = self.currentPollen;
}
// Reduce pollen instead of zeroing it
self.currentPollen -= pollenUsed;
// Update pollen types properly
var pType = self.pollenTypes[0];
var color = pType.color; // New line to store color
pType.amount -= pollenUsed;
// Update UI
game.beeUI.updatePollen(color, self.currentPollen, self.maxPollen); // Update UI using game.beeUI
// Only clear type if it's empty
if (pType.amount <= 0) {
self.pollenTypes.shift();
}
// Only end trail if we're actually out of pollen
if (self.currentPollen <= 0 || self.pollenTypes.length === 0) {
self.pollenTrail.active = false;
self.pollenTrail.points = [];
}
return color; // Updated to return color
}
return null;
};
return self;
});
// Bud class
var Bud = Container.expand(function () {
var self = Container.call(this);
var budGraphics = self.attachAsset('Bud', {
anchorX: 0.5,
anchorY: 0.5
});
// Timer properties
self.bloomTimer = 5 * 60; // 5 seconds (assuming 60fps)
self.isBud = true;
self.isFlower = false;
self.isBeingReplaced = false; // Add this flag
// Update now handles timer and auto-bloom
self.update = function () {
// Basic animation
self.rotation = Math.sin(LK.ticks * 0.05) * 0.1;
};
self.autoBloom = function () {
if (!self.isBud || self.isBeingReplaced) {
return; // Prevent double-blooming or if already being replaced
}
self.isBeingReplaced = true;
// Get grid position
var localPos = garden.toLocal({
x: self.x,
y: self.y
}, game);
var gridX = Math.floor(localPos.x / garden.cellSize);
var gridY = Math.floor(localPos.y / garden.cellSize);
// Create random color flower
var flowerColors = ['red', 'blue', 'yellow'];
var randomColor = flowerColors[Math.floor(Math.random() * flowerColors.length)];
var newFlower = new BasicFlower(randomColor);
newFlower.x = self.x;
newFlower.y = self.y;
newFlower.isFlower = true;
newFlower.hasActivePollen = false; // Auto-bloomed flowers start dead
// Update grid
if (garden.grid[gridY] && garden.grid[gridY][gridX] === self) {
garden.removeChild(self);
garden.grid[gridY][gridX] = newFlower;
garden.addChild(newFlower);
newFlower.bloom();
}
self.isBud = false;
};
return self;
});
// Add BudSpawner to handle progressive difficulty
var BudSpawner = Container.expand(function () {
var self = Container.call(this);
self.garden = null;
self.gameTime = 0;
self.init = function (garden) {
self.garden = garden;
self.gameTime = 0;
self.firstBloom = false;
// Just set the first bloom timer
self.nextBloomTime = 90; // 1.5 seconds for first bloom
};
self.findEmptySpot = function () {
var validSpots = [];
// Match flower removal coordinate system [gridY][gridX]
for (var gridY = 0; gridY < self.garden.rows; gridY++) {
for (var gridX = 0; gridX < self.garden.cols; gridX++) {
if (!self.garden.grid[gridY][gridX]) {
validSpots.push({
x: gridX,
y: gridY
});
}
}
}
if (validSpots.length > 0) {
return validSpots[Math.floor(Math.random() * validSpots.length)];
}
return null;
};
self.getSpawnRate = function () {
// Keep original timing logic
return 16; // Spawn every frame for immediate filling
};
self.update = function () {
self.gameTime = LK.ticks / 60;
// Count down to next bloom
if (self.nextBloomTime > 0) {
self.nextBloomTime--;
if (self.nextBloomTime <= 0) {
// Find a random bud to bloom
var validBuds = [];
for (var i = 0; i < self.garden.rows; i++) {
for (var j = 0; j < self.garden.cols; j++) {
var gridItem = self.garden.grid[i][j];
if (gridItem && gridItem.isBud) {
validBuds.push({
item: gridItem,
x: j,
y: i
});
}
}
}
if (validBuds.length > 0) {
// Pick a random bud
var randomIndex = Math.floor(Math.random() * validBuds.length);
var selectedBud = validBuds[randomIndex];
// Create the flower
var flowerColors = ['red', 'blue', 'yellow'];
var randomColor = flowerColors[Math.floor(Math.random() * flowerColors.length)];
var newFlower = new BasicFlower(randomColor);
newFlower.x = selectedBud.item.x;
newFlower.y = selectedBud.item.y;
newFlower.isFlower = true;
newFlower.hasActivePollen = false; // Auto-bloomed flowers start without pollen
// Update grid
self.garden.removeChild(selectedBud.item);
self.garden.grid[selectedBud.y][selectedBud.x] = newFlower;
self.garden.addChild(newFlower);
newFlower.bloom();
// Set timer for next bloom (15-20 seconds)
self.nextBloomTime = (15 + Math.random() * 5) * 60;
}
}
}
};
});
// Simplified FlowerManager - mainly for flower conversion and management
var FlowerManager = Container.expand(function () {
var self = Container.call(this);
// Convert a bud to a flower
self.convertBudToFlower = function (bud, garden) {
var gridPos = {
x: Math.floor((bud.y - garden.y) / garden.cellSize),
y: Math.floor((bud.x - garden.x) / garden.cellSize)
};
var newFlower = new BasicFlower();
newFlower.x = bud.x;
newFlower.y = bud.y;
newFlower.isFlower = true;
garden.removeChild(bud);
garden.grid[gridPos.x][gridPos.y] = newFlower;
garden.addChild(newFlower);
// When a flower blooms:
createPollenBurst(newFlower.x, newFlower.y);
return newFlower;
};
// Empty touch handler as we're using the new trail system
self.handleTouch = function () {};
});
var FlowerMatcher = Container.expand(function () {
var self = Container.call(this);
self.checkForMatches = function (garden, x, y) {
var matches = self.findMatches(garden, x, y);
if (matches.length >= 3) {
self.clearMatches(garden, matches);
return true;
}
return false;
};
self.findMatches = function (garden, startX, startY) {
if (startY < 0 || startY >= garden.rows || startX < 0 || startX >= garden.cols) {
return [];
}
var startFlower = garden.grid[startY][startX];
if (!startFlower || !startFlower.isFlower) {
return [];
}
var flowerColor = startFlower.color;
var matches = [];
var visited = {};
var _checkFlower = function checkFlower(x, y) {
if (x < 0 || x >= garden.cols || y < 0 || y >= garden.rows) {
return;
}
var key = x + ',' + y;
if (visited[key]) {
return;
}
visited[key] = true;
var flower = garden.grid[y][x];
if (flower && flower.isFlower && !flower.hasActivePollen && flower.scale.x >= 1 && flower.pollenCollected && flower.color === flowerColor) {
matches.push({
x: x,
y: y,
flower: flower
});
_checkFlower(x + 1, y);
_checkFlower(x - 1, y);
_checkFlower(x, y + 1);
_checkFlower(x, y - 1);
}
};
_checkFlower(startX, startY);
return matches.length >= 3 ? matches : [];
};
self.clearMatches = function (garden, matches) {
matches.forEach(function (match) {
var flower = match.flower;
// Expand and pop animation
tween(flower.scale, {
x: 1.3,
// Expand to 1.5 times the size
y: 1.3 // Expand to 1.5 times the size
}, {
duration: 500,
onFinish: function onFinish() {
// Check if flower is still in expected position
if (garden.grid[match.y][match.x] === flower) {
// Create petal burst after animation
self.createPetalBurst(match.x, match.y, flower.color);
garden.grid[match.y][match.x] = null;
garden.removeChild(flower);
// Only create new bud if position is still empty
if (!garden.grid[match.y][match.x]) {
var newBud = new Bud();
newBud.x = flower.x;
newBud.y = flower.y;
newBud.scale.set(0, 0);
garden.grid[match.y][match.x] = newBud;
garden.addChild(newBud);
tween(newBud.scale, {
x: 1,
y: 1
}, {
duration: 1000,
ease: 'elasticOut'
});
}
}
}
});
});
};
self.createPetalBurst = function (x, y, color) {
var colorTints = {
'red': 0xFF0000,
'blue': 0x0000FF,
'yellow': 0xFFFF00,
'purple': 0x800080,
'orange': 0xFFA500,
'green': 0x00FF00
};
var worldPos = garden.gridToWorld(x, y);
for (var i = 0; i < 12; i++) {
var particle = new PollenParticle().init('burst');
var angle = i / 12 * Math.PI * 2;
particle.x = worldPos.x;
particle.y = worldPos.y;
particle.vx = Math.cos(angle) * 8;
particle.vy = Math.sin(angle) * 8;
particle.scale.set(0.8);
particle.tint = colorTints[color];
game.addChild(particle);
}
};
return self;
});
//<Assets used in the game will automatically appear here>
// Garden class to manage the grid of soil
var Garden = Container.expand(function () {
var self = Container.call(this);
// Add new helper method for safe grid updates
self.updateGridPosition = function (row, col, item) {
if (row >= 0 && row < self.rows && col >= 0 && col < self.cols) {
// First clear any existing item
var existingItem = self.grid[row][col];
if (existingItem && existingItem.parent) {
existingItem.parent.removeChild(existingItem);
}
// Then set new item
self.grid[row][col] = item;
return true;
}
return false;
};
self.grid = [];
self.rows = 8;
self.cols = 8;
self.cellSize = 210;
self.init = function () {
var _this = this;
// Add source flowers
this.sourceFlowers = new Container();
this.addChild(this.sourceFlowers);
// Calculate positions
var centerX = this.cols * this.cellSize / 2;
// Blue flower at top center
var blueFlower = new SourceFlower('blue');
blueFlower.x = centerX;
blueFlower.y = -75; // Moved closer to top row
this.sourceFlowers.addChild(blueFlower);
// Red flower at bottom left corner (under the garden)
var redFlower = new SourceFlower('red');
redFlower.x = 0;
redFlower.y = (this.rows + 1) * this.cellSize;
this.sourceFlowers.addChild(redFlower);
// Yellow flower at bottom right corner (under the garden)
var yellowFlower = new SourceFlower('yellow');
yellowFlower.x = (this.cols - 1) * this.cellSize;
yellowFlower.y = (this.rows + 1) * this.cellSize;
this.sourceFlowers.addChild(yellowFlower);
// Center the grid on screen
self.x = (2048 - self.cols * self.cellSize) / 2;
self.y = (2732 - self.rows * self.cellSize) / 2 + 2732 * 0.12 - 400;
// Initialize grid and fill with buds
for (var i = 0; i < self.rows; i++) {
self.grid[i] = [];
for (var j = 0; j < self.cols; j++) {
var bud = new Bud();
bud.x = j * self.cellSize + self.cellSize / 2;
bud.y = i * self.cellSize + self.cellSize / 2;
bud.isBud = true;
bud.isFlower = false;
self.grid[i][j] = bud;
self.addChild(bud);
}
}
};
// Helper method to convert grid position to world position
self.gridToWorld = function (gridX, gridY) {
return {
x: self.x + gridX * self.cellSize + self.cellSize / 2,
y: self.y + gridY * self.cellSize + self.cellSize / 2
};
};
// Helper method to convert world position to grid position
self.worldToGrid = function (worldX, worldY) {
var localX = worldX - self.x;
var localY = worldY - self.y;
return {
x: Math.floor(localX / self.cellSize),
y: Math.floor(localY / self.cellSize)
};
};
});
// GardenBackground class
var GardenBackground = Container.expand(function () {
var self = Container.call(this);
var gardenBackground = LK.getAsset('GardenBackground', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.02,
scaleY: 1.02,
x: 2048 / 2,
y: 2732 / 2
});
self.addChild(gardenBackground);
});
var Hive = Container.expand(function () {
var self = Container.call(this);
var hiveSprite = self.attachAsset('Hive', {
anchorX: 0.5,
anchorY: 0.5
});
self.storedPollen = {
'red': 0,
'blue': 0,
'yellow': 0
};
// Add meter above hive
self.pollenMeter = new PollenMeter();
self.pollenMeter.y = -200;
self.addChild(self.pollenMeter);
// Collection method
self.collectFromBee = function (bee) {
if (bee.currentPollen > 0) {
// Transfer each type of pollen
bee.pollenTypes.forEach(function (type) {
// Initialize hive's stored pollen for this color if needed
if (!self.storedPollen) {
self.storedPollen = {};
}
if (!self.storedPollen[type.color]) {
self.storedPollen[type.color] = 0;
}
// Add to hive's storage
self.storedPollen[type.color] += type.amount;
// Update hive UI
game.hiveUI.updatePollen(type.color, self.storedPollen[type.color], 1000); // Update UI using game.hiveUI
});
// Create particles spread across the hive's width
var particleCount = 20;
var hiveWidth = 300;
for (var i = 0; i < particleCount; i++) {
var particle = new PollenParticle().init('transfer');
particle.x = -hiveWidth / 2 + Math.random() * hiveWidth;
particle.y = -200;
particle.vx = (Math.random() - 0.5) * 0.5;
particle.vy = 1 + Math.random();
particle.twinkleOffset = Math.random() * Math.PI * 2;
particle.twinkleSpeed = 0.1 + Math.random() * 0.1;
particle.scale.set(0.5);
self.addChild(particle);
}
// Clear bee's pollen
bee.currentPollen = 0;
bee.pollenTypes = [];
// Update bee UI to show empty
['red', 'blue', 'yellow'].forEach(function (color) {
game.beeUI.updatePollen(color, 0, bee.maxPollen); // Clear bee's pollen using game.beeUI
});
// End bee's trail
bee.pollenTrail.active = false;
bee.pollenTrail.points = [];
}
};
return self;
});
var PollenMeter = Container.expand(function () {
var self = Container.call(this);
// Create background bar
var background = LK.getAsset('marker', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1,
scaleY: 0.1
});
self.addChild(background);
// Create fill bar
var fill = LK.getAsset('marker', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0,
scaleY: 0.1
});
fill.tint = 0xFFFF00; // Yellow for pollen
self.fillBar = fill;
self.addChild(fill);
// Update method to show current pollen
self.updateMeter = function (current, max) {
fill.scale.x = current / max;
};
return self;
});
// PollenParticle class
var PollenParticle = Container.expand(function () {
var self = Container.call(this);
// Particle properties
self.velocity = {
x: 0,
y: 0
};
self.lifespan = 1; // Goes from 1 to 0
self.decayRate = 0.02; // How fast the particle fades
self.type = 'trail'; // Can be 'trail' or 'burst'
// Create the visual element
var assetMap = {
'trail': 'PollenSparkle',
'burst': 'Petal',
'fairy': 'PollenSparkle',
'transfer': 'PollenSparkle'
};
var pollenGraphics;
// Initialize with random properties for more organic feel
self.init = function (type) {
self.type = type || 'trail';
if (!pollenGraphics) {
pollenGraphics = self.attachAsset(assetMap[self.type], {
anchorX: 0.5,
anchorY: 0.5
});
}
// Set initial scale based on type
if (self.type === 'trail') {
self.scale.set(0.7 + Math.random() * 0.3); // Larger for trail
self.decayRate = 0.03; // Faster decay for trail
// Slight random velocity for trail movement
self.velocity = {
x: (Math.random() - 0.5) * 2,
y: (Math.random() - 0.5) * 2
};
} else if (self.type === 'burst') {
self.scale.set(0.5 + Math.random() * 0.3); // Smaller initial size for bursts
self.decayRate = 0.01; // Slower decay for longer travel
// Radial burst velocity
var angle = Math.random() * Math.PI * 2;
var speed = 3 + Math.random() * 5; // Increased speed for further travel
self.velocity = {
x: Math.cos(angle) * speed,
y: Math.sin(angle) * speed
};
} else if (self.type === 'fairy') {
self.lifespan = undefined; // Don't fade out
self.startAngle = Math.random() * Math.PI * 2; // Random start position
self.orbitRadius = 20 + Math.random() * 40; // Increase orbit radius variation
self.orbitSpeed = 0.005 + Math.random() * 0.03; // Increase orbit speed variation
self.update = function () {
var time = LK.ticks * self.orbitSpeed;
// Orbit motion
self.x = Math.cos(time + self.startAngle) * self.orbitRadius;
self.y = Math.sin(time + self.startAngle) * self.orbitRadius;
// Add bobbing
self.y += Math.sin(time * 2 + self.startAngle) * 10;
};
}
// Random rotation speed
self.rotationSpeed = (Math.random() - 0.5) * 0.2;
// Random starting rotation
self.rotation = Math.random() * Math.PI * 2;
// Add random rotation speed for dynamic movement
self.rotationSpeed = (Math.random() - 0.5) * 0.2;
// Full opacity to start
self.alpha = 1;
if (self.type === 'transfer') {
self.scale.set(0.5);
self.alpha = 1;
self.twinkleOffset = 0; // Initialize twinkle offset
self.twinkleSpeed = 0.1; // Initialize twinkle speed
self.update = function () {
// Gentle drift down
self.x += self.vx;
self.y += self.vy;
// Individual twinkle effect
self.alpha = 0.6 + Math.sin(LK.ticks * self.twinkleSpeed + self.twinkleOffset) * 0.4;
// Remove when below hive
if (self.y > 100) {
self.destroy();
}
};
}
return self;
};
self.update = function () {
// Update position based on velocity
self.x += self.velocity.x;
self.y += self.velocity.y;
// Add rotation
self.rotation += self.rotationSpeed;
// Slow down velocity over time
self.velocity.x *= 0.95;
self.velocity.y *= 0.95;
// Update lifespan and alpha
self.lifespan -= self.decayRate;
self.alpha = self.lifespan;
// Scale slightly varies with life
var scalePulse = 1 + Math.sin(LK.ticks * 0.2) * 0.1;
pollenGraphics.scale.set(scalePulse * self.scale.x);
// Remove when lifecycle complete
if (self.lifespan <= 0) {
self.destroy();
}
};
});
// First, let's add a PollenTrail class to handle the dragging mechanic
var PollenTrail = Container.expand(function () {
var self = Container.call(this);
self.points = [];
self.active = false;
self.currentGarden = null; // Store reference to garden
self.MAX_SPEED = 15; // Adjust this value for proper feel
self.startTrail = function (x, y, garden, bee) {
self.active = true;
self.points = [{
x: x,
y: y,
time: Date.now()
}];
self.startTime = Date.now();
self.trailStartTime = Date.now();
self.currentGarden = garden;
self.bee = bee; // Store bee reference
self.lastPoint = {
x: x,
y: y
}; // Initialize lastPoint
// Force red on first particle to verify bee storage
var particle = new PollenParticle().init('trail');
particle.children[0].tint = 0xFF0000;
particle.x = x;
particle.y = y;
game.addChild(particle);
};
self.updateTrail = function (x, y) {
if (!self.active) {
return;
}
// Enforce maximum speed
var dx = x - self.lastPoint.x;
var dy = y - self.lastPoint.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > self.MAX_SPEED) {
var ratio = self.MAX_SPEED / distance;
x = self.lastPoint.x + dx * ratio;
y = self.lastPoint.y + dy * ratio;
}
self.points.push({
x: x,
y: y,
time: Date.now()
});
self.lastPoint = {
x: x,
y: y
};
// Create particle effect along trail
var particle = new PollenParticle().init('trail');
if (self.bee && self.bee.pollenTypes && self.bee.pollenTypes[0]) {
if (self.bee.pollenTypes[0].color === 'red') {
particle.children[0].tint = 0xFF0000;
} else if (self.bee.pollenTypes[0].color === 'blue') {
particle.children[0].tint = 0x0000FF;
} else if (self.bee.pollenTypes[0].color === 'yellow') {
particle.children[0].tint = 0xFFFF00;
}
}
particle.x = x;
particle.y = y;
game.addChild(particle);
};
// Add the burst effect function
self.createPollenBurst = function (x, y) {
for (var i = 0; i < 12; i++) {
var particle = new PollenParticle().init('burst');
var angle = i / 12 * Math.PI * 2;
var distance = 30;
particle.x = x + Math.cos(angle) * distance;
particle.y = y + Math.sin(angle) * distance;
// Give particles outward velocity
particle.vx = Math.cos(angle) * 3;
particle.vy = Math.sin(angle) * 3;
game.addChild(particle);
}
};
self.endTrail = function () {
if (!self.active) {
return;
}
var affectedBuds = [];
var checkedPositions = {};
self.points.forEach(function (point) {
var localPos = self.currentGarden.toLocal({
x: point.x,
y: point.y
}, game);
var gridX = Math.floor(localPos.x / self.currentGarden.cellSize);
var gridY = Math.floor(localPos.y / self.currentGarden.cellSize);
var posKey = gridX + ',' + gridY;
if (!checkedPositions[posKey] && gridX >= 0 && gridX < self.currentGarden.cols && gridY >= 0 && gridY < self.currentGarden.rows) {
checkedPositions[posKey] = true;
var gridItem = self.currentGarden.grid[gridY][gridX];
// Verify it's a valid bud
if (gridItem && gridItem.isBud === true && gridItem.isFlower === false) {
affectedBuds.push({
bud: gridItem,
gridX: gridX,
gridY: gridY
});
}
}
});
if (affectedBuds.length >= 2) {
affectedBuds.forEach(function (budInfo) {
// IMPORTANT: Clear the grid position first
self.currentGarden.grid[budInfo.gridY][budInfo.gridX] = null;
// Remove the bud from display list
self.currentGarden.removeChild(budInfo.bud);
// Create new flower
var newFlower = new BasicFlower();
newFlower.x = budInfo.bud.x;
newFlower.y = budInfo.bud.y;
newFlower.isFlower = true;
// Update grid position and add to display list
self.currentGarden.grid[budInfo.gridY][budInfo.gridX] = newFlower;
self.currentGarden.addChild(newFlower);
// Start bloom animation
newFlower.bloom();
});
}
self.active = false;
self.points = [];
};
self.update = function () {
// Just update particles, no time checks
// Update all children particles
for (var i = self.children.length - 1; i >= 0; i--) {
var particle = self.children[i];
if (particle && particle.update) {
particle.update();
}
}
};
});
var PollenUI = Container.expand(function () {
var self = Container.call(this);
// Create cells with their fill indicators
// Red cell and fill
// Red cell initialization and position
var redCell = LK.getAsset('pollenCellBase', {
anchorX: 0.5,
anchorY: 0.5,
x: -300 // Set position in initialization
});
redCell.tint = 0xFF0000;
redCell.alpha = 0.4;
self.addChild(redCell);
self.redFill = LK.getAsset('pollenCellBase', {
anchorX: 0.5,
anchorY: 0,
x: -300 // Set position in initialization
});
self.redFill.tint = 0xFF0000;
self.redFill.alpha = 0.7;
self.redFill.y = 90;
self.redFill.scale.y = 0;
self.addChild(self.redFill);
// Blue cell initialization and position
var blueCell = LK.getAsset('pollenCellBase', {
anchorX: 0.5,
anchorY: 0.5,
x: 0 // Set position in initialization
});
blueCell.tint = 0x0000FF;
blueCell.alpha = 0.4;
self.addChild(blueCell);
self.blueFill = LK.getAsset('pollenCellBase', {
anchorX: 0.5,
anchorY: 0,
x: 0 // Set position in initialization
});
self.blueFill.tint = 0x0000FF;
self.blueFill.alpha = 0.7;
self.blueFill.y = 90;
self.blueFill.scale.y = 0;
self.addChild(self.blueFill);
// Yellow cell initialization and position
var yellowCell = LK.getAsset('pollenCellBase', {
anchorX: 0.5,
anchorY: 0.5,
x: 300 // Set position in initialization
});
yellowCell.tint = 0xFFFF00;
yellowCell.alpha = 0.4;
self.addChild(yellowCell);
self.yellowFill = LK.getAsset('pollenCellBase', {
anchorX: 0.5,
anchorY: 0,
x: 300 // Set position in initialization
});
self.yellowFill.tint = 0xFFFF00;
self.yellowFill.alpha = 0.7;
self.yellowFill.y = 90;
self.yellowFill.scale.y = 0;
self.addChild(self.yellowFill);
// Add update method
self.updatePollen = function (color, amount, max) {
var fillAmount = Math.min(amount / max, 1);
if (color === 'red') {
self.redFill.scale.y = fillAmount;
self.redFill.y = 90 - 180 * fillAmount; // Start at 90, move up as it fills
} else if (color === 'blue') {
self.blueFill.scale.y = fillAmount;
self.blueFill.y = 90 - 180 * fillAmount;
} else if (color === 'yellow') {
self.yellowFill.scale.y = fillAmount;
self.yellowFill.y = 90 - 180 * fillAmount;
}
};
return self;
});
// Add ScoreManager to handle chain reactions and scoring
var ScoreManager = Container.expand(function () {
var self = Container.call(this);
self.currentScore = 0;
self.currentChain = 0;
self.chainMultiplier = 1;
self.addToChain = function () {
self.currentChain++;
self.chainMultiplier = Math.min(1 + self.currentChain * 0.5, 5); // Cap at 5x
self.addScore(100 * self.chainMultiplier);
};
self.resetChain = function () {
self.currentChain = 0;
self.chainMultiplier = 1;
};
self.addScore = function (points) {
self.currentScore += Math.floor(points);
// Update score display
if (game.scoreDisplay) {
game.scoreDisplay.text = self.currentScore.toString();
}
};
});
var SourceFlower = Container.expand(function (color) {
var self = Container.call(this);
// Store flower color
self.color = color;
self.isSourceFlower = true; // Flag to identify source flowers
// Map color to asset name
var assetMap = {
'red': 'RedFlower',
'blue': 'BlueFlower',
'yellow': 'YellowFlower'
};
// Create flower sprite
var flowerGraphics = self.attachAsset(assetMap[self.color], {
anchorX: 0.5,
anchorY: 0.5
});
// Source flowers always have pollen
self.hasActivePollen = true;
self.fairyParticles = [];
self.FAIRY_COUNT = 3;
// Initialize fairy particles
for (var i = 0; i < self.FAIRY_COUNT; i++) {
var fairy = new PollenParticle().init('fairy');
fairy.scale.set(0.3 + Math.random() * 0.2);
fairy.x += (Math.random() - 0.5) * 60;
fairy.y += (Math.random() - 0.5) * 60;
fairy.rotation = Math.random() * Math.PI * 2;
fairy.rotationSpeed = (Math.random() - 0.5) * 0.2;
self.addChild(fairy);
self.fairyParticles.push(fairy);
}
// Gentle animation
self.update = function () {
var scaleFactor = 1 + Math.sin(LK.ticks * 0.1) * 0.05;
flowerGraphics.scale.x = scaleFactor;
flowerGraphics.scale.y = scaleFactor;
flowerGraphics.rotation = Math.sin(LK.ticks * 0.1) * 0.05;
// Update fairy particles
self.fairyParticles.forEach(function (fairy) {
if (fairy && fairy.update) {
fairy.update();
}
});
};
// Override collection behavior - source flowers regenerate pollen immediately
self.pollenCollected = false;
self.resetPollen = function () {
self.hasActivePollen = true;
self.pollenCollected = false;
};
return self;
});
// Level display class
var LevelDisplay = Text2.expand(function () {
var self = Text2.call(this, 'Level 1', {
size: 150,
fill: 0xFFFFFF
});
});
// Score display class
var ScoreDisplay = Text2.expand(function () {
var self = Text2.call(this, '0', {
size: 150,
fill: 0xFFFFFF
});
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Declare and initialize flowerManager in global scope
var flowerManager = new FlowerManager();
var titleScreen = new Container();
var background = LK.getAsset('titlebackground', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
titleScreen.addChild(background);
var logo = LK.getAsset('logo', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
titleScreen.addChild(logo);
var playButton = LK.getAsset('playButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2 + 200
});
titleScreen.addChild(playButton);
var tutorialButton = LK.getAsset('tutorialButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2 + 400
});
titleScreen.addChild(tutorialButton);
game.addChild(titleScreen);
playButton.down = function (x, y, obj) {
game.removeChild(titleScreen);
var gardenBackground = new GardenBackground();
game.addChild(gardenBackground);
garden = new Garden();
garden.init();
game.addChild(garden);
var flowerManager = new FlowerManager();
game.flowerMatcher = new FlowerMatcher();
game.addChild(game.flowerMatcher);
var pollenTrail = new PollenTrail();
game.addChild(pollenTrail);
// Create and position hive
var hive = new Hive();
hive.x = 2048 / 2;
hive.y = 2732 * 0.97 - 200;
// Create bee and position above hive
var bee = new Bee();
bee.x = hive.x;
bee.y = hive.y - 150;
// Create UI and attach to game object so it's globally accessible
game.beeUI = new PollenUI();
game.beeUI.position.set(hive.x - 600, hive.y + 100);
game.beeUI.scale.set(0.8);
game.addChild(game.beeUI);
game.hiveUI = new PollenUI();
game.hiveUI.position.set(hive.x + 600, hive.y + 100);
game.addChild(game.hiveUI);
// Add objects to game
game.addChild(hive);
game.addChild(bee);
// Ensure pollen particles are rendered on top by adding them last
game.setChildIndex(pollenTrail, game.children.length - 1);
// Initialize bud spawner
garden.budSpawner = new BudSpawner();
garden.budSpawner.init(garden);
game.addChild(garden.budSpawner);
// Touch handlers
game.down = function (x, y, obj) {
bee.isMoving = true;
bee.targetX = x;
bee.targetY = y;
};
game.move = function (x, y, obj) {
if (bee.isMoving) {
bee.targetX = x;
bee.targetY = y - 200;
}
};
game.up = function (x, y, obj) {
bee.isMoving = false;
};
// Initialize score display
var scoreDisplay = new ScoreDisplay();
scoreDisplay.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreDisplay);
game.scoreDisplay = scoreDisplay;
// Add the main update loop
game.update = function () {
// Update spawning system
if (game.budSpawner) {
game.budSpawner.update();
}
// Update trail system
if (pollenTrail) {
pollenTrail.update();
}
// Update garden elements
if (garden) {
// Update all flowers and buds in the grid
for (var i = 0; i < garden.rows; i++) {
for (var j = 0; j < garden.cols; j++) {
var gridItem = garden.grid[i][j];
if (gridItem && gridItem.update) {
gridItem.update();
}
}
}
}
// Update all children that have update methods
for (var i = 0; i < game.children.length; i++) {
var child = game.children[i];
if (child && child.update) {
child.update();
}
}
// Update all particles
if (game.particlesToUpdate) {
for (var i = game.particlesToUpdate.length - 1; i >= 0; i--) {
var particle = game.particlesToUpdate[i];
if (particle && particle.update) {
particle.update();
}
}
}
// Update bee
if (bee && bee.update) {
bee.update();
// Collision detection between bee and hive
if (hive) {
var dx = bee.x - hive.x;
var dy = bee.y - hive.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < 100) {
// Adjust collection radius as needed
hive.collectFromBee(bee);
}
}
}
};
};
tutorialButton.down = function (x, y, obj) {
// Open tutorial
};
// Removed duplicate playPollenPatternAnimation method
A background image for a puzzle video game depicting the season of summer. Cartoon. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A background image for a puzzle video game depicting the season of fall. Cartoon. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A background image for a puzzle video game depicting the season of winter. Cartoon. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Multiple stylized texts with phrases that include “Hurry!” “Time’s up!” Cartoon style.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Create a SVG text design in bold cartoon style: "SPRING" in chunky rounded letters with floral accents and vines. Use spring pastels.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Create an SVG text design for "SUMMER" in bold cartoon style with chunky rounded letters. Add sun rays and small flower details in warm, vibrant colors.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Create an SVG text design for "FALL" in bold cartoon style with chunky rounded letters. Add small falling leaves and acorn accents in warm autumn colors.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Create an SVG text design for "WINTER" in bold cartoon style with chunky rounded letters. Add small snowflake accents and icy details in cool, frosty blues and white.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Create a SVG text design in bold cartoon style: “Bloom the garden" in chunky rounded letters with floral accents and vines. Use spring pastels.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Create an SVG text design for "Match the blooms" in bold cartoon style with chunky rounded letters. Add sun rays and small flower details in warm, vibrant colors.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Create an SVG text design for "Match to clear leaves" in bold cartoon style with chunky rounded letters. Add small falling leaves and acorn accents in warm autumn colors.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Create an SVG text design for "DANCE TO STAY WARM" in bold cartoon style with chunky rounded letters. Add small snowflake accents and icy details in cool, frosty blues and white.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Create a SVG text design in bold cartoon style: "SEASON COMPLETE!" in chunky rounded letters with stars around it . Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.