Code edit (4 edits merged)
Please save this source code
User prompt
send to slightly up
User prompt
send to slightly down
Code edit (1 edits merged)
Please save this source code
User prompt
increase size
User prompt
send to slightly down
User prompt
same size as score txt
User prompt
not bottom add to left
User prompt
change position to opposite side of score txt
User prompt
increase size of killed Zombie same as Score txt
User prompt
killed zombie text is not shown solve problem pls
User prompt
Add another thing like a text written in it at the left bottom (Killed Zombie =)
Code edit (2 edits merged)
Please save this source code
User prompt
hange score text position slightly left
User prompt
change score text position slightly left
User prompt
change score text position slightly left
User prompt
when powerup is gained by player then full fill the health of player
Code edit (1 edits merged)
Please save this source code
User prompt
images are not shown only boxes are shown
User prompt
image assests are not working
Code edit (1 edits merged)
Please save this source code
User prompt
improve wave massega design
User prompt
Please fix the bug: 'setTimeout is not a function' in or related to this line: 'setTimeout(function () {' Line Number: 171
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Timeout.tick error: this.spawnWaveZombies is not a function' in or related to this line: 'this.spawnWaveZombies(zombieComposition);' Line Number: 175
===================================================================
--- original.js
+++ change.js
@@ -6,15 +6,35 @@
****/
var BaseContainer = Container.expand(function () {
var self = Container.call(this);
self.health = 1;
+ self.maxHealth = 1;
self.takeDamage = function (amount) {
self.health -= amount;
return self.health <= 0;
};
+ self.heal = function (amount) {
+ self.health = Math.min(self.health + amount, self.maxHealth);
+ };
return self;
});
/****
+* Power-Up Class
+****/
+var PowerUp = BaseContainer.expand(function () {
+ var self = BaseContainer.call(this);
+ var powerUpGraphics = self.attachAsset('powerUp', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.type = ['speedBoost', 'damageBoost', 'healthBoost'][Math.floor(Math.random() * 3)];
+ self.speed = -5;
+ self.update = function () {
+ self.x += self.speed;
+ };
+ return self;
+});
+/****
* Player Class
****/
var Player = BaseContainer.expand(function () {
var self = BaseContainer.call(this);
@@ -23,9 +43,41 @@
anchorY: 0.5
});
self.speed = 10;
self.health = 100;
- self.update = function () {};
+ self.maxHealth = 100;
+ self.powerUpDuration = 0;
+ self.powerUpType = null;
+ self.bulletDamageMultiplier = 1;
+ self.activatePowerUp = function (type) {
+ self.powerUpType = type;
+ self.powerUpDuration = 300; // 5 seconds at 60 FPS
+ switch (type) {
+ case 'speedBoost':
+ self.speed *= 2;
+ break;
+ case 'damageBoost':
+ self.bulletDamageMultiplier = 2;
+ break;
+ case 'healthBoost':
+ self.heal(50);
+ break;
+ }
+ };
+ self.updatePowerUp = function () {
+ if (self.powerUpDuration > 0) {
+ self.powerUpDuration--;
+ if (self.powerUpDuration <= 0) {
+ // Reset power-up effects
+ self.speed = 10;
+ self.bulletDamageMultiplier = 1;
+ self.powerUpType = null;
+ }
+ }
+ };
+ self.update = function () {
+ self.updatePowerUp();
+ };
return self;
});
/****
* Bullet Class
@@ -42,8 +94,11 @@
self.x += self.speed;
};
return self;
});
+/****
+* Zombie Base Class
+****/
var BaseZombie = BaseContainer.expand(function () {
var self = BaseContainer.call(this);
self.speed = 2;
self.update = function () {
@@ -58,8 +113,11 @@
}
};
return self;
});
+/****
+* Specific Zombie Types
+****/
var WeakZombie = BaseZombie.expand(function () {
var self = BaseZombie.call(this);
var zombieGraphics = self.attachAsset('weakZombie', {
anchorX: 0.5,
@@ -80,11 +138,8 @@
self.health = 3;
self.damage = 20;
return self;
});
-/****
-* Wave System
-****/
var FastZombie = BaseZombie.expand(function () {
var self = BaseZombie.call(this);
var zombieGraphics = self.attachAsset('fastZombie', {
anchorX: 0.5,
@@ -99,31 +154,36 @@
/****
* Initialize Game
****/
/****
+* Wave System
+****/
+/****
* Game Initialization
****/
var game = new LK.Game({
- backgroundColor: 0x87CEEB // Sky blue background
+ backgroundColor: 0x2C3E50
});
/****
* Game Code
****/
/****
* Wave System
****/
+// Sound Assets
+// Image Assets
/*****
* Zombie Shooter Game
-* Full Implementation with Improved Wave System
+* Full Implementation with Enhanced Features
*****/
// Background
var WaveSystem = {
currentWave: 0,
zombiesRemaining: 0,
zombiesKilled: 0,
waveCooldown: 300,
- // Initial delay between waves (5 seconds at 60 FPS)
+ powerUpSpawnChance: 0.1,
zombieTypes: [{
type: WeakZombie,
baseCount: 3
}, {
@@ -135,42 +195,29 @@
}],
startNextWave: function startNextWave() {
this.currentWave++;
this.zombiesKilled = 0;
- // Calculate zombie counts for each type
var zombieComposition = this.calculateZombieComposition();
this.zombiesRemaining = zombieComposition.total;
- // Create a background for the wave announcement text
- var waveTextBackground = LK.getAsset('centerCircle', {
- anchorX: 0.5,
- anchorY: 0.5,
- scaleX: 5,
- scaleY: 5,
- x: 2048 / 2,
- y: 2732 / 2
- });
- game.addChild(waveTextBackground);
- // Create detailed wave announcement text with improved design
- var waveText = new Text2('Wave ' + this.currentWave + '\n' + 'Incoming Zombies:\n' + 'Weak: ' + zombieComposition.weakCount + '\n' + 'Fast: ' + zombieComposition.fastCount + '\n' + 'Tough: ' + zombieComposition.toughCount, {
- size: 100,
- fill: 0xFFFFFF,
+ var waveText = new Text2('WAVE ' + this.currentWave + '\n' + '⚔️ Zombie Invasion ⚔️\n' + '🧟 Weak: ' + zombieComposition.weakCount + '\n' + '⚡ Fast: ' + zombieComposition.fastCount + '\n' + '💪 Tough: ' + zombieComposition.toughCount, {
+ size: 70,
+ fill: 0xFF0000,
align: 'center'
});
waveText.anchor.set(0.5, 0.5);
waveText.x = 2048 / 2;
waveText.y = 2732 / 2;
game.addChild(waveText);
- // Play wave start sound
LK.getSound('waveStart').play();
- // Remove text after 2 seconds
LK.setTimeout(function () {
game.removeChild(waveText);
}, 2000);
- // Spawn zombies for this wave
this.spawnWaveZombies(zombieComposition);
+ if (Math.random() < this.powerUpSpawnChance) {
+ this.spawnPowerUp();
+ }
},
calculateZombieComposition: function calculateZombieComposition() {
- // Base zombie counts increase with wave number
var weakBase = this.zombieTypes[0].baseCount + Math.floor(this.currentWave / 2);
var fastBase = this.zombieTypes[1].baseCount + Math.floor(this.currentWave / 3);
var toughBase = this.zombieTypes[2].baseCount + Math.floor(this.currentWave / 4);
var composition = {
@@ -181,32 +228,35 @@
composition.total = composition.weakCount + composition.fastCount + composition.toughCount;
return composition;
},
spawnWaveZombies: function spawnWaveZombies(zombieComposition) {
- // Spawn weak zombies
for (var i = 0; i < zombieComposition.weakCount; i++) {
this.spawnZombie(WeakZombie);
}
- // Spawn fast zombies
for (var j = 0; j < zombieComposition.fastCount; j++) {
this.spawnZombie(FastZombie);
}
- // Spawn tough zombies
for (var k = 0; k < zombieComposition.toughCount; k++) {
this.spawnZombie(ToughZombie);
}
},
spawnZombie: function spawnZombie(ZombieClass) {
var zombie = new ZombieClass();
- zombie.x = 2048; // Start from right side of screen
+ zombie.x = 2048;
zombie.y = Math.random() * 2732;
zombies.push(zombie);
game.addChild(zombie);
},
+ spawnPowerUp: function spawnPowerUp() {
+ var powerUp = new PowerUp();
+ powerUp.x = 2048;
+ powerUp.y = Math.random() * 2732;
+ powerUps.push(powerUp);
+ game.addChild(powerUp);
+ },
zombieKilled: function zombieKilled() {
this.zombiesRemaining--;
this.zombiesKilled++;
- // Update score text to show zombies killed
if (scoreTxt) {
scoreTxt.setText('Score: ' + score + ' | Zombies Killed: ' + this.zombiesKilled);
}
}
@@ -214,13 +264,13 @@
var background = game.attachAsset('background', {
anchorX: 0,
anchorY: 0
});
-// Initialize player
+// Player
var player = game.addChild(new Player());
player.x = 150;
player.y = 2732 / 2;
-// Initialize health bar
+// Health Bar
var healthBarBorder = LK.getAsset('healthBarBorder', {
anchorX: 0.5,
anchorY: 0.5
});
@@ -233,9 +283,13 @@
});
healthBar.x = healthBarBorder.x - healthBarBorder.width / 2;
healthBar.y = healthBarBorder.y;
game.addChild(healthBar);
-// Initialize score
+// Tracking Arrays
+var bullets = [];
+var zombies = [];
+var powerUps = [];
+// Score
var score = 0;
var scoreTxt = new Text2('Score: 0 | Zombies Killed: 0', {
size: 100,
fill: 0xFFFFFF
@@ -243,15 +297,13 @@
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
scoreTxt.x = 2048 / 2;
scoreTxt.y = 50;
-// Bullet and zombie tracking
-var bullets = [];
-var zombies = [];
+// Power-Up Bar
+var powerUpBar = null;
/****
* Game Mechanics
****/
-// Shooting bullets
function shootBullet() {
var bullet = new Bullet();
bullet.x = player.x;
bullet.y = player.y;
@@ -263,42 +315,74 @@
* Game Update Loop
****/
game.update = function () {
player.update();
- // Update health bar width and position
+ // Health Bar Update
if (player.health > 0) {
healthBar.width = player.health * 10;
} else {
healthBar.width = 0;
LK.showGameOver();
}
- // Update bullets
+ // Power-Up Bar Update
+ if (player.powerUpType) {
+ if (!powerUpBar) {
+ powerUpBar = LK.getAsset('powerUpBar', {
+ anchorX: 0,
+ anchorY: 0.5
+ });
+ powerUpBar.x = healthBarBorder.x - healthBarBorder.width / 2;
+ powerUpBar.y = healthBarBorder.y + 50;
+ game.addChild(powerUpBar);
+ }
+ powerUpBar.width = player.powerUpDuration / 300 * 500;
+ } else if (powerUpBar) {
+ game.removeChild(powerUpBar);
+ powerUpBar = null;
+ }
+ // Bullets Update
for (var i = bullets.length - 1; i >= 0; i--) {
bullets[i].update();
if (bullets[i].x > 2048) {
bullets[i].destroy();
bullets.splice(i, 1);
}
}
- // Update zombies
+ // Zombies Update
for (var j = zombies.length - 1; j >= 0; j--) {
zombies[j].update();
- // Zombie-player collision
if (zombies[j].intersects(player)) {
player.takeDamage(zombies[j].damage);
zombies[j].destroy();
zombies.splice(j, 1);
LK.getSound('zombieHit').play();
}
}
- // Bullet-zombie collisions
+ // Power-Ups Update
+ for (var p = powerUps.length - 1; p >= 0; p--) {
+ powerUps[p].update();
+ // Power-up collection
+ if (powerUps[p].intersects(player)) {
+ player.activatePowerUp(powerUps[p].type);
+ LK.getSound('powerUp').play();
+ powerUps[p].destroy();
+ powerUps.splice(p, 1);
+ }
+ // Remove power-ups that go off-screen
+ if (powerUps[p] && powerUps[p].x < -100) {
+ powerUps[p].destroy();
+ powerUps.splice(p, 1);
+ }
+ }
+ // Bullet-Zombie Collisions
for (var k = bullets.length - 1; k >= 0; k--) {
for (var l = zombies.length - 1; l >= 0; l--) {
if (bullets[k].intersects(zombies[l])) {
- // Zombie takes damage from bullet
- if (zombies[l].takeDamage(bullets[k].damage)) {
+ // Calculate damage with potential power-up multiplier
+ var damage = bullets[k].damage * (player.bulletDamageMultiplier || 1);
+ if (zombies[l].takeDamage(damage)) {
score += 10;
- WaveSystem.zombieKilled(); // Track killed zombies
+ WaveSystem.zombieKilled();
zombies[l].destroy();
zombies.splice(l, 1);
LK.getSound('zombieKill').play();
}
@@ -307,11 +391,10 @@
break;
}
}
}
- // Wave system management
+ // Wave System Management
if (LK.ticks % WaveSystem.waveCooldown === 0) {
- // If no zombies exist, start a new wave
if (zombies.length === 0) {
WaveSystem.startNextWave();
}
}
@@ -325,6 +408,50 @@
game.move = function (x, y, obj) {
player.x = x;
player.y = y;
};
+// Game Over Handler (if not already defined)
+LK.showGameOver = function () {
+ // Create game over screen
+ var gameOverText = new Text2('GAME OVER\nScore: ' + score, {
+ size: 100,
+ fill: 0xFF0000,
+ align: 'center'
+ });
+ gameOverText.anchor.set(0.5, 0.5);
+ gameOverText.x = 2048 / 2;
+ gameOverText.y = 2732 / 2;
+ game.addChild(gameOverText);
+ // Add restart button
+ var restartButton = new Text2('RESTART', {
+ size: 50,
+ fill: 0xFFFFFF,
+ align: 'center'
+ });
+ restartButton.anchor.set(0.5, 0.5);
+ restartButton.x = 2048 / 2;
+ restartButton.y = 2732 / 2 + 200;
+ game.addChild(restartButton);
+ // Restart functionality
+ restartButton.interactive = true;
+ restartButton.on('mousedown', function () {
+ // Reset game state
+ score = 0;
+ zombies = [];
+ bullets = [];
+ powerUps = [];
+ // Reset player
+ player.health = 100;
+ player.powerUpType = null;
+ player.powerUpDuration = 0;
+ player.bulletDamageMultiplier = 1;
+ // Reset wave system
+ WaveSystem.currentWave = 0;
+ // Remove game over elements
+ game.removeChild(gameOverText);
+ game.removeChild(restartButton);
+ // Restart the game
+ WaveSystem.startNextWave();
+ });
+};
// Start the first wave when the game begins
WaveSystem.startNextWave();
\ No newline at end of file
make player like this style
make full legs of this player
bullet. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
more dangorous
make horror
red heart. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
rename text to -- Zombie Killed