/****
* 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 sky = game.addChild(LK.getAsset('sky', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
}));
var background = game.addChild(LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
}));
var player = game.addChild(new Player('player'));
player.x = 1024; // Center horizontally
player.y = 2500; // Near bottom
var zombies = [];
var bullets = [];
var score = 0;
var combo = 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
var lastTouchPoint = null;
game.on('move', function (obj) {
lastTouchPoint = obj.event.getLocalPosition(game);
});
game.on('down', function (obj) {
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 player towards last touch point
if (lastTouchPoint) {
if (lastTouchPoint.x < player.x) {
player.move('left');
} else if (lastTouchPoint.x > player.x) {
player.move('right');
}
}
// 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);
combo = 0; // Reset combo multiplier when a bullet misses
}
}
// 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);
combo += 1; // Increase combo multiplier on zombie kill
score += combo; // Increase score by combo multiplier
LK.setScore(score);
scoreTxt.setText(score.toString());
if (score === 10) {
player.destroy();
player = game.addChild(new Player('playerType2'));
player.x = 1024; // Center horizontally
player.y = 2500; // Near bottom
} else if (score === 20) {
player.destroy();
player = game.addChild(new Player('playerType3'));
player.x = 1024; // Center horizontally
player.y = 2500; // Near bottom
}
break;
}
// Check for player-zombie collisions
if (player && zombies[z] && player.intersects(zombies[z])) {
// Game over
LK.showGameOver();
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.