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
/**** * 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; }); // 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 = 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); // 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 += 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 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 = 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: 0x5D4E37 // Darker brown paper background color }); /**** * 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 = []; 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 Level 1 game 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 = 7; var gridCols = 12; var gridCellWidth = 150; var gridCellHeight = 100; var gridStartX = 200; var gridStartY = 600; // UI elements sunText = new Text2('Sun: ' + sun, { size: 40, fill: 0xFFD700 }); sunText.x = 50; sunText.y = 50; game.addChild(sunText); 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('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 var peashooterButton = LK.getAsset('selectionBox', { anchorX: 0.5, anchorY: 0.5 }); peashooterButton.x = 100; peashooterButton.y = 300; 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('selectionBox', { anchorX: 0.5, anchorY: 0.5 }); sunflowerButton.x = 100; sunflowerButton.y = 400; sunflowerButton.tint = 0xFF8C00; 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 };
/****
* 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;
});
// 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 = 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);
// 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 += 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 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 = 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: 0x5D4E37 // Darker brown paper background color
});
/****
* 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 = [];
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 Level 1 game
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 = 7;
var gridCols = 12;
var gridCellWidth = 150;
var gridCellHeight = 100;
var gridStartX = 200;
var gridStartY = 600;
// UI elements
sunText = new Text2('Sun: ' + sun, {
size: 40,
fill: 0xFFD700
});
sunText.x = 50;
sunText.y = 50;
game.addChild(sunText);
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('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
var peashooterButton = LK.getAsset('selectionBox', {
anchorX: 0.5,
anchorY: 0.5
});
peashooterButton.x = 100;
peashooterButton.y = 300;
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('selectionBox', {
anchorX: 0.5,
anchorY: 0.5
});
sunflowerButton.x = 100;
sunflowerButton.y = 400;
sunflowerButton.tint = 0xFF8C00;
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
};
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