/****
* Classes
****/
//<Assets used in the game will automatically appear here>
// Plane class to represent each plane in the game
var Plane = Container.expand(function () {
var self = Container.call(this);
var planeGraphics = self.attachAsset('plane', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.direction = Math.random() * 2 * Math.PI; // Random initial direction
self.update = function () {
self.x += self.speed * Math.cos(self.direction);
self.y += self.speed * Math.sin(self.direction);
};
self.changeDirection = function (newDirection) {
self.direction = newDirection;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Sky blue background
});
/****
* Game Code
****/
// Initialize arrays and variables
var planes = [];
var score = 0;
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Function to handle plane collisions
function checkCollisions() {
for (var i = 0; i < planes.length; i++) {
for (var j = i + 1; j < planes.length; j++) {
if (planes[i].intersects(planes[j])) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
}
}
// Function to spawn a new plane
function spawnPlane() {
var newPlane = new Plane();
newPlane.x = Math.random() * 2048;
newPlane.y = Math.random() * 2732;
planes.push(newPlane);
game.addChild(newPlane);
}
// Event handler for touch/mouse down
game.down = function (x, y, obj) {
var game_position = game.toLocal(obj.global);
for (var i = 0; i < planes.length; i++) {
if (planes[i].containsPoint(game_position)) {
planes[i].changeDirection(Math.random() * 2 * Math.PI);
}
}
};
// Update function called every game tick
game.update = function () {
for (var i = 0; i < planes.length; i++) {
planes[i].update();
}
checkCollisions();
if (LK.ticks % 120 == 0) {
// Spawn a new plane every 2 seconds
spawnPlane();
}
};
// Initialize the game with a few planes
for (var i = 0; i < 5; i++) {
spawnPlane();
} /****
* Classes
****/
//<Assets used in the game will automatically appear here>
// Plane class to represent each plane in the game
var Plane = Container.expand(function () {
var self = Container.call(this);
var planeGraphics = self.attachAsset('plane', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.direction = Math.random() * 2 * Math.PI; // Random initial direction
self.update = function () {
self.x += self.speed * Math.cos(self.direction);
self.y += self.speed * Math.sin(self.direction);
};
self.changeDirection = function (newDirection) {
self.direction = newDirection;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Sky blue background
});
/****
* Game Code
****/
// Initialize arrays and variables
var planes = [];
var score = 0;
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Function to handle plane collisions
function checkCollisions() {
for (var i = 0; i < planes.length; i++) {
for (var j = i + 1; j < planes.length; j++) {
if (planes[i].intersects(planes[j])) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
}
}
// Function to spawn a new plane
function spawnPlane() {
var newPlane = new Plane();
newPlane.x = Math.random() * 2048;
newPlane.y = Math.random() * 2732;
planes.push(newPlane);
game.addChild(newPlane);
}
// Event handler for touch/mouse down
game.down = function (x, y, obj) {
var game_position = game.toLocal(obj.global);
for (var i = 0; i < planes.length; i++) {
if (planes[i].containsPoint(game_position)) {
planes[i].changeDirection(Math.random() * 2 * Math.PI);
}
}
};
// Update function called every game tick
game.update = function () {
for (var i = 0; i < planes.length; i++) {
planes[i].update();
}
checkCollisions();
if (LK.ticks % 120 == 0) {
// Spawn a new plane every 2 seconds
spawnPlane();
}
};
// Initialize the game with a few planes
for (var i = 0; i < 5; i++) {
spawnPlane();
}