User prompt
Change the flytrap icon and texture into the flytrap
User prompt
Fix the bug
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'obj = new Flytrap();' Line Number: 917
User prompt
Put flytrap in organisim selection
User prompt
Make another organism that does nothing yet nickname it flytrap
User prompt
Please fix the bug: 'undefined is not an object (evaluating 'extinctionBtn.y')' in or related to this line: 'infoBtn.y = extinctionBtn.y + 120;' Line Number: 1802
User prompt
Add it to the menu
User prompt
Make it so parasites detach when its autumn and they cant infect in autumn but they can lay eggs but only one time for each parasite
User prompt
Make it so if you try to spawn a parasite in winter they die
User prompt
Make it so carnivores cant starve
User prompt
Make it so hunters will not eat in autumn
User prompt
Make it so eggs hatch less in the autmn
User prompt
Make it in autumn the seeds have a slightly higher chance of not germinating and dying instead
User prompt
Make it so in autumn that pollinators stop laying eggs and they just pollinate
User prompt
Make a new season that happens after summer called autumn that makes the background brown
User prompt
Make a new season that happens after summer called autumn that makes the background brown
User prompt
Make it so parasites die in the winter
User prompt
Make it so parasites can be dragged
User prompt
Make it so that there is an uncommon attribute where organisms can be resistant to parasites and parasites will avoid them
User prompt
Make it so that there is an uncommon attribute where organisms can be resistant to parasites and parasites will avoid them
User prompt
Make it so parasites let go of spore infected herbivores or avoid spore infected herbivores when they are infected by shrooms
User prompt
When skipping a cycle make it so the parasites remain attached to their host
User prompt
Make parasites smaller
User prompt
During winter parasites will die and lay eggs before their death! And when spring comes their eggs hatch
User prompt
Change the icon into the parasite asset too
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // --- Flytrap Organism Class --- // Minimal organism that does nothing (placeholder) var Flytrap = Container.expand(function () { var self = Container.call(this); // Attach the Flytrap image asset as the visual for the flytrap self.flytrapAsset = self.attachAsset('Flytrap', { anchorX: 0.5, anchorY: 0.5, scaleX: 1, scaleY: 1 }); return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x2ecc40 //{7C} // Set to a green background }); /**** * Game Code ****/ // --- Pollinator Hibernation State --- var pollinatorsHibernating = false; // --- Cycle Counter --- // Add a cycle counter at the bottom of the screen that increments every 50 seconds (3000 frames at 60fps) var cycleCount = 0; var cycleTxt = new Text2("Cycle: 0", { size: 80, fill: "#000" }); cycleTxt.anchor.set(0.5, 0); // Place at top left, but not in the top 100px reserved area LK.gui.top.addChild(cycleTxt); cycleTxt.x = 500; cycleTxt.y = 120; // --- Season Text at Bottom --- // Helper to get current season as string function getCurrentSeason() { if (window.summerState) return "Summer"; if (window.winterState) return "Winter"; if (window.springState) return "Spring"; if (window.autumnState) return "Autumn"; // Fallback: guess from background color if (game.backgroundColor === 0xffff00) return "Summer"; if (game.backgroundColor === 0xffffff) return "Winter"; if (game.backgroundColor === 0x8B5A2B) return "Autumn"; return "Spring"; } var seasonTxt = new Text2("Season: " + getCurrentSeason(), { size: 90, fill: "#000" }); seasonTxt.anchor.set(0, 1); LK.gui.bottom.addChild(seasonTxt); seasonTxt.x = 40; seasonTxt.y = 0; // Helper to update season text function updateSeasonText() { if (seasonTxt && typeof seasonTxt.setText === "function") { seasonTxt.setText("Season: " + getCurrentSeason()); if (typeof seasonTxt.setStyle === "function") seasonTxt.setStyle({ fill: "#000" }); } } // --- Cycle Countdown Timer Text --- var cycleDurationMs = 50000; // 50,000 ms = 50 seconds var cycleTimeLeftMs = cycleDurationMs; var cycleTimerTxt = new Text2("Next cycle: 50s", { size: 60, fill: "#000" }); cycleTimerTxt.anchor.set(0.5, 0); LK.gui.top.addChild(cycleTimerTxt); cycleTimerTxt.x = 500; cycleTimerTxt.y = cycleTxt.y + 80; // Place under the cycle counter // Timer to increment cycle every 50 seconds var cycleInterval = null; // Will be started after first organism is placed var cycleCountdownInterval = null; // For updating the countdown text // Helper to set all on-screen text color to black function updateTextColors(bgColor) { var textColor = "#000"; if (cycleTxt && typeof cycleTxt.setStyle === "function") cycleTxt.setStyle({ fill: textColor }); if (cycleTimerTxt && typeof cycleTimerTxt.setStyle === "function") cycleTimerTxt.setStyle({ fill: textColor }); if (deleteBtnTxt && typeof deleteBtnTxt.setStyle === "function") deleteBtnTxt.setStyle({ fill: textColor }); if (skipCycleBtnTxt && typeof skipCycleBtnTxt.setStyle === "function") skipCycleBtnTxt.setStyle({ fill: textColor }); // Palette item labels for (var i = 0; i < paletteItems.length; i++) { for (var j = 0; j < paletteItems[i].children.length; j++) { var child = paletteItems[i].children[j]; if (child instanceof Text2 && typeof child.setStyle === "function") { child.setStyle({ fill: textColor }); } } } // Palette scroll arrows if (window.paletteLeftBtn) { for (var i = 0; i < window.paletteLeftBtn.children.length; i++) { var child = window.paletteLeftBtn.children[i]; if (child instanceof Text2 && typeof child.setStyle === "function") child.setStyle({ fill: textColor }); } } if (window.paletteRightBtn) { for (var i = 0; i < window.paletteRightBtn.children.length; i++) { var child = window.paletteRightBtn.children[i]; if (child instanceof Text2 && typeof child.setStyle === "function") child.setStyle({ fill: textColor }); } } } function startCycleInterval() { if (cycleInterval !== null) return; cycleTimeLeftMs = cycleDurationMs; cycleTimerTxt.setText("Next cycle: " + Math.ceil(cycleTimeLeftMs / 1000) + "s"); cycleInterval = LK.setInterval(function () { cycleCount++; cycleTxt.setText("Cycle: " + cycleCount); cycleTimeLeftMs = cycleDurationMs; cycleTimerTxt.setText("Next cycle: " + Math.ceil(cycleTimeLeftMs / 1000) + "s"); // Set background color every 3 cycles: green, yellow, brown, white, repeat (spring, summer, autumn, winter) var mod = cycleCount % 12; if (mod === 0) { // SPRING game.setBackgroundColor(0x2ecc40); // green updateTextColors(0x2ecc40); pollinatorsHibernating = false; window.summerState = false; window.springState = true; window.winterState = false; window.autumnState = false; // Restore plant color to normal (green) and allow dying for (var i = 0; i < plants.length; i++) { if (plants[i] && plants[i].plantAsset && typeof plants[i].plantAsset.tint !== "undefined") { plants[i].plantAsset.tint = 0xffffff; } plants[i]._canDie = true; } // --- SPRING: Hatch all parasite eggs (eggs with _isParasiteEgg and _parasiteHatch) --- for (var i = eggs.length - 1; i >= 0; i--) { var e = eggs[i]; if (e && e._isParasiteEgg && e._parasiteHatch && !e.hatched) { // Instantly hatch the egg into a parasite e.hatched = true; // Animate egg hatching tween(e, { scaleX: 1.2, scaleY: 1.2, alpha: 0.5 }, { duration: 200, easing: tween.easeOut, onFinish: function (egg) { return function () { var parasite = new Parasite(); parasite.x = egg.x; parasite.y = egg.y; parasite.scaleX = 1; parasite.scaleY = 1; parasite.alpha = 1; if (egg.parent) egg.parent.addChild(parasite); if (typeof parasites !== "undefined") parasites.push(parasite); egg.destroy(); }; }(e) }); eggs.splice(i, 1); } } // --- Resume herbivore movement after winter ends --- for (var i = 0; i < herbivores.length; i++) { if (herbivores[i] && typeof herbivores[i].speed === "number") { herbivores[i].speed = 1.2 + Math.random() * 1.0; } } // --- Resume carnivore hunting after winter ends --- (Ava) // Reset carnivore state to "hungry" so they resume hunting in spring for (var i = 0; i < carnivores.length; i++) { if (carnivores[i]) { carnivores[i].state = "hungry"; carnivores[i]._tired = false; carnivores[i]._tiredTimer = 0; carnivores[i]._chaseTime = 0; carnivores[i].target = null; } } updateSeasonText(); } else if (mod === 3) { // SUMMER game.setBackgroundColor(0xffff00); // yellow updateTextColors(0xffff00); pollinatorsHibernating = false; window.summerState = true; window.winterState = false; window.springState = false; window.autumnState = false; // Plants can die, but keep their color normal for (var i = 0; i < plants.length; i++) { if (plants[i] && plants[i].plantAsset && typeof plants[i].plantAsset.tint !== "undefined") { plants[i].plantAsset.tint = 0xffffff; } plants[i]._canDie = true; } updateSeasonText(); } else if (mod === 6) { // AUTUMN game.setBackgroundColor(0x8B5A2B); // brown updateTextColors(0x8B5A2B); pollinatorsHibernating = false; window.summerState = false; window.springState = false; window.winterState = false; window.autumnState = true; // Make all plants brown and allow dying for (var i = 0; i < plants.length; i++) { if (plants[i] && plants[i].plantAsset && typeof plants[i].plantAsset.tint !== "undefined") { plants[i].plantAsset.tint = 0x996633; // brown } plants[i]._canDie = true; plants[i]._isBrown = true; } updateSeasonText(); } else if (mod === 9) { // WINTER game.setBackgroundColor(0xffffff); // white updateTextColors(0xffffff); pollinatorsHibernating = true; window.summerState = false; window.springState = false; window.winterState = true; window.autumnState = false; // --- WINTER: Parasites die and lay eggs before death --- for (var i = parasites.length - 1; i >= 0; i--) { var parasite = parasites[i]; if (parasite && !parasite.eaten) { // Lay a parasite egg at current position before dying var egg = new Egg(); egg.x = parasite.x; egg.y = parasite.y; egg.scaleX = 0.5; egg.scaleY = 0.5; egg.alpha = 1; egg._isParasiteEgg = true; egg._parasiteHatch = true; if (parasite.parent) parasite.parent.addChild(egg); if (typeof eggs !== "undefined") eggs.push(egg); // Animate parasite dying and remove from array tween(parasite, { scaleX: 0, scaleY: 0, alpha: 0 }, { duration: 200, easing: tween.easeIn, onFinish: function (p) { return function () { if (typeof parasites !== "undefined") { var idx = parasites.indexOf(p); if (idx !== -1) parasites.splice(idx, 1); } p.destroy(); }; }(parasite) }); } } // Kill all brown plants when winter starts for (var i = plants.length - 1; i >= 0; i--) { var p = plants[i]; // Only kill brown plants; healthy plants do not die in winter if (p && p._isBrown && !p.eaten && typeof p.die === "function") { p.die(); } } // Make all plants blue and prevent dying for (var i = 0; i < plants.length; i++) { if (plants[i] && plants[i].plantAsset && typeof plants[i].plantAsset.tint !== "undefined") { plants[i].plantAsset.tint = 0x3399ff; } plants[i]._canDie = false; } // Cull a random portion of eggs during winter to reduce lag if (eggs && eggs.length > 0) { // Remove up to 40% of eggs at random, but always leave at least 3 eggs if possible var eggsToCull = Math.floor(eggs.length * 0.4); var minEggsLeft = 3; if (eggs.length - eggsToCull < minEggsLeft) { eggsToCull = Math.max(0, eggs.length - minEggsLeft); } for (var i = 0; i < eggsToCull; i++) { // Pick a random egg index var idx = Math.floor(Math.random() * eggs.length); var e = eggs[idx]; if (e && typeof e.destroy === "function") { e.destroy(); } eggs.splice(idx, 1); } } updateSeasonText(); } }, cycleDurationMs); // Start countdown updater (every 100ms for smoothness) if (cycleCountdownInterval === null) { cycleCountdownInterval = LK.setInterval(function () { if (cycleTimeLeftMs > 0) { cycleTimeLeftMs -= 100; if (cycleTimeLeftMs < 0) cycleTimeLeftMs = 0; cycleTimerTxt.setText("Next cycle: " + Math.ceil(cycleTimeLeftMs / 1000) + "s"); } }, 100); } } // --- End of Game Code ---;; // --- Asset Initialization --- // new carnivore egg texture var plants = []; var herbivores = []; var carnivores = []; var seeds = []; var eggs = []; // Track all eggs globally var pollinators = []; var fungis = []; // Track all fungi globally var parasites = []; // Track all parasites globally var fungiSpores = []; // Track all spores shot by fungi // --- Palette UI --- var paletteY = 180; // y position for palette var paletteSpacing = 260; var paletteItems = []; // --- Delete Mode Button --- var deleteMode = false; var deleteBtn = new Container(); var deleteBtnBox = deleteBtn.attachAsset('box', { anchorX: 0.5, anchorY: 0.5, width: 220, height: 100, color: 0xcc3333, shape: 'box' }); var deleteBtnTxt = new Text2("Delete: OFF", { size: 54, fill: "#000" }); deleteBtnTxt.anchor.set(0.5, 0.5); deleteBtn.addChild(deleteBtnTxt); // Place delete button under the cycle counter and timer deleteBtn.x = 500; deleteBtn.y = cycleTimerTxt.y + 140; // Move further down (was 90px, now 140px below the timer text) deleteBtn.interactive = true; deleteBtn.visible = true; deleteBtn.down = function () { deleteMode = !deleteMode; deleteBtnBox.color = deleteMode ? 0xff4444 : 0xcc3333; deleteBtnTxt.setText(deleteMode ? "Delete: ON" : "Delete: OFF"); }; LK.gui.top.addChild(deleteBtn); // --- Skip Cycle Button --- var skipCycleBtn = new Container(); var skipCycleBtnBox = skipCycleBtn.attachAsset('box', { anchorX: 0.5, anchorY: 0.5, width: 220, height: 100, color: 0x3388cc, shape: 'box' }); var skipCycleBtnTxt = new Text2("Skip Cycle", { size: 54, fill: "#000" }); skipCycleBtnTxt.anchor.set(0.5, 0.5); skipCycleBtn.addChild(skipCycleBtnTxt); // Place skip button under the delete button skipCycleBtn.x = 500; skipCycleBtn.y = deleteBtn.y + 120; skipCycleBtn.interactive = true; skipCycleBtn.visible = true; // --- Extinction Button --- var extinctionBtn = new Container(); var extinctionBtnBox = extinctionBtn.attachAsset('box', { anchorX: 0.5, anchorY: 0.5, width: 220, height: 100, color: 0x555555, shape: 'box' }); var extinctionBtnTxt = new Text2("Extinction", { size: 54, fill: "#fff" }); extinctionBtnTxt.anchor.set(0.5, 0.5); extinctionBtn.addChild(extinctionBtnTxt); // Place extinction button under the skip cycle button extinctionBtn.x = 500; extinctionBtn.y = skipCycleBtn.y + 120; extinctionBtn.interactive = true; extinctionBtn.visible = true; LK.gui.top.addChild(extinctionBtn); // Asteroid extinction event handler extinctionBtn.down = function () { // Asteroid visual: big circle in center of map var asteroid = LK.getAsset('box', { anchorX: 0.5, anchorY: 0.5, width: 400, height: 400, color: 0x888888, shape: 'ellipse' }); asteroid.x = 124 + 1800 / 2; asteroid.y = paletteY + 320 + 2000 / 2; asteroid.alpha = 0.0; game.addChild(asteroid); // Animate asteroid fade in, then out tween(asteroid, { alpha: 1 }, { duration: 300, easing: tween.easeIn, onFinish: function onFinish() { tween(asteroid, { alpha: 0 }, { duration: 700, easing: tween.easeOut, onFinish: function onFinish() { asteroid.destroy(); } }); } }); // Flash screen for dramatic effect LK.effects.flashScreen(0xff6600, 800); // Gather all organisms (plants, herbivores, carnivores, pollinators, fungis, seeds, eggs) var allGroups = [plants, herbivores, carnivores, pollinators, fungis, seeds, eggs]; for (var g = 0; g < allGroups.length; g++) { var arr = allGroups[g]; // Only kill half (rounded down), random selection var survivors = Math.ceil(arr.length / 2); var toKill = arr.length - survivors; for (var i = 0; i < toKill; i++) { if (arr.length === 0) break; var idx = Math.floor(Math.random() * arr.length); var org = arr[idx]; // Remove from array arr.splice(idx, 1); // Destroy or die if (org && typeof org.die === "function") { org.die(); } else if (org && typeof org.destroy === "function") { org.destroy(); } } } }; skipCycleBtn.down = function () { // Increment cycle and update UI cycleCount++; cycleTxt.setText("Cycle: " + cycleCount); cycleTimeLeftMs = cycleDurationMs; cycleTimerTxt.setText("Next cycle: " + Math.ceil(cycleTimeLeftMs / 1000) + "s"); // Set background color every 3 cycles: green, yellow, brown, white, repeat (spring, summer, autumn, winter) var mod = cycleCount % 12; if (mod === 0) { // SPRING game.setBackgroundColor(0x2ecc40); // green updateTextColors(0x2ecc40); pollinatorsHibernating = false; window.summerState = false; window.springState = true; window.winterState = false; window.autumnState = false; for (var i = 0; i < plants.length; i++) { if (plants[i] && plants[i].plantAsset && typeof plants[i].plantAsset.tint !== "undefined") { plants[i].plantAsset.tint = 0xffffff; } plants[i]._canDie = true; } for (var i = 0; i < herbivores.length; i++) { if (herbivores[i] && typeof herbivores[i].speed === "number") { herbivores[i].speed = 1.2 + Math.random() * 1.0; } } for (var i = 0; i < carnivores.length; i++) { if (carnivores[i]) { carnivores[i].state = "hungry"; carnivores[i]._tired = false; carnivores[i]._tiredTimer = 0; carnivores[i]._chaseTime = 0; carnivores[i].target = null; } } updateSeasonText(); } else if (mod === 3) { // SUMMER game.setBackgroundColor(0xffff00); // yellow updateTextColors(0xffff00); pollinatorsHibernating = false; window.summerState = true; window.winterState = false; window.springState = false; window.autumnState = false; for (var i = 0; i < plants.length; i++) { if (plants[i] && plants[i].plantAsset && typeof plants[i].plantAsset.tint !== "undefined") { plants[i].plantAsset.tint = 0xffffff; } plants[i]._canDie = true; } updateSeasonText(); } else if (mod === 6) { // AUTUMN game.setBackgroundColor(0x8B5A2B); // brown updateTextColors(0x8B5A2B); pollinatorsHibernating = false; window.summerState = false; window.springState = false; window.winterState = false; window.autumnState = true; for (var i = 0; i < plants.length; i++) { if (plants[i] && plants[i].plantAsset && typeof plants[i].plantAsset.tint !== "undefined") { plants[i].plantAsset.tint = 0x996633; // brown } plants[i]._canDie = true; plants[i]._isBrown = true; } updateSeasonText(); } else if (mod === 9) { // WINTER game.setBackgroundColor(0xffffff); // white updateTextColors(0xffffff); pollinatorsHibernating = true; window.summerState = false; window.springState = false; window.winterState = true; window.autumnState = false; for (var i = plants.length - 1; i >= 0; i--) { var p = plants[i]; if (p && p._isBrown && !p.eaten && typeof p.die === "function") { p.die(); } } for (var i = 0; i < plants.length; i++) { if (plants[i] && plants[i].plantAsset && typeof plants[i].plantAsset.tint !== "undefined") { plants[i].plantAsset.tint = 0x3399ff; } plants[i]._canDie = false; } updateSeasonText(); } // Randomize all organism positions except fungi, plants, and lichen var minX = 124 + 60; var maxX = 124 + 1800 - 60; var minY = paletteY + 320 + 60; var maxY = paletteY + 320 + 2000 - 60; // Helper to randomize array of organisms function randomizeOrganisms(arr) { for (var i = 0; i < arr.length; i++) { var org = arr[i]; // If this is a host with a parasite attached, skip randomizing its position if (org && typeof org.x === "number" && typeof org.y === "number" && !org.eaten && !org._parasiteAttached // Only randomize if not hosting a parasite ) { org.x = minX + Math.random() * (maxX - minX); org.y = minY + Math.random() * (maxY - minY); } } } // When randomizing parasites, only randomize those not attached to a host function randomizeFreeParasites(arr) { for (var i = 0; i < arr.length; i++) { var parasite = arr[i]; if (parasite && typeof parasite.x === "number" && typeof parasite.y === "number" && !parasite.eaten && parasite.state !== "attached") { parasite.x = minX + Math.random() * (maxX - minX); parasite.y = minY + Math.random() * (maxY - minY); } } } randomizeOrganisms(herbivores); randomizeOrganisms(carnivores); randomizeOrganisms(pollinators); randomizeOrganisms(seeds); randomizeOrganisms(eggs); randomizeFreeParasites(parasites); // Fungi, plants, and lichen are NOT moved // (fungis, plants, window.lichens) }; LK.gui.top.addChild(skipCycleBtn); LK.gui.top.addChild(extinctionBtn); // Shift the palette even further left so it is not offscreen var paletteTotalWidth = paletteSpacing * 2; var paletteXStart = 2048 / 2 - paletteTotalWidth / 2 - 1300; // Create palette items for drag-and-drop function createPaletteItem(type, x, y) { var assetId, color, label; if (type === 'plant') { assetId = 'plant'; color = 0x6adf60; label = 'Fern'; } else if (type === 'herbivore') { assetId = 'herbivore'; color = 0xf7e26b; label = 'Nummer'; } else if (type === 'pollinator') { assetId = 'pollinator'; color = 0xffc300; label = 'Pollinator'; } else if (type === 'fungi') { assetId = 'fungi'; color = 0xbb88ff; label = 'Shroom'; } else if (type === 'parasite') { assetId = 'Parasite'; color = 0x8888ff; label = 'Parasite'; } else if (type === 'flytrap') { assetId = 'Flytrap'; color = 0x228B22; label = 'Flytrap'; } else { assetId = 'carnivore'; color = 0xe74c3c; label = 'Hunter'; } ; // Update all eggs for (var i = eggs.length - 1; i >= 0; i--) { var e = eggs[i]; if (!e.parent || e.hatched) { eggs.splice(i, 1); continue; } if (e.update) e.update(); } ; // Update all pollinators for (var i = pollinators.length - 1; i >= 0; i--) { var p = pollinators[i]; if (p.eaten) { pollinators.splice(i, 1); continue; } if (p.update) p.update(); } var node = new Container(); var icon; if (type === 'parasite') { icon = node.attachAsset(assetId, { anchorX: 0.5, anchorY: 0.5, scaleX: 0.5, scaleY: 0.5 }); } else { icon = node.attachAsset(assetId, { anchorX: 0.5, anchorY: 0.5 }); } node.x = x; node.y = y; node.type = type; // Add label var txt = new Text2(label, { size: 60, fill: "#000" }); txt.anchor.set(0.5, 0); txt.y = 60; node.addChild(txt); // Add to GUI overlay (so it stays on top) LK.gui.top.addChild(node); paletteItems.push(node); return node; } // --- Palette Scroll Bar --- // All available organism types in palette var paletteTypes = ['plant', 'herbivore', 'carnivore', 'pollinator', 'fungi', 'parasite', 'flytrap']; var paletteScrollOffset = 0; // How much the palette is scrolled (in px) var paletteScrollMin = 0; var paletteScrollMax = Math.max(0, paletteTypes.length * paletteSpacing - paletteSpacing * 3); // Show 3 at a time // Remove old palette items if any for (var i = 0; i < paletteItems.length; i++) { if (paletteItems[i].parent) paletteItems[i].parent.removeChild(paletteItems[i]); } paletteItems = []; // Helper to render palette items based on scroll offset function renderPaletteItems() { // Remove all current palette items from GUI for (var i = 0; i < paletteItems.length; i++) { if (paletteItems[i].parent) paletteItems[i].parent.removeChild(paletteItems[i]); } paletteItems = []; // Only show up to 3 at a time, centered var visibleCount = 3; var startIdx = Math.floor(paletteScrollOffset / paletteSpacing); var offsetPx = paletteScrollOffset % paletteSpacing; for (var i = 0; i < visibleCount; i++) { var idx = startIdx + i; if (idx >= 0 && idx < paletteTypes.length) { var px = paletteXStart + i * paletteSpacing - offsetPx; var node = createPaletteItem(paletteTypes[idx], px, paletteY); paletteItems.push(node); } } // Draw left/right scroll buttons if (!window.paletteLeftBtn) { window.paletteLeftBtn = new Container(); var leftIcon = window.paletteLeftBtn.attachAsset('box', { anchorX: 0.5, anchorY: 0.5, width: 80, height: 120, color: 0x444444, shape: 'box' }); var leftArrow = new Text2("<", { size: 80, fill: "#000" }); leftArrow.anchor.set(0.5, 0.5); leftArrow.x = 0; leftArrow.y = 0; window.paletteLeftBtn.addChild(leftArrow); window.paletteLeftBtn.x = paletteXStart - 120; window.paletteLeftBtn.y = paletteY; window.paletteLeftBtn.interactive = true; LK.gui.top.addChild(window.paletteLeftBtn); window.paletteLeftBtn.visible = false; } if (!window.paletteRightBtn) { window.paletteRightBtn = new Container(); var rightIcon = window.paletteRightBtn.attachAsset('box', { anchorX: 0.5, anchorY: 0.5, width: 80, height: 120, color: 0x444444, shape: 'box' }); var rightArrow = new Text2(">", { size: 80, fill: "#000" }); rightArrow.anchor.set(0.5, 0.5); rightArrow.x = 0; rightArrow.y = 0; window.paletteRightBtn.addChild(rightArrow); window.paletteRightBtn.x = paletteXStart + paletteSpacing * visibleCount + 40; window.paletteRightBtn.y = paletteY; window.paletteRightBtn.interactive = true; LK.gui.top.addChild(window.paletteRightBtn); window.paletteRightBtn.visible = false; } // Show/hide buttons window.paletteLeftBtn.visible = paletteScrollOffset > paletteScrollMin; window.paletteRightBtn.visible = paletteScrollOffset < paletteScrollMax; } renderPaletteItems(); // --- Palette Scroll Button Handlers --- window.paletteLeftBtn.down = function () { if (paletteScrollOffset > paletteScrollMin) { paletteScrollOffset -= paletteSpacing; if (paletteScrollOffset < paletteScrollMin) paletteScrollOffset = paletteScrollMin; renderPaletteItems(); } }; window.paletteRightBtn.down = function () { if (paletteScrollOffset < paletteScrollMax) { paletteScrollOffset += paletteSpacing; if (paletteScrollOffset > paletteScrollMax) paletteScrollOffset = paletteScrollMax; renderPaletteItems(); } }; // --- End Palette Scroll Bar --- // --- Drag and Drop Logic --- var dragging = null; // {type, node, paletteRef} var dragOffsetX = 0, dragOffsetY = 0; // Helper: create organism at x,y function createOrganism(type, x, y) { var obj; if (type === 'plant') { obj = new Plant(); plants.push(obj); // If background is white, make plant blue and undying if (game.backgroundColor === 0xffffff) { if (obj.plantAsset && typeof obj.plantAsset.tint !== "undefined") { obj.plantAsset.tint = 0x3399ff; } obj._canDie = false; } // If placed in summer, make plant invulnerable for 10 seconds if (game.backgroundColor === 0xffff00 || window.summerState) { obj._invulnerable = true; obj._canDie = false; // Remove invulnerability after 10 seconds (600 frames) LK.setTimeout(function () { if (plants.indexOf(obj) !== -1) { obj._invulnerable = false; obj._canDie = true; } }, 10000); } } else if (type === 'herbivore') { obj = new Nummer(); herbivores.push(obj); } else if (type === 'pollinator') { obj = new Pollinator(); pollinators.push(obj); } else if (type === 'fungi') { obj = new Fungi(); fungis.push(obj); } else if (type === 'parasite') { obj = new Parasite(); parasites.push(obj); // If spawned in winter, kill parasite immediately if (window.winterState) { // Animate parasite dying and remove from array tween(obj, { scaleX: 0, scaleY: 0, alpha: 0 }, { duration: 200, easing: tween.easeIn, onFinish: function onFinish() { if (typeof parasites !== "undefined") { var idx = parasites.indexOf(obj); if (idx !== -1) parasites.splice(idx, 1); } obj.destroy(); } }); } } else if (type === 'flytrap') { obj = new Flytrap(); game.addChild(obj); } else { obj = new Carnivore(); carnivores.push(obj); } obj.x = x; obj.y = y; obj.scaleX = 1; obj.scaleY = 1; obj.alpha = 1; game.addChild(obj); // Start the cycle interval if not already started if (typeof startCycleInterval === "function") startCycleInterval(); return obj; } // Helper: check if point is inside a palette item function isInPalette(x, y, node) { var bounds = { x: node.x - 60, y: node.y - 60, w: 120, h: 120 }; return x >= bounds.x && x <= bounds.x + bounds.w && y >= bounds.y && y <= bounds.y + bounds.h; } // --- Event Handlers --- // Down: start drag if on palette game.down = function (x, y, obj) { // If delete mode is ON, check if click is on an organism and delete it if (deleteMode) { // Include lichens in allOrganisms if present var allOrganisms = plants.concat(herbivores, carnivores, pollinators, fungis, parasites); for (var i = allOrganisms.length - 1; i >= 0; i--) { var org = allOrganisms[i]; var dx = x - org.x; var dy = y - org.y; var dist = Math.sqrt(dx * dx + dy * dy); var isFungi = fungis.indexOf(org) !== -1; var canDelete = isFungi || !org.eaten; if (canDelete && dist < 60) { // Remove from correct array if (plants.indexOf(org) !== -1) { var idx = plants.indexOf(org); if (idx !== -1) plants.splice(idx, 1); } else if (herbivores.indexOf(org) !== -1) { var idx = herbivores.indexOf(org); if (idx !== -1) herbivores.splice(idx, 1); } else if (carnivores.indexOf(org) !== -1) { var idx = carnivores.indexOf(org); if (idx !== -1) carnivores.splice(idx, 1); } else if (pollinators.indexOf(org) !== -1) { var idx = pollinators.indexOf(org); if (idx !== -1) pollinators.splice(idx, 1); } else if (fungis.indexOf(org) !== -1) { var idx = fungis.indexOf(org); if (idx !== -1) fungis.splice(idx, 1); } if (typeof org.die === "function") { org.die(); } else if (typeof org.destroy === "function") { org.destroy(); } return; } } // If not on an organism, do nothing in delete mode return; } // Check if touch/click is on a palette item for (var i = 0; i < paletteItems.length; i++) { var p = paletteItems[i]; // Convert GUI coordinates to game coordinates var guiPos = LK.gui.top.toLocal({ x: x, y: y }, game); if (isInPalette(guiPos.x, guiPos.y, p)) { // Start dragging a new organism dragging = { type: p.type, node: createOrganism(p.type, x, y), paletteRef: p }; dragOffsetX = 0; dragOffsetY = 0; // Make it semi-transparent while dragging dragging.node.alpha = 0.7; return; } } // If not on palette, check if on an organism to move it // Check if touch/click is on an organism to move it var found = false; var allOrganisms = plants.concat(herbivores, carnivores, pollinators, fungis, parasites); for (var i = allOrganisms.length - 1; i >= 0; i--) { var org = allOrganisms[i]; // Only allow moving if not eaten and touch is within 60px radius of center var dx = x - org.x; var dy = y - org.y; var dist = Math.sqrt(dx * dx + dy * dy); var isFungi = fungis.indexOf(org) !== -1; var isParasite = parasites.indexOf(org) !== -1; var canDrag = isFungi || isParasite || !org.eaten; if (canDrag && dist < 60) { var type; if (plants.indexOf(org) !== -1) type = 'plant';else if (herbivores.indexOf(org) !== -1) type = 'herbivore';else if (carnivores.indexOf(org) !== -1) type = 'carnivore';else if (pollinators.indexOf(org) !== -1) type = 'pollinator';else if (fungis.indexOf(org) !== -1) type = 'fungi';else if (parasites.indexOf(org) !== -1) type = 'parasite'; // (UI label is handled in createPaletteItem, so no change needed here for type) dragging = { type: type, node: org, paletteRef: null }; dragOffsetX = org.x - x; dragOffsetY = org.y - y; org.alpha = 0.7; found = true; break; } } if (!found) { dragging = null; } }; // Move: update drag position game.move = function (x, y, obj) { if (dragging && dragging.node) { var minX = 124 + 60; var maxX = 124 + 1800 - 60; var minY = paletteY + 320 + 60; var maxY = paletteY + 320 + 2000 - 60; var newX = x + dragOffsetX; var newY = y + dragOffsetY; // Clamp to map area if (newX < minX) newX = minX; if (newX > maxX) newX = maxX; if (newY < minY) newY = minY; if (newY > maxY) newY = maxY; dragging.node.x = newX; dragging.node.y = newY; } }; // Up: drop organism if dragging game.up = function (x, y, obj) { if (dragging && dragging.node) { // If dropped inside palette area, destroy (cancel) var guiPos = LK.gui.top.toLocal({ x: x, y: y }, game); var cancel = false; for (var i = 0; i < paletteItems.length; i++) { if (isInPalette(guiPos.x, guiPos.y, paletteItems[i])) { cancel = true; break; } } if (cancel) { // Remove organism dragging.node.destroy(); if (dragging.type === 'plant') { var idx = plants.indexOf(dragging.node); if (idx !== -1) plants.splice(idx, 1); } else if (dragging.type === 'herbivore') { var idx = herbivores.indexOf(dragging.node); if (idx !== -1) herbivores.splice(idx, 1); } else if (dragging.type === 'carnivore') { var idx = carnivores.indexOf(dragging.node); if (idx !== -1) carnivores.splice(idx, 1); } else if (dragging.type === 'pollinator') { var idx = pollinators.indexOf(dragging.node); if (idx !== -1) pollinators.splice(idx, 1); } else if (dragging.type === 'fungi') { var idx = fungis.indexOf(dragging.node); if (idx !== -1) fungis.splice(idx, 1); } else if (dragging.type === 'parasite') { var idx = parasites.indexOf(dragging.node); if (idx !== -1) parasites.splice(idx, 1); } } else { // Place organism: snap alpha to 1 dragging.node.alpha = 1; // If dropping a parasite, set state to 'seek' and detach from host if needed if (dragging.type === 'parasite') { // If attached, detach if (dragging.node.state === "attached") { if (dragging.node.attachedTo && dragging.node.attachedTo._parasiteAttached === dragging.node) { dragging.node.attachedTo._parasiteAttached = null; } dragging.node.attachedTo = null; } dragging.node.state = "seek"; dragging.node.target = null; } } dragging = null; } }; // --- Main Update Loop --- game.update = function () { // Update all herbivores for (var i = herbivores.length - 1; i >= 0; i--) { var h = herbivores[i]; if (h.eaten) { herbivores.splice(i, 1); continue; } if (h.update) h.update(); } // Update all carnivores for (var i = carnivores.length - 1; i >= 0; i--) { var c = carnivores[i]; if (c.eaten) { carnivores.splice(i, 1); continue; } if (c.update) c.update(); } // In summer, randomly turn some healthy plants brown if (window.summerState) { for (var i = 0; i < plants.length; i++) { var p = plants[i]; // Only affect healthy, non-brown, non-eaten plants if (!p.eaten && !p._isBrown) { // Smaller chance per frame (e.g. 0.0005 = ~0.05% per frame) if (Math.random() < 0.0005) { p._isBrown = true; if (p.plantAsset && typeof p.plantAsset.tint !== "undefined") { p.plantAsset.tint = 0x996633; // brown } } } } } // Clean up dead plants for (var i = plants.length - 1; i >= 0; i--) { var p = plants[i]; if (p.eaten) { plants.splice(i, 1); } } // Update all seeds for (var i = seeds.length - 1; i >= 0; i--) { var s = seeds[i]; if (s.eaten) { seeds.splice(i, 1); continue; } if (s.update) s.update(); } ; // Update all fungi for (var i = fungis.length - 1; i >= 0; i--) { var f = fungis[i]; if (f.update) f.update(); } // Update all fungi spores for (var i = fungiSpores.length - 1; i >= 0; i--) { var s = fungiSpores[i]; if (!s.parent || !s._alive) { fungiSpores.splice(i, 1); continue; } if (s.update) s.update(); } // Update all parasites for (var i = parasites.length - 1; i >= 0; i--) { var b = parasites[i]; if (b.update) b.update(); } }; // --- Instructions Text --- // --- Random seed spawning around the map if there are any plants --- var randomSeedSpawnTimer = null; function startRandomSeedSpawning() { if (randomSeedSpawnTimer !== null) return; randomSeedSpawnTimer = LK.setInterval(function () { // Only spawn if there are any plants if (plants.length > 0) { // 40% chance per interval to spawn a seed if (Math.random() < 0.4) { // Pick a random position inside the map area var minX = 124 + 60; var maxX = 124 + 1800 - 60; var minY = paletteY + 320 + 60; var maxY = paletteY + 320 + 2000 - 60; var sx = minX + Math.random() * (maxX - minX); var sy = minY + Math.random() * (maxY - minY); var seed = new Seed(); seed.x = sx; seed.y = sy; seed.scaleX = 0.4; seed.scaleY = 0.4; seed.alpha = 1; seeds.push(seed); game.addChild(seed); } } // If no plants, stop spawning if (plants.length === 0 && randomSeedSpawnTimer !== null) { LK.clearInterval(randomSeedSpawnTimer); randomSeedSpawnTimer = null; } }, 120); // Try every 2 seconds } // Start random seed spawning at game start startRandomSeedSpawning(); // --- Map Area Border (for visual feedback) --- // Use a simple colored rectangle instead of a plant asset for the map border background var mapBorder = LK.getAsset('box', { anchorX: 0, anchorY: 0, width: 1800, height: 2000, color: 0x2e8b57, shape: 'box' }); mapBorder.alpha = 0.12; game.addChild(mapBorder); mapBorder.x = 124; mapBorder.y = paletteY + 320; // --- Add invisible border walls to prevent creatures from exiting the map area --- var borderThickness = 40; var borderAlpha = 0; // fully invisible // Left border var borderLeft = LK.getAsset('box', { anchorX: 0, anchorY: 0, width: borderThickness, height: 2000, color: 0x000000, shape: 'box' }); borderLeft.alpha = borderAlpha; game.addChild(borderLeft); borderLeft.x = 124 - borderThickness; borderLeft.y = paletteY + 320; // Right border var borderRight = LK.getAsset('box', { anchorX: 0, anchorY: 0, width: borderThickness, height: 2000, color: 0x000000, shape: 'box' }); borderRight.alpha = borderAlpha; game.addChild(borderRight); borderRight.x = 124 + 1800; borderRight.y = paletteY + 320; // Top border var borderTop = LK.getAsset('box', { anchorX: 0, anchorY: 0, width: 1800 + borderThickness * 2, height: borderThickness, color: 0x000000, shape: 'box' }); borderTop.alpha = borderAlpha; game.addChild(borderTop); borderTop.x = 124 - borderThickness; borderTop.y = paletteY + 320 - borderThickness; // Bottom border var borderBottom = LK.getAsset('box', { anchorX: 0, anchorY: 0, width: 1800 + borderThickness * 2, height: borderThickness, color: 0x000000, shape: 'box' }); borderBottom.alpha = borderAlpha; game.addChild(borderBottom); borderBottom.x = 124 - borderThickness; borderBottom.y = paletteY + 320 + 2000;
===================================================================
--- original.js
+++ change.js
@@ -9,18 +9,15 @@
// --- Flytrap Organism Class ---
// Minimal organism that does nothing (placeholder)
var Flytrap = Container.expand(function () {
var self = Container.call(this);
- // Attach a plant asset as the visual for the flytrap
- self.flytrapAsset = self.attachAsset('plant', {
+ // Attach the Flytrap image asset as the visual for the flytrap
+ self.flytrapAsset = self.attachAsset('Flytrap', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1,
scaleY: 1
- // Optionally, set a unique color if desired
- // color: 0x228B22
});
- // No update logic yet
return self;
});
/****
@@ -639,9 +636,9 @@
assetId = 'Parasite';
color = 0x8888ff;
label = 'Parasite';
} else if (type === 'flytrap') {
- assetId = 'plant';
+ assetId = 'Flytrap';
color = 0x228B22;
label = 'Flytrap';
} else {
assetId = 'carnivore';
tentacled red circle with a mouth and no eyes. In-Game asset. 2d. High contrast. No shadows. Very simple
A plant. In-Game asset. 2d. High contrast. No shadows. Very simple
Brown Seed. In-Game asset. 2d. High contrast. No shadows. Very simple
A small orange circle with spider legs 1 cute eye and no mouth. In-Game asset. 2d. High contrast. No shadows. Very very simple
Make a red egg with dark red spots. In-Game asset. 2d. High contrast. No shadows
Purple mushroom. In-Game asset. 2d. High contrast. No shadows. Very simple
A green shiny orb with a black circle. In-Game asset. 2d. High contrast. No shadows. Very simple
make a cyan lichen. In-Game asset. 2d. High contrast. No shadows. very simple
Just the color blue filling the entire space. In-Game asset. 2d. High contrast. No shadows
A brown circle with bug like antennas and bug legs with bug jaws and no eyes. In-Game asset. 2d. High contrast. No shadows. Very simple
A venus flytrap with one mouth and is looking up side view. In-Game asset. 2d. High contrast. No shadows VERY SIMPLE
Short brown worm. In-Game asset. 2d. High contrast. No shadows. Very simple
Pile of dirt. In-Game asset. 2d. High contrast. No shadows. Very simple
A yellow circle with 3 eyes no mouth and the eyes are in a triangle orientation. In-Game asset. 2d. High contrast. No shadows
Shrub. In-Game asset. 2d. High contrast. No shadows. Very simple