/****
* Classes
****/
// Define a 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.update = function () {
self.y += self.speed;
if (self.y < -bulletGraphics.height) {
self.destroy();
}
};
});
// Define a Hero class
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphics = self.attachAsset('hero', {
anchorX: 0.5,
anchorY: 0.5
});
self.shoot = function () {
var bullet = new Bullet();
bullet.x = self.x;
bullet.y = self.y - heroGraphics.height / 2;
bullets.push(bullet);
game.addChild(bullet);
};
self.move = function (x, y) {
self.x = x;
self.y = y;
};
});
// Define a SpaceShip class
var SpaceShip = Container.expand(function () {
var self = Container.call(this);
var shipGraphics = self.attachAsset('hero', {
anchorX: 0.5,
anchorY: 0.5
});
self.shoot = function () {
var bullet = new Bullet();
bullet.x = self.x;
bullet.y = self.y - shipGraphics.height / 2;
bullets.push(bullet);
game.addChild(bullet);
};
self.move = function (x, y) {
self.x = x;
self.y = y;
};
});
// Assets will be automatically created and loaded by the LK engine based on their usage in the code.
// Define a Zombie class
var Zombie = Container.expand(function () {
var self = Container.call(this);
this.level = 1; // Initialize level property
var zombieGraphics = self.attachAsset('zombie', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.update = function () {
self.y += self.speed;
self.x += Math.sin(self.y / 100) * 5; // Add horizontal movement
if (self.y > 2732) {
self.respawn();
self.level++;
self.speed += 0.5; // Increase speed with level
LK.setScore(LK.getScore() - 1);
scoreTxt.setText('Score: ' + LK.getScore());
}
if (self.intersects(hero)) {
self.attack();
}
};
self.attack = function () {
LK.effects.flashObject(hero, 0xff0000, 500);
};
self.respawn = function () {
self.y = -zombieGraphics.height;
self.x = Math.random() * 2048;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize score display
var scoreTxt = new Text2('Score: 0', {
size: 100,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Initialize game variables
var hero = new Hero();
hero.x = 2048 / 2;
hero.y = 2732 - 150;
game.addChild(hero);
var zombies = [];
for (var i = 0; i < 5; i++) {
var zombie = new Zombie();
zombie.x = Math.random() * 2048;
zombie.y = Math.random() * 2732;
zombies.push(zombie);
game.addChild(zombie);
}
var bullets = [];
// Handle game updates
game.update = function () {
for (var i = bullets.length - 1; i >= 0; i--) {
bullets[i].update();
for (var j = zombies.length - 1; j >= 0; j--) {
if (bullets[i].intersects(zombies[j])) {
bullets[i].destroy();
bullets.splice(i, 1);
zombies[j].respawn();
LK.setScore(LK.getScore() + 1);
scoreTxt.setText('Score: ' + LK.getScore());
break;
}
}
}
if (LK.ticks % Math.max(600 - zombies[0].level * 10, 300) === 0) {
// Increase level every 10 seconds (assuming 60 FPS)
for (var l = 0; l < zombies.length; l++) {
zombies[l].level++;
zombies[l].speed += 0.5; // Increase speed with level
}
}
if (LK.ticks % 1800 === 0) {
// Every 30 seconds
var newZombie = new Zombie();
newZombie.x = Math.random() * 2048;
newZombie.y = -newZombie.height;
zombies.push(newZombie);
game.addChild(newZombie);
}
for (var k = 0; k < zombies.length; k++) {
zombies[k].update();
if (zombies[k].intersects(hero)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
};
// Handle touch events for moving the hero
game.down = function (x, y, obj) {
hero.move(x, y);
hero.shoot();
}; /****
* Classes
****/
// Define a 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.update = function () {
self.y += self.speed;
if (self.y < -bulletGraphics.height) {
self.destroy();
}
};
});
// Define a Hero class
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphics = self.attachAsset('hero', {
anchorX: 0.5,
anchorY: 0.5
});
self.shoot = function () {
var bullet = new Bullet();
bullet.x = self.x;
bullet.y = self.y - heroGraphics.height / 2;
bullets.push(bullet);
game.addChild(bullet);
};
self.move = function (x, y) {
self.x = x;
self.y = y;
};
});
// Define a SpaceShip class
var SpaceShip = Container.expand(function () {
var self = Container.call(this);
var shipGraphics = self.attachAsset('hero', {
anchorX: 0.5,
anchorY: 0.5
});
self.shoot = function () {
var bullet = new Bullet();
bullet.x = self.x;
bullet.y = self.y - shipGraphics.height / 2;
bullets.push(bullet);
game.addChild(bullet);
};
self.move = function (x, y) {
self.x = x;
self.y = y;
};
});
// Assets will be automatically created and loaded by the LK engine based on their usage in the code.
// Define a Zombie class
var Zombie = Container.expand(function () {
var self = Container.call(this);
this.level = 1; // Initialize level property
var zombieGraphics = self.attachAsset('zombie', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.update = function () {
self.y += self.speed;
self.x += Math.sin(self.y / 100) * 5; // Add horizontal movement
if (self.y > 2732) {
self.respawn();
self.level++;
self.speed += 0.5; // Increase speed with level
LK.setScore(LK.getScore() - 1);
scoreTxt.setText('Score: ' + LK.getScore());
}
if (self.intersects(hero)) {
self.attack();
}
};
self.attack = function () {
LK.effects.flashObject(hero, 0xff0000, 500);
};
self.respawn = function () {
self.y = -zombieGraphics.height;
self.x = Math.random() * 2048;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize score display
var scoreTxt = new Text2('Score: 0', {
size: 100,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Initialize game variables
var hero = new Hero();
hero.x = 2048 / 2;
hero.y = 2732 - 150;
game.addChild(hero);
var zombies = [];
for (var i = 0; i < 5; i++) {
var zombie = new Zombie();
zombie.x = Math.random() * 2048;
zombie.y = Math.random() * 2732;
zombies.push(zombie);
game.addChild(zombie);
}
var bullets = [];
// Handle game updates
game.update = function () {
for (var i = bullets.length - 1; i >= 0; i--) {
bullets[i].update();
for (var j = zombies.length - 1; j >= 0; j--) {
if (bullets[i].intersects(zombies[j])) {
bullets[i].destroy();
bullets.splice(i, 1);
zombies[j].respawn();
LK.setScore(LK.getScore() + 1);
scoreTxt.setText('Score: ' + LK.getScore());
break;
}
}
}
if (LK.ticks % Math.max(600 - zombies[0].level * 10, 300) === 0) {
// Increase level every 10 seconds (assuming 60 FPS)
for (var l = 0; l < zombies.length; l++) {
zombies[l].level++;
zombies[l].speed += 0.5; // Increase speed with level
}
}
if (LK.ticks % 1800 === 0) {
// Every 30 seconds
var newZombie = new Zombie();
newZombie.x = Math.random() * 2048;
newZombie.y = -newZombie.height;
zombies.push(newZombie);
game.addChild(newZombie);
}
for (var k = 0; k < zombies.length; k++) {
zombies[k].update();
if (zombies[k].intersects(hero)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
};
// Handle touch events for moving the hero
game.down = function (x, y, obj) {
hero.move(x, y);
hero.shoot();
};