/****
* Classes
****/
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
self.directionX = 1;
self.directionY = 0;
self.lifespan = 120;
self.update = function () {
self.x += self.directionX * self.speed;
self.y += self.directionY * self.speed;
self.lifespan--;
if (self.lifespan <= 0) {
self.shouldDestroy = true;
}
if (self.x < -50 || self.x > 2098 || self.y < -50 || self.y > 2782) {
self.shouldDestroy = true;
}
};
return self;
});
var HealthPack = Container.expand(function () {
var self = Container.call(this);
var healthGraphics = self.attachAsset('healthPack', {
anchorX: 0.5,
anchorY: 0.5
});
self.healAmount = 30;
self.collected = false;
self.update = function () {
if (!self.collected && self.intersects(player)) {
player.heal(self.healAmount);
LK.getSound('pickup').play();
self.collected = true;
self.shouldDestroy = true;
}
};
return self;
});
var Plant = Container.expand(function () {
var self = Container.call(this);
var plantGraphics = self.attachAsset('plant', {
anchorX: 0.5,
anchorY: 0.5
});
self.shootCooldown = 0;
self.range = 300;
self.health = 100;
self.maxHealth = 100;
self.takeDamage = function (damage) {
self.health -= damage;
if (self.health <= 0) {
self.shouldDestroy = true;
}
LK.effects.flashObject(self, 0xFF0000, 300);
};
self.update = function () {
if (self.shootCooldown > 0) {
self.shootCooldown--;
}
// Find nearest zombie in range
var nearestZombie = null;
var nearestDistance = self.range;
for (var i = 0; i < zombies.length; i++) {
var zombie = zombies[i];
var dx = zombie.x - self.x;
var dy = zombie.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < nearestDistance) {
nearestZombie = zombie;
nearestDistance = distance;
}
}
// Shoot at nearest zombie
if (nearestZombie && self.shootCooldown <= 0) {
var bullet = new PlantBullet();
bullet.x = self.x;
bullet.y = self.y;
var dx = nearestZombie.x - self.x;
var dy = nearestZombie.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 0) {
bullet.directionX = dx / distance;
bullet.directionY = dy / distance;
}
plantBullets.push(bullet);
game.addChild(bullet);
self.shootCooldown = 40;
}
};
return self;
});
var PlantBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('plantBullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 6;
self.directionX = 1;
self.directionY = 0;
self.lifespan = 150;
self.update = function () {
self.x += self.directionX * self.speed;
self.y += self.directionY * self.speed;
self.lifespan--;
if (self.lifespan <= 0) {
self.shouldDestroy = true;
}
if (self.x < -50 || self.x > 2098 || self.y < -50 || self.y > 2782) {
self.shouldDestroy = true;
}
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 100;
self.maxHealth = 100;
self.shootCooldown = 0;
self.lastMoveX = 1;
self.lastMoveY = 0;
self.takeDamage = function (damage) {
self.health -= damage;
if (self.health <= 0) {
self.health = 0;
}
LK.effects.flashObject(self, 0xFF0000, 300);
};
self.heal = function (amount) {
self.health = Math.min(self.maxHealth, self.health + amount);
};
self.update = function () {
if (self.shootCooldown > 0) {
self.shootCooldown--;
}
};
return self;
});
var Zombie = Container.expand(function () {
var self = Container.call(this);
var zombieGraphics = self.attachAsset('zombie', {
anchorX: 0.5,
anchorY: 0.5,
tint: 0x2d4a2d
});
self.speed = 1;
self.health = 1;
self.damage = 10;
self.lastPlayerCollision = false;
self.update = function () {
var dx = player.x - self.x;
var dy = player.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 0) {
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
}
var currentCollision = self.intersects(player);
if (!self.lastPlayerCollision && currentCollision) {
player.takeDamage(self.damage);
}
self.lastPlayerCollision = currentCollision;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2C5530
});
/****
* Game Code
****/
var player;
var zombies = [];
var bullets = [];
var plantBullets = [];
var plants = [];
var healthPacks = [];
var waveNumber = 1;
var zombieSpawnRate = 120;
var healthPackSpawnRate = 1800;
var lastHealthPackSpawn = 0;
var dragActive = false;
var plantingMode = false;
var sunlight = 50;
var plantCost = 25;
// UI Elements
var scoreText = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreText.anchor.set(0, 0);
scoreText.x = 120;
scoreText.y = 50;
LK.gui.topLeft.addChild(scoreText);
var healthText = new Text2('Health: 100', {
size: 60,
fill: 0xFF0000
});
healthText.anchor.set(1, 0);
LK.gui.topRight.addChild(healthText);
var waveText = new Text2('Wave: 1', {
size: 50,
fill: 0xFFFF00
});
waveText.anchor.set(0.5, 0);
LK.gui.top.addChild(waveText);
var sunlightText = new Text2('Sun: 50', {
size: 50,
fill: 0xFFD700
});
sunlightText.anchor.set(0, 1);
sunlightText.x = 20;
LK.gui.bottomLeft.addChild(sunlightText);
var plantModeText = new Text2('Tap to plant (Cost: 25)', {
size: 40,
fill: 0x90EE90
});
plantModeText.anchor.set(0.5, 1);
LK.gui.bottom.addChild(plantModeText);
// Create grass background
for (var i = 0; i < 200; i++) {
var grass = LK.getAsset('grass', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.3 + Math.random() * 0.7,
scaleY: 0.3 + Math.random() * 0.7,
alpha: 0.6 + Math.random() * 0.4,
tint: 0x228B22 + Math.floor(Math.random() * 0x002200)
});
grass.x = Math.random() * 2048;
grass.y = Math.random() * 2732;
grass.rotation = Math.random() * Math.PI * 2;
game.addChild(grass);
}
// Initialize player
player = game.addChild(new Player());
player.x = 1024;
player.y = 1366;
function spawnZombie() {
var zombie = new Zombie();
var side = Math.floor(Math.random() * 4);
switch (side) {
case 0:
// Top
zombie.x = Math.random() * 2048;
zombie.y = -30;
break;
case 1:
// Right
zombie.x = 2078;
zombie.y = Math.random() * 2732;
break;
case 2:
// Bottom
zombie.x = Math.random() * 2048;
zombie.y = 2762;
break;
case 3:
// Left
zombie.x = -30;
zombie.y = Math.random() * 2732;
break;
}
zombie.speed = 0.8 + waveNumber * 0.1;
zombies.push(zombie);
game.addChild(zombie);
}
function spawnHealthPack() {
var healthPack = new HealthPack();
healthPack.x = 200 + Math.random() * 1648;
healthPack.y = 200 + Math.random() * 2332;
healthPacks.push(healthPack);
game.addChild(healthPack);
}
function shootBullet() {
if (player.shootCooldown <= 0) {
var bullet = new Bullet();
bullet.x = player.x;
bullet.y = player.y;
bullet.directionX = player.lastMoveX;
bullet.directionY = player.lastMoveY;
bullets.push(bullet);
game.addChild(bullet);
player.shootCooldown = 15;
LK.getSound('shoot').play();
}
}
game.down = function (x, y, obj) {
// Toggle plant mode with double tap
if (!plantingMode) {
dragActive = true;
player.x = x;
player.y = y;
var dx = x - player.x;
var dy = y - player.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 0) {
player.lastMoveX = dx / distance;
player.lastMoveY = dy / distance;
}
shootBullet();
} else {
// Plant mode - place plant
if (sunlight >= plantCost) {
var canPlace = true;
// Check if too close to other plants
for (var i = 0; i < plants.length; i++) {
var plant = plants[i];
var dx = x - plant.x;
var dy = y - plant.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < 150) {
canPlace = false;
break;
}
}
// Check if too close to player
var dx = x - player.x;
var dy = y - player.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < 100) {
canPlace = false;
}
if (canPlace) {
var plant = new Plant();
plant.x = x;
plant.y = y;
plants.push(plant);
game.addChild(plant);
sunlight -= plantCost;
plantingMode = false;
}
}
}
};
game.move = function (x, y, obj) {
if (dragActive) {
var dx = x - player.x;
var dy = y - player.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 5) {
player.x = x;
player.y = y;
if (distance > 0) {
player.lastMoveX = dx / distance;
player.lastMoveY = dy / distance;
}
}
}
};
game.up = function (x, y, obj) {
dragActive = false;
// Long press to toggle plant mode
if (!dragActive) {
plantingMode = !plantingMode;
}
};
game.update = function () {
// Check for game over
if (player.health <= 0) {
LK.showGameOver();
return;
}
// Update UI
scoreText.setText('Score: ' + LK.getScore());
healthText.setText('Health: ' + player.health);
waveText.setText('Wave: ' + waveNumber);
sunlightText.setText('Sun: ' + sunlight);
if (plantingMode) {
plantModeText.setText('PLANT MODE - Tap to place (Cost: ' + plantCost + ')');
plantModeText.alpha = 1;
} else {
plantModeText.setText('Tap and hold to enter plant mode');
plantModeText.alpha = 0.7;
}
// Spawn zombies
if (LK.ticks % zombieSpawnRate === 0) {
spawnZombie();
}
// Increase difficulty over time
if (LK.ticks % 1800 === 0) {
waveNumber++;
if (zombieSpawnRate > 30) {
zombieSpawnRate -= 5;
}
}
// Spawn health packs
if (LK.ticks - lastHealthPackSpawn > healthPackSpawnRate && Math.random() < 0.1) {
spawnHealthPack();
lastHealthPackSpawn = LK.ticks;
}
// Generate sunlight over time
if (LK.ticks % 180 === 0) {
sunlight += 5;
}
// Auto shoot
if (LK.ticks % 20 === 0) {
shootBullet();
}
// Update plant bullets
for (var i = plantBullets.length - 1; i >= 0; i--) {
var bullet = plantBullets[i];
if (bullet.shouldDestroy) {
bullet.destroy();
plantBullets.splice(i, 1);
continue;
}
// Check plant bullet-zombie collisions
for (var j = zombies.length - 1; j >= 0; j--) {
var zombie = zombies[j];
if (bullet.intersects(zombie)) {
zombie.health--;
if (zombie.health <= 0) {
LK.setScore(LK.getScore() + 10);
sunlight += 10;
LK.getSound('zombieHit').play();
zombie.destroy();
zombies.splice(j, 1);
}
bullet.shouldDestroy = true;
break;
}
}
}
// Update plants and check zombie collisions
for (var i = plants.length - 1; i >= 0; i--) {
var plant = plants[i];
if (plant.shouldDestroy) {
plant.destroy();
plants.splice(i, 1);
continue;
}
// Check if zombies are attacking plant
for (var j = 0; j < zombies.length; j++) {
var zombie = zombies[j];
if (plant.intersects(zombie)) {
plant.takeDamage(zombie.damage);
}
}
}
// Keep player in bounds
player.x = Math.max(40, Math.min(2008, player.x));
player.y = Math.max(40, Math.min(2692, player.y));
// Update bullets
for (var i = bullets.length - 1; i >= 0; i--) {
var bullet = bullets[i];
if (bullet.shouldDestroy) {
bullet.destroy();
bullets.splice(i, 1);
continue;
}
// Check bullet-zombie collisions
for (var j = zombies.length - 1; j >= 0; j--) {
var zombie = zombies[j];
if (bullet.intersects(zombie)) {
zombie.health--;
if (zombie.health <= 0) {
LK.setScore(LK.getScore() + 10);
LK.getSound('zombieHit').play();
zombie.destroy();
zombies.splice(j, 1);
}
bullet.shouldDestroy = true;
break;
}
}
}
// Update health packs
for (var i = healthPacks.length - 1; i >= 0; i--) {
var healthPack = healthPacks[i];
if (healthPack.shouldDestroy) {
healthPack.destroy();
healthPacks.splice(i, 1);
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -231,8 +231,23 @@
fill: 0x90EE90
});
plantModeText.anchor.set(0.5, 1);
LK.gui.bottom.addChild(plantModeText);
+// Create grass background
+for (var i = 0; i < 200; i++) {
+ var grass = LK.getAsset('grass', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 0.3 + Math.random() * 0.7,
+ scaleY: 0.3 + Math.random() * 0.7,
+ alpha: 0.6 + Math.random() * 0.4,
+ tint: 0x228B22 + Math.floor(Math.random() * 0x002200)
+ });
+ grass.x = Math.random() * 2048;
+ grass.y = Math.random() * 2732;
+ grass.rotation = Math.random() * Math.PI * 2;
+ game.addChild(grass);
+}
// Initialize player
player = game.addChild(new Player());
player.x = 1024;
player.y = 1366;
Fullscreen modern App Store landscape banner, 16:9, high definition, for a game titled "Zombie Survival Shooter" and with the description "Survive endless zombie waves in this action-packed shooter. Move, shoot, and stay alive as long as possible while zombies attack from all directions.". No text on banner!
un zombi de pixeles. In-Game asset. 2d. High contrast. No shadows
árbol echo de pixeles. In-Game asset. 2d. High contrast. No shadows
césped de pixeles. In-Game asset. 2d. High contrast. No shadows
bala de pistola de pixeles. In-Game asset. 2d. High contrast. No shadows
paquete de salud de pixeles. In-Game asset. 2d. High contrast. No shadows