User prompt
Seviye içindeki kareleri kücült ve çoğalt
User prompt
Seviye içindeki bitki koyma alanini buyut
User prompt
Seviye içindeki görseller için yeni görseller çıkar
User prompt
Seviye içindindeki görselleri farkli yap
User prompt
Please fix the bug: 'ReferenceError: sunText is not defined' in or related to this line: 'sunText.setText('Sun: ' + sun);' Line Number: 183
User prompt
Başlık arka planı kalsın sadece başlığı kaldır
User prompt
Başlığı kaldır
User prompt
Plants vs zombies level collection yazısıni plants vs zombies oyunundaki yazilar gibi yao
User prompt
Arka plan rengi biraz daha koyu bir sayfa gibi olsun
User prompt
Arka plqnı kahverengi bir sayfa yaprağı yap
User prompt
Please fix the bug: 'ReferenceError: sun is not defined' in or related to this line: 'sun += 25;' Line Number: 181
User prompt
Please fix the bug: 'ReferenceError: plants is not defined' in or related to this line: 'for (var i = plants.length - 1; i >= 0; i--) {' Line Number: 219
User prompt
Level 1 e bastiğim zaman beni level birin içine göndersin
User prompt
Level 1 2 3 böyle gitsin
User prompt
Ekrandaki herşey kaldır ve planrs vs zombies bölum dizynini yap
User prompt
Gridhücresini karelere böl kareler büyük olaun
User prompt
Grid hücresini ve evi büyüt
User prompt
Evi uzat
User prompt
Evi büyüt
User prompt
Evi büyüt grid hücresi ile eşit yap
User prompt
Evin uzunluğunu gridhücresi ile aynı hizada yap
User prompt
Evin Uzunluğunu hücre ile aynı hizada yap
User prompt
Grid hicresini ve evi büyüt
User prompt
Grid hücresini kare kare alanlara böl
User prompt
Başlangıç parasını arttiŕ
/**** * Classes ****/ var Bullet = Container.expand(function () { var self = Container.call(this); var graphics = self.attachAsset('starShape', { anchorX: 0.5, anchorY: 0.5 }); graphics.width = 20; graphics.height = 20; graphics.tint = 0x00FF00; 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; }); // 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 graphics = self.attachAsset('levelButton', { anchorX: 0.5, anchorY: 0.5 }); graphics.width = 80; graphics.height = 80; graphics.tint = 0x00FF00; self.health = 100; self.lastShot = 0; self.shootDelay = 90; // 1.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); var graphics = self.attachAsset('starShape', { anchorX: 0.5, anchorY: 0.5 }); graphics.width = 80; graphics.height = 80; graphics.tint = 0xFFD700; self.health = 100; self.lastSunGeneration = 0; self.sunDelay = 300; // 5 seconds at 60fps self.gridRow = 0; self.gridCol = 0; self.generateSun = function () { sun += 25; 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 graphics = self.attachAsset('levelButton', { anchorX: 0.5, anchorY: 0.5 }); graphics.width = 80; graphics.height = 80; graphics.tint = 0x8B4513; self.health = 100; self.speed = 0.5; self.gridRow = 0; self.isEating = false; self.eatDamage = 1; self.update = function () { if (!self.isEating) { self.x -= self.speed; } // Check if reached house if (self.x <= 150) { houseHealth -= self.eatDamage; healthText.setText('House Health: ' + houseHealth); 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: 0x2d5a27 // Dark green background for level selection }); /**** * Game Code ****/ // Level selection screen variables var levelButtons = []; var totalLevels = 50; var unlockedLevels = 1; // Only first level unlocked initially var levelProgress = {}; // Store stars for each level // Global game variables var plants = []; var zombies = []; var bullets = []; // Create background var background = LK.getAsset('levelBackground', { 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); var titleText = new Text2('Plants vs Zombies\nLevel Selection', { size: 60, fill: 0xFFFFFF }); titleText.anchor.set(0.5, 0.5); titleText.x = 1024; titleText.y = 300; game.addChild(titleText); // 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 Level 1 game initializeLevel1(); } // Initialize Level 1 Plants vs Zombies game function initializeLevel1() { // Game variables var sun = 150; var 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 = 5; var gridCols = 9; var gridCellWidth = 200; var gridCellHeight = 120; var gridStartX = 200; var gridStartY = 600; // UI elements var sunText = new Text2('Sun: ' + sun, { size: 40, fill: 0xFFD700 }); sunText.x = 50; sunText.y = 50; game.addChild(sunText); var healthText = new Text2('House Health: ' + houseHealth, { size: 40, fill: 0xFF0000 }); healthText.x = 50; 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('levelButton', { anchorX: 0.5, anchorY: 0.5 }); gridCell.x = gridStartX + col * gridCellWidth; gridCell.y = gridStartY + row * gridCellHeight; gridCell.width = gridCellWidth - 10; gridCell.height = gridCellHeight - 10; gridCell.tint = 0x90EE90; gridCell.alpha = 0.3; game.addChild(gridCell); } } // Plant selection buttons var peashooterButton = LK.getAsset('levelButton', { anchorX: 0.5, anchorY: 0.5 }); peashooterButton.x = 100; peashooterButton.y = 300; peashooterButton.width = 150; peashooterButton.height = 80; peashooterButton.tint = 0x00FF00; game.addChild(peashooterButton); var peashooterText = new Text2('Peashooter\n50 Sun', { size: 20, fill: 0x000000 }); peashooterText.anchor.set(0.5, 0.5); peashooterText.x = 100; peashooterText.y = 300; game.addChild(peashooterText); var sunflowerButton = LK.getAsset('levelButton', { anchorX: 0.5, anchorY: 0.5 }); sunflowerButton.x = 100; sunflowerButton.y = 400; sunflowerButton.width = 150; sunflowerButton.height = 80; sunflowerButton.tint = 0xFFD700; game.addChild(sunflowerButton); var sunflowerText = new Text2('Sunflower\n50 Sun', { size: 20, fill: 0x000000 }); sunflowerText.anchor.set(0.5, 0.5); sunflowerText.x = 100; sunflowerText.y = 400; 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 if (LK.ticks - lastSunGeneration > 600) { // Every 10 seconds sun += 10; sunText.setText('Sun: ' + sun); lastSunGeneration = LK.ticks; } // Check win condition if (LK.ticks > 3600 && zombies.length === 0) { // After 1 minute with no zombies LK.showYouWin(); } }; } // Function to unlock next level function unlockNextLevel() { if (unlockedLevels < totalLevels) { unlockedLevels++; if (levelButtons[unlockedLevels - 1]) { levelButtons[unlockedLevels - 1].setUnlocked(true); } } } // Function to set stars for a level function setLevelStars(levelNumber, stars) { levelProgress[levelNumber] = stars; 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
@@ -237,8 +237,12 @@
var levelButtons = [];
var totalLevels = 50;
var unlockedLevels = 1; // Only first level unlocked initially
var levelProgress = {}; // Store stars for each level
+// Global game variables
+var plants = [];
+var zombies = [];
+var bullets = [];
// Create background
var background = LK.getAsset('levelBackground', {
anchorX: 0,
anchorY: 0
@@ -298,11 +302,11 @@
function initializeLevel1() {
// Game variables
var sun = 150;
var houseHealth = 100;
- var plants = [];
- var zombies = [];
- var bullets = [];
+ plants = []; // Make plants global
+ zombies = []; // Make zombies global
+ bullets = []; // Make bullets global
var sunflowers = [];
var lastSunGeneration = 0;
var lastZombieSpawn = 0;
// Grid setup
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