User prompt
Make house 2 times bigger and let the blood splatter spray ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Make the zombies about 3 times bigger
User prompt
Make the zombies always face the house
User prompt
Make the zombies a bit bigger
Code edit (1 edits merged)
Please save this source code
User prompt
Zombie House Defense
Initial prompt
Create a top down tower defense game where hordes of zombies comes in increasing difficult waves try to reach your house.kill the zombies by tapping on them leaving a physics based blood splatter.if they reach your house and your house health becomes zero you are game over and can start over.this is a endless game and when you have certain score or kills you level up
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var BloodSplatter = Container.expand(function () {
var self = Container.call(this);
var blood = self.attachAsset('bloodSplatter', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.8
});
self.fadeOut = function () {
tween(blood, {
alpha: 0,
scaleX: 2,
scaleY: 2
}, {
duration: 1000,
onFinish: function onFinish() {
self.destroy();
}
});
};
return self;
});
var House = Container.expand(function () {
var self = Container.call(this);
var houseGraphics = self.attachAsset('house', {
anchorX: 0.5,
anchorY: 0.5
});
self.maxHealth = 100;
self.health = self.maxHealth;
self.takeDamage = function (damage) {
self.health -= damage;
if (self.health < 0) self.health = 0;
// Flash red when hit
tween(houseGraphics, {
tint: 0xFF0000
}, {
duration: 300,
onFinish: function onFinish() {
tween(houseGraphics, {
tint: 0xFFFFFF
}, {
duration: 300
});
}
});
// Play sound
LK.getSound('houseHit').play();
// Update health bar
updateHealthBar();
// Check game over
if (self.health <= 0) {
gameOver();
}
};
return self;
});
var Zombie = Container.expand(function (type) {
var self = Container.call(this);
type = type || 'normal';
var assetId = 'zombie';
if (type === 'fast') assetId = 'fastZombie';else if (type === 'strong') assetId = 'strongZombie';
var zombieGraphics = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5
});
self.type = type;
self.health = type === 'strong' ? 3 : 1;
self.maxHealth = self.health;
self.speed = type === 'fast' ? 2.5 : type === 'strong' ? 1.2 : 1.8;
self.damage = type === 'strong' ? 2 : 1;
self.targetX = 1024;
self.targetY = 1366;
self.takeDamage = function () {
self.health--;
if (self.health > 0) {
// Flash red when damaged but not killed
tween(zombieGraphics, {
tint: 0xFF0000
}, {
duration: 200,
onFinish: function onFinish() {
tween(zombieGraphics, {
tint: 0xFFFFFF
}, {
duration: 200
});
}
});
}
return self.health <= 0;
};
self.update = function () {
var dx = self.targetX - self.x;
var dy = self.targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 10) {
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
}
};
self.down = function (x, y, obj) {
var isDead = self.takeDamage();
if (isDead) {
// Create blood splatter
var blood = new BloodSplatter();
blood.x = self.x;
blood.y = self.y;
game.addChild(blood);
blood.fadeOut();
// Update score and stats
zombiesKilled++;
var points = self.type === 'strong' ? 15 : self.type === 'fast' ? 10 : 5;
LK.setScore(LK.getScore() + points);
// Play sound
LK.getSound('zombieHit').play();
// Remove from array and destroy
for (var i = zombies.length - 1; i >= 0; i--) {
if (zombies[i] === self) {
zombies.splice(i, 1);
break;
}
}
self.destroy();
// Check for level up
checkLevelUp();
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2F4F2F
});
/****
* Game Code
****/
// Game variables
var zombies = [];
var house;
var healthBar;
var healthBarBg;
var scoreTxt;
var levelTxt;
var waveTxt;
var zombiesKilled = 0;
var currentLevel = 1;
var currentWave = 1;
var waveTimer = 0;
var spawnTimer = 0;
var gameRunning = true;
// Initialize UI
scoreTxt = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0, 0);
scoreTxt.x = 120;
scoreTxt.y = 50;
LK.gui.topLeft.addChild(scoreTxt);
levelTxt = new Text2('Level: 1', {
size: 50,
fill: 0xFFD700
});
levelTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(levelTxt);
waveTxt = new Text2('Wave: 1', {
size: 50,
fill: 0x87CEEB
});
waveTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(waveTxt);
// Initialize house
house = game.addChild(new House());
house.x = 1024;
house.y = 1366;
// Initialize health bar
healthBarBg = LK.getAsset('healthBarBg', {
anchorX: 0.5,
anchorY: 0.5
});
healthBarBg.x = 1024;
healthBarBg.y = 200;
game.addChild(healthBarBg);
healthBar = LK.getAsset('healthBar', {
anchorX: 0.5,
anchorY: 0.5
});
healthBar.x = 1024;
healthBar.y = 200;
game.addChild(healthBar);
function updateHealthBar() {
var healthPercent = house.health / house.maxHealth;
healthBar.width = 400 * healthPercent;
// Change color based on health
if (healthPercent > 0.6) {
healthBar.tint = 0x00FF00; // Green
} else if (healthPercent > 0.3) {
healthBar.tint = 0xFFFF00; // Yellow
} else {
healthBar.tint = 0xFF0000; // Red
}
}
function spawnZombie() {
var zombie = new Zombie(getZombieType());
// Spawn from random edge
var edge = Math.floor(Math.random() * 4);
switch (edge) {
case 0:
// Top
zombie.x = Math.random() * 2048;
zombie.y = -50;
break;
case 1:
// Right
zombie.x = 2098;
zombie.y = Math.random() * 2732;
break;
case 2:
// Bottom
zombie.x = Math.random() * 2048;
zombie.y = 2782;
break;
case 3:
// Left
zombie.x = -50;
zombie.y = Math.random() * 2732;
break;
}
zombies.push(zombie);
game.addChild(zombie);
}
function getZombieType() {
var rand = Math.random();
if (currentLevel > 3 && rand < 0.2) return 'strong';
if (currentLevel > 2 && rand < 0.4) return 'fast';
return 'normal';
}
function checkLevelUp() {
var newLevel = Math.floor(zombiesKilled / 10) + 1;
if (newLevel > currentLevel) {
currentLevel = newLevel;
levelTxt.setText('Level: ' + currentLevel);
LK.effects.flashScreen(0xFFD700, 500);
}
}
function gameOver() {
gameRunning = false;
LK.showGameOver();
}
game.update = function () {
if (!gameRunning) return;
// Update score display
scoreTxt.setText('Score: ' + LK.getScore());
// Wave management
waveTimer++;
if (waveTimer > 1800) {
// 30 seconds per wave
currentWave++;
waveTxt.setText('Wave: ' + currentWave);
waveTimer = 0;
}
// Spawn zombies
spawnTimer++;
var spawnRate = Math.max(30 - currentWave * 2, 10); // Faster spawning each wave
if (spawnTimer > spawnRate) {
spawnZombie();
spawnTimer = 0;
}
// Check zombie collisions with house
for (var i = zombies.length - 1; i >= 0; i--) {
var zombie = zombies[i];
if (zombie.intersects(house)) {
house.takeDamage(zombie.damage);
zombies.splice(i, 1);
zombie.destroy();
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,290 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var BloodSplatter = Container.expand(function () {
+ var self = Container.call(this);
+ var blood = self.attachAsset('bloodSplatter', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ alpha: 0.8
+ });
+ self.fadeOut = function () {
+ tween(blood, {
+ alpha: 0,
+ scaleX: 2,
+ scaleY: 2
+ }, {
+ duration: 1000,
+ onFinish: function onFinish() {
+ self.destroy();
+ }
+ });
+ };
+ return self;
+});
+var House = Container.expand(function () {
+ var self = Container.call(this);
+ var houseGraphics = self.attachAsset('house', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.maxHealth = 100;
+ self.health = self.maxHealth;
+ self.takeDamage = function (damage) {
+ self.health -= damage;
+ if (self.health < 0) self.health = 0;
+ // Flash red when hit
+ tween(houseGraphics, {
+ tint: 0xFF0000
+ }, {
+ duration: 300,
+ onFinish: function onFinish() {
+ tween(houseGraphics, {
+ tint: 0xFFFFFF
+ }, {
+ duration: 300
+ });
+ }
+ });
+ // Play sound
+ LK.getSound('houseHit').play();
+ // Update health bar
+ updateHealthBar();
+ // Check game over
+ if (self.health <= 0) {
+ gameOver();
+ }
+ };
+ return self;
+});
+var Zombie = Container.expand(function (type) {
+ var self = Container.call(this);
+ type = type || 'normal';
+ var assetId = 'zombie';
+ if (type === 'fast') assetId = 'fastZombie';else if (type === 'strong') assetId = 'strongZombie';
+ var zombieGraphics = self.attachAsset(assetId, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.type = type;
+ self.health = type === 'strong' ? 3 : 1;
+ self.maxHealth = self.health;
+ self.speed = type === 'fast' ? 2.5 : type === 'strong' ? 1.2 : 1.8;
+ self.damage = type === 'strong' ? 2 : 1;
+ self.targetX = 1024;
+ self.targetY = 1366;
+ self.takeDamage = function () {
+ self.health--;
+ if (self.health > 0) {
+ // Flash red when damaged but not killed
+ tween(zombieGraphics, {
+ tint: 0xFF0000
+ }, {
+ duration: 200,
+ onFinish: function onFinish() {
+ tween(zombieGraphics, {
+ tint: 0xFFFFFF
+ }, {
+ duration: 200
+ });
+ }
+ });
+ }
+ return self.health <= 0;
+ };
+ self.update = function () {
+ var dx = self.targetX - self.x;
+ var dy = self.targetY - self.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ if (distance > 10) {
+ self.x += dx / distance * self.speed;
+ self.y += dy / distance * self.speed;
+ }
+ };
+ self.down = function (x, y, obj) {
+ var isDead = self.takeDamage();
+ if (isDead) {
+ // Create blood splatter
+ var blood = new BloodSplatter();
+ blood.x = self.x;
+ blood.y = self.y;
+ game.addChild(blood);
+ blood.fadeOut();
+ // Update score and stats
+ zombiesKilled++;
+ var points = self.type === 'strong' ? 15 : self.type === 'fast' ? 10 : 5;
+ LK.setScore(LK.getScore() + points);
+ // Play sound
+ LK.getSound('zombieHit').play();
+ // Remove from array and destroy
+ for (var i = zombies.length - 1; i >= 0; i--) {
+ if (zombies[i] === self) {
+ zombies.splice(i, 1);
+ break;
+ }
+ }
+ self.destroy();
+ // Check for level up
+ checkLevelUp();
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x2F4F2F
+});
+
+/****
+* Game Code
+****/
+// Game variables
+var zombies = [];
+var house;
+var healthBar;
+var healthBarBg;
+var scoreTxt;
+var levelTxt;
+var waveTxt;
+var zombiesKilled = 0;
+var currentLevel = 1;
+var currentWave = 1;
+var waveTimer = 0;
+var spawnTimer = 0;
+var gameRunning = true;
+// Initialize UI
+scoreTxt = new Text2('Score: 0', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0, 0);
+scoreTxt.x = 120;
+scoreTxt.y = 50;
+LK.gui.topLeft.addChild(scoreTxt);
+levelTxt = new Text2('Level: 1', {
+ size: 50,
+ fill: 0xFFD700
+});
+levelTxt.anchor.set(1, 0);
+LK.gui.topRight.addChild(levelTxt);
+waveTxt = new Text2('Wave: 1', {
+ size: 50,
+ fill: 0x87CEEB
+});
+waveTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(waveTxt);
+// Initialize house
+house = game.addChild(new House());
+house.x = 1024;
+house.y = 1366;
+// Initialize health bar
+healthBarBg = LK.getAsset('healthBarBg', {
+ anchorX: 0.5,
+ anchorY: 0.5
+});
+healthBarBg.x = 1024;
+healthBarBg.y = 200;
+game.addChild(healthBarBg);
+healthBar = LK.getAsset('healthBar', {
+ anchorX: 0.5,
+ anchorY: 0.5
+});
+healthBar.x = 1024;
+healthBar.y = 200;
+game.addChild(healthBar);
+function updateHealthBar() {
+ var healthPercent = house.health / house.maxHealth;
+ healthBar.width = 400 * healthPercent;
+ // Change color based on health
+ if (healthPercent > 0.6) {
+ healthBar.tint = 0x00FF00; // Green
+ } else if (healthPercent > 0.3) {
+ healthBar.tint = 0xFFFF00; // Yellow
+ } else {
+ healthBar.tint = 0xFF0000; // Red
+ }
+}
+function spawnZombie() {
+ var zombie = new Zombie(getZombieType());
+ // Spawn from random edge
+ var edge = Math.floor(Math.random() * 4);
+ switch (edge) {
+ case 0:
+ // Top
+ zombie.x = Math.random() * 2048;
+ zombie.y = -50;
+ break;
+ case 1:
+ // Right
+ zombie.x = 2098;
+ zombie.y = Math.random() * 2732;
+ break;
+ case 2:
+ // Bottom
+ zombie.x = Math.random() * 2048;
+ zombie.y = 2782;
+ break;
+ case 3:
+ // Left
+ zombie.x = -50;
+ zombie.y = Math.random() * 2732;
+ break;
+ }
+ zombies.push(zombie);
+ game.addChild(zombie);
+}
+function getZombieType() {
+ var rand = Math.random();
+ if (currentLevel > 3 && rand < 0.2) return 'strong';
+ if (currentLevel > 2 && rand < 0.4) return 'fast';
+ return 'normal';
+}
+function checkLevelUp() {
+ var newLevel = Math.floor(zombiesKilled / 10) + 1;
+ if (newLevel > currentLevel) {
+ currentLevel = newLevel;
+ levelTxt.setText('Level: ' + currentLevel);
+ LK.effects.flashScreen(0xFFD700, 500);
+ }
+}
+function gameOver() {
+ gameRunning = false;
+ LK.showGameOver();
+}
+game.update = function () {
+ if (!gameRunning) return;
+ // Update score display
+ scoreTxt.setText('Score: ' + LK.getScore());
+ // Wave management
+ waveTimer++;
+ if (waveTimer > 1800) {
+ // 30 seconds per wave
+ currentWave++;
+ waveTxt.setText('Wave: ' + currentWave);
+ waveTimer = 0;
+ }
+ // Spawn zombies
+ spawnTimer++;
+ var spawnRate = Math.max(30 - currentWave * 2, 10); // Faster spawning each wave
+ if (spawnTimer > spawnRate) {
+ spawnZombie();
+ spawnTimer = 0;
+ }
+ // Check zombie collisions with house
+ for (var i = zombies.length - 1; i >= 0; i--) {
+ var zombie = zombies[i];
+ if (zombie.intersects(house)) {
+ house.takeDamage(zombie.damage);
+ zombies.splice(i, 1);
+ zombie.destroy();
+ }
+ }
+};
\ No newline at end of file