User prompt
Пусть еда появляется чаще
User prompt
Если хищник ест травоядного, появляется ещё два хищник в random точках экрана
User prompt
Если травоядный не ест 6 секунд, он умирает
User prompt
Чаще
User prompt
Пусть еда появляется в мире
User prompt
Если хищник ест, появляется ещё два хищник в random точках экрана
User prompt
Если хищник ест, появляется ещё два хищник в random точках экрана
User prompt
ещё быстрее
User prompt
сделай плотоядных быстрее травоядных
User prompt
сделай травоядных быстрее плотоядных
User prompt
Если хищник ест, появляется ещё два хищник в random точках экрана
User prompt
Если хищник ест, появляется ещё один хищник в random точке экрана
User prompt
Если травоядный ест, появляется ещё один травоядный в random точке экрана
User prompt
Если травоядный ест, появляется ещё один травоядный в случайной точке экрана
User prompt
Хищники чуть быстрее травоядных
User prompt
Если хищник ест, появляется ещё один хищник в случайной точке экрана
User prompt
Если травоядный ест, он делится на две части
User prompt
Если хищник съедает травоядного, то продлевает свой срок жизни до 6 секунд
User prompt
СДелай чтобы травоядные ели еду моментально и чтобы хищники умирали, если в течение 5 секунд никого не едят
User prompt
Пускай травоядные будут быстрее и смогут размножаться, едя еду
User prompt
они должны сами двигаться и эволюционировать
Initial prompt
Evolution
===================================================================
--- original.js
+++ change.js
@@ -1,102 +1,158 @@
-/****
+/****
* Classes
****/
// Carnivore class
var Carnivore = Container.expand(function () {
- var self = Container.call(this);
- var carnivoreGraphics = self.attachAsset('carnivore', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 2;
- self.move = function () {
- // Simple AI for movement towards nearest herbivore
- };
- self.eat = function () {
- // Eat nearby herbivores
- };
+ var self = Container.call(this);
+ var carnivoreGraphics = self.attachAsset('carnivore', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 2;
+ self.move = function () {
+ // Simple AI for movement towards nearest herbivore
+ var closestHerbivore = null;
+ var closestDistance = Infinity;
+ herbivores.forEach(function (herbivore) {
+ var dx = herbivore.x - self.x;
+ var dy = herbivore.y - self.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ if (distance < closestDistance) {
+ closestHerbivore = herbivore;
+ closestDistance = distance;
+ }
+ });
+ if (closestHerbivore) {
+ var dx = closestHerbivore.x - self.x;
+ var dy = closestHerbivore.y - self.y;
+ var angle = Math.atan2(dy, dx);
+ self.x += Math.cos(angle) * self.speed;
+ self.y += Math.sin(angle) * self.speed;
+ }
+ };
+ self.eat = function () {
+ // Eat nearby herbivores
+ herbivores.forEach(function (herbivore, index) {
+ var dx = herbivore.x - self.x;
+ var dy = herbivore.y - self.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ if (distance < 50) {
+ herbivores.splice(index, 1);
+ herbivore.destroy();
+ self.speed += 0.1; // Evolve by increasing speed
+ }
+ });
+ };
});
// Food class
var Food = Container.expand(function () {
- var self = Container.call(this);
- var foodGraphics = self.attachAsset('food', {
- anchorX: 0.5,
- anchorY: 0.5
- });
+ var self = Container.call(this);
+ var foodGraphics = self.attachAsset('food', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
});
// Herbivore class
var Herbivore = Container.expand(function () {
- var self = Container.call(this);
- var herbivoreGraphics = self.attachAsset('herbivore', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 1.5;
- self.move = function () {
- // Simple AI for movement towards nearest food
- };
- self.eat = function () {
- // Eat nearby food
- };
+ var self = Container.call(this);
+ var herbivoreGraphics = self.attachAsset('herbivore', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 1.5;
+ self.move = function () {
+ // Simple AI for movement towards nearest food
+ var closestFood = null;
+ var closestDistance = Infinity;
+ foods.forEach(function (food) {
+ var dx = food.x - self.x;
+ var dy = food.y - self.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ if (distance < closestDistance) {
+ closestFood = food;
+ closestDistance = distance;
+ }
+ });
+ if (closestFood) {
+ var dx = closestFood.x - self.x;
+ var dy = closestFood.y - self.y;
+ var angle = Math.atan2(dy, dx);
+ self.x += Math.cos(angle) * self.speed;
+ self.y += Math.sin(angle) * self.speed;
+ }
+ };
+ self.eat = function () {
+ // Eat nearby food
+ foods.forEach(function (food, index) {
+ var dx = food.x - self.x;
+ var dy = food.y - self.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ if (distance < 50) {
+ foods.splice(index, 1);
+ food.destroy();
+ self.speed += 0.05; // Evolve by increasing speed
+ }
+ });
+ };
});
-/****
+/****
* Initialize Game
****/
var game = new LK.Game({
- backgroundColor: 0x000000 // Init game with black background
+ backgroundColor: 0x000000 // Init game with black background
});
-/****
+/****
* Game Code
****/
// Initialize assets for carnivores, herbivores, and food.
var carnivores = [];
var herbivores = [];
var foods = [];
// Populate the game with initial entities
function initializeEntities() {
- for (var i = 0; i < 10; i++) {
- var newCarnivore = new Carnivore();
- newCarnivore.x = Math.random() * 2048;
- newCarnivore.y = Math.random() * 2732;
- game.addChild(newCarnivore);
- carnivores.push(newCarnivore);
- var newHerbivore = new Herbivore();
- newHerbivore.x = Math.random() * 2048;
- newHerbivore.y = Math.random() * 2732;
- game.addChild(newHerbivore);
- herbivores.push(newHerbivore);
- }
- for (var j = 0; j < 50; j++) {
- var newFood = new Food();
- newFood.x = Math.random() * 2048;
- newFood.y = Math.random() * 2732;
- game.addChild(newFood);
- foods.push(newFood);
- }
+ for (var i = 0; i < 10; i++) {
+ var newCarnivore = new Carnivore();
+ newCarnivore.x = Math.random() * 2048;
+ newCarnivore.y = Math.random() * 2732;
+ game.addChild(newCarnivore);
+ carnivores.push(newCarnivore);
+ var newHerbivore = new Herbivore();
+ newHerbivore.x = Math.random() * 2048;
+ newHerbivore.y = Math.random() * 2732;
+ game.addChild(newHerbivore);
+ herbivores.push(newHerbivore);
+ }
+ for (var j = 0; j < 50; j++) {
+ var newFood = new Food();
+ newFood.x = Math.random() * 2048;
+ newFood.y = Math.random() * 2732;
+ game.addChild(newFood);
+ foods.push(newFood);
+ }
}
initializeEntities();
// Main game loop
LK.on('tick', function () {
- // Move and eat logic for carnivores
- carnivores.forEach(function (carnivore, index) {
- carnivore.move();
- // Example eat logic, actual implementation needed
- if (Math.random() < 0.01) {
- // Simulate eating
- carnivore.eat();
- }
- });
- // Move and eat logic for herbivores
- herbivores.forEach(function (herbivore, index) {
- herbivore.move();
- // Example eat logic, actual implementation needed
- if (Math.random() < 0.01) {
- // Simulate eating
- herbivore.eat();
- }
- });
- // Food does not need to move, but could be consumed
+ // Move and eat logic for carnivores
+ carnivores.forEach(function (carnivore, index) {
+ carnivore.move();
+ // Example eat logic, actual implementation needed
+ if (Math.random() < 0.01) {
+ // Simulate eating
+ carnivore.eat();
+ }
+ });
+ // Move and eat logic for herbivores
+ herbivores.forEach(function (herbivore, index) {
+ herbivore.move();
+ // Example eat logic, actual implementation needed
+ if (Math.random() < 0.01) {
+ // Simulate eating
+ herbivore.eat();
+ }
+ });
+ // Food does not need to move, but could be consumed
});
// Note: This is a simplified structure. Actual movement, eating logic, and interactions between entities need to be implemented.
\ No newline at end of file