User prompt
when mouse go the left sideind middle make it turon 180 degrees
User prompt
add a health bar
User prompt
delete all player movement
User prompt
make bullet go where player clicked
User prompt
make zombies go to surviver and make their speed to low
User prompt
make zombies rotate to player
User prompt
rotate player to maouse
User prompt
MAKE ZOMbies come differnt positions and chance player movement add play in the middle
Code edit (1 edits merged)
Please save this source code
User prompt
Zombie Shooter: Survival Rush
Initial prompt
make a zombie shotter game
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Bullet class
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletSprite = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -22;
self.update = function () {
self.y += self.speed;
};
return self;
});
// Powerup class
var Powerup = Container.expand(function () {
var self = Container.call(this);
var powerupSprite = self.attachAsset('powerup', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 7;
self.update = function () {
self.y += self.speed;
};
return self;
});
// Survivor class
var Survivor = Container.expand(function () {
var self = Container.call(this);
var survivorSprite = self.attachAsset('survivor', {
anchorX: 0.5,
anchorY: 0.5
});
// For powerup effect
self.isPowered = false;
self.powerTimer = 0;
// For future: add more survivor logic here
return self;
});
// Zombie class
var Zombie = Container.expand(function () {
var self = Container.call(this);
var zombieSprite = self.attachAsset('zombie', {
anchorX: 0.5,
anchorY: 0.5
});
// Movement speed (pixels per frame)
self.speed = 4 + Math.random() * 2;
// Sway amplitude and frequency for zigzag
self.swayAmp = 60 + Math.random() * 80;
self.swayFreq = 0.005 + Math.random() * 0.003;
self.baseX = 0;
self.t = 0;
// For tracking last position for offscreen detection
self.lastY = undefined;
// For tracking intersection with bullets
self.lastIntersecting = false;
// For tracking intersection with survivor
self.lastTouchSurvivor = false;
// For powerup drop
self.hasDroppedPowerup = false;
self.update = function () {
self.t += 1;
self.y += self.speed;
self.x = self.baseX + Math.sin(self.t * self.swayFreq * 60) * self.swayAmp;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x181818
});
/****
* Game Code
****/
// Music (not played in MVP as per instructions, but asset is here for future)
// Sound for zombie hit
// Sound for powerup
// Sound for shooting
// Powerup asset: a magenta ellipse
// Bullet asset: a yellow box
// Zombie asset: a green ellipse
// Survivor (player) asset: a blue box
// Survivor instance
var survivor = new Survivor();
game.addChild(survivor);
// Place survivor at bottom center, above bottom edge
survivor.x = 2048 / 2;
survivor.y = 2732 - 180;
// Arrays for game objects
var zombies = [];
var bullets = [];
var powerups = [];
// Score display
var scoreTxt = new Text2('0', {
size: 120,
fill: "#fff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Powerup timer display
var powerupTxt = new Text2('', {
size: 70,
fill: 0xFF3FD6
});
powerupTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(powerupTxt);
powerupTxt.y = 120;
// Game state
var dragNode = null;
var canShoot = true;
var shootCooldown = 0;
var shootInterval = 12; // frames between shots
var zombieSpawnTimer = 0;
var zombieSpawnInterval = 60; // frames between spawns, will decrease
var zombieSpeedIncrease = 0;
var powerupActive = false;
var powerupTimer = 0;
var powerupDuration = 360; // frames (6 seconds)
var lastGameOver = false;
// Helper: spawn a zombie
function spawnZombie() {
var z = new Zombie();
// Random x within screen, but not too close to edge
var margin = 120;
z.baseX = margin + Math.random() * (2048 - 2 * margin);
z.x = z.baseX;
z.y = -100;
// Increase speed as game progresses
z.speed += zombieSpeedIncrease;
zombies.push(z);
game.addChild(z);
}
// Helper: spawn a powerup at (x, y)
function spawnPowerup(x, y) {
var p = new Powerup();
p.x = x;
p.y = y;
powerups.push(p);
game.addChild(p);
}
// Helper: shoot a bullet
function shootBullet() {
if (!canShoot) return;
canShoot = false;
shootCooldown = 0;
var b = new Bullet();
b.x = survivor.x;
b.y = survivor.y - 80;
bullets.push(b);
game.addChild(b);
LK.getSound('shoot').play();
}
// Dragging logic
game.down = function (x, y, obj) {
// Only allow drag if touch is on lower 1/3 of screen
if (y > 2732 * 0.66) {
dragNode = survivor;
}
};
game.up = function (x, y, obj) {
dragNode = null;
};
function handleMove(x, y, obj) {
if (dragNode === survivor) {
// Clamp survivor to screen horizontally
var halfW = survivor.width / 2;
var nx = Math.max(halfW, Math.min(2048 - halfW, x));
survivor.x = nx;
}
}
game.move = handleMove;
// Tap to shoot logic
game.tap = function (x, y, obj) {
// Only allow tap to shoot if not dragging
if (!dragNode) {
shootBullet();
}
};
// For touch devices, simulate tap on quick down/up
var lastDownTime = 0;
game.down = function (x, y, obj) {
if (y > 2732 * 0.66) {
dragNode = survivor;
lastDownTime = Date.now();
} else {
lastDownTime = Date.now();
}
};
game.up = function (x, y, obj) {
if (dragNode === survivor) {
dragNode = null;
} else {
// If quick tap, treat as tap to shoot
if (Date.now() - lastDownTime < 250) {
shootBullet();
}
}
};
// Main update loop
game.update = function () {
// Handle survivor powerup timer
if (powerupActive) {
powerupTimer--;
if (powerupTimer <= 0) {
powerupActive = false;
survivor.isPowered = false;
powerupTxt.setText('');
// Visual: scale back to normal
tween(survivor, {
scaleX: 1,
scaleY: 1
}, {
duration: 200,
easing: tween.easeOut
});
} else {
powerupTxt.setText('POWER! ' + Math.ceil(powerupTimer / 60));
}
}
// Shooting cooldown
if (!canShoot) {
shootCooldown++;
if (shootCooldown >= (powerupActive ? 4 : shootInterval)) {
canShoot = true;
}
}
// Spawn zombies
zombieSpawnTimer++;
if (zombieSpawnTimer >= zombieSpawnInterval) {
spawnZombie();
zombieSpawnTimer = 0;
// Increase difficulty over time
if (zombieSpawnInterval > 24) zombieSpawnInterval -= 1;
zombieSpeedIncrease += 0.01;
}
// Update bullets
for (var i = bullets.length - 1; i >= 0; i--) {
var b = bullets[i];
b.update();
// Remove if offscreen
if (b.y < -100) {
b.destroy();
bullets.splice(i, 1);
continue;
}
// Check collision with zombies
for (var j = zombies.length - 1; j >= 0; j--) {
var z = zombies[j];
if (b.intersects(z)) {
// Hit!
LK.getSound('zombiehit').play();
// Score
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
// Powerup drop chance
if (!z.hasDroppedPowerup && Math.random() < 0.08) {
spawnPowerup(z.x, z.y);
z.hasDroppedPowerup = true;
}
// Visual: flash zombie
LK.effects.flashObject(z, 0xffffff, 200);
// Remove both
z.destroy();
zombies.splice(j, 1);
b.destroy();
bullets.splice(i, 1);
break;
}
}
}
// Update zombies
for (var i = zombies.length - 1; i >= 0; i--) {
var z = zombies[i];
z.update();
// Remove if offscreen (bottom)
if (z.y > 2732 + 100) {
z.destroy();
zombies.splice(i, 1);
continue;
}
// Check collision with survivor
if (z.intersects(survivor)) {
if (!lastGameOver) {
// Game over
LK.effects.flashScreen(0xff0000, 1000);
lastGameOver = true;
LK.showGameOver();
return;
}
}
}
// Update powerups
for (var i = powerups.length - 1; i >= 0; i--) {
var p = powerups[i];
p.update();
// Remove if offscreen
if (p.y > 2732 + 100) {
p.destroy();
powerups.splice(i, 1);
continue;
}
// Check collision with survivor
if (p.intersects(survivor)) {
LK.getSound('powerup').play();
// Activate powerup: rapid fire
powerupActive = true;
powerupTimer = powerupDuration;
survivor.isPowered = true;
// Visual: scale up
tween(survivor, {
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 200,
easing: tween.easeOut
});
powerupTxt.setText('POWER! ' + Math.ceil(powerupTimer / 60));
p.destroy();
powerups.splice(i, 1);
continue;
}
}
};
// Reset game state on restart
LK.on('gameStart', function () {
// Remove all zombies, bullets, powerups
for (var i = 0; i < zombies.length; i++) zombies[i].destroy();
for (var i = 0; i < bullets.length; i++) bullets[i].destroy();
for (var i = 0; i < powerups.length; i++) powerups[i].destroy();
zombies = [];
bullets = [];
powerups = [];
// Reset survivor
survivor.x = 2048 / 2;
survivor.y = 2732 - 180;
survivor.isPowered = false;
survivor.scaleX = 1;
survivor.scaleY = 1;
// Reset timers and state
canShoot = true;
shootCooldown = 0;
zombieSpawnTimer = 0;
zombieSpawnInterval = 60;
zombieSpeedIncrease = 0;
powerupActive = false;
powerupTimer = 0;
powerupTxt.setText('');
lastGameOver = false;
LK.setScore(0);
scoreTxt.setText('0');
}); ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,364 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+// Bullet class
+var Bullet = Container.expand(function () {
+ var self = Container.call(this);
+ var bulletSprite = self.attachAsset('bullet', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = -22;
+ self.update = function () {
+ self.y += self.speed;
+ };
+ return self;
+});
+// Powerup class
+var Powerup = Container.expand(function () {
+ var self = Container.call(this);
+ var powerupSprite = self.attachAsset('powerup', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 7;
+ self.update = function () {
+ self.y += self.speed;
+ };
+ return self;
+});
+// Survivor class
+var Survivor = Container.expand(function () {
+ var self = Container.call(this);
+ var survivorSprite = self.attachAsset('survivor', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // For powerup effect
+ self.isPowered = false;
+ self.powerTimer = 0;
+ // For future: add more survivor logic here
+ return self;
+});
+// Zombie class
+var Zombie = Container.expand(function () {
+ var self = Container.call(this);
+ var zombieSprite = self.attachAsset('zombie', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Movement speed (pixels per frame)
+ self.speed = 4 + Math.random() * 2;
+ // Sway amplitude and frequency for zigzag
+ self.swayAmp = 60 + Math.random() * 80;
+ self.swayFreq = 0.005 + Math.random() * 0.003;
+ self.baseX = 0;
+ self.t = 0;
+ // For tracking last position for offscreen detection
+ self.lastY = undefined;
+ // For tracking intersection with bullets
+ self.lastIntersecting = false;
+ // For tracking intersection with survivor
+ self.lastTouchSurvivor = false;
+ // For powerup drop
+ self.hasDroppedPowerup = false;
+ self.update = function () {
+ self.t += 1;
+ self.y += self.speed;
+ self.x = self.baseX + Math.sin(self.t * self.swayFreq * 60) * self.swayAmp;
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
+ backgroundColor: 0x181818
+});
+
+/****
+* Game Code
+****/
+// Music (not played in MVP as per instructions, but asset is here for future)
+// Sound for zombie hit
+// Sound for powerup
+// Sound for shooting
+// Powerup asset: a magenta ellipse
+// Bullet asset: a yellow box
+// Zombie asset: a green ellipse
+// Survivor (player) asset: a blue box
+// Survivor instance
+var survivor = new Survivor();
+game.addChild(survivor);
+// Place survivor at bottom center, above bottom edge
+survivor.x = 2048 / 2;
+survivor.y = 2732 - 180;
+// Arrays for game objects
+var zombies = [];
+var bullets = [];
+var powerups = [];
+// Score display
+var scoreTxt = new Text2('0', {
+ size: 120,
+ fill: "#fff"
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+// Powerup timer display
+var powerupTxt = new Text2('', {
+ size: 70,
+ fill: 0xFF3FD6
+});
+powerupTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(powerupTxt);
+powerupTxt.y = 120;
+// Game state
+var dragNode = null;
+var canShoot = true;
+var shootCooldown = 0;
+var shootInterval = 12; // frames between shots
+var zombieSpawnTimer = 0;
+var zombieSpawnInterval = 60; // frames between spawns, will decrease
+var zombieSpeedIncrease = 0;
+var powerupActive = false;
+var powerupTimer = 0;
+var powerupDuration = 360; // frames (6 seconds)
+var lastGameOver = false;
+// Helper: spawn a zombie
+function spawnZombie() {
+ var z = new Zombie();
+ // Random x within screen, but not too close to edge
+ var margin = 120;
+ z.baseX = margin + Math.random() * (2048 - 2 * margin);
+ z.x = z.baseX;
+ z.y = -100;
+ // Increase speed as game progresses
+ z.speed += zombieSpeedIncrease;
+ zombies.push(z);
+ game.addChild(z);
+}
+// Helper: spawn a powerup at (x, y)
+function spawnPowerup(x, y) {
+ var p = new Powerup();
+ p.x = x;
+ p.y = y;
+ powerups.push(p);
+ game.addChild(p);
+}
+// Helper: shoot a bullet
+function shootBullet() {
+ if (!canShoot) return;
+ canShoot = false;
+ shootCooldown = 0;
+ var b = new Bullet();
+ b.x = survivor.x;
+ b.y = survivor.y - 80;
+ bullets.push(b);
+ game.addChild(b);
+ LK.getSound('shoot').play();
+}
+// Dragging logic
+game.down = function (x, y, obj) {
+ // Only allow drag if touch is on lower 1/3 of screen
+ if (y > 2732 * 0.66) {
+ dragNode = survivor;
+ }
+};
+game.up = function (x, y, obj) {
+ dragNode = null;
+};
+function handleMove(x, y, obj) {
+ if (dragNode === survivor) {
+ // Clamp survivor to screen horizontally
+ var halfW = survivor.width / 2;
+ var nx = Math.max(halfW, Math.min(2048 - halfW, x));
+ survivor.x = nx;
+ }
+}
+game.move = handleMove;
+// Tap to shoot logic
+game.tap = function (x, y, obj) {
+ // Only allow tap to shoot if not dragging
+ if (!dragNode) {
+ shootBullet();
+ }
+};
+// For touch devices, simulate tap on quick down/up
+var lastDownTime = 0;
+game.down = function (x, y, obj) {
+ if (y > 2732 * 0.66) {
+ dragNode = survivor;
+ lastDownTime = Date.now();
+ } else {
+ lastDownTime = Date.now();
+ }
+};
+game.up = function (x, y, obj) {
+ if (dragNode === survivor) {
+ dragNode = null;
+ } else {
+ // If quick tap, treat as tap to shoot
+ if (Date.now() - lastDownTime < 250) {
+ shootBullet();
+ }
+ }
+};
+// Main update loop
+game.update = function () {
+ // Handle survivor powerup timer
+ if (powerupActive) {
+ powerupTimer--;
+ if (powerupTimer <= 0) {
+ powerupActive = false;
+ survivor.isPowered = false;
+ powerupTxt.setText('');
+ // Visual: scale back to normal
+ tween(survivor, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 200,
+ easing: tween.easeOut
+ });
+ } else {
+ powerupTxt.setText('POWER! ' + Math.ceil(powerupTimer / 60));
+ }
+ }
+ // Shooting cooldown
+ if (!canShoot) {
+ shootCooldown++;
+ if (shootCooldown >= (powerupActive ? 4 : shootInterval)) {
+ canShoot = true;
+ }
+ }
+ // Spawn zombies
+ zombieSpawnTimer++;
+ if (zombieSpawnTimer >= zombieSpawnInterval) {
+ spawnZombie();
+ zombieSpawnTimer = 0;
+ // Increase difficulty over time
+ if (zombieSpawnInterval > 24) zombieSpawnInterval -= 1;
+ zombieSpeedIncrease += 0.01;
+ }
+ // Update bullets
+ for (var i = bullets.length - 1; i >= 0; i--) {
+ var b = bullets[i];
+ b.update();
+ // Remove if offscreen
+ if (b.y < -100) {
+ b.destroy();
+ bullets.splice(i, 1);
+ continue;
+ }
+ // Check collision with zombies
+ for (var j = zombies.length - 1; j >= 0; j--) {
+ var z = zombies[j];
+ if (b.intersects(z)) {
+ // Hit!
+ LK.getSound('zombiehit').play();
+ // Score
+ LK.setScore(LK.getScore() + 1);
+ scoreTxt.setText(LK.getScore());
+ // Powerup drop chance
+ if (!z.hasDroppedPowerup && Math.random() < 0.08) {
+ spawnPowerup(z.x, z.y);
+ z.hasDroppedPowerup = true;
+ }
+ // Visual: flash zombie
+ LK.effects.flashObject(z, 0xffffff, 200);
+ // Remove both
+ z.destroy();
+ zombies.splice(j, 1);
+ b.destroy();
+ bullets.splice(i, 1);
+ break;
+ }
+ }
+ }
+ // Update zombies
+ for (var i = zombies.length - 1; i >= 0; i--) {
+ var z = zombies[i];
+ z.update();
+ // Remove if offscreen (bottom)
+ if (z.y > 2732 + 100) {
+ z.destroy();
+ zombies.splice(i, 1);
+ continue;
+ }
+ // Check collision with survivor
+ if (z.intersects(survivor)) {
+ if (!lastGameOver) {
+ // Game over
+ LK.effects.flashScreen(0xff0000, 1000);
+ lastGameOver = true;
+ LK.showGameOver();
+ return;
+ }
+ }
+ }
+ // Update powerups
+ for (var i = powerups.length - 1; i >= 0; i--) {
+ var p = powerups[i];
+ p.update();
+ // Remove if offscreen
+ if (p.y > 2732 + 100) {
+ p.destroy();
+ powerups.splice(i, 1);
+ continue;
+ }
+ // Check collision with survivor
+ if (p.intersects(survivor)) {
+ LK.getSound('powerup').play();
+ // Activate powerup: rapid fire
+ powerupActive = true;
+ powerupTimer = powerupDuration;
+ survivor.isPowered = true;
+ // Visual: scale up
+ tween(survivor, {
+ scaleX: 1.3,
+ scaleY: 1.3
+ }, {
+ duration: 200,
+ easing: tween.easeOut
+ });
+ powerupTxt.setText('POWER! ' + Math.ceil(powerupTimer / 60));
+ p.destroy();
+ powerups.splice(i, 1);
+ continue;
+ }
+ }
+};
+// Reset game state on restart
+LK.on('gameStart', function () {
+ // Remove all zombies, bullets, powerups
+ for (var i = 0; i < zombies.length; i++) zombies[i].destroy();
+ for (var i = 0; i < bullets.length; i++) bullets[i].destroy();
+ for (var i = 0; i < powerups.length; i++) powerups[i].destroy();
+ zombies = [];
+ bullets = [];
+ powerups = [];
+ // Reset survivor
+ survivor.x = 2048 / 2;
+ survivor.y = 2732 - 180;
+ survivor.isPowered = false;
+ survivor.scaleX = 1;
+ survivor.scaleY = 1;
+ // Reset timers and state
+ canShoot = true;
+ shootCooldown = 0;
+ zombieSpawnTimer = 0;
+ zombieSpawnInterval = 60;
+ zombieSpeedIncrease = 0;
+ powerupActive = false;
+ powerupTimer = 0;
+ powerupTxt.setText('');
+ lastGameOver = false;
+ LK.setScore(0);
+ scoreTxt.setText('0');
});
\ No newline at end of file