/**** * Classes ****/ //<Assets used in the game will automatically appear here> // Class for the Blue Team var BlueTeam = Container.expand(function () { var self = Container.call(this); var blueTeamGraphics = self.attachAsset('hero', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { // Update logic for blue team }; }); // Class for the Bullet 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; }; }); // Class for the Enemy var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 3; self.update = function () { // Move the enemy downwards self.y += self.speed; // Check for collision with hero if (self.intersects(hero)) { // Handle hero and enemy collision LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } }; }); // Class for the Flag var Flag = Container.expand(function () { var self = Container.call(this); var flagGraphics = self.attachAsset('flag', { anchorX: 0.5, anchorY: 0.5 }); }); // Class for the Red Team var RedTeam = Container.expand(function () { var self = Container.call(this); var redTeamGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { // Update logic for red team }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize game elements var blueTeam = game.addChild(new BlueTeam()); blueTeam.x = 2048 / 2; blueTeam.y = 2732 - 200; var redTeam = game.addChild(new RedTeam()); redTeam.x = 2048 / 2; redTeam.y = 200; var enemies = []; var bullets = []; var redFlag = game.addChild(new Flag()); redFlag.x = 2048 / 2; redFlag.y = 200; var blueFlag = game.addChild(new Flag()); blueFlag.x = 2048 / 2; blueFlag.y = 2732 - 200; // Create a map with trees and cities var map = []; for (var i = 0; i < 20; i++) { map[i] = []; for (var j = 0; j < 20; j++) { var tileType = 'box'; var tileColor = 0x808080; // Create different types of tiles for trees and cities if (i % 2 === 0 && j % 2 === 0) { tileType = 'tree'; tileColor = 0x008000; // Green for trees } else if (i % 3 === 0 && j % 3 === 0) { tileType = 'city'; tileColor = 0x808080; // Grey for cities } var tile = game.addChild(LK.getAsset(tileType, { width: 102.4, height: 136.6, color: tileColor })); tile.x = i * 102.4; tile.y = j * 136.6; map[i][j] = tile; } } // Function to handle game updates game.update = function () { // Update hero blueTeam.update(); // Update enemies for (var i = enemies.length - 1; i >= 0; i--) { enemies[i].update(); if (enemies[i].intersects(hero)) { // Handle hero and enemy collision LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } // Update bullets for (var j = bullets.length - 1; j >= 0; j--) { bullets[j].update(); if (blueTeam.intersects(redFlag)) { // Handle blue team capturing red flag LK.setScore(LK.getScore() + 1); LK.effects.flashScreen(0x0000ff, 1000); // Flash screen blue redFlag.destroy(); // Remove the red flag from the game } if (redTeam.intersects(blueFlag)) { // Handle red team capturing blue flag LK.setScore(LK.getScore() + 1); LK.effects.flashScreen(0xff0000, 1000); // Flash screen red blueFlag.destroy(); // Remove the blue flag from the game } if (bullets[j] && bullets[j].y < -50) { bullets[j].destroy(); bullets.splice(j, 1); } } // Fire bullet if (LK.ticks % 30 == 0) { var newBullet = new Bullet(); newBullet.x = blueTeam.x; newBullet.y = blueTeam.y; bullets.push(newBullet); game.addChild(newBullet); } }; // Handle touch events for hero movement game.down = function (x, y, obj) { blueTeam.x = x; blueTeam.y = y; }; game.move = function (x, y, obj) { blueTeam.x = x; blueTeam.y = y; }; game.up = function (x, y, obj) { // Stop hero movement }; // Spawn enemies at intervals if (LK.ticks % 120 == 0) { var newEnemy = new Enemy(); newEnemy.x = Math.random() * 2048; newEnemy.y = 0; enemies.push(newEnemy); game.addChild(newEnemy); }
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
// Class for the Blue Team
var BlueTeam = Container.expand(function () {
var self = Container.call(this);
var blueTeamGraphics = self.attachAsset('hero', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
// Update logic for blue team
};
});
// Class for the Bullet
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;
};
});
// Class for the Enemy
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
// Move the enemy downwards
self.y += self.speed;
// Check for collision with hero
if (self.intersects(hero)) {
// Handle hero and enemy collision
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
};
});
// Class for the Flag
var Flag = Container.expand(function () {
var self = Container.call(this);
var flagGraphics = self.attachAsset('flag', {
anchorX: 0.5,
anchorY: 0.5
});
});
// Class for the Red Team
var RedTeam = Container.expand(function () {
var self = Container.call(this);
var redTeamGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
// Update logic for red team
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize game elements
var blueTeam = game.addChild(new BlueTeam());
blueTeam.x = 2048 / 2;
blueTeam.y = 2732 - 200;
var redTeam = game.addChild(new RedTeam());
redTeam.x = 2048 / 2;
redTeam.y = 200;
var enemies = [];
var bullets = [];
var redFlag = game.addChild(new Flag());
redFlag.x = 2048 / 2;
redFlag.y = 200;
var blueFlag = game.addChild(new Flag());
blueFlag.x = 2048 / 2;
blueFlag.y = 2732 - 200;
// Create a map with trees and cities
var map = [];
for (var i = 0; i < 20; i++) {
map[i] = [];
for (var j = 0; j < 20; j++) {
var tileType = 'box';
var tileColor = 0x808080;
// Create different types of tiles for trees and cities
if (i % 2 === 0 && j % 2 === 0) {
tileType = 'tree';
tileColor = 0x008000; // Green for trees
} else if (i % 3 === 0 && j % 3 === 0) {
tileType = 'city';
tileColor = 0x808080; // Grey for cities
}
var tile = game.addChild(LK.getAsset(tileType, {
width: 102.4,
height: 136.6,
color: tileColor
}));
tile.x = i * 102.4;
tile.y = j * 136.6;
map[i][j] = tile;
}
}
// Function to handle game updates
game.update = function () {
// Update hero
blueTeam.update();
// Update enemies
for (var i = enemies.length - 1; i >= 0; i--) {
enemies[i].update();
if (enemies[i].intersects(hero)) {
// Handle hero and enemy collision
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
// Update bullets
for (var j = bullets.length - 1; j >= 0; j--) {
bullets[j].update();
if (blueTeam.intersects(redFlag)) {
// Handle blue team capturing red flag
LK.setScore(LK.getScore() + 1);
LK.effects.flashScreen(0x0000ff, 1000); // Flash screen blue
redFlag.destroy(); // Remove the red flag from the game
}
if (redTeam.intersects(blueFlag)) {
// Handle red team capturing blue flag
LK.setScore(LK.getScore() + 1);
LK.effects.flashScreen(0xff0000, 1000); // Flash screen red
blueFlag.destroy(); // Remove the blue flag from the game
}
if (bullets[j] && bullets[j].y < -50) {
bullets[j].destroy();
bullets.splice(j, 1);
}
}
// Fire bullet
if (LK.ticks % 30 == 0) {
var newBullet = new Bullet();
newBullet.x = blueTeam.x;
newBullet.y = blueTeam.y;
bullets.push(newBullet);
game.addChild(newBullet);
}
};
// Handle touch events for hero movement
game.down = function (x, y, obj) {
blueTeam.x = x;
blueTeam.y = y;
};
game.move = function (x, y, obj) {
blueTeam.x = x;
blueTeam.y = y;
};
game.up = function (x, y, obj) {
// Stop hero movement
};
// Spawn enemies at intervals
if (LK.ticks % 120 == 0) {
var newEnemy = new Enemy();
newEnemy.x = Math.random() * 2048;
newEnemy.y = 0;
enemies.push(newEnemy);
game.addChild(newEnemy);
}