Code edit (1 edits merged)
Please save this source code
User prompt
zombies should get harvested if they have been in the radius for 4 seconds. currectly i know it's set to 5 seconds. but even after keeping the zombie in the radius for 5 seconds, he was not harvested.
User prompt
no it should be initialized with a maximum of 5. so it start with 5/5. Also we want some text above our global health bar that says health
User prompt
Declare healthBar in a higher scope please so it is accessible globally.
User prompt
trye this: var Zombie = Container.expand(function (healthBar) { var self = Container.call(this); // Add Zombie-specific properties here // Attack Mishnu and update the health bar self.update = function () { if (distance < 50 && Date.now() - self.lastAttackTime > self.attackCooldown) { healthBar.setHealth(healthBar.currentHealth - 1); // Ensure health is updated self.lastAttackTime = Date.now(); } }; return self; });
User prompt
i do not see damage reflected in the health bar when zombie makes contact with mishnu. It seems the zombie class is unable to change the global health bar to reflect damage.
User prompt
Please fix the bug: 'ReferenceError: globalHealthBar is not defined' in or related to this line: 'globalHealthBar.setHealth(globalHealthBar.currentHealth - 1); // Update global health bar' Line Number: 448
User prompt
The healthBar is created globally and added to the UI layer. However, the zombie class might not be accessing the same instance or is failing to interact with it correctly. Double-check that the healthBar used within the Zombie class is the same instance created globally. Fix: Ensure healthBar is accessible from the Zombie class. Because zombie is not giving damage to mishnu
User prompt
Zombie attack cool down needs to be longer. Also when zombie makes contact with mishnu, she effectively takes damage, and that damage should be reflected in our global healthbar as we indicated in our healthbar logic. not sure why she isnt losing hit points when the zombie makes contact
User prompt
To fix the error, the damage is done to global healthbar. global healthbar maanages the health of mishnu.
User prompt
no we dont want mishnu to have the health bar. our health bar is already there. it needs to be global health bar
User prompt
Please fix the bug: 'TypeError: mishnu.healthBar is undefined' in or related to this line: 'mishnu.healthBar.setHealth(mishnu.healthBar.currentHealth - 1);' Line Number: 443
User prompt
our zombies are not spawning
Code edit (6 edits merged)
Please save this source code
User prompt
we're going in a circle here you keep trying to fix that error and it keep happening over and over again. break out of the loop and fix the error for good
User prompt
please fix zombies not spawning
User prompt
/**** * Zombie Spawning ****/ function spawnZombies(count, maxZombiesOnScreen) { console.log(`Spawning zombies: ${count}, Max zombies: ${maxZombiesOnScreen}`); for (var i = 0; i < count; i++) { if (zombies.length >= maxZombiesOnScreen) { break; } var spawnEdge = Math.floor(Math.random() * 3); var spawnX, spawnY; switch (spawnEdge) { case 0: spawnX = Math.random() * 2048; spawnY = -50; break; case 1: spawnX = -50; spawnY = Math.random() * (2432 - 300); break; case 2: spawnX = 2048 + 50; spawnY = Math.random() * (2432 - 300); break; } var newZombie = new Zombie(); newZombie.x = spawnX; newZombie.y = spawnY; zombies.push(newZombie); game.addChild(newZombie); } } /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); var maxZombiesOnScreen = 10; var zombies = []; var factory = new Factory(); factory.x = 950; factory.y = 2332; var radius = game.addChild(new HarvestRadius()); var mishnu = game.addChild(new Mishnu()); mishnu.x = 2048 / 2; mishnu.y = 2432 - 200; radius.x = mishnu.x; radius.y = mishnu.y; var factoryText = new Text2('Meat: 0\nDog Food: 0\nNext level at: 5', { size: 50, fill: 0xFFFFFF }); factoryText.anchor.set(0, 1); LK.gui.bottomLeft.addChild(factoryText); function updateFactoryText() { factoryText.setText(`Level: ${factory.level}\nMeat: ${factory.meat}\nDog Food: ${factory.dogFood}\nNext level at: ${factory.nextLevelRequirement}`); } /**** * Game Update Loop ****/ game.update = function () { factory.update(); zombies.forEach(function (zombie) { zombie.update(); }); }; add this code in there
User prompt
well i produced 1 dog food, and i don't see any zombies.. so i dont think they are spawning properly
User prompt
we need to make sure that 2*dog food # of zombies spawn for every increment of dog food.
Code edit (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
its even worst now, lets go the other way
User prompt
the inner health bar is offset from the outer healthbar. please fix this
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Sprite is not a constructor' in or related to this line: 'var frame = new Sprite('LK_Health_Bar');' Line Number: 192
/**** * Classes ****/ // Blood Splash Class var BloodSplash = Container.expand(function (x, y, isFinal) { var self = Container.call(this); var bloodGraphics = self.attachAsset('Blood_Splash_1', { anchorX: 0.5, anchorY: 0.5, alpha: 0, rotation: Math.random() * Math.PI * 2, scaleX: 0, scaleY: 0 }); self.x = x; self.y = y; var growSpeed = isFinal ? 0.1 : 0.05; self.update = function () { bloodGraphics.alpha += 0.05; bloodGraphics.scaleX += growSpeed; bloodGraphics.scaleY += growSpeed; if (bloodGraphics.alpha >= 1) { game.removeChild(self); } }; return self; }); // Factory Class var Factory = Container.expand(function () { var self = Container.call(this); var factoryGraphics = self.attachAsset('Factory', { anchorX: 0.5, anchorY: 0.5, zIndex: 3 }); self.x = 950; self.y = 2432 - 100; // Position factory in the text box area self.meat = 0; self.dogFood = 0; self.processing = false; self.processInterval = null; self.rumbleTimer = 0; // Timer for rumble effect self.level = 1; // Current level self.nextLevelRequirement = 5; // Starting requirement for level 2 // Start processing meat into dog food self.startProcessing = function () { if (!self.processing && self.meat >= 5) { self.processing = true; LK.getSound('Factory_Operation').play({ loop: true }); self.processInterval = LK.setInterval(function () { if (self.meat >= 5) { self.meat -= 5; self.dogFood++; updateFactoryText(); checkLevelProgression(); // Check if the next level is reached spawnZombies(1, maxZombiesOnScreen); // Spawn a zombie when dog food is produced } else { self.stopProcessing(); } }, 5000); } }; // Stop processing self.stopProcessing = function () { if (self.processing) { self.processing = false; LK.clearInterval(self.processInterval); LK.getSound('Factory_Operation').stop(); } }; // Update the factory self.update = function () { // Check for Mishnu depositing cargo if (mishnu.humansHarvested > 0 && self.intersects(mishnu)) { // Mishnu deposits cargo self.meat += mishnu.humansHarvested; mishnu.humansHarvested = 0; LK.getSound('Factory_Deposit').play(); // Play deposit sound updateFactoryText(); self.startProcessing(); } // Add rumble effect when processing if (self.processing) { self.rumbleTimer += 16; // Assume 16ms per frame if (self.rumbleTimer >= 100) { // Rumble every 100ms factoryGraphics.x = Math.random() * 6 - 3; // Horizontal rumble factoryGraphics.y = Math.random() * 6 - 3; // Vertical rumble self.rumbleTimer = 0; } } else { // Reset position when not processing factoryGraphics.x = 0; factoryGraphics.y = 0; } // Stop processing if out of meat if (self.meat < 5 && self.processing) { self.stopProcessing(); } }; function triggerLevelTextShake() { var shakeIntensity = 5; // Maximum shake offset in pixels var shakeDuration = 500; // Duration of the shake in milliseconds var elapsedTime = 0; // Tracks elapsed time var originalX = factoryText.x; // Save the original x position var originalY = factoryText.y; // Save the original y position // Function to perform shaking var shakeInterval = LK.setInterval(function () { if (elapsedTime >= shakeDuration) { LK.clearInterval(shakeInterval); factoryText.x = originalX; // Reset to original position factoryText.y = originalY; return; } // Apply random offset for shaking factoryText.x = originalX + (Math.random() * shakeIntensity * 2 - shakeIntensity); factoryText.y = originalY + (Math.random() * shakeIntensity * 2 - shakeIntensity); elapsedTime += 16; // Assume 16ms per frame (60 FPS) }, 16); } function checkLevelProgression() { if (self.dogFood >= self.nextLevelRequirement) { self.level++; LK.getSound('Level_Up').play(); // Play level-up sound self.nextLevelRequirement += Math.round(self.nextLevelRequirement * 0.75); // Increase requirement by 75% // Reset spawn counter and calculate new spawn limit humansSpawnedThisLevel = 0; humanSpawnLimit = self.nextLevelRequirement * 5; // Trigger level-up animation triggerLevelTextShake(); updateFactoryText(); spawnZombies(1, maxZombiesOnScreen); // Spawn a zombie when leveling up } } }); // GlobalHealthBar Class var GlobalHealthBar = Container.expand(function (initialHealth, maxHealth) { var self = Container.call(this); self.currentHealth = initialHealth; self.maxHealth = maxHealth; // Define frame dimensions if dynamic retrieval isn't available var frameWidth = LK.getAsset('LK_Health_Bar', {}).width; // Create filler (health bar inner part) var filler = self.attachAsset('LK_Inner_Health_Bar', { anchorX: 0, // Anchor to the left anchorY: 0.5, // Center vertically x: -frameWidth / 2, // Align with the outer frame // Start from the left edge of the frame y: 0, // Center vertically scaleX: 1 // Fully filled initially }); // Create frame (health bar outer part) var frame = self.attachAsset('LK_Health_Bar', { anchorX: 0.5, // Center horizontally anchorY: 0.5, // Center vertically x: 0, // Centered relative to the container y: 0 // Center vertically }); // Update the visual representation of the health bar self.updateHealth = function () { // Ensure filler width matches current health filler.scaleX = Math.max(0, self.currentHealth / self.maxHealth); // Scale proportionally }; // Change health value self.setHealth = function (newHealth) { self.currentHealth = Math.max(0, Math.min(newHealth, self.maxHealth)); // Clamp between 0 and maxHealth self.updateHealth(); }; // Change maximum health and adjust health proportionally self.setMaxHealth = function (newMaxHealth) { var healthRatio = self.currentHealth / self.maxHealth; self.maxHealth = Math.max(1, newMaxHealth); // Ensure at least 1 max health self.currentHealth = Math.min(self.currentHealth, self.maxHealth); self.updateHealth(); }; // Initialize the health bar self.setHealth(initialHealth); return self; }); // Declare healthBar globally for accessibility // Assuming initial and max health are both 100 // Class for Mishnu's harvest radius var HarvestRadius = Container.expand(function () { var self = Container.call(this); var radiusGraphics = self.attachAsset('radius', { anchorX: 0.5, anchorY: 0.5, scaleX: 10, scaleY: 10 }); self.radiusSize = 300; // Effective radius size var rotationSpeed = 0.001; // Extremely slow rotation speed self.update = function () { self.x = mishnu.x; self.y = mishnu.y; // Apply slow rotation to the radius radiusGraphics.rotation += rotationSpeed; }; return self; }); // Class for Humans var Human = Container.expand(function () { var self = Container.call(this); var humanGraphics = self.attachAsset('human', { anchorX: 0.5, anchorY: 0.5 }); var bloodSplashes = []; self.speedX = (Math.random() * 2 - 1) * 2; self.speedY = (Math.random() * 2 - 1) * 2; self.isBeingHarvested = false; self.inRadiusStartTime = null; self.currentAgonySound = null; self.currentCrunchSound = null; self.yellStarted = false; // Tracks if the yell has started self.yellShouldPlay = Math.random() < 1 / 3; // 1-in-3 chance for yelling self.crunchShouldPlay = Math.random() < 1 / 6; // 1-in-3 chance for crunch sound self.flashTimer = 0; // Timer for red flashing self.flashInterval = 500; // Initial interval for flashing self.update = function () { // Escape logic self.x += self.speedX; self.y += self.speedY; // Keep humans within the viewport margins var margin = 50; var bottomMargin = 300; // Extra margin for bottom text box if (self.x <= margin) { self.x = margin; self.speedX *= -1; } else if (self.x >= 2048 - margin) { self.x = 2048 - margin; self.speedX *= -1; } if (self.y <= margin) { self.y = margin; self.speedY *= -1; } else if (self.y >= 2432 - margin) { // Ensure humans respect new boundary height self.y = 2432 - margin; self.speedY *= -1; } // Check distance to Mishnu var dx = self.x - mishnu.x; var dy = self.y - mishnu.y; var distance = Math.sqrt(dx * dx + dy * dy); if (mishnu.humansHarvested >= mishnu.cargoMax * 1.5) { // Stop all sounds when cargo exceeds 150% capacity if (self.currentAgonySound) { fadeOutSound(self.currentAgonySound, 500); } if (self.currentCrunchSound) { self.currentCrunchSound.stop(); } self.isBeingHarvested = false; humanGraphics.tint = 0xFFFFFF; // Reset flashing return; } if (distance < radius.radiusSize - 2) { if (!self.isBeingHarvested) { self.isBeingHarvested = true; self.inRadiusStartTime = Date.now(); self.flashTimer = 0; bloodSplashes = []; self.yellStarted = false; // Play crunch sound if applicable if (self.crunchShouldPlay) { self.currentCrunchSound = getRandomSound(['Dog_Crunch', 'Dog_Crunch_2', 'Dog_Crunch_3']); self.currentCrunchSound.volume = 0.3; self.currentCrunchSound.play(); } } else { // Calculate vibration intensity based on time in the radius var elapsedTime = Date.now() - self.inRadiusStartTime; var intensity = Math.min(1, elapsedTime / 3000); // Max intensity at 3 seconds // Add vibration effect humanGraphics.x = Math.random() * intensity * 10 - intensity * 5; humanGraphics.y = Math.random() * intensity * 10 - intensity * 5; // Escape logic during vibration var runSpeed = 2; // Speed humans try to escape the radius self.x += dx / distance * runSpeed; self.y += dy / distance * runSpeed; // Flash red effect self.flashTimer += 16; // Assume a fixed delta of 16ms per frame if (self.flashTimer >= self.flashInterval) { self.flashTimer = 0; humanGraphics.tint = humanGraphics.tint === 0xFFFFFF ? 0xFF0000 : 0xFFFFFF; // Emit blood splash var bloodSplash = game.addChild(new BloodSplash(self.x, self.y)); bloodSplashes.push(bloodSplash); } // Increase flash frequency closer to harvest self.flashInterval = Math.max(100, 500 - elapsedTime / 3000 * 400); // Start agony yell after 1 second of harvesting if (elapsedTime > 1000 && !self.yellStarted && self.yellShouldPlay) { self.yellStarted = true; self.currentAgonySound = getRandomSound(['Agony_Yell_1', 'Agony_Yell_2', 'Agony_Yell_3', 'Agony_Yell_4', 'Agony_Yell_5', 'Agony_Yell_6', 'Agony_Yell_7']); self.currentAgonySound.volume = 0.3; self.currentAgonySound.play(); } if (elapsedTime >= 3000) { // Harvest after 3 seconds if (mishnu.humansHarvested < mishnu.cargoMax * 1.5) { game.removeChild(self); // Remove human from the game humans.splice(humans.indexOf(self), 1); // Remove from array mishnu.humansHarvested++; // Stop yelling abruptly if (self.currentAgonySound) { self.currentAgonySound.stop(); } // Play ding and squish sounds on harvest LK.getSound('Ding_1').play(); getRandomSound(['Squish_1', 'Squish_2', 'Squish_3', 'Squish_4']).play(); // Final blood splashes for (var i = 0; i < 10; i++) { var bloodSplash = game.addChild(new BloodSplash(self.x, self.y, true)); bloodSplashes.push(bloodSplash); } } } } } else { // Reset harvesting state if outside the radius if (self.isBeingHarvested) { if (self.currentAgonySound && self.yellStarted) { self.currentAgonySound.loop = false; } if (self.currentCrunchSound) { self.currentCrunchSound.stop(); } } self.isBeingHarvested = false; self.inRadiusStartTime = null; self.flashTimer = 0; humanGraphics.tint = 0xFFFFFF; // Reset flashing bloodSplashes.forEach(function (splash) { game.removeChild(splash); }); } }; return self; }); // Class for Mishnu var Mishnu = Container.expand(function () { var self = Container.call(this); var mishnuGraphics = self.attachAsset('mishnu', { anchorX: 0.5, anchorY: 0.5, zIndex: 1 }); self.speed = 4; self.humansHarvested = 0; self.cargoMax = 10; self.targetX = 2048 / 2; self.targetY = 2432 - 200; self.update = function () { var dx = self.targetX - self.x; var dy = self.targetY - self.y; var distance = Math.sqrt(dx * dx + dy * dy); // Adjust speed based on cargo if (self.humansHarvested > self.cargoMax) { var overCapacityFactor = (self.humansHarvested - self.cargoMax) / (self.cargoMax * 0.5); self.speed = Math.max(1, 4 - 3 * overCapacityFactor); // Minimum speed of 1 } else { self.speed = 4; // Full speed } if (distance > 0) { self.x += dx / distance * self.speed; self.y += dy / distance * self.speed; } // Keep Mishnu within viewport margins var margin = 50; var bottomMargin = 300; // Extra margin for bottom text box self.x = Math.max(margin, Math.min(2048 - margin, self.x)); self.y = Math.max(margin, Math.min(2432 - bottomMargin, self.y)); }; // Create and position the health bar at the top center of the viewport globalHealthBar.x = 1820; // Center horizontally globalHealthBar.y = 2560; // Position at the top center uiLayer.addChild(globalHealthBar); // Add to the UI layer to ensure visibility return self; }); var Zombie = Container.expand(function () { var self = Container.call(this); var zombieGraphics = self.attachAsset('Zombie', { anchorX: 0.5, anchorY: 0.5 }); var bloodSplashes = []; self.harvestTime = 4000; // 4 seconds to harvest self.meatYield = 2; // Zombies provide 2 meat self.attackCooldown = 3000; // 3-second cooldown for attacks self.lastAttackTime = 0; // Tracks the last attack time self.speed = 2; // Movement speed for zombies self.inRadiusStartTime = null; // Tracks time inside radius self.isBeingHarvested = false; self.isFleeing = false; // Tracks if the zombie is fleeing self.currentAgonySound = null; self.update = function () { var dx = self.x - mishnu.x; var dy = self.y - mishnu.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < radius.radiusSize) { // Inside radius if (!self.isFleeing) { if (!self.isBeingHarvested) { self.inRadiusStartTime = self.inRadiusStartTime || Date.now(); } // Harvesting logic var elapsedTime = Date.now() - self.inRadiusStartTime; if (elapsedTime >= self.harvestTime) { self.isBeingHarvested = true; game.removeChild(self); // Remove zombie from the game zombies.splice(zombies.indexOf(self), 1); // Remove from array mishnu.humansHarvested += self.meatYield; // Stop agony sounds if (self.currentAgonySound) { self.currentAgonySound.stop(); } // Play harvest effects LK.getSound('Ding_1').play(); getRandomSound(['Squish_1', 'Squish_2', 'Squish_3', 'Squish_4']).play(); for (var i = 0; i < 10; i++) { var bloodSplash = game.addChild(new BloodSplash(self.x, self.y, true)); bloodSplashes.push(bloodSplash); } return; } // Agony yell during harvesting if (!self.currentAgonySound && elapsedTime > 1000) { self.currentAgonySound = getRandomSound(['Agony_Yell_1', 'Agony_Yell_2', 'Agony_Yell_3']); self.currentAgonySound.volume = 0.3; self.currentAgonySound.play(); } // Attack logic if (distance < 50 && Date.now() - self.lastAttackTime > self.attackCooldown) { globalHealthBar.setHealth(globalHealthBar.currentHealth - 1); // Damage Mishnu self.lastAttackTime = Date.now(); self.isFleeing = true; // Start fleeing after attack } } else { // Fleeing logic self.x += dx / distance * self.speed * 2; self.y += dy / distance * self.speed * 2; } } else { // Outside radius self.isBeingHarvested = false; self.inRadiusStartTime = null; self.isFleeing = false; // Reset state if fleeing if (self.currentAgonySound) { self.currentAgonySound.stop(); self.currentAgonySound = null; } // Roaming behavior self.x += (Math.random() * 2 - 1) * self.speed; self.y += (Math.random() * 2 - 1) * self.speed; // Keep zombies within game boundaries var margin = 50; var bottomMargin = 300; // Extra margin for bottom UI self.x = Math.max(margin, Math.min(2048 - margin, self.x)); self.y = Math.max(margin, Math.min(2432 - bottomMargin, self.y)); } }; return self; }); /**** * Initialize Game ****/ // Modify game logic to include zombie spawning var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ // Declare healthBar globally for accessibility // Modify game logic to include zombie spawning var globalHealthBar = new GlobalHealthBar(100, 100); function spawnZombies(count, maxZombiesOnScreen) { for (var i = 0; i < count; i++) { if (zombies.length >= maxZombiesOnScreen) { break; } var spawnEdge = Math.floor(Math.random() * 3); // 0: top, 1: left, 2: right var spawnX, spawnY; switch (spawnEdge) { case 0: spawnX = Math.random() * 2048; spawnY = -50; break; case 1: spawnX = -50; spawnY = Math.random() * (2432 - 300); break; case 2: spawnX = 2048 + 50; spawnY = Math.random() * (2432 - 300); break; } var newZombie = new Zombie(); newZombie.x = spawnX; newZombie.y = spawnY; zombies.push(newZombie); game.addChild(newZombie); } } // Initialize zombies var zombies = []; var zombieSpawnCooldown = 3000; // Time (ms) between zombie spawn attempts var zombieSpawnElapsedTime = 0; var maxZombiesOnScreen = 10; // Update game loop to handle zombies var originalGameUpdate = game.update; game.update = function () { originalGameUpdate.call(this); // Update zombies zombies.forEach(function (zombie) { zombie.update(); }); // Spawn zombies if needed zombieSpawnElapsedTime += 16; // Assume 16ms per frame if (zombieSpawnElapsedTime >= zombieSpawnCooldown && zombies.length < maxZombiesOnScreen) { spawnZombies(1, maxZombiesOnScreen); // Spawn one zombie at a time zombieSpawnElapsedTime = 0; } // Ensure zombie count does not exceed maximum if (zombies.length > maxZombiesOnScreen) { while (zombies.length > maxZombiesOnScreen) { var zombieToRemove = zombies.pop(); game.removeChild(zombieToRemove); } } }; var isMusicPlaying = { 'Music_Level_1_4': false, 'Music_Level_1_5': false }; // Update factory text function updateFactoryText() { factoryText.setText("Level: " + factory.level + "\nMeat: " + factory.meat + "\nDog Food: " + factory.dogFood + "\nNext level at: " + factory.nextLevelRequirement); } // Function to randomly select a sound from a list ; // Add a UI layer to ensure factory is rendered above the background and mask var uiLayer = new Container(); uiLayer.zIndex = 10; // Ensure it's above the background and mask game.addChild(uiLayer); // Create and position the health bar at the top center of the viewport var globalHealthBar = new GlobalHealthBar(5, 5); // Initialize with initial and max health of 5 globalHealthBar.x = 1820; // Center horizontally globalHealthBar.y = 2560; // Position at the top center // Add text label 'Health' above the global health bar var healthLabel = new Text2('Health', { size: 50, fill: 0xFFFFFF }); healthLabel.anchor.set(0.5, 1); healthLabel.x = globalHealthBar.x; healthLabel.y = globalHealthBar.y - 60; // Position above the health bar uiLayer.addChild(healthLabel); uiLayer.addChild(globalHealthBar); // Add to the UI layer to ensure visibility // Add the factory to the UI layer var factory = uiLayer.addChild(new Factory()); // Initialize factory text var factoryText = new Text2('Meat: 0\nDog Food: 0\nNext level at: 100', { size: 50, fill: 0xFFFFFF, align: 'left' }); factoryText.anchor.set(0, 1); LK.gui.bottomLeft.addChild(factoryText); var nextLevel = 100; // Placeholder for next level goal // Function to randomly spawn a human at the edges of the viewport function spawnHumans(count, maxHumansOnScreen) { for (var i = 0; i < count; i++) { // Ensure we don't exceed maxHumansOnScreen if (humans.length >= maxHumansOnScreen) { break; } // Randomly select a spawn edge (excluding the bottom) var spawnEdge = Math.floor(Math.random() * 3); // 0: top, 1: left, 2: right var spawnX, spawnY; switch (spawnEdge) { case 0: // Top spawnX = Math.random() * 2048; spawnY = -50; // Just outside the top boundary break; case 1: // Left spawnX = -50; // Just outside the left boundary spawnY = Math.random() * (2432 - 300); // Exclude bottom UI area break; case 2: // Right spawnX = 2048 + 50; // Just outside the right boundary spawnY = Math.random() * (2432 - 300); // Exclude bottom UI area break; } // Create a new human and add it to the game var newHuman = new Human(); newHuman.x = spawnX; newHuman.y = spawnY; humans.push(newHuman); game.addChild(newHuman); } } // Update game loop var originalUpdate = game.update; game.update = function () { originalUpdate.call(this); // Update factory factory.update(); // Check for level progression if (factory.dogFood >= nextLevel) { // Handle level progression logic here nextLevel += 100; // Example: increase next level goal updateFactoryText(); } }; function getRandomSound(soundList) { return LK.getSound(soundList[Math.floor(Math.random() * soundList.length)]); } // Function to fade out a sound function fadeOutSound(sound, duration) { var initialVolume = sound.volume; var fadeStep = initialVolume / (duration / 100); var fadeInterval = LK.setInterval(function () { if (sound.volume > 0) { sound.volume = Math.max(0, sound.volume - fadeStep); } else { LK.clearInterval(fadeInterval); sound.stop(); } }, 100); } var radius = game.addChild(new HarvestRadius()); var mishnu = game.addChild(new Mishnu()); mishnu.x = 2048 / 2; mishnu.y = 2432 - 200; radius.x = mishnu.x; radius.y = mishnu.y; // Initialize humans var humans = []; for (var i = 0; i < 50; i++) { var human = new Human(); human.x = Math.random() * 2048; human.y = Math.random() * (2432 - 100); humans.push(human); game.addChild(human); var humansSpawnedThisLevel = 0; // Tracks how many humans have spawned in the current level var humanSpawnLimit = factory.nextLevelRequirement * 7; // Set minimum spawn limit to nextLevelRequirement * 7 } var spawnCooldown = 20; // Reduced time (in ms) between spawn attempts for faster spawning var spawnElapsedTime = 0; // Tracks time elapsed since the last spawn attempt // Play looping Dog Panting sound LK.getSound('Dog_panting').play({ loop: true }); // Handle mouse movement game.move = function (x, y, obj) { mishnu.targetX = x; mishnu.targetY = y; }; // Display cargo count var cargoText = new Text2('Cargo: 0 / 10', { size: 50, fill: 0xFFFFFF }); cargoText.anchor.set(1, 1); LK.gui.bottomRight.addChild(cargoText); // Music alternation logic var currentMusic = 'Music_Level_1_5'; game.update = function () { humans.forEach(function (human) { human.update(); }); mishnu.update(); zombies.forEach(function (zombie) { zombie.update(); }); radius.update(); // Calculate dynamic minimum and maximum humans on screen var minHumansOnScreen = Math.max((factory.nextLevelRequirement - factory.dogFood) * 7, 20); // Ensure a minimum of 20 var maxHumansOnScreen = Math.ceil(minHumansOnScreen * 1.5); // Scale max to 150% of min // Ensure minimum number of humans on screen if (humans.length < minHumansOnScreen) { spawnElapsedTime += 16; // Assume 16ms per frame if (spawnElapsedTime >= spawnCooldown) { spawnHumans(minHumansOnScreen - humans.length, maxHumansOnScreen); // Pass the maxHumansOnScreen value spawnElapsedTime = 0; // Reset spawn elapsed time } } // Cap the number of humans to maxHumansOnScreen if (humans.length > maxHumansOnScreen) { // Remove excess humans from the game while (humans.length > maxHumansOnScreen) { var humanToRemove = humans.pop(); game.removeChild(humanToRemove); } } // Update cargo text var textColor = mishnu.humansHarvested > mishnu.cargoMax ? 0xFF0000 : 0xFFFFFF; if (cargoText.fill !== textColor) { LK.gui.bottomRight.removeChild(cargoText); cargoText = new Text2('Cargo: ' + mishnu.humansHarvested + ' / ' + mishnu.cargoMax, { size: 50, fill: textColor }); cargoText.anchor.set(1, 1); LK.gui.bottomRight.addChild(cargoText); } else { cargoText.setText('Cargo: ' + mishnu.humansHarvested + ' / ' + mishnu.cargoMax); } // Play Music_Level_1_4 in a loop if (!isMusicPlaying['Music_Level_1_4']) { LK.playMusic('Music_Level_1_4', { loop: true }); isMusicPlaying['Music_Level_1_4'] = true; // Track music state } // Play Music_Level_1_5 in a loop if (!isMusicPlaying['Music_Level_1_5']) { LK.playMusic('Music_Level_1_5', { loop: true }); isMusicPlaying['Music_Level_1_5'] = true; // Track music state } // Update factory factory.update(); };
===================================================================
--- original.js
+++ change.js
@@ -387,44 +387,85 @@
globalHealthBar.y = 2560; // Position at the top center
uiLayer.addChild(globalHealthBar); // Add to the UI layer to ensure visibility
return self;
});
-var Zombie = Container.expand(function (healthBar) {
+var Zombie = Container.expand(function () {
var self = Container.call(this);
- // Add Zombie-specific properties
var zombieGraphics = self.attachAsset('Zombie', {
anchorX: 0.5,
anchorY: 0.5
});
- self.harvestTime = 4000; // Time required to harvest (4 seconds)
+ var bloodSplashes = [];
+ self.harvestTime = 4000; // 4 seconds to harvest
self.meatYield = 2; // Zombies provide 2 meat
self.attackCooldown = 3000; // 3-second cooldown for attacks
self.lastAttackTime = 0; // Tracks the last attack time
self.speed = 2; // Movement speed for zombies
- // Update logic for the zombie
+ self.inRadiusStartTime = null; // Tracks time inside radius
+ self.isBeingHarvested = false;
+ self.isFleeing = false; // Tracks if the zombie is fleeing
+ self.currentAgonySound = null;
self.update = function () {
var dx = self.x - mishnu.x;
var dy = self.y - mishnu.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < radius.radiusSize) {
- // Zombie behavior when close to Mishnu
- if (distance < 50 && Date.now() - self.lastAttackTime > self.attackCooldown) {
- // Attack Mishnu if close enough
- globalHealthBar.setHealth(globalHealthBar.currentHealth - 1); // Ensure health is updated
- self.lastAttackTime = Date.now();
- // Knock the zombie back after attacking
- self.x += dx / distance * 100;
- self.y += dy / distance * 100;
+ // Inside radius
+ if (!self.isFleeing) {
+ if (!self.isBeingHarvested) {
+ self.inRadiusStartTime = self.inRadiusStartTime || Date.now();
+ }
+ // Harvesting logic
+ var elapsedTime = Date.now() - self.inRadiusStartTime;
+ if (elapsedTime >= self.harvestTime) {
+ self.isBeingHarvested = true;
+ game.removeChild(self); // Remove zombie from the game
+ zombies.splice(zombies.indexOf(self), 1); // Remove from array
+ mishnu.humansHarvested += self.meatYield;
+ // Stop agony sounds
+ if (self.currentAgonySound) {
+ self.currentAgonySound.stop();
+ }
+ // Play harvest effects
+ LK.getSound('Ding_1').play();
+ getRandomSound(['Squish_1', 'Squish_2', 'Squish_3', 'Squish_4']).play();
+ for (var i = 0; i < 10; i++) {
+ var bloodSplash = game.addChild(new BloodSplash(self.x, self.y, true));
+ bloodSplashes.push(bloodSplash);
+ }
+ return;
+ }
+ // Agony yell during harvesting
+ if (!self.currentAgonySound && elapsedTime > 1000) {
+ self.currentAgonySound = getRandomSound(['Agony_Yell_1', 'Agony_Yell_2', 'Agony_Yell_3']);
+ self.currentAgonySound.volume = 0.3;
+ self.currentAgonySound.play();
+ }
+ // Attack logic
+ if (distance < 50 && Date.now() - self.lastAttackTime > self.attackCooldown) {
+ globalHealthBar.setHealth(globalHealthBar.currentHealth - 1); // Damage Mishnu
+ self.lastAttackTime = Date.now();
+ self.isFleeing = true; // Start fleeing after attack
+ }
} else {
- // Move toward Mishnu
- self.x -= dx / distance * self.speed;
- self.y -= dy / distance * self.speed;
+ // Fleeing logic
+ self.x += dx / distance * self.speed * 2;
+ self.y += dy / distance * self.speed * 2;
}
} else {
- // Roaming behavior when far from Mishnu
+ // Outside radius
+ self.isBeingHarvested = false;
+ self.inRadiusStartTime = null;
+ self.isFleeing = false;
+ // Reset state if fleeing
+ if (self.currentAgonySound) {
+ self.currentAgonySound.stop();
+ self.currentAgonySound = null;
+ }
+ // Roaming behavior
self.x += (Math.random() * 2 - 1) * self.speed;
self.y += (Math.random() * 2 - 1) * self.speed;
- // Keep zombies within the game boundaries
+ // Keep zombies within game boundaries
var margin = 50;
var bottomMargin = 300; // Extra margin for bottom UI
self.x = Math.max(margin, Math.min(2048 - margin, self.x));
self.y = Math.max(margin, Math.min(2432 - bottomMargin, self.y));
blurry texture background 4k black and white
can of Dog Food. Game asset. 3d clipart. Blank background. High contrast. No shadows..
black capsule. Game asset. 3d clipart. Blank background. High contrast. No shadows..
woman in short shorts. mobile game art. pixel art. full body. front facing. Blank background. High contrast. No shadows.
laser beam cartoon game asset. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
bone. clipart. cartoon. Blank background. High contrast. No shadows..
Game Over. Red game letters, dripping. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Dog_panting
Sound effect
Agony_Yell_1
Sound effect
Music_Level_1_5
Music
Music_Level_1_4
Music
Agony_Yell_2
Sound effect
Agony_Yell_3
Sound effect
Agony_Yell_4
Sound effect
Agony_Yell_5
Sound effect
Agony_Yell_6
Sound effect
Agony_Yell_7
Sound effect
Dog_Crunch
Sound effect
Dog_Crunch_2
Sound effect
Dog_Crunch_3
Sound effect
Ding_1
Sound effect
Squish_1
Sound effect
Squish_2
Sound effect
Squish_4
Sound effect
Squish_3
Sound effect
Factory_Deposit
Sound effect
Factory_Operation
Sound effect
Level_Up
Sound effect
Bark
Sound effect
Hit
Sound effect
Agony_Yell_8
Sound effect
Agony_Yell_9
Sound effect
GiggleMan_1
Sound effect
GiggleMan_2
Sound effect
GiggleMan_3
Sound effect
GiggleMan_4
Sound effect
Booster_Sound
Sound effect
Can
Sound effect
woosh
Sound effect
Agony_Yell_10
Sound effect
Bark_2
Sound effect
Bark_3
Sound effect
laser
Sound effect
searing
Sound effect
laser_2
Sound effect
Laser_3
Sound effect
Laser_4
Sound effect
Boss_Hit
Sound effect
Boss_Hit_2
Sound effect
Boss_Hit_3
Sound effect
GiggleMan_5
Sound effect
GiggleMan_6
Sound effect
hip_hop_loop
Sound effect