User prompt
Whenever a zombie, zombie2, or zombie3 is killed change the score by 100
User prompt
Make background the size of the screen and make it go behind eveythibg
User prompt
Make all of the zombies point towards the player
User prompt
When a zombie is killed change score by 100
User prompt
Put a score at the top of the screen
User prompt
Make it so every time you kill a zombie it increases a score by 100
User prompt
Set the cooldown to 0.1
User prompt
Make all of the zombies spawn more frequently
User prompt
Make the zombies speed vary from 2 to 5
User prompt
Make the zombies speed vary
User prompt
Make backgroundMusic loop
User prompt
Make the cooldown 0.3 seconds
User prompt
Add a 0.1 second cooldown before you can shoot again
User prompt
Play the shoot sound when the player shoots a bullet
User prompt
Double the size of zombie
User prompt
Double the size of zombie zombie2 and zombie3
User prompt
Make zombie3 spawn randomly around the border of the map and go towards the player and give it health
User prompt
Make it so zombie2 has health
User prompt
Make zombie2 spawn randomly around the border of the map and go towards the player
User prompt
Make zombie2 and zombie3 have the same behavior as zombie
User prompt
Make the bullet and player 2 times bigger
User prompt
Make the bullets pierce through enemies
User prompt
Make the player a little bigger
User prompt
Make the bullet shoot farther from the player
User prompt
Make the bullet shoot even higher than the player
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.direction = 0; self.update = function () { self.x += Math.cos(self.direction) * self.speed; self.y += Math.sin(self.direction) * self.speed; }; return self; }); var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5, scaleX: 3, // Scale the player 3 times bigger horizontally scaleY: 3 // Scale the player 3 times bigger vertically }); self.rotation = 0; self.shoot = function () { var bullet = new Bullet(); bullet.x = self.x; bullet.y = self.y - 100; // Adjust bullet's initial y-position to shoot even higher than the player bullet.direction = self.rotation; bullets.push(bullet); game.addChild(bullet); LK.getSound('shoot').play(); }; return self; }); var Zombie = Container.expand(function () { var self = Container.call(this); var zombieGraphics = self.attachAsset('zombie', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 2; self.health = 2; // Add health property to track hits self.update = function () { var angle = Math.atan2(player.y - self.y, player.x - self.x); self.x += Math.cos(angle) * self.speed; self.y += Math.sin(angle) * self.speed; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ // Initialize assets used in this game. Scale them according to what is needed for the game. game.setBackgroundColor(0x000000); var player = new Player(); player.x = 2048 / 2; player.y = 2732 / 2; game.addChild(player); var bullets = []; var zombies = []; var score = 0; function spawnZombie() { var zombie = new Zombie(); 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 = 2048 + 50; zombie.y = Math.random() * 2732; break; case 2: // Bottom zombie.x = Math.random() * 2048; zombie.y = 2732 + 50; break; case 3: // Left zombie.x = -50; zombie.y = Math.random() * 2732; break; } zombies.push(zombie); game.addChild(zombie); } game.down = function (x, y, obj) { var angle = Math.atan2(y - player.y, x - player.x); player.rotation = angle; // Update player rotation to face the touch location player.shoot(); // Use the player's shoot method to create and shoot the bullet }; game.update = function () { for (var i = bullets.length - 1; i >= 0; i--) { var bullet = bullets[i]; bullet.update(); if (bullet.x < 0 || bullet.x > 2048 || bullet.y < 0 || bullet.y > 2732) { bullet.destroy(); bullets.splice(i, 1); } } for (var j = zombies.length - 1; j >= 0; j--) { var zombie = zombies[j]; zombie.update(); if (zombie.intersects(player)) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); return; } for (var k = bullets.length - 1; k >= 0; k--) { var bullet = bullets[k]; if (bullet.intersects(zombie)) { LK.getSound('zombieHit').play(); score += 10; bullet.destroy(); bullets.splice(k, 1); zombie.health -= 1; // Decrease zombie health by 1 if (zombie.health <= 0) { // Check if zombie health is depleted zombie.destroy(); zombies.splice(j, 1); } break; } } } if (LK.ticks % 60 === 0) { spawnZombie(); } }; LK.playMusic('backgroundMusic');
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.direction = 0;
self.update = function () {
self.x += Math.cos(self.direction) * self.speed;
self.y += Math.sin(self.direction) * self.speed;
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3,
// Scale the player 3 times bigger horizontally
scaleY: 3 // Scale the player 3 times bigger vertically
});
self.rotation = 0;
self.shoot = function () {
var bullet = new Bullet();
bullet.x = self.x;
bullet.y = self.y - 100; // Adjust bullet's initial y-position to shoot even higher than the player
bullet.direction = self.rotation;
bullets.push(bullet);
game.addChild(bullet);
LK.getSound('shoot').play();
};
return self;
});
var Zombie = Container.expand(function () {
var self = Container.call(this);
var zombieGraphics = self.attachAsset('zombie', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.health = 2; // Add health property to track hits
self.update = function () {
var angle = Math.atan2(player.y - self.y, player.x - self.x);
self.x += Math.cos(angle) * self.speed;
self.y += Math.sin(angle) * self.speed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Initialize assets used in this game. Scale them according to what is needed for the game.
game.setBackgroundColor(0x000000);
var player = new Player();
player.x = 2048 / 2;
player.y = 2732 / 2;
game.addChild(player);
var bullets = [];
var zombies = [];
var score = 0;
function spawnZombie() {
var zombie = new Zombie();
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 = 2048 + 50;
zombie.y = Math.random() * 2732;
break;
case 2:
// Bottom
zombie.x = Math.random() * 2048;
zombie.y = 2732 + 50;
break;
case 3:
// Left
zombie.x = -50;
zombie.y = Math.random() * 2732;
break;
}
zombies.push(zombie);
game.addChild(zombie);
}
game.down = function (x, y, obj) {
var angle = Math.atan2(y - player.y, x - player.x);
player.rotation = angle; // Update player rotation to face the touch location
player.shoot(); // Use the player's shoot method to create and shoot the bullet
};
game.update = function () {
for (var i = bullets.length - 1; i >= 0; i--) {
var bullet = bullets[i];
bullet.update();
if (bullet.x < 0 || bullet.x > 2048 || bullet.y < 0 || bullet.y > 2732) {
bullet.destroy();
bullets.splice(i, 1);
}
}
for (var j = zombies.length - 1; j >= 0; j--) {
var zombie = zombies[j];
zombie.update();
if (zombie.intersects(player)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
}
for (var k = bullets.length - 1; k >= 0; k--) {
var bullet = bullets[k];
if (bullet.intersects(zombie)) {
LK.getSound('zombieHit').play();
score += 10;
bullet.destroy();
bullets.splice(k, 1);
zombie.health -= 1; // Decrease zombie health by 1
if (zombie.health <= 0) {
// Check if zombie health is depleted
zombie.destroy();
zombies.splice(j, 1);
}
break;
}
}
}
if (LK.ticks % 60 === 0) {
spawnZombie();
}
};
LK.playMusic('backgroundMusic');