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 LevelButton = Container.expand(function () { var self = Container.call(this); var buttonBg = self.attachAsset('levelButton', { anchorX: 0.5, anchorY: 0.5 }); self.levelNumber = 1; self.isUnlocked = true; self.stars = 0; self.maxStars = 3; // Create level number text self.levelText = new Text2('Level ' + self.levelNumber, { size: 40, 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; }); /**** * 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 // 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.levelNumber = 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(); // Here you would implement the actual level loading // For now, just show a message console.log('Starting level: ' + levelNumber); // You could implement level loading here // For example: loadLevel(levelNumber); } // 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
@@ -1,679 +1,156 @@
/****
* Classes
****/
-var Pea = Container.expand(function () {
+var LevelButton = Container.expand(function () {
var self = Container.call(this);
- var graphics = self.attachAsset('pea', {
+ var buttonBg = self.attachAsset('levelButton', {
anchorX: 0.5,
anchorY: 0.5
});
- self.speed = 8;
- self.damage = 20;
- self.lane = 0;
- self.update = function () {
- self.x += self.speed;
- // Check collision with zombies in same lane
- for (var i = zombies.length - 1; i >= 0; i--) {
- var zombie = zombies[i];
- if (zombie.lane === self.lane && self.intersects(zombie)) {
- zombie.takeDamage(self.damage);
- self.destroy();
- break;
- }
- }
- // Remove if off screen
- if (self.x > 2048) {
- self.destroy();
- }
- };
- return self;
-});
-var Plant = Container.expand(function () {
- var self = Container.call(this);
- self.gridX = 0;
- self.gridY = 0;
- self.lane = 0;
- self.health = 100;
- self.maxHealth = 100;
- self.type = 'basic';
- self.takeDamage = function (damage) {
- self.health -= damage;
- if (self.health <= 0) {
- self.destroy();
- }
- };
- self.destroy = function () {
- // Remove from grid
- if (gameGrid[self.gridY] && gameGrid[self.gridY][self.gridX]) {
- gameGrid[self.gridY][self.gridX] = null;
- }
- Container.prototype.destroy.call(self);
- };
- return self;
-});
-var Wallnut = Plant.expand(function () {
- var self = Plant.call(this);
- var graphics = self.attachAsset('wallnut', {
- anchorX: 0.5,
- anchorY: 0.5
+ self.levelNumber = 1;
+ self.isUnlocked = true;
+ self.stars = 0;
+ self.maxStars = 3;
+ // Create level number text
+ self.levelText = new Text2('Level ' + self.levelNumber, {
+ size: 40,
+ fill: 0xFFFFFF
});
- self.type = 'wallnut';
- self.health = 300;
- self.maxHealth = 300;
- self.update = function () {
- // Update visual based on health
- var healthPercent = self.health / self.maxHealth;
- if (healthPercent < 0.3) {
- graphics.tint = 0x8B0000; // Dark red when damaged
- } else if (healthPercent < 0.6) {
- graphics.tint = 0xCD853F; // Brown when moderately damaged
- }
- };
- return self;
-});
-var Sunflower = Plant.expand(function () {
- var self = Plant.call(this);
- var graphics = self.attachAsset('sunflower', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.type = 'sunflower';
- self.sunTimer = 0;
- self.sunInterval = 300; // 5 seconds at 60fps
- self.update = function () {
- self.sunTimer++;
- if (self.sunTimer >= self.sunInterval) {
- self.sunTimer = 0;
- self.generateSun();
- }
- };
- self.generateSun = function () {
- var sun = new Sunlight();
- sun.x = self.x + (Math.random() - 0.5) * 60;
- sun.y = self.y + (Math.random() - 0.5) * 60;
- sunlights.push(sun);
- game.addChild(sun);
- };
- return self;
-});
-var Shooter = Plant.expand(function () {
- var self = Plant.call(this);
- var graphics = self.attachAsset('shooter', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.type = 'shooter';
- self.shootTimer = 0;
- self.shootInterval = 60; // 1 second at 60fps
- self.update = function () {
- // Check if there's a zombie in this lane
- var zombieInLane = false;
- for (var i = 0; i < zombies.length; i++) {
- if (zombies[i].lane === self.lane && zombies[i].x > self.x) {
- zombieInLane = true;
- break;
+ 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
}
}
- if (zombieInLane) {
- self.shootTimer++;
- if (self.shootTimer >= self.shootInterval) {
- self.shootTimer = 0;
- self.shoot();
- }
- }
};
- self.shoot = function () {
- var pea = new Pea();
- pea.x = self.x + 40;
- pea.y = self.y;
- pea.lane = self.lane;
- peas.push(pea);
- game.addChild(pea);
- LK.getSound('shoot').play();
- };
- return self;
-});
-var Peashooter = Plant.expand(function () {
- var self = Plant.call(this);
- var graphics = self.attachAsset('peashooter', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.type = 'peashooter';
- self.shootTimer = 0;
- self.shootInterval = 90; // 1.5 seconds at 60fps
- self.update = function () {
- // Check if there's a zombie in this lane
- var zombieInLane = false;
- for (var i = 0; i < zombies.length; i++) {
- if (zombies[i].lane === self.lane && zombies[i].x > self.x) {
- zombieInLane = true;
- break;
- }
+ self.setUnlocked = function (unlocked) {
+ self.isUnlocked = unlocked;
+ if (unlocked) {
+ buttonBg.tint = 0xFFFFFF;
+ self.levelText.tint = 0xFFFFFF;
+ } else {
+ buttonBg.tint = 0x666666;
+ self.levelText.tint = 0x666666;
}
- if (zombieInLane) {
- self.shootTimer++;
- if (self.shootTimer >= self.shootInterval) {
- self.shootTimer = 0;
- self.shoot();
- }
- }
};
- self.shoot = function () {
- var pea = new Pea();
- pea.x = self.x + 40;
- pea.y = self.y;
- pea.lane = self.lane;
- peas.push(pea);
- game.addChild(pea);
- LK.getSound('shoot').play();
- };
- return self;
-});
-var Sunlight = Container.expand(function () {
- var self = Container.call(this);
- var graphics = self.attachAsset('sunlight', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.collected = false;
- self.lifeTime = 0;
- self.maxLifeTime = 600; // 10 seconds at 60fps
- self.update = function () {
- self.lifeTime++;
- if (self.lifeTime > self.maxLifeTime && !self.collected) {
- self.destroy();
- }
- };
self.down = function (x, y, obj) {
- if (!self.collected) {
- self.collected = true;
- sunlightCount += 25;
- updateSunlightDisplay();
- LK.getSound('collect').play();
- self.destroy();
+ if (self.isUnlocked) {
+ LK.getSound('buttonClick').play();
+ // Start the selected level
+ startLevel(self.levelNumber);
}
};
return self;
});
-var Zombie = Container.expand(function () {
- var self = Container.call(this);
- self.speed = 1;
- self.health = 100;
- self.damage = 20;
- self.lane = 0;
- self.attackTimer = 0;
- self.attackInterval = 60; // 1 second at 60fps
- self.isAttacking = false;
- self.update = function () {
- if (!self.isAttacking) {
- self.x -= self.speed;
- // Check for collision with plants
- var plantToAttack = null;
- for (var row = 0; row < gameGrid.length; row++) {
- for (var col = 0; col < gameGrid[row].length; col++) {
- var plant = gameGrid[row][col];
- if (plant && plant.lane === self.lane && self.intersects(plant)) {
- plantToAttack = plant;
- break;
- }
- }
- if (plantToAttack) break;
- }
- if (plantToAttack) {
- self.isAttacking = true;
- self.attackTarget = plantToAttack;
- }
- } else {
- // Attack mode
- self.attackTimer++;
- if (self.attackTimer >= self.attackInterval) {
- self.attackTimer = 0;
- if (self.attackTarget && !self.attackTarget.destroyed) {
- self.attackTarget.takeDamage(self.damage);
- if (self.attackTarget.health <= 0) {
- self.isAttacking = false;
- self.attackTarget = null;
- }
- } else {
- self.isAttacking = false;
- self.attackTarget = null;
- }
- }
- }
- // Check if reached house
- if (self.x < 50) {
- // Damage house and remove zombie
- houseHealth -= self.damage;
- updateHouseHealth();
- self.destroy();
- // Check if house is destroyed
- if (houseHealth <= 0) {
- LK.showGameOver();
- }
- }
- };
- self.takeDamage = function (damage) {
- self.health -= damage;
- if (self.health <= 0) {
- LK.getSound('zombieDie').play();
- self.destroy();
- }
- };
- self.destroy = function () {
- // Remove from zombies array
- for (var i = zombies.length - 1; i >= 0; i--) {
- if (zombies[i] === self) {
- zombies.splice(i, 1);
- break;
- }
- }
- Container.prototype.destroy.call(self);
- };
- return self;
-});
-var FastZombie = Zombie.expand(function () {
- var self = Zombie.call(this);
- var graphics = self.attachAsset('fastZombie', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 1.5;
- self.health = 60;
- return self;
-});
-// Game state variables
-var BasicZombie = Zombie.expand(function () {
- var self = Zombie.call(this);
- var graphics = self.attachAsset('basicZombie', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 0.8;
- self.health = 100;
- return self;
-});
/****
* Initialize Game
****/
var game = new LK.Game({
- backgroundColor: 0x228B22 // Forest green background
+ backgroundColor: 0x2d5a27 // Dark green background for level selection
});
/****
* Game Code
****/
-// Sound effects
-// Grid and UI assets
-// Projectile and resource assets
-// Zombie assets
-// Plant assets
-// Game state variables
-var sunlightCount = 150;
-var selectedPlantType = 'sunflower';
-var justPurchased = false;
-var gameStarted = false;
-var waveNumber = 1;
-var zombiesSpawned = 0;
-var zombiesPerWave = 5;
-var waveTimer = 0;
-var waveInterval = 600; // 10 seconds between waves
-var houseHealth = 100;
-var maxHouseHealth = 100;
-// Game object arrays
-var plants = [];
-var zombies = [];
-var peas = [];
-var sunlights = [];
-// Shop variables
-var shopButtons = [];
-var shopStartY = 2400;
-var shopHeight = 200;
-// Grid system (5 lanes, 9 columns)
-var gameGrid = [];
-var gridStartX = 200;
-var gridStartY = 400;
-var cellWidth = 150;
-var cellHeight = 150;
-var gridRows = 7;
-var gridCols = 8;
-// Plant costs
-var plantCosts = {
- 'sunflower': 50,
- 'peashooter': 100,
- 'wallnut': 50,
- 'shooter': 50
-};
-// Initialize grid
-for (var row = 0; row < gridRows; row++) {
- gameGrid[row] = [];
- for (var col = 0; col < gridCols; col++) {
- gameGrid[row][col] = null;
- }
-}
-// Create visual grid
-for (var row = 0; row < gridRows; row++) {
- for (var col = 0; col < gridCols; col++) {
- var cell = LK.getAsset('gridCell', {
- anchorX: 0.5,
- anchorY: 0.5,
- alpha: 0.3
- });
- cell.x = gridStartX + col * cellWidth;
- cell.y = gridStartY + row * cellHeight;
- cell.gridRow = row;
- cell.gridCol = col;
- game.addChild(cell);
- }
-}
-// Create house
-var house = LK.getAsset('house', {
- anchorX: 0.5,
- anchorY: 0.5
+// Level selection screen variables
+var levelButtons = [];
+var totalLevels = 50;
+var unlockedLevels = 1; // Only first level unlocked initially
+var levelProgress = {}; // Store stars for each level
+// Create background
+var background = LK.getAsset('levelBackground', {
+ anchorX: 0,
+ anchorY: 0
});
-house.x = 75;
-house.y = gridStartY + gridRows * cellHeight / 2;
-game.addChild(house);
-// Create house health bar
-var healthBarBg = LK.getAsset('healthBarBg', {
+game.addChild(background);
+// Create title
+var titleBg = LK.getAsset('titleBackground', {
anchorX: 0.5,
anchorY: 0.5
});
-healthBarBg.x = house.x;
-healthBarBg.y = house.y - 450;
-game.addChild(healthBarBg);
-var healthBarFill = LK.getAsset('healthBarFill', {
- anchorX: 0,
- anchorY: 0.5
-});
-healthBarFill.x = house.x - 60;
-healthBarFill.y = house.y - 450;
-game.addChild(healthBarFill);
-var healthText = new Text2('House: ' + houseHealth + '/' + maxHouseHealth, {
- size: 30,
- fill: 0xFFFFFF
-});
-healthText.anchor.set(0.5, 0.5);
-healthText.x = house.x;
-healthText.y = house.y - 480;
-game.addChild(healthText);
-// Create UI
-var sunlightDisplay = new Text2('Sun: ' + sunlightCount, {
+titleBg.x = 1024;
+titleBg.y = 300;
+game.addChild(titleBg);
+var titleText = new Text2('Plants vs Zombies\nLevel Selection', {
size: 60,
- fill: 0xFFD700
-});
-sunlightDisplay.anchor.set(1, 0);
-LK.gui.topRight.addChild(sunlightDisplay);
-var waveDisplay = new Text2('Wave: ' + waveNumber, {
- size: 50,
fill: 0xFFFFFF
});
-waveDisplay.anchor.set(0.5, 0);
-LK.gui.top.addChild(waveDisplay);
-// Plant selection buttons
-var sunflowerBtn = new Text2('Sunflower (50)', {
- size: 40,
- fill: 0xFFD700
-});
-sunflowerBtn.anchor.set(1, 0);
-sunflowerBtn.x = -20;
-sunflowerBtn.y = 100;
-LK.gui.topRight.addChild(sunflowerBtn);
-var peashooterBtn = new Text2('Peashooter (100)', {
- size: 40,
- fill: 0x00FF00
-});
-peashooterBtn.anchor.set(1, 0);
-peashooterBtn.x = -20;
-peashooterBtn.y = 150;
-LK.gui.topRight.addChild(peashooterBtn);
-var wallnutBtn = new Text2('Wall-nut (50)', {
- size: 40,
- fill: 0x8B4513
-});
-wallnutBtn.anchor.set(1, 0);
-wallnutBtn.x = -20;
-wallnutBtn.y = 200;
-LK.gui.topRight.addChild(wallnutBtn);
-// Create shop at bottom of screen
-var shopBackground = LK.getAsset('shopBackground', {
- anchorX: 0.5,
- anchorY: 0.5
-});
-shopBackground.x = 1024;
-shopBackground.y = shopStartY + shopHeight / 2;
-game.addChild(shopBackground);
-// Create shop buttons for each plant type
-var shopPlantTypes = ['sunflower', 'peashooter', 'wallnut', 'shooter'];
-var shopPlantNames = ['Sunflower', 'Peashooter', 'Wall-nut', 'Shooter'];
-var shopPlantCosts = [50, 100, 50, 50];
-for (var i = 0; i < shopPlantTypes.length; i++) {
- var shopBtn = LK.getAsset('shopButton', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- shopBtn.x = 300 + i * 200;
- shopBtn.y = shopStartY + shopHeight / 2;
- shopBtn.plantType = shopPlantTypes[i];
- shopBtn.cost = shopPlantCosts[i];
- game.addChild(shopBtn);
- shopButtons.push(shopBtn);
- // Add text label for shop button
- var shopBtnText = new Text2(shopPlantNames[i] + '\n' + shopPlantCosts[i] + ' Sun', {
- size: 30,
- fill: 0xFFFFFF
- });
- shopBtnText.anchor.set(0.5, 0.5);
- shopBtnText.x = shopBtn.x;
- shopBtnText.y = shopBtn.y;
- game.addChild(shopBtnText);
- shopBtn.textLabel = shopBtnText;
-}
-function updateSunlightDisplay() {
- sunlightDisplay.setText('Sun: ' + sunlightCount);
- // Update button colors based on affordability using tint property
- sunflowerBtn.tint = sunlightCount >= 50 ? 0xFFD700 : 0x666666;
- peashooterBtn.tint = sunlightCount >= 100 ? 0x00FF00 : 0x666666;
- wallnutBtn.tint = sunlightCount >= 50 ? 0x8B4513 : 0x666666;
- // Update shop button colors
- for (var i = 0; i < shopButtons.length; i++) {
- var btn = shopButtons[i];
- if (sunlightCount >= btn.cost) {
- btn.tint = 0xFFFFFF;
- btn.textLabel.tint = 0xFFFFFF;
- } else {
- btn.tint = 0x666666;
- btn.textLabel.tint = 0x666666;
- }
- }
-}
-function updateHouseHealth() {
- // Update health bar fill width based on current health
- var healthPercent = houseHealth / maxHouseHealth;
- healthBarFill.width = 120 * healthPercent;
- // Update health bar color based on health level
- if (healthPercent <= 0.3) {
- healthBarFill.tint = 0xff0000; // Red when low health
- } else if (healthPercent <= 0.6) {
- healthBarFill.tint = 0xffff00; // Yellow when medium health
+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.levelNumber = 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 {
- healthBarFill.tint = 0x00ff00; // Green when high health
+ levelButton.setStars(0);
}
- // Update health text
- healthText.setText('House: ' + houseHealth + '/' + maxHouseHealth);
+ levelButtons.push(levelButton);
+ game.addChild(levelButton);
}
-// Input handling
-game.down = function (x, y, obj) {
- // Check if clicking on shop buttons
- if (y >= shopStartY && y <= shopStartY + shopHeight) {
- for (var i = 0; i < shopButtons.length; i++) {
- var btn = shopButtons[i];
- if (x >= btn.x - 75 && x <= btn.x + 75 && sunlightCount >= btn.cost) {
- // Purchase plant and set it as selected for placement
- sunlightCount -= btn.cost;
- selectedPlantType = btn.plantType;
- updateSunlightDisplay();
- // Store that we just purchased this plant
- justPurchased = true;
- return;
- }
+// Function to start a level
+function startLevel(levelNumber) {
+ LK.getSound('levelSelect').play();
+ // Here you would implement the actual level loading
+ // For now, just show a message
+ console.log('Starting level: ' + levelNumber);
+ // You could implement level loading here
+ // For example: loadLevel(levelNumber);
+}
+// Function to unlock next level
+function unlockNextLevel() {
+ if (unlockedLevels < totalLevels) {
+ unlockedLevels++;
+ if (levelButtons[unlockedLevels - 1]) {
+ levelButtons[unlockedLevels - 1].setUnlocked(true);
}
}
- // Check if clicking on plant selection buttons
- var localPos = LK.gui.topRight.toLocal({
- x: x,
- y: y
- });
- if (localPos.x >= -300 && localPos.x <= -20) {
- if (localPos.y >= 100 && localPos.y <= 140 && sunlightCount >= 50) {
- selectedPlantType = 'sunflower';
- return;
- } else if (localPos.y >= 150 && localPos.y <= 190 && sunlightCount >= 100) {
- selectedPlantType = 'peashooter';
- return;
- } else if (localPos.y >= 200 && localPos.y <= 240 && sunlightCount >= 50) {
- selectedPlantType = 'wallnut';
- return;
- }
- }
- // Check if clicking on grid for plant placement
- var gridCol = Math.floor((x - gridStartX + cellWidth / 2) / cellWidth);
- var gridRow = Math.floor((y - gridStartY + cellHeight / 2) / cellHeight);
- if (gridCol >= 0 && gridCol < gridCols && gridRow >= 0 && gridRow < gridRows) {
- if (gameGrid[gridRow][gridCol] === null) {
- // If we just purchased from shop, place immediately without additional cost
- if (justPurchased) {
- placePlantFromShop(gridRow, gridCol, selectedPlantType);
- justPurchased = false;
- } else if (sunlightCount >= plantCosts[selectedPlantType]) {
- // Regular placement from selection buttons
- placePlant(gridRow, gridCol, selectedPlantType);
- }
- }
- }
-};
-function placePlant(row, col, type) {
- var plant;
- switch (type) {
- case 'sunflower':
- plant = new Sunflower();
- break;
- case 'peashooter':
- plant = new Peashooter();
- break;
- case 'wallnut':
- plant = new Wallnut();
- break;
- case 'shooter':
- plant = new Shooter();
- break;
- default:
- return;
- }
- plant.gridX = col;
- plant.gridY = row;
- plant.lane = row;
- plant.x = gridStartX + col * cellWidth;
- plant.y = gridStartY + row * cellHeight;
- gameGrid[row][col] = plant;
- plants.push(plant);
- game.addChild(plant);
- sunlightCount -= plantCosts[type];
- updateSunlightDisplay();
- LK.getSound('plantPlace').play();
- // Start the game when first plant is placed
- if (!gameStarted) {
- gameStarted = true;
- }
}
-function placePlantFromShop(row, col, type) {
- var plant;
- switch (type) {
- case 'sunflower':
- plant = new Sunflower();
- break;
- case 'peashooter':
- plant = new Peashooter();
- break;
- case 'wallnut':
- plant = new Wallnut();
- break;
- case 'shooter':
- plant = new Shooter();
- break;
- default:
- return;
+// Function to set stars for a level
+function setLevelStars(levelNumber, stars) {
+ levelProgress[levelNumber] = stars;
+ if (levelButtons[levelNumber - 1]) {
+ levelButtons[levelNumber - 1].setStars(stars);
}
- plant.gridX = col;
- plant.gridY = row;
- plant.lane = row;
- plant.x = gridStartX + col * cellWidth;
- plant.y = gridStartY + row * cellHeight;
- gameGrid[row][col] = plant;
- plants.push(plant);
- game.addChild(plant);
- // No additional cost since already paid in shop
- updateSunlightDisplay();
- LK.getSound('plantPlace').play();
- // Start the game when first plant is placed
- if (!gameStarted) {
- gameStarted = true;
- }
}
-// Main game loop
+// Simple game update for level selection screen
game.update = function () {
- // Only start spawning zombies after first plant is placed
- if (gameStarted) {
- // Update wave timer and spawn zombies
- waveTimer++;
- if (waveTimer >= waveInterval && zombiesSpawned < zombiesPerWave) {
- spawnZombie();
- waveTimer = 0;
- zombiesSpawned++;
- if (zombiesSpawned >= zombiesPerWave && zombies.length === 0) {
- // Start next wave
- waveNumber++;
- zombiesPerWave = Math.min(10, 5 + waveNumber);
- zombiesSpawned = 0;
- waveDisplay.setText('Wave: ' + waveNumber);
- }
- }
- }
- // Clean up destroyed objects
- for (var i = peas.length - 1; i >= 0; i--) {
- if (peas[i].destroyed) {
- peas.splice(i, 1);
- }
- }
- for (var i = sunlights.length - 1; i >= 0; i--) {
- if (sunlights[i].destroyed) {
- sunlights.splice(i, 1);
- }
- }
- for (var i = plants.length - 1; i >= 0; i--) {
- if (plants[i].destroyed) {
- plants.splice(i, 1);
- }
- }
- // Check win condition (survived 10 waves)
- if (waveNumber > 10 && zombies.length === 0) {
- LK.showYouWin();
- }
-};
-function spawnZombie() {
- var zombie;
- // 70% chance for basic zombie, 30% for fast zombie
- if (Math.random() < 0.7) {
- zombie = new BasicZombie();
- } else {
- zombie = new FastZombie();
- }
- // Random lane
- var lane = Math.floor(Math.random() * gridRows);
- zombie.lane = lane;
- zombie.x = 2048 - 50;
- zombie.y = gridStartY + lane * cellHeight;
- zombies.push(zombie);
- game.addChild(zombie);
-}
\ No newline at end of file
+ // No specific updates needed for level selection
+ // All interactions are handled by level button click events
+};
\ No newline at end of file
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