User prompt
make food spawn even more often
User prompt
make the counter more beautiful
User prompt
make the ants faster
User prompt
make the background green
User prompt
make food spawn only next to the anthill
User prompt
make food spawn more often
User prompt
make the sound of a bite play when the ant eats food
User prompt
do it when the ant spawned it spawned in the anthill
User prompt
add an anthill in the middle and when the ant ate the food, another ant crawled out of the anthill
User prompt
make the ants go to the mouse cursor
Initial prompt
ants strategy
/**** * 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 = 2; self.update = function () { // Ant movement logic self.x += self.speed * Math.cos(self.direction); self.y += self.speed * Math.sin(self.direction); }; }); // 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: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize arrays and variables var ants = []; var foods = []; 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 spawn ants function spawnAnt() { var ant = new Ant(); ant.x = Math.random() * 2048; ant.y = Math.random() * 2732; ant.direction = Math.random() * 2 * Math.PI; ants.push(ant); game.addChild(ant); } // 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); // Remove food foods[j].destroy(); foods.splice(j, 1); 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 periodically if (LK.ticks % 300 == 0) { spawnFood(); } }; // Handle touch events to move ants game.down = function (x, y, obj) { for (var i = 0; i < ants.length; i++) { if (ants[i].intersects(obj)) { 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 = 2;
self.update = function () {
// Ant movement logic
self.x += self.speed * Math.cos(self.direction);
self.y += self.speed * Math.sin(self.direction);
};
});
// 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: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize arrays and variables
var ants = [];
var foods = [];
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 spawn ants
function spawnAnt() {
var ant = new Ant();
ant.x = Math.random() * 2048;
ant.y = Math.random() * 2732;
ant.direction = Math.random() * 2 * Math.PI;
ants.push(ant);
game.addChild(ant);
}
// 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);
// Remove food
foods[j].destroy();
foods.splice(j, 1);
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 periodically
if (LK.ticks % 300 == 0) {
spawnFood();
}
};
// Handle touch events to move ants
game.down = function (x, y, obj) {
for (var i = 0; i < ants.length; i++) {
if (ants[i].intersects(obj)) {
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.