/****
* Classes
****/
// Cure class
var Cure = Container.expand(function () {
var self = Container.call(this);
var cureGraphics = self.attachAsset('cure', {
anchorX: 0.5,
anchorY: 0.5
});
});
// The assets will be automatically created and loaded by the LK engine
// 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.update = function () {
// Player movement logic goes here
};
});
// 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.update = function () {
// Zombie movement logic goes here
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize player
var player = game.addChild(new Player());
player.x = 2048 / 2;
player.y = 2732 / 2;
// Initialize zombies
var zombies = [];
for (var i = 0; i < 10; i++) {
var zombie = game.addChild(new Zombie());
zombie.x = Math.random() * 2048;
zombie.y = Math.random() * 2732;
zombies.push(zombie);
}
// Initialize cure
var cure = game.addChild(new Cure());
cure.x = Math.random() * 2048;
cure.y = Math.random() * 2732;
// Game update function
game.update = function () {
// Check if player has found the cure
if (player.intersects(cure)) {
// Player wins the game
LK.showGameOver();
}
// Check if player has been caught by a zombie
for (var i = 0; i < zombies.length; i++) {
if (player.intersects(zombies[i])) {
// Player loses the game
LK.showGameOver();
}
}
};
// Handle player movement
game.move = function (x, y, obj) {
player.x = x;
player.y = y;
};