User prompt
Her seviye sonunda birdennbiraz fazla zombi gelsin
User prompt
Ikinci seviyede zombiler daha fazla gelsin yeni zombi türü gelsin
User prompt
Birinci seviye gećildiğibzaman ikinci swviye açılsin ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Çiçek koyma karelerini azalt
User prompt
Çicek koyma kisimlarini azalt
User prompt
Aycicegi kutusubrengini kapalinsari
User prompt
Bezelye secim kutusunu kapqlinyesil ay cicegi kutusunu kapali sqri yap
User prompt
Boyutunu biraz daha arttır
User prompt
Yüzde 25 yukarı tası
User prompt
Yüzde 25 aşağıya indir
User prompt
Seçim kutularıni y ekseninde ýuzde 50 yukarı taşı
User prompt
Biraz fazla yukari taşı
User prompt
Seçim kutulqrini biraz daha yukarı cıkar
User prompt
Ay çiçegi yoksa pqrq artmasin
User prompt
Ay çiçekleri daha az para versin bezelyelerin mermi sikma sikliğı azalsin
User prompt
Seçim kutularinı ayır ve çiçeklerin fotolorıni koy
User prompt
Zombiler eve geldiği zaman yok olsun
User prompt
Çiçek seçim kutularını aşağıya koy
User prompt
Zombiler eve geldiği zaman 10 can götürsün sadwce
User prompt
Zombi evi yemesin
User prompt
Bir zombi 10 can götursun sadece
User prompt
Ev cani tek zombi ile bitmesin
User prompt
Yazıları sağa al
User prompt
Çiçek koyma alanininaşağiya dogru büyüt
User prompt
Please fix the bug: 'ReferenceError: houseHealth is not defined' in or related to this line: 'houseHealth -= self.eatDamage;' Line Number: 233
/**** * Plugins ****/ var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var Bullet = Container.expand(function () { var self = Container.call(this); var graphics = self.attachAsset('bulletCore', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.damage = 50; self.row = 0; self.update = function () { self.x += self.speed; // Check collision with zombies for (var i = zombies.length - 1; i >= 0; i--) { var zombie = zombies[i]; if (zombie.gridRow === self.row && Math.abs(self.x - zombie.x) < 30) { zombie.health -= self.damage; if (zombie.health <= 0) { zombie.destroy(); zombies.splice(i, 1); } self.destroy(); for (var j = bullets.length - 1; j >= 0; j--) { if (bullets[j] === self) { bullets.splice(j, 1); break; } } return; } } // Remove if off screen if (self.x > 2048) { self.destroy(); for (var k = bullets.length - 1; k >= 0; k--) { if (bullets[k] === self) { bullets.splice(k, 1); break; } } } }; return self; }); var FastZombie = Container.expand(function () { var self = Container.call(this); var body = self.attachAsset('zombieBody', { anchorX: 0.5, anchorY: 1 }); body.y = 25; body.tint = 0xFF6666; // Reddish tint to distinguish from regular zombie var head = self.attachAsset('zombieHead', { anchorX: 0.5, anchorY: 1 }); head.y = -10; head.tint = 0xFF6666; // Reddish tint to distinguish from regular zombie self.health = 60; // Lower health than regular zombie self.speed = 1.2; // Faster than regular zombie self.gridRow = 0; self.isEating = false; self.eatDamage = 15; // More damage when eating self.hasAttackedHouse = false; self.update = function () { if (!self.isEating) { self.x -= self.speed; } // Check if reached house - zombie damages house once with 15 health if (self.x <= 150 && !self.hasAttackedHouse) { houseHealth -= 15; healthText.setText('House Health: ' + houseHealth); self.hasAttackedHouse = true; // Destroy zombie after attacking house self.destroy(); for (var z = zombies.length - 1; z >= 0; z--) { if (zombies[z] === self) { zombies.splice(z, 1); break; } } // Check game over condition if (houseHealth <= 0) { LK.showGameOver(); } } // Check collision with plants for (var i = plants.length - 1; i >= 0; i--) { var plant = plants[i]; if (plant.gridRow === self.gridRow && Math.abs(self.x - plant.x) < 50) { self.isEating = true; plant.health -= 3; // Fast zombie eats faster if (plant.health <= 0) { plant.destroy(); plants.splice(i, 1); self.isEating = false; } break; } } }; return self; }); // Event handlers var LevelButton = Container.expand(function () { var self = Container.call(this); var buttonBg = self.attachAsset('levelButton', { anchorX: 0.5, anchorY: 0.5 }); self.levelNumber = 1; self.setLevelNumber = function (number) { self.levelNumber = number; self.levelText.setText(number.toString()); }; self.isUnlocked = true; self.stars = 0; self.maxStars = 3; // Create level number text self.levelText = new Text2(self.levelNumber.toString(), { size: 50, fill: 0xFFFFFF }); self.levelText.anchor.set(0.5, 0.5); self.levelText.y = -30; self.addChild(self.levelText); // Create stars display self.starContainers = []; for (var i = 0; i < self.maxStars; i++) { var star = LK.getAsset('starShape', { anchorX: 0.5, anchorY: 0.5 }); star.x = (i - 1) * 50; star.y = 30; star.tint = 0x666666; // Dark by default self.addChild(star); self.starContainers.push(star); } self.setStars = function (starCount) { self.stars = starCount; for (var i = 0; i < self.maxStars; i++) { if (i < starCount) { self.starContainers[i].tint = 0xFFD700; // Golden } else { self.starContainers[i].tint = 0x666666; // Dark } } }; self.setUnlocked = function (unlocked) { self.isUnlocked = unlocked; if (unlocked) { buttonBg.tint = 0xFFFFFF; self.levelText.tint = 0xFFFFFF; } else { buttonBg.tint = 0x666666; self.levelText.tint = 0x666666; } }; self.down = function (x, y, obj) { if (self.isUnlocked) { LK.getSound('buttonClick').play(); // Start the selected level startLevel(self.levelNumber); } }; return self; }); // Plant classes var Peashooter = Container.expand(function () { var self = Container.call(this); var body = self.attachAsset('peashooterBody', { anchorX: 0.5, anchorY: 0.5 }); var cannon = self.attachAsset('peashooterCannon', { anchorX: 0, anchorY: 0.5 }); cannon.x = 25; cannon.y = 0; self.health = 100; self.lastShot = 0; self.shootDelay = 150; // 2.5 seconds at 60fps self.gridRow = 0; self.gridCol = 0; self.shoot = function () { var bullet = new Bullet(); bullet.x = self.x + 50; bullet.y = self.y; bullet.row = self.gridRow; bullets.push(bullet); game.addChild(bullet); }; self.update = function () { if (LK.ticks - self.lastShot > self.shootDelay) { // Check if there's a zombie in this row var zombieInRow = false; for (var i = 0; i < zombies.length; i++) { if (zombies[i].gridRow === self.gridRow && zombies[i].x > self.x) { zombieInRow = true; break; } } if (zombieInRow) { self.shoot(); self.lastShot = LK.ticks; } } }; return self; }); var Sunflower = Container.expand(function () { var self = Container.call(this); // Create petals around center for (var i = 0; i < 8; i++) { var petal = self.attachAsset('sunflowerPetal', { anchorX: 0.5, anchorY: 1 }); var angle = i / 8 * Math.PI * 2; petal.x = Math.cos(angle) * 25; petal.y = Math.sin(angle) * 25; petal.rotation = angle + Math.PI / 2; } var center = self.attachAsset('sunflowerCenter', { anchorX: 0.5, anchorY: 0.5 }); self.health = 100; self.lastSunGeneration = 0; self.sunDelay = 300; // 5 seconds at 60fps self.gridRow = 0; self.gridCol = 0; self.generateSun = function () { sun += 15; sunText.setText('Sun: ' + sun); self.lastSunGeneration = LK.ticks; }; self.update = function () { if (LK.ticks - self.lastSunGeneration > self.sunDelay) { self.generateSun(); } }; return self; }); var Zombie = Container.expand(function () { var self = Container.call(this); var body = self.attachAsset('zombieBody', { anchorX: 0.5, anchorY: 1 }); body.y = 25; var head = self.attachAsset('zombieHead', { anchorX: 0.5, anchorY: 1 }); head.y = -10; self.health = 100; self.speed = 0.5; self.gridRow = 0; self.isEating = false; self.eatDamage = 10; self.hasAttackedHouse = false; self.update = function () { if (!self.isEating) { self.x -= self.speed; } // Check if reached house - zombie damages house once with 10 health if (self.x <= 150 && !self.hasAttackedHouse) { houseHealth -= 10; healthText.setText('House Health: ' + houseHealth); self.hasAttackedHouse = true; // Destroy zombie after attacking house self.destroy(); for (var z = zombies.length - 1; z >= 0; z--) { if (zombies[z] === self) { zombies.splice(z, 1); break; } } // Check game over condition if (houseHealth <= 0) { LK.showGameOver(); } } // Check collision with plants for (var i = plants.length - 1; i >= 0; i--) { var plant = plants[i]; if (plant.gridRow === self.gridRow && Math.abs(self.x - plant.x) < 50) { self.isEating = true; plant.health -= 2; if (plant.health <= 0) { plant.destroy(); plants.splice(i, 1); self.isEating = false; } break; } } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x5D4E37 // Darker brown paper background color }); /**** * Game Code ****/ // Level selection screen variables // Import storage for persistent level progression var levelButtons = []; var totalLevels = 50; var unlockedLevels = storage.unlockedLevels || 1; // Load from storage or default to 1 var levelProgress = storage.levelProgress || {}; // Load from storage or default to empty // Global game variables var plants = []; var zombies = []; var bullets = []; var sun = 150; var sunText; var houseHealth; var healthText; // Create brown paper background var background = LK.getAsset('paperBackground', { anchorX: 0, anchorY: 0 }); game.addChild(background); // Create title var titleBg = LK.getAsset('titleBackground', { anchorX: 0.5, anchorY: 0.5 }); titleBg.x = 1024; titleBg.y = 300; game.addChild(titleBg); // Create level buttons in a grid layout var buttonsPerRow = 5; var buttonSpacingX = 350; var buttonSpacingY = 200; var startX = 400; var startY = 600; for (var i = 0; i < totalLevels; i++) { var levelButton = new LevelButton(); levelButton.setLevelNumber(i + 1); // Calculate position in grid var row = Math.floor(i / buttonsPerRow); var col = i % buttonsPerRow; levelButton.x = startX + col * buttonSpacingX; levelButton.y = startY + row * buttonSpacingY; // Set unlock status levelButton.setUnlocked(i < unlockedLevels); // Set stars from progress (if any) if (levelProgress[i + 1]) { levelButton.setStars(levelProgress[i + 1]); } else { levelButton.setStars(0); } levelButtons.push(levelButton); game.addChild(levelButton); } // Function to start a level function startLevel(levelNumber) { LK.getSound('levelSelect').play(); console.log('Starting level: ' + levelNumber); // Clear the level selection screen game.removeChildren(); // Initialize the appropriate level if (levelNumber === 1) { initializeLevel1(); } else if (levelNumber === 2) { initializeLevel2(); } else { // Default to level 1 for other levels initializeLevel1(); } } // Initialize Level 1 Plants vs Zombies game function initializeLevel1() { // Game variables houseHealth = 100; plants = []; // Make plants global zombies = []; // Make zombies global bullets = []; // Make bullets global var sunflowers = []; var lastSunGeneration = 0; var lastZombieSpawn = 0; // Grid setup var gridRows = 10; var gridCols = 12; var gridCellWidth = 150; var gridCellHeight = 100; var gridStartX = 200; var gridStartY = 500; // UI elements sunText = new Text2('Sun: ' + sun, { size: 40, fill: 0xFFD700 }); sunText.x = 1500; sunText.y = 50; game.addChild(sunText); healthText = new Text2('House Health: ' + houseHealth, { size: 40, fill: 0xFF0000 }); healthText.x = 1500; healthText.y = 100; game.addChild(healthText); // Create grid for (var row = 0; row < gridRows; row++) { for (var col = 0; col < gridCols; col++) { var gridCell = LK.getAsset('gridTile', { anchorX: 0.5, anchorY: 0.5 }); gridCell.x = gridStartX + col * gridCellWidth; gridCell.y = gridStartY + row * gridCellHeight; gridCell.alpha = 0.3; game.addChild(gridCell); } } // Plant selection buttons with proper spacing var peashooterButton = LK.getAsset('selectionBox', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.2, scaleY: 1.2 }); peashooterButton.x = 500; peashooterButton.y = 1617; peashooterButton.tint = 0x006400; game.addChild(peashooterButton); // Add peashooter image to button var peashooterImage = LK.getAsset('peashooterBody', { anchorX: 0.5, anchorY: 0.5 }); peashooterImage.x = 500; peashooterImage.y = 1597; peashooterImage.scaleX = 1.0; peashooterImage.scaleY = 1.0; game.addChild(peashooterImage); var peashooterText = new Text2('50 Sun', { size: 24, fill: 0x000000 }); peashooterText.anchor.set(0.5, 0.5); peashooterText.x = 500; peashooterText.y = 1647; game.addChild(peashooterText); var sunflowerButton = LK.getAsset('selectionBox', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.2, scaleY: 1.2 }); sunflowerButton.x = 900; sunflowerButton.y = 1617; sunflowerButton.tint = 0xB8860B; game.addChild(sunflowerButton); // Add sunflower image to button var sunflowerImage = LK.getAsset('sunflowerCenter', { anchorX: 0.5, anchorY: 0.5 }); sunflowerImage.x = 900; sunflowerImage.y = 1597; sunflowerImage.scaleX = 0.75; sunflowerImage.scaleY = 0.75; game.addChild(sunflowerImage); var sunflowerText = new Text2('50 Sun', { size: 24, fill: 0x000000 }); sunflowerText.anchor.set(0.5, 0.5); sunflowerText.x = 900; sunflowerText.y = 1647; game.addChild(sunflowerText); var selectedPlant = null; // Event handlers peashooterButton.down = function () { if (sun >= 50) { selectedPlant = 'peashooter'; } }; sunflowerButton.down = function () { if (sun >= 50) { selectedPlant = 'sunflower'; } }; game.down = function (x, y, obj) { if (selectedPlant && x >= gridStartX && x <= gridStartX + gridCols * gridCellWidth && y >= gridStartY && y <= gridStartY + gridRows * gridCellHeight) { var gridCol = Math.floor((x - gridStartX) / gridCellWidth); var gridRow = Math.floor((y - gridStartY) / gridCellHeight); // Check if position is valid and empty var positionEmpty = true; for (var i = 0; i < plants.length; i++) { if (plants[i].gridRow === gridRow && plants[i].gridCol === gridCol) { positionEmpty = false; break; } } if (positionEmpty && gridCol >= 0 && gridCol < gridCols && gridRow >= 0 && gridRow < gridRows) { var plant = null; if (selectedPlant === 'peashooter' && sun >= 50) { plant = new Peashooter(); sun -= 50; } else if (selectedPlant === 'sunflower' && sun >= 50) { plant = new Sunflower(); sun -= 50; } if (plant) { plant.x = gridStartX + gridCol * gridCellWidth; plant.y = gridStartY + gridRow * gridCellHeight; plant.gridRow = gridRow; plant.gridCol = gridCol; plants.push(plant); game.addChild(plant); sunText.setText('Sun: ' + sun); selectedPlant = null; } } } }; // Game update function game.update = function () { // Spawn zombies if (LK.ticks - lastZombieSpawn > 300) { // Every 5 seconds var zombie = new Zombie(); var row = Math.floor(Math.random() * gridRows); zombie.x = 1900; zombie.y = gridStartY + row * gridCellHeight; zombie.gridRow = row; zombies.push(zombie); game.addChild(zombie); lastZombieSpawn = LK.ticks; } // Update all game objects for (var i = plants.length - 1; i >= 0; i--) { plants[i].update(); } for (var j = zombies.length - 1; j >= 0; j--) { zombies[j].update(); } for (var k = bullets.length - 1; k >= 0; k--) { bullets[k].update(); } // Generate sun from sunflowers - only if sunflowers exist var sunflowerCount = 0; for (var s = 0; s < plants.length; s++) { if (plants[s] instanceof Sunflower) { sunflowerCount++; } } if (sunflowerCount > 0 && LK.ticks - lastSunGeneration > 600) { // Every 10 seconds, only if sunflowers exist sun += 5; sunText.setText('Sun: ' + sun); lastSunGeneration = LK.ticks; } // Check win condition if (LK.ticks > 3600 && zombies.length === 0) { // After 1 minute with no zombies unlockNextLevel(); // Unlock next level when current level is completed setLevelStars(1, 3); // Give 3 stars for completing level 1 LK.showYouWin(); } }; } // Initialize Level 2 Plants vs Zombies game with more zombies and fast zombies function initializeLevel2() { // Game variables houseHealth = 100; plants = []; // Make plants global zombies = []; // Make zombies global bullets = []; // Make bullets global var sunflowers = []; var lastSunGeneration = 0; var lastZombieSpawn = 0; var lastFastZombieSpawn = 0; // Grid setup var gridRows = 10; var gridCols = 12; var gridCellWidth = 150; var gridCellHeight = 100; var gridStartX = 200; var gridStartY = 500; // UI elements sunText = new Text2('Sun: ' + sun, { size: 40, fill: 0xFFD700 }); sunText.x = 1500; sunText.y = 50; game.addChild(sunText); healthText = new Text2('House Health: ' + houseHealth, { size: 40, fill: 0xFF0000 }); healthText.x = 1500; healthText.y = 100; game.addChild(healthText); // Level indicator var levelText = new Text2('Level 2', { size: 50, fill: 0xFFFFFF }); levelText.x = 1500; levelText.y = 150; game.addChild(levelText); // Create grid for (var row = 0; row < gridRows; row++) { for (var col = 0; col < gridCols; col++) { var gridCell = LK.getAsset('gridTile', { anchorX: 0.5, anchorY: 0.5 }); gridCell.x = gridStartX + col * gridCellWidth; gridCell.y = gridStartY + row * gridCellHeight; gridCell.alpha = 0.3; game.addChild(gridCell); } } // Plant selection buttons with proper spacing var peashooterButton = LK.getAsset('selectionBox', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.2, scaleY: 1.2 }); peashooterButton.x = 500; peashooterButton.y = 1617; peashooterButton.tint = 0x006400; game.addChild(peashooterButton); // Add peashooter image to button var peashooterImage = LK.getAsset('peashooterBody', { anchorX: 0.5, anchorY: 0.5 }); peashooterImage.x = 500; peashooterImage.y = 1597; peashooterImage.scaleX = 1.0; peashooterImage.scaleY = 1.0; game.addChild(peashooterImage); var peashooterText = new Text2('50 Sun', { size: 24, fill: 0x000000 }); peashooterText.anchor.set(0.5, 0.5); peashooterText.x = 500; peashooterText.y = 1647; game.addChild(peashooterText); var sunflowerButton = LK.getAsset('selectionBox', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.2, scaleY: 1.2 }); sunflowerButton.x = 900; sunflowerButton.y = 1617; sunflowerButton.tint = 0xB8860B; game.addChild(sunflowerButton); // Add sunflower image to button var sunflowerImage = LK.getAsset('sunflowerCenter', { anchorX: 0.5, anchorY: 0.5 }); sunflowerImage.x = 900; sunflowerImage.y = 1597; sunflowerImage.scaleX = 0.75; sunflowerImage.scaleY = 0.75; game.addChild(sunflowerImage); var sunflowerText = new Text2('50 Sun', { size: 24, fill: 0x000000 }); sunflowerText.anchor.set(0.5, 0.5); sunflowerText.x = 900; sunflowerText.y = 1647; game.addChild(sunflowerText); var selectedPlant = null; // Event handlers peashooterButton.down = function () { if (sun >= 50) { selectedPlant = 'peashooter'; } }; sunflowerButton.down = function () { if (sun >= 50) { selectedPlant = 'sunflower'; } }; game.down = function (x, y, obj) { if (selectedPlant && x >= gridStartX && x <= gridStartX + gridCols * gridCellWidth && y >= gridStartY && y <= gridStartY + gridRows * gridCellHeight) { var gridCol = Math.floor((x - gridStartX) / gridCellWidth); var gridRow = Math.floor((y - gridStartY) / gridCellHeight); // Check if position is valid and empty var positionEmpty = true; for (var i = 0; i < plants.length; i++) { if (plants[i].gridRow === gridRow && plants[i].gridCol === gridCol) { positionEmpty = false; break; } } if (positionEmpty && gridCol >= 0 && gridCol < gridCols && gridRow >= 0 && gridRow < gridRows) { var plant = null; if (selectedPlant === 'peashooter' && sun >= 50) { plant = new Peashooter(); sun -= 50; } else if (selectedPlant === 'sunflower' && sun >= 50) { plant = new Sunflower(); sun -= 50; } if (plant) { plant.x = gridStartX + gridCol * gridCellWidth; plant.y = gridStartY + gridRow * gridCellHeight; plant.gridRow = gridRow; plant.gridCol = gridCol; plants.push(plant); game.addChild(plant); sunText.setText('Sun: ' + sun); selectedPlant = null; } } } }; // Game update function for Level 2 game.update = function () { // Spawn regular zombies more frequently (every 3 seconds instead of 5) if (LK.ticks - lastZombieSpawn > 180) { var zombie = new Zombie(); var row = Math.floor(Math.random() * gridRows); zombie.x = 1900; zombie.y = gridStartY + row * gridCellHeight; zombie.gridRow = row; zombies.push(zombie); game.addChild(zombie); lastZombieSpawn = LK.ticks; } // Spawn fast zombies every 8 seconds if (LK.ticks - lastFastZombieSpawn > 480) { var fastZombie = new FastZombie(); var row = Math.floor(Math.random() * gridRows); fastZombie.x = 1900; fastZombie.y = gridStartY + row * gridCellHeight; fastZombie.gridRow = row; zombies.push(fastZombie); game.addChild(fastZombie); lastFastZombieSpawn = LK.ticks; } // Update all game objects for (var i = plants.length - 1; i >= 0; i--) { plants[i].update(); } for (var j = zombies.length - 1; j >= 0; j--) { zombies[j].update(); } for (var k = bullets.length - 1; k >= 0; k--) { bullets[k].update(); } // Generate sun from sunflowers - only if sunflowers exist var sunflowerCount = 0; for (var s = 0; s < plants.length; s++) { if (plants[s] instanceof Sunflower) { sunflowerCount++; } } if (sunflowerCount > 0 && LK.ticks - lastSunGeneration > 600) { // Every 10 seconds, only if sunflowers exist sun += 5; sunText.setText('Sun: ' + sun); lastSunGeneration = LK.ticks; } // Check win condition (Level 2 lasts longer and requires more survival) if (LK.ticks > 5400 && zombies.length === 0) { // After 1.5 minutes with no zombies unlockNextLevel(); // Unlock next level when current level is completed setLevelStars(2, 3); // Give 3 stars for completing level 2 LK.showYouWin(); } }; } // Function to unlock next level function unlockNextLevel() { if (unlockedLevels < totalLevels) { unlockedLevels++; storage.unlockedLevels = unlockedLevels; // Save to storage if (levelButtons[unlockedLevels - 1]) { levelButtons[unlockedLevels - 1].setUnlocked(true); } } } // Function to set stars for a level function setLevelStars(levelNumber, stars) { levelProgress[levelNumber] = stars; storage.levelProgress = levelProgress; // Save to storage if (levelButtons[levelNumber - 1]) { levelButtons[levelNumber - 1].setStars(stars); } } // Simple game update for level selection screen game.update = function () { // No specific updates needed for level selection // All interactions are handled by level button click events };
===================================================================
--- original.js
+++ change.js
@@ -48,8 +48,67 @@
}
};
return self;
});
+var FastZombie = Container.expand(function () {
+ var self = Container.call(this);
+ var body = self.attachAsset('zombieBody', {
+ anchorX: 0.5,
+ anchorY: 1
+ });
+ body.y = 25;
+ body.tint = 0xFF6666; // Reddish tint to distinguish from regular zombie
+ var head = self.attachAsset('zombieHead', {
+ anchorX: 0.5,
+ anchorY: 1
+ });
+ head.y = -10;
+ head.tint = 0xFF6666; // Reddish tint to distinguish from regular zombie
+ self.health = 60; // Lower health than regular zombie
+ self.speed = 1.2; // Faster than regular zombie
+ self.gridRow = 0;
+ self.isEating = false;
+ self.eatDamage = 15; // More damage when eating
+ self.hasAttackedHouse = false;
+ self.update = function () {
+ if (!self.isEating) {
+ self.x -= self.speed;
+ }
+ // Check if reached house - zombie damages house once with 15 health
+ if (self.x <= 150 && !self.hasAttackedHouse) {
+ houseHealth -= 15;
+ healthText.setText('House Health: ' + houseHealth);
+ self.hasAttackedHouse = true;
+ // Destroy zombie after attacking house
+ self.destroy();
+ for (var z = zombies.length - 1; z >= 0; z--) {
+ if (zombies[z] === self) {
+ zombies.splice(z, 1);
+ break;
+ }
+ }
+ // Check game over condition
+ if (houseHealth <= 0) {
+ LK.showGameOver();
+ }
+ }
+ // Check collision with plants
+ for (var i = plants.length - 1; i >= 0; i--) {
+ var plant = plants[i];
+ if (plant.gridRow === self.gridRow && Math.abs(self.x - plant.x) < 50) {
+ self.isEating = true;
+ plant.health -= 3; // Fast zombie eats faster
+ if (plant.health <= 0) {
+ plant.destroy();
+ plants.splice(i, 1);
+ self.isEating = false;
+ }
+ break;
+ }
+ }
+ };
+ return self;
+});
// Event handlers
var LevelButton = Container.expand(function () {
var self = Container.call(this);
var buttonBg = self.attachAsset('levelButton', {
@@ -318,10 +377,17 @@
LK.getSound('levelSelect').play();
console.log('Starting level: ' + levelNumber);
// Clear the level selection screen
game.removeChildren();
- // Initialize Level 1 game
- initializeLevel1();
+ // Initialize the appropriate level
+ if (levelNumber === 1) {
+ initializeLevel1();
+ } else if (levelNumber === 2) {
+ initializeLevel2();
+ } else {
+ // Default to level 1 for other levels
+ initializeLevel1();
+ }
}
// Initialize Level 1 Plants vs Zombies game
function initializeLevel1() {
// Game variables
@@ -515,8 +581,221 @@
LK.showYouWin();
}
};
}
+// Initialize Level 2 Plants vs Zombies game with more zombies and fast zombies
+function initializeLevel2() {
+ // Game variables
+ houseHealth = 100;
+ plants = []; // Make plants global
+ zombies = []; // Make zombies global
+ bullets = []; // Make bullets global
+ var sunflowers = [];
+ var lastSunGeneration = 0;
+ var lastZombieSpawn = 0;
+ var lastFastZombieSpawn = 0;
+ // Grid setup
+ var gridRows = 10;
+ var gridCols = 12;
+ var gridCellWidth = 150;
+ var gridCellHeight = 100;
+ var gridStartX = 200;
+ var gridStartY = 500;
+ // UI elements
+ sunText = new Text2('Sun: ' + sun, {
+ size: 40,
+ fill: 0xFFD700
+ });
+ sunText.x = 1500;
+ sunText.y = 50;
+ game.addChild(sunText);
+ healthText = new Text2('House Health: ' + houseHealth, {
+ size: 40,
+ fill: 0xFF0000
+ });
+ healthText.x = 1500;
+ healthText.y = 100;
+ game.addChild(healthText);
+ // Level indicator
+ var levelText = new Text2('Level 2', {
+ size: 50,
+ fill: 0xFFFFFF
+ });
+ levelText.x = 1500;
+ levelText.y = 150;
+ game.addChild(levelText);
+ // Create grid
+ for (var row = 0; row < gridRows; row++) {
+ for (var col = 0; col < gridCols; col++) {
+ var gridCell = LK.getAsset('gridTile', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ gridCell.x = gridStartX + col * gridCellWidth;
+ gridCell.y = gridStartY + row * gridCellHeight;
+ gridCell.alpha = 0.3;
+ game.addChild(gridCell);
+ }
+ }
+ // Plant selection buttons with proper spacing
+ var peashooterButton = LK.getAsset('selectionBox', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 1.2,
+ scaleY: 1.2
+ });
+ peashooterButton.x = 500;
+ peashooterButton.y = 1617;
+ peashooterButton.tint = 0x006400;
+ game.addChild(peashooterButton);
+ // Add peashooter image to button
+ var peashooterImage = LK.getAsset('peashooterBody', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ peashooterImage.x = 500;
+ peashooterImage.y = 1597;
+ peashooterImage.scaleX = 1.0;
+ peashooterImage.scaleY = 1.0;
+ game.addChild(peashooterImage);
+ var peashooterText = new Text2('50 Sun', {
+ size: 24,
+ fill: 0x000000
+ });
+ peashooterText.anchor.set(0.5, 0.5);
+ peashooterText.x = 500;
+ peashooterText.y = 1647;
+ game.addChild(peashooterText);
+ var sunflowerButton = LK.getAsset('selectionBox', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 1.2,
+ scaleY: 1.2
+ });
+ sunflowerButton.x = 900;
+ sunflowerButton.y = 1617;
+ sunflowerButton.tint = 0xB8860B;
+ game.addChild(sunflowerButton);
+ // Add sunflower image to button
+ var sunflowerImage = LK.getAsset('sunflowerCenter', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ sunflowerImage.x = 900;
+ sunflowerImage.y = 1597;
+ sunflowerImage.scaleX = 0.75;
+ sunflowerImage.scaleY = 0.75;
+ game.addChild(sunflowerImage);
+ var sunflowerText = new Text2('50 Sun', {
+ size: 24,
+ fill: 0x000000
+ });
+ sunflowerText.anchor.set(0.5, 0.5);
+ sunflowerText.x = 900;
+ sunflowerText.y = 1647;
+ game.addChild(sunflowerText);
+ var selectedPlant = null;
+ // Event handlers
+ peashooterButton.down = function () {
+ if (sun >= 50) {
+ selectedPlant = 'peashooter';
+ }
+ };
+ sunflowerButton.down = function () {
+ if (sun >= 50) {
+ selectedPlant = 'sunflower';
+ }
+ };
+ game.down = function (x, y, obj) {
+ if (selectedPlant && x >= gridStartX && x <= gridStartX + gridCols * gridCellWidth && y >= gridStartY && y <= gridStartY + gridRows * gridCellHeight) {
+ var gridCol = Math.floor((x - gridStartX) / gridCellWidth);
+ var gridRow = Math.floor((y - gridStartY) / gridCellHeight);
+ // Check if position is valid and empty
+ var positionEmpty = true;
+ for (var i = 0; i < plants.length; i++) {
+ if (plants[i].gridRow === gridRow && plants[i].gridCol === gridCol) {
+ positionEmpty = false;
+ break;
+ }
+ }
+ if (positionEmpty && gridCol >= 0 && gridCol < gridCols && gridRow >= 0 && gridRow < gridRows) {
+ var plant = null;
+ if (selectedPlant === 'peashooter' && sun >= 50) {
+ plant = new Peashooter();
+ sun -= 50;
+ } else if (selectedPlant === 'sunflower' && sun >= 50) {
+ plant = new Sunflower();
+ sun -= 50;
+ }
+ if (plant) {
+ plant.x = gridStartX + gridCol * gridCellWidth;
+ plant.y = gridStartY + gridRow * gridCellHeight;
+ plant.gridRow = gridRow;
+ plant.gridCol = gridCol;
+ plants.push(plant);
+ game.addChild(plant);
+ sunText.setText('Sun: ' + sun);
+ selectedPlant = null;
+ }
+ }
+ }
+ };
+ // Game update function for Level 2
+ game.update = function () {
+ // Spawn regular zombies more frequently (every 3 seconds instead of 5)
+ if (LK.ticks - lastZombieSpawn > 180) {
+ var zombie = new Zombie();
+ var row = Math.floor(Math.random() * gridRows);
+ zombie.x = 1900;
+ zombie.y = gridStartY + row * gridCellHeight;
+ zombie.gridRow = row;
+ zombies.push(zombie);
+ game.addChild(zombie);
+ lastZombieSpawn = LK.ticks;
+ }
+ // Spawn fast zombies every 8 seconds
+ if (LK.ticks - lastFastZombieSpawn > 480) {
+ var fastZombie = new FastZombie();
+ var row = Math.floor(Math.random() * gridRows);
+ fastZombie.x = 1900;
+ fastZombie.y = gridStartY + row * gridCellHeight;
+ fastZombie.gridRow = row;
+ zombies.push(fastZombie);
+ game.addChild(fastZombie);
+ lastFastZombieSpawn = LK.ticks;
+ }
+ // Update all game objects
+ for (var i = plants.length - 1; i >= 0; i--) {
+ plants[i].update();
+ }
+ for (var j = zombies.length - 1; j >= 0; j--) {
+ zombies[j].update();
+ }
+ for (var k = bullets.length - 1; k >= 0; k--) {
+ bullets[k].update();
+ }
+ // Generate sun from sunflowers - only if sunflowers exist
+ var sunflowerCount = 0;
+ for (var s = 0; s < plants.length; s++) {
+ if (plants[s] instanceof Sunflower) {
+ sunflowerCount++;
+ }
+ }
+ if (sunflowerCount > 0 && LK.ticks - lastSunGeneration > 600) {
+ // Every 10 seconds, only if sunflowers exist
+ sun += 5;
+ sunText.setText('Sun: ' + sun);
+ lastSunGeneration = LK.ticks;
+ }
+ // Check win condition (Level 2 lasts longer and requires more survival)
+ if (LK.ticks > 5400 && zombies.length === 0) {
+ // After 1.5 minutes with no zombies
+ unlockNextLevel(); // Unlock next level when current level is completed
+ setLevelStars(2, 3); // Give 3 stars for completing level 2
+ LK.showYouWin();
+ }
+ };
+}
// Function to unlock next level
function unlockNextLevel() {
if (unlockedLevels < totalLevels) {
unlockedLevels++;
Kahverengi sayfa yaprağı. In-Game asset. 2d. High contrast. No shadows
Kağıdın içinde plants vs zombies yazsin
Plant vs zombies ay çiçeği. In-Game asset. 2d. High contrast. No shadows
boş buton. In-Game asset. 2d. High contrast. No shadows
plans vs zombies double shoters. In-Game asset. 2d. High contrast. No shadows
çöl. In-Game asset. 2d. High contrast. No shadows
buz arkaplan. In-Game asset. 2d. High contrast. No shadows
gece gökyüzü. In-Game asset. 2d. High contrast. No shadows
orman. In-Game asset. 2d. High contrast. No shadows
toprak arka plan. In-Game asset. 2d. High contrast. No shadows
plants vs zombies ceviz. In-Game asset. 2d. High contrast. No shadows
ıcepeasshooter plants vs zombies. In-Game asset. 2d. High contrast. No shadows
kankanlı zombi plants vs zombies. In-Game asset. 2d. High contrast. No shadows
plants vs zombies olü ceviz. In-Game asset. 2d. High contrast. No shadows
bombacı zombi plants vs zombies. In-Game asset. 2d. High contrast. No shadows