User prompt
Make the hero always move towards last touch point.
User prompt
If the player got hit by the zombie, then that is game over.
User prompt
Let's add the second layer of the background, or the sky, please.
User prompt
Move the hero from left and right through player inputs.
User prompt
Let's edit the background with an open road for the player to move.
User prompt
Let's add the background, like, for example, a city, please.
User prompt
Let's add a combo multiplier. Every time you shoot the zombie, you get a combo. More combos, more points.
User prompt
Let's choose classes. Every time you choose a class, you get new weapons for shooting zombies.
User prompt
Let's add the score to Killing the Zombies.
Initial prompt
Simply Zombies
/****
* Classes
****/
// Bullet class
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.move = function () {
self.y += self.speed;
};
});
// Assets will be automatically created based on usage in the code.
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.move = function (direction) {
if (direction === 'left' && self.x > 0) {
self.x -= self.speed;
} else if (direction === 'right' && self.x < 2048) {
self.x += self.speed;
}
};
});
// Zombie class
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.move = function () {
self.y += self.speed;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
var player = game.addChild(new Player());
player.x = 1024; // Center horizontally
player.y = 2500; // Near bottom
var zombies = [];
var bullets = [];
var score = 0;
var scoreTxt = new Text2(score.toString(), {
size: 150,
fill: "#ffffff"
});
LK.gui.top.addChild(scoreTxt);
// Create zombies at intervals
var zombieInterval = LK.setInterval(function () {
var zombie = new Zombie();
zombie.x = Math.random() * 2048; // Random horizontal position
zombie.y = 0; // Start from top
zombies.push(zombie);
game.addChild(zombie);
}, 2000);
// Touch event to move player and shoot bullets
game.on('down', function (obj) {
var pos = obj.event.getLocalPosition(game);
if (pos.x < 1024) {
player.move('left');
} else {
player.move('right');
}
var bullet = new Bullet();
bullet.x = player.x;
bullet.y = player.y;
bullets.push(bullet);
game.addChild(bullet);
});
// Game tick
LK.on('tick', function () {
// Move zombies
for (var i = zombies.length - 1; i >= 0; i--) {
zombies[i].move();
if (zombies[i].y > 2732) {
// Off screen
zombies[i].destroy();
zombies.splice(i, 1);
}
}
// Move bullets
for (var j = bullets.length - 1; j >= 0; j--) {
bullets[j].move();
if (bullets[j].y < 0) {
// Off screen
bullets[j].destroy();
bullets.splice(j, 1);
}
}
// Check for bullet-zombie collisions
for (var b = bullets.length - 1; b >= 0; b--) {
for (var z = zombies.length - 1; z >= 0; z--) {
if (bullets[b] && zombies[z] && bullets[b].intersects(zombies[z])) {
bullets[b].destroy();
bullets.splice(b, 1);
zombies[z].destroy();
zombies.splice(z, 1);
score += 1;
scoreTxt.setText(score.toString());
break;
}
}
}
});
Soldier in a zombie infested world. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Bullet. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Open road in a city that is plagued by zombies. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
zombie. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Orange coved sky for the zombie infested town. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.