/****
* Classes
****/
//<Assets used in the game will automatically appear here>
// Shooter class
var Shooter = Container.expand(function () {
var self = Container.call(this);
var shooterGraphics = self.attachAsset('shooter', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Shooter movement logic
self.x += (Math.random() - 0.5) * 10;
self.y += (Math.random() - 0.5) * 10;
// Keep shooter within bounds
self.x = Math.max(0, Math.min(2048, self.x));
self.y = Math.max(0, Math.min(2732, self.y));
};
});
// Zombie class
var Zombie = Container.expand(function () {
var self = Container.call(this);
var zombieGraphics = self.attachAsset('zombie', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Zombie movement logic
self.x += (Math.random() - 0.5) * 5;
self.y += (Math.random() - 0.5) * 5;
// Keep zombie within bounds
self.x = Math.max(0, Math.min(2048, self.x));
self.y = Math.max(0, Math.min(2732, self.y));
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize shooter
var shooter = game.addChild(new Shooter());
shooter.x = 1024; // Center horizontally
shooter.y = 1366; // Center vertically
// Initialize zombies
var zombies = [];
for (var i = 0; i < 50; i++) {
var zombie = new Zombie();
zombie.x = Math.random() * 2048;
zombie.y = Math.random() * 2732;
zombies.push(zombie);
game.addChild(zombie);
}
// Game update logic
game.update = function () {
shooter.update();
for (var i = 0; i < zombies.length; i++) {
zombies[i].update();
}
};