/****
* Classes
****/
// Define a simple 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 = -15;
self.update = function () {
self.y += self.speed;
if (self.y < 0) {
self.destroy();
}
};
return self;
});
// Define a simple Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
// Enemy will stack at the top without falling
self.update = function () {
// Check collision with other enemies for stacking at the top
for (var i = 0; i < enemies.length; i++) {
var other = enemies[i];
if (other !== self && self.intersects(other)) {
if (self.y < other.y) {
// This enemy is above the other, stack above it
self.y = other.y - 100;
break;
} else {
// This enemy is below the other, move down by own height
other.y = self.y + 100;
}
}
}
};
return self;
});
//<Assets used in the game will automatically appear here>
// Define a simple Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.8,
scaleY: 0.8
});
self.speed = 10;
self.update = function () {
// Player update logic
};
return self;
});
/****
* 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 - 200;
// Add leaf assets to the left and right sides of the screen
var leftLeaf = game.addChild(LK.getAsset('leaf', {
x: 0,
y: 0
}));
var rightLeaf = game.addChild(LK.getAsset('leaf', {
x: 2048 - 100,
y: 0
}));
var line = game.addChild(LK.getAsset('line', {
x: 0,
y: 2732 / 2
}));
var centerCircle = game.addChild(LK.getAsset('centerCircle', {
x: 2048 / 2,
y: 2732 / 2,
anchorX: 0.5,
anchorY: 0.5,
fill: false
}));
// Initialize enemies array
var enemies = [];
// Initialize bullets array
var bullets = [];
var destroyedEnemies = 0;
// Handle player movement
game.move = function (x, y, obj) {
player.x = x;
player.y = y;
if (player.y < line.y) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
};
// Handle shooting
game.down = function (x, y, obj) {
var bullet = new Bullet();
bullet.x = player.x;
bullet.y = player.y;
bullets.push(bullet);
game.addChild(bullet);
};
// Update game state
game.update = function () {
// Update player
player.update();
// Update enemies
for (var i = enemies.length - 1; i >= 0; i--) {
enemies[i].update();
if (enemies[i].intersects(player)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
// Check if enemy crosses the center line
if (enemies[i].y >= line.y) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
// Update bullets
for (var j = bullets.length - 1; j >= 0; j--) {
bullets[j].update();
for (var k = enemies.length - 1; k >= 0; k--) {
if (bullets[j].intersects(enemies[k])) {
bullets[j].destroy();
enemies[k].destroy();
bullets.splice(j, 1);
enemies.splice(k, 1);
LK.effects.flashScreen(0xaaaaaa, 1000); // Add flash screen effect
destroyedEnemies++;
if (destroyedEnemies == 5) {
var superText = new Text2('Super!', {
size: 150,
fill: 0xFFFFFF
});
superText.anchor.set(0.5, 0);
LK.gui.center.addChild(superText);
LK.setTimeout(function () {
superText.destroy();
}, 3000);
}
if (destroyedEnemies % 20 == 0 && destroyedEnemies != 0) {
var goodText = new Text2('Good!', {
size: 150,
fill: 0xFFFFFF
});
goodText.anchor.set(0.5, 0);
LK.gui.center.addChild(goodText);
LK.setTimeout(function () {
goodText.destroy();
}, 3000);
}
break;
}
}
}
// Spawn enemies more frequently
if (LK.ticks % 30 == 0) {
var enemy = new Enemy();
enemy.x = Math.random() * (2048 - 100) + 50; // Keep within screen bounds
enemy.y = 0; // Start from the very top of the screen
enemies.push(enemy);
game.addChild(enemy);
}
}; /****
* Classes
****/
// Define a simple 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 = -15;
self.update = function () {
self.y += self.speed;
if (self.y < 0) {
self.destroy();
}
};
return self;
});
// Define a simple Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
// Enemy will stack at the top without falling
self.update = function () {
// Check collision with other enemies for stacking at the top
for (var i = 0; i < enemies.length; i++) {
var other = enemies[i];
if (other !== self && self.intersects(other)) {
if (self.y < other.y) {
// This enemy is above the other, stack above it
self.y = other.y - 100;
break;
} else {
// This enemy is below the other, move down by own height
other.y = self.y + 100;
}
}
}
};
return self;
});
//<Assets used in the game will automatically appear here>
// Define a simple Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.8,
scaleY: 0.8
});
self.speed = 10;
self.update = function () {
// Player update logic
};
return self;
});
/****
* 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 - 200;
// Add leaf assets to the left and right sides of the screen
var leftLeaf = game.addChild(LK.getAsset('leaf', {
x: 0,
y: 0
}));
var rightLeaf = game.addChild(LK.getAsset('leaf', {
x: 2048 - 100,
y: 0
}));
var line = game.addChild(LK.getAsset('line', {
x: 0,
y: 2732 / 2
}));
var centerCircle = game.addChild(LK.getAsset('centerCircle', {
x: 2048 / 2,
y: 2732 / 2,
anchorX: 0.5,
anchorY: 0.5,
fill: false
}));
// Initialize enemies array
var enemies = [];
// Initialize bullets array
var bullets = [];
var destroyedEnemies = 0;
// Handle player movement
game.move = function (x, y, obj) {
player.x = x;
player.y = y;
if (player.y < line.y) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
};
// Handle shooting
game.down = function (x, y, obj) {
var bullet = new Bullet();
bullet.x = player.x;
bullet.y = player.y;
bullets.push(bullet);
game.addChild(bullet);
};
// Update game state
game.update = function () {
// Update player
player.update();
// Update enemies
for (var i = enemies.length - 1; i >= 0; i--) {
enemies[i].update();
if (enemies[i].intersects(player)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
// Check if enemy crosses the center line
if (enemies[i].y >= line.y) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
// Update bullets
for (var j = bullets.length - 1; j >= 0; j--) {
bullets[j].update();
for (var k = enemies.length - 1; k >= 0; k--) {
if (bullets[j].intersects(enemies[k])) {
bullets[j].destroy();
enemies[k].destroy();
bullets.splice(j, 1);
enemies.splice(k, 1);
LK.effects.flashScreen(0xaaaaaa, 1000); // Add flash screen effect
destroyedEnemies++;
if (destroyedEnemies == 5) {
var superText = new Text2('Super!', {
size: 150,
fill: 0xFFFFFF
});
superText.anchor.set(0.5, 0);
LK.gui.center.addChild(superText);
LK.setTimeout(function () {
superText.destroy();
}, 3000);
}
if (destroyedEnemies % 20 == 0 && destroyedEnemies != 0) {
var goodText = new Text2('Good!', {
size: 150,
fill: 0xFFFFFF
});
goodText.anchor.set(0.5, 0);
LK.gui.center.addChild(goodText);
LK.setTimeout(function () {
goodText.destroy();
}, 3000);
}
break;
}
}
}
// Spawn enemies more frequently
if (LK.ticks % 30 == 0) {
var enemy = new Enemy();
enemy.x = Math.random() * (2048 - 100) + 50; // Keep within screen bounds
enemy.y = 0; // Start from the very top of the screen
enemies.push(enemy);
game.addChild(enemy);
}
};