/**** * Classes ****/ //<Assets used in the game will automatically appear here> // Ant class representing individual ants in the colony var Ant = Container.expand(function () { var self = Container.call(this); var antGraphics = self.attachAsset('ant', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 4; self.update = function () { // Ant movement logic self.x += self.speed * Math.cos(self.direction); self.y += self.speed * Math.sin(self.direction); // Kill ant if it goes out of bounds if (self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) { self.destroy(); var index = ants.indexOf(self); if (index > -1) { ants.splice(index, 1); antCount--; antCountTxt.setText(antCount); } } // Randomly change direction if (Math.random() < 0.01) { self.direction = Math.random() * 2 * Math.PI; } }; }); // Anthill class representing the anthill in the game var Anthill = Container.expand(function () { var self = Container.call(this); var anthillGraphics = self.attachAsset('anthill', { anchorX: 0.5, anchorY: 0.5 }); }); // Food class representing food items var Food = Container.expand(function () { var self = Container.call(this); var foodGraphics = self.attachAsset('food', { anchorX: 0.5, anchorY: 0.5 }); }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x008000 //Init game with green background }); /**** * Game Code ****/ // Add grass image asset var grass = game.attachAsset('grass', { // Attach the grass background to the game scene anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 }); // Initialize arrays and variables var ants = []; var foods = []; var score = 0; var scoreTxt = new Text2('0', { size: 200, fill: "#FFD700", font: "'Comic Sans MS', cursive, sans-serif" }); var antCount = 0; var antCountTxt = new Text2('0', { size: 200, fill: "#FFD700", font: "'Comic Sans MS', cursive, sans-serif" }); antCountTxt.anchor.set(0.5, 1); LK.gui.bottomRight.addChild(antCountTxt); antCountTxt.x -= 600; // Initialize the anthill var anthill = new Anthill(); anthill.x = 2048 / 2; anthill.y = 2732 / 2; game.addChild(anthill); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Function to spawn ants function spawnAnt() { var ant = new Ant(); ant.x = anthill.x; ant.y = anthill.y; ant.direction = Math.random() * 2 * Math.PI; ants.push(ant); game.addChild(ant); antCount++; antCountTxt.setText(antCount); } // Function to spawn food function spawnFood() { var food = new Food(); food.x = Math.random() * 2048; food.y = Math.random() * 2732; foods.push(food); game.addChild(food); } // Function to handle ant-food collision function checkCollisions() { for (var i = ants.length - 1; i >= 0; i--) { for (var j = foods.length - 1; j >= 0; j--) { if (ants[i].intersects(foods[j])) { // Increase score score += 1; LK.setScore(score); scoreTxt.setText(score); // Play bite sound LK.getSound('bite').play(); // Remove food foods[j].destroy(); foods.splice(j, 1); // Spawn a new ant from the anthill spawnAnt(); break; } } } } // Spawn initial ants and food for (var i = 0; i < 10; i++) { spawnAnt(); } for (var i = 0; i < 5; i++) { spawnFood(); } // Game update function game.update = function () { // Update ants for (var i = 0; i < ants.length; i++) { ants[i].update(); } // Check for collisions checkCollisions(); // Spawn new food more often if (LK.ticks % 50 == 0) { spawnFood(); } // Game over if there are no ants left if (ants.length == 0) { LK.showGameOver(); } }; // Handle touch events to move ants game.down = function (x, y, obj) { for (var i = 0; i < ants.length; i++) { ants[i].direction = Math.atan2(y - ants[i].y, x - ants[i].x); } };
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
// Ant class representing individual ants in the colony
var Ant = Container.expand(function () {
var self = Container.call(this);
var antGraphics = self.attachAsset('ant', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 4;
self.update = function () {
// Ant movement logic
self.x += self.speed * Math.cos(self.direction);
self.y += self.speed * Math.sin(self.direction);
// Kill ant if it goes out of bounds
if (self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) {
self.destroy();
var index = ants.indexOf(self);
if (index > -1) {
ants.splice(index, 1);
antCount--;
antCountTxt.setText(antCount);
}
}
// Randomly change direction
if (Math.random() < 0.01) {
self.direction = Math.random() * 2 * Math.PI;
}
};
});
// Anthill class representing the anthill in the game
var Anthill = Container.expand(function () {
var self = Container.call(this);
var anthillGraphics = self.attachAsset('anthill', {
anchorX: 0.5,
anchorY: 0.5
});
});
// Food class representing food items
var Food = Container.expand(function () {
var self = Container.call(this);
var foodGraphics = self.attachAsset('food', {
anchorX: 0.5,
anchorY: 0.5
});
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x008000 //Init game with green background
});
/****
* Game Code
****/
// Add grass image asset
var grass = game.attachAsset('grass', {
// Attach the grass background to the game scene
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
// Initialize arrays and variables
var ants = [];
var foods = [];
var score = 0;
var scoreTxt = new Text2('0', {
size: 200,
fill: "#FFD700",
font: "'Comic Sans MS', cursive, sans-serif"
});
var antCount = 0;
var antCountTxt = new Text2('0', {
size: 200,
fill: "#FFD700",
font: "'Comic Sans MS', cursive, sans-serif"
});
antCountTxt.anchor.set(0.5, 1);
LK.gui.bottomRight.addChild(antCountTxt);
antCountTxt.x -= 600;
// Initialize the anthill
var anthill = new Anthill();
anthill.x = 2048 / 2;
anthill.y = 2732 / 2;
game.addChild(anthill);
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Function to spawn ants
function spawnAnt() {
var ant = new Ant();
ant.x = anthill.x;
ant.y = anthill.y;
ant.direction = Math.random() * 2 * Math.PI;
ants.push(ant);
game.addChild(ant);
antCount++;
antCountTxt.setText(antCount);
}
// Function to spawn food
function spawnFood() {
var food = new Food();
food.x = Math.random() * 2048;
food.y = Math.random() * 2732;
foods.push(food);
game.addChild(food);
}
// Function to handle ant-food collision
function checkCollisions() {
for (var i = ants.length - 1; i >= 0; i--) {
for (var j = foods.length - 1; j >= 0; j--) {
if (ants[i].intersects(foods[j])) {
// Increase score
score += 1;
LK.setScore(score);
scoreTxt.setText(score);
// Play bite sound
LK.getSound('bite').play();
// Remove food
foods[j].destroy();
foods.splice(j, 1);
// Spawn a new ant from the anthill
spawnAnt();
break;
}
}
}
}
// Spawn initial ants and food
for (var i = 0; i < 10; i++) {
spawnAnt();
}
for (var i = 0; i < 5; i++) {
spawnFood();
}
// Game update function
game.update = function () {
// Update ants
for (var i = 0; i < ants.length; i++) {
ants[i].update();
}
// Check for collisions
checkCollisions();
// Spawn new food more often
if (LK.ticks % 50 == 0) {
spawnFood();
}
// Game over if there are no ants left
if (ants.length == 0) {
LK.showGameOver();
}
};
// Handle touch events to move ants
game.down = function (x, y, obj) {
for (var i = 0; i < ants.length; i++) {
ants[i].direction = Math.atan2(y - ants[i].y, x - ants[i].x);
}
};
ant. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
apple. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
anthill. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
трава. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.