User prompt
Fix Bug: 'TypeError: self.playWithObject is not a function' in this line: 'self.playWithObject(toy);' Line Number: 687
User prompt
Fix Bug: 'TypeError: self.playWithObject is not a function' in this line: 'self.playWithObject(self.curiosityTarget);' Line Number: 665
User prompt
Fish move 3 time faster
User prompt
Improve the entire code with 3 new functionality
User prompt
Improve the entire code with 3 new functionality
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'prototype')' in this line: 'Fish.prototype.hideInCastle = function (castle) {' Line Number: 9
User prompt
Improve the entire code with 3 new functionality
User prompt
Fix Bug: 'TypeError: self.findNearestCleaner is not a function' in this line: 'var cleaner = self.findNearestCleaner();' Line Number: 519
User prompt
Fix Bug: 'TypeError: self.findNearestCleaner is not a function' in this line: 'var cleaner = self.findNearestCleaner();' Line Number: 519
User prompt
Fix Bug: 'TypeError: self.findNearestCleaner is not a function' in this line: 'var cleaner = self.findNearestCleaner();' Line Number: 519
User prompt
Improve the entire code with 3 new functionality
User prompt
Fix Bug: 'TypeError: self.findClosestFood is not a function' in this line: 'food = self.findClosestFood();' Line Number: 617
User prompt
Improve the entire code with 8 new functionality
User prompt
All fish move 3 time faster
User prompt
Improve the entire code with 7 new functionality
User prompt
Improve the entire code with 6 new functionality
User prompt
Improve the entire code with 5 new functionality
User prompt
Fix Bug: 'ReferenceError: Food is not defined' in this line: 'if (child instanceof Food) {' Line Number: 116
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'expand')' in this line: 'var Predator = Fish.expand(function () {' Line Number: 35
User prompt
Improve the entire code with 5 new functionality
User prompt
imprtove fish Ai with 5 new functionality
User prompt
Fix Bug: 'ReferenceError: Bubble is not defined' in this line: 'var bubble = new Bubble();' Line Number: 631
User prompt
imprtove fish Ai with 10 new functionality
User prompt
imprtove fish Ai with 10 new functionality
User prompt
imprtove fish Ai with 10 new functionality
var Plant = Container.expand(function () { var self = Container.call(this); var plantGraphics = self.createAsset('plant', 'Plant Graphics', 0.5, 0.5); self.size = 50; }); var Egg = Container.expand(function () { var self = Container.call(this); var eggGraphics = self.createAsset('egg', 'Egg Graphics', 0.5, 0.5); self.hatchTime = LK.ticks + Math.random() * 3000 + 2000; self.on('tick', function () { if (LK.ticks > self.hatchTime) { var babyFish = new Fish(); babyFish.x = self.x; babyFish.y = self.y; LK.stageContainer.addChild(babyFish); self.destroy(); } }); }); var Food = Container.expand(function () { var self = Container.call(this); self.nutrition = 20; var foodGraphics = self.createAsset('food', 'Food Graphics', 0.5, 0.5); self.consume = function () { self.destroy(); }; }); var Obstacle = Container.expand(function () { var self = Container.call(this); self.radius = 50; }); var Fish = Container.expand(function () { var self = Container.call(this); self.hunger = 100; self.isResting = false; self.lastRestTime = LK.ticks; self.restInterval = Math.random() * 3000 + 2000; self.isMating = false; self.lastMateTime = LK.ticks; self.mateInterval = Math.random() * 5000 + 3000; self.isLayingEggs = false; self.lastEggTime = LK.ticks; self.eggInterval = Math.random() * 3000 + 2000; self.hungerDecayRate = 0.1; self.eatFood = function (food) { if (self.distanceTo(food) < 50) { self.hunger = Math.min(self.hunger + food.nutrition, 100); food.consume(); self.triggerFeedingFrenzy(); } }; self.updateHunger = function () { self.hunger -= self.hungerDecayRate; if (self.hunger <= 0) { self.die(); } }; self.greetFish = function (otherFish) { if (!self.memory.includes(otherFish)) { self.targetRotation = Math.atan2(otherFish.y - self.y, otherFish.x - self.x); self.directionChangeTime = LK.ticks; self.directionChangeInterval = 5; self.rememberObject(otherFish); } }; self.playWithObject = function (target) { self.targetRotation = Math.atan2(target.y - self.y, target.x - self.x) + Math.random() * Math.PI - Math.PI / 2; self.directionChangeTime = LK.ticks; self.directionChangeInterval = 5; }; self.memory = []; self.rememberObject = function (target) { if (!self.memory.includes(target)) { self.memory.push(target); } }; self.findClosestFood = function () { var closestFood = null; var closestDistance = Infinity; LK.stageContainer.children.forEach(function (child) { if (child instanceof Food) { var distance = self.distanceTo(child); if (distance < closestDistance) { closestDistance = distance; closestFood = child; } } }); return closestFood; }; self.forgetObject = function (target) { var index = self.memory.indexOf(target); if (index > -1) { self.memory.splice(index, 1); } }; self.getNearbyObjects = function () { var nearbyObjects = []; LK.stageContainer.children.forEach(function (child) { if (!(child instanceof Fish) && child !== self) { var dx = child.x - self.x; var dy = child.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < 300) { nearbyObjects.push(child); } } }); return nearbyObjects; }; self.findCuriosityTarget = function () { var possibleTargets = self.getNearbyObjects(); if (possibleTargets.length > 0) { self.curiosityTarget = possibleTargets[Math.floor(Math.random() * possibleTargets.length)]; } }; self.investigateCuriosity = function (target) { self.targetRotation = Math.atan2(target.y - self.y, target.x - self.x); self.directionChangeTime = LK.ticks; self.directionChangeInterval = 10; }; self.distanceTo = function (target) { var dx = target.x - self.x; var dy = target.y - self.y; return Math.sqrt(dx * dx + dy * dy); }; self.formSchool = function (similarFish) { var alignmentAngle = 0; similarFish.forEach(function (fish) { alignmentAngle += fish.rotation; }); alignmentAngle /= similarFish.length; self.targetRotation = alignmentAngle; self.directionChangeTime = LK.ticks; self.directionChangeInterval = 30; }; self.evadePredators = function (predators) { var evadeAngle = 0; predators.forEach(function (predator) { var angleToPredator = Math.atan2(predator.y - self.y, predator.x - self.x); evadeAngle += angleToPredator + Math.PI; }); evadeAngle /= predators.length; self.targetRotation = evadeAngle + (Math.random() * Math.PI - Math.PI / 2); self.directionChangeTime = LK.ticks; self.directionChangeInterval = 10; }; self.followLeader = function (leaderFish) { var followDistance = 50; var dx = leaderFish.x - self.x; var dy = leaderFish.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > followDistance) { self.targetRotation = Math.atan2(dy, dx); self.directionChangeTime = LK.ticks; self.directionChangeInterval = 10; } }; self.findLeaderFish = function (nearbyFish) { var leader = null; var maxScore = 0; nearbyFish.forEach(function (fish) { var score = fish.size + fish.speed; if (score > maxScore) { maxScore = score; leader = fish; } }); return leader; }; self.evadeLargerFish = function (largerFish) {}; self.getNearbyFish = function () { var nearbyFish = []; LK.stageContainer.children.forEach(function (child) { if (child instanceof Fish && child !== self) { var dx = child.x - self.x; var dy = child.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < 300) { nearbyFish.push(child); } } }); return nearbyFish; }; self.avoidObstacles = function (obstacles) { if (obstacles.length > 0) { var sumAngles = 0; var count = 0; for (var i = 0; i < obstacles.length; i++) { var obstacle = obstacles[i]; var angleToObstacle = Math.atan2(obstacle.y - self.y, obstacle.x - self.x); sumAngles += angleToObstacle + Math.PI; count++; } if (count > 0) { var averageAvoidAngle = sumAngles / count; self.targetRotation = averageAvoidAngle; self.directionChangeTime = LK.ticks; self.directionChangeInterval = Math.random() * 50 + 30; } } }; self.isPathBlocked = function (newX, newY, obstacles) { for (var i = 0; i < obstacles.length; i++) { var obstacle = obstacles[i]; var dx = obstacle.x - newX; var dy = obstacle.y - newY; if (Math.sqrt(dx * dx + dy * dy) < obstacle.radius + self.radius) { return true; } } return false; }; self.die = function () { self.destroy(); }; self.getNearbyObstacles = function () { var nearbyObstacles = []; LK.stageContainer.children.forEach(function (child) { if (typeof Obstacle !== 'undefined' && child instanceof Obstacle) { var dx = child.x - self.x; var dy = child.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < 300) { nearbyObstacles.push(child); } } }); return nearbyObstacles; }; this.getWaterBounds = function () { var waterGraphics = LK.getAsset('water', 'Water Graphics', 0, 0); return { left: (2048 - waterGraphics.width) / 2, right: (2048 + waterGraphics.width) / 2, top: (2732 - waterGraphics.height) / 2 - 150, bottom: (2732 + waterGraphics.height) / 2 - 150 }; }; }); var Surgeonfish = Fish.expand(function () { var self = Fish.call(this) || this; var fishGraphics = self.createAsset('surgeonfish', 'Surgeonfish Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = (Math.random() * 0.2 + 0.5) * 2; self.move = function () { if (!self.directionChangeTime || LK.ticks - self.directionChangeTime > self.directionChangeInterval) { self.directionChangeTime = LK.ticks; self.directionChangeInterval = Math.random() * 120 + 60; self.targetRotation = Math.random() * Math.PI * 2; } var progress = (LK.ticks - self.directionChangeTime) / self.directionChangeInterval; if (progress < 1) { var rotationSpeed = 0.05; var rotationDifference = self.targetRotation - self.rotation; if (rotationDifference > Math.PI) rotationDifference -= Math.PI * 2; if (rotationDifference < -Math.PI) rotationDifference += Math.PI * 2; self.rotation += Math.sign(rotationDifference) * Math.min(Math.abs(rotationDifference), rotationSpeed); } else { self.rotation = self.targetRotation; } var newX = self.x + Math.cos(self.rotation) * self.speed; var newY = self.y + Math.sin(self.rotation) * self.speed; var obstacles = self.getNearbyObstacles(); var nearbyFish = self.getNearbyFish(); nearbyFish.forEach(function (otherFish) { if (self.distanceTo(otherFish) < self.radius + otherFish.radius) { var angleBetween = Math.atan2(otherFish.y - self.y, otherFish.x - self.x); self.targetRotation = angleBetween + Math.PI; self.directionChangeTime = LK.ticks; self.directionChangeInterval = 10; } }); if (self.isPathBlocked(newX, newY, obstacles)) { var leaderFish = self.findLeaderFish(nearbyFish); if (leaderFish) { self.followLeader(leaderFish); } else { self.avoidObstacles(obstacles); } } else if (nearbyFish.some(fish => fish.size > self.size)) { var predators = nearbyFish.filter(fish => fish.size > self.size); if (predators.length > 0) { self.isFleeing = true; predators.forEach(function (predator) { self.rememberObject(predator); }); self.evadePredators(predators); if (self.isFleeing) { var predators = self.getNearbyFish().filter(function (fish) { return fish.size > self.size; }); if (predators.length > 0) { var hidingSpots = self.getNearbyObjects().filter(function (obj) { return obj instanceof Plant; }); if (hidingSpots.length > 0) { var hidingSpot = hidingSpots[Math.floor(Math.random() * hidingSpots.length)]; self.targetRotation = Math.atan2(hidingSpot.y - self.y, hidingSpot.x - self.x); self.directionChangeTime = LK.ticks; self.directionChangeInterval = 20; } } } } else { if (self.isFleeing && LK.ticks - self.directionChangeTime > 300) { self.isFleeing = false; self.memory = self.memory.filter(function (obj) { return !(obj instanceof Fish); }); } } } else if (nearbyFish.length > 0) { var similarFish = nearbyFish.filter(fish => fish.constructor === self.constructor); if (similarFish.length > 0) { var schoolCenterX = similarFish.reduce(function (sum, fish) { return sum + fish.x; }, 0) / similarFish.length; var schoolCenterY = similarFish.reduce(function (sum, fish) { return sum + fish.y; }, 0) / similarFish.length; self.targetRotation = Math.atan2(schoolCenterY - self.y, schoolCenterX - self.x); self.directionChangeTime = LK.ticks; self.directionChangeInterval = 30; } } else if (self.curiosityTarget && self.distanceTo(self.curiosityTarget) < 100) { self.playWithObject(self.curiosityTarget); self.rememberObject(self.curiosityTarget); } else { self.x = newX; self.y = newY; if (self.hunger < 30 || self.hunger > 70 && Math.random() < 0.1) { var food = self.findClosestFood(); if (food) { self.targetRotation = Math.atan2(food.y - self.y, food.x - self.x); } else { if (Math.random() < 0.05) { var toys = self.getNearbyObjects().filter(function (obj) { return !(obj instanceof Food) && !(obj instanceof Fish); }); if (toys.length > 0) { var toy = toys[Math.floor(Math.random() * toys.length)]; self.playWithObject(toy); } } else { if (Math.random() < 0.1) { self.findCuriosityTarget(); if (self.curiosityTarget) { self.investigateCuriosity(self.curiosityTarget); } } } } } else { self.findCuriosityTarget(); } } var waterBounds = self.getWaterBounds(); if (self.x < waterBounds.left || self.x > waterBounds.right) { self.rotation = Math.PI - self.rotation; } if (self.y < waterBounds.top || self.y > waterBounds.bottom) { self.rotation = -self.rotation; } if (self.isMating) { fishGraphics.tint = 0xFF69B4; } else if (self.isResting) { fishGraphics.tint = 0xADD8E6; } else { fishGraphics.tint = 0xFFFFFF; } fishGraphics.scale.x = Math.cos(self.rotation) < 0 ? -1 : 1; fishGraphics.rotation = self.rotation; }; }); var Pufferfish = Fish.expand(function () { var self = Fish.call(this) || this; var fishGraphics = self.createAsset('pufferfish', 'Pufferfish Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = Math.random() * 0.2 + 0.4; self.move = function () { if (!self.directionChangeTime || LK.ticks - self.directionChangeTime > self.directionChangeInterval) { self.directionChangeTime = LK.ticks; self.directionChangeInterval = Math.random() * 140 + 80; self.targetRotation = Math.random() * Math.PI * 2; } var progress = (LK.ticks - self.directionChangeTime) / self.directionChangeInterval; if (progress < 1) { self.rotation += (self.targetRotation - self.rotation) * progress; } else { self.rotation = self.targetRotation; } var tentativeX = self.x + Math.cos(self.rotation) * self.speed; var tentativeY = self.y + Math.sin(self.rotation) * self.speed; var waterBounds = self.getWaterBounds(); tentativeX = Math.max(waterBounds.left, Math.min(tentativeX, waterBounds.right)); tentativeY = Math.max(waterBounds.top, Math.min(tentativeY, waterBounds.bottom)); var waterBounds = self.getWaterBounds(); tentativeX = Math.max(waterBounds.left, Math.min(tentativeX, waterBounds.right)); tentativeY = Math.max(waterBounds.top, Math.min(tentativeY, waterBounds.bottom)); self.x = tentativeX; self.y = tentativeY; var waterBounds = self.getWaterBounds(); if (self.x < waterBounds.left || self.x > waterBounds.right) { self.rotation = Math.PI - self.rotation; } if (self.y < waterBounds.top || self.y > waterBounds.bottom) { self.rotation = -self.rotation; } fishGraphics.scale.x = Math.cos(self.rotation) < 0 ? -1 : 1; fishGraphics.rotation = self.rotation; }; }); var Clownfish = Fish.expand(function () { var self = Fish.call(this) || this; var fishGraphics = self.createAsset('clownfish', 'Clownfish Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = Math.random() * 0.2 + 0.4; self.move = function () { if (!self.directionChangeTime || LK.ticks - self.directionChangeTime > self.directionChangeInterval) { self.directionChangeTime = LK.ticks; self.directionChangeInterval = Math.random() * 110 + 70; self.targetRotation = Math.random() * Math.PI * 2; } var progress = (LK.ticks - self.directionChangeTime) / self.directionChangeInterval; if (progress < 1) { self.rotation += (self.targetRotation - self.rotation) * progress; } else { self.rotation = self.targetRotation; } var tentativeX = self.x + Math.cos(self.rotation) * self.speed * 2; var tentativeY = self.y + Math.sin(self.rotation) * self.speed * 2; var waterBounds = self.getWaterBounds(); tentativeX = Math.max(waterBounds.left, Math.min(tentativeX, waterBounds.right)); tentativeY = Math.max(waterBounds.top, Math.min(tentativeY, waterBounds.bottom)); self.x = tentativeX; self.y = tentativeY; var waterBounds = self.getWaterBounds(); if (self.x < waterBounds.left || self.x > waterBounds.right) { self.rotation = Math.PI - self.rotation; } if (self.y < waterBounds.top || self.y > waterBounds.bottom) { self.rotation = -self.rotation; } fishGraphics.scale.x = Math.cos(self.rotation) < 0 ? -1 : 1; fishGraphics.rotation = self.rotation; }; }); var Angelfish = Fish.expand(function () { var self = Fish.call(this) || this; var fishGraphics = self.createAsset('angelfish', 'Angelfish Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = Math.random() * 0.2 + 0.45; self.move = function () { if (!self.directionChangeTime || LK.ticks - self.directionChangeTime > self.directionChangeInterval) { self.directionChangeTime = LK.ticks; self.directionChangeInterval = Math.random() * 130 + 90; self.targetRotation = Math.random() * Math.PI * 2; } var progress = (LK.ticks - self.directionChangeTime) / self.directionChangeInterval; if (progress < 1) { self.rotation += (self.targetRotation - self.rotation) * progress; } else { self.rotation = self.targetRotation; } if (!self.velocity) { self.velocity = { x: 0, y: 0 }; self.acceleration = Math.random() * 0.05 + 0.025; } var targetVelocityX = Math.cos(self.rotation) * self.speed; var targetVelocityY = Math.sin(self.rotation) * self.speed; self.velocity.x += (targetVelocityX - self.velocity.x) * self.acceleration; self.velocity.y += (targetVelocityY - self.velocity.y) * self.acceleration; self.x += self.velocity.x; self.y += self.velocity.y; var waterBounds = self.getWaterBounds(); if (self.x < waterBounds.left || self.x > waterBounds.right) { self.rotation = Math.PI - self.rotation; } if (self.y < waterBounds.top || self.y > waterBounds.bottom) { self.rotation = -self.rotation; } fishGraphics.scale.x = Math.cos(self.rotation) < 0 ? -1 : 1; fishGraphics.rotation = self.rotation; }; }); var Aquarium = Container.expand(function () { var self = Container.call(this); this.getWaterBounds = function () { var waterGraphics = LK.getAsset('water', 'Water Graphics', 0, 0); return { left: (2048 - waterGraphics.width) / 2, right: (2048 + waterGraphics.width) / 2, top: (2732 - waterGraphics.height) / 2 - 150, bottom: (2732 + waterGraphics.height) / 2 - 150 }; }; var aquariumGraphics = self.createAsset('aquarium', 'Aquarium Background', 0, 0); aquariumGraphics.width = 2048 * 1.3; aquariumGraphics.height = 2732 * 1.3; aquariumGraphics.x = (2048 - aquariumGraphics.width) / 2; aquariumGraphics.y = (2732 - aquariumGraphics.height) / 2; self.addChild(aquariumGraphics); var waterGraphics = self.createAsset('water', 'Water Graphics', 0, 0); waterGraphics.width = 2048 / 3 * 2 * 1.08; waterGraphics.height = 2732 / 3 * 1.26; waterGraphics.x = (2048 - waterGraphics.width) / 2; waterGraphics.y = (2732 - waterGraphics.height) / 2 - 150; waterGraphics.alpha = 0; self.addChild(waterGraphics); }); var KoiFish = Fish.expand(function () { var self = Fish.call(this) || this; var fishGraphics = self.createAsset('koiFish', 'Koi Fish Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = Math.random() * 0.2 + 0.48; self.move = function () { if (self.targetRotation === undefined || LK.ticks - self.rotationStartTime >= self.rotationDuration) { self.targetRotation = Math.random() * Math.PI * 2; self.rotationStartTime = LK.ticks; self.rotationDuration = Math.random() * 130 + 70; } var progress = (LK.ticks - self.rotationStartTime) / self.rotationDuration; if (progress < 1) { var deltaRotation = (self.targetRotation - self.rotation) * progress; self.rotation += deltaRotation; } else { self.rotation = self.targetRotation; } if (!self.isResting) { if (!self.isSleeping) { if (!self.isLayingEggs && LK.ticks - self.lastEggTime > self.eggInterval && self.hunger > 70) { self.isLayingEggs = true; self.lastEggTime = LK.ticks; self.eggInterval = Math.random() * 3000 + 2000; var egg = new Egg(); egg.x = self.x; egg.y = self.y; LK.stageContainer.addChild(egg); } else if (self.isLayingEggs && LK.ticks - self.lastEggTime > 200) { self.isLayingEggs = false; } var nearbyPredators = self.getNearbyFish().filter(function (fish) { return fish.size > self.size && self.distanceTo(fish) < 200; }); if (nearbyPredators.length > 0) { var hidingSpots = self.getNearbyObjects().filter(function (obj) { return obj instanceof Plant; }); if (hidingSpots.length > 0) { var hidingSpot = hidingSpots[Math.floor(Math.random() * hidingSpots.length)]; self.targetRotation = Math.atan2(hidingSpot.y - self.y, hidingSpot.x - self.x); self.directionChangeTime = LK.ticks; self.directionChangeInterval = 20; } } var similarFish = self.getNearbyFish().filter(function (fish) { return fish.constructor === self.constructor; }); if (similarFish.length > 1) { var averageX = similarFish.reduce(function (sum, fish) { return sum + fish.x; }, 0) / similarFish.length; var averageY = similarFish.reduce(function (sum, fish) { return sum + fish.y; }, 0) / similarFish.length; self.targetRotation = Math.atan2(averageY - self.y, averageX - self.x); self.directionChangeTime = LK.ticks; self.directionChangeInterval = 30; } if (self.hunger < 20) { var food = self.findClosestFood(); if (food) { self.targetRotation = Math.atan2(food.y - self.y, food.x - self.x); self.directionChangeTime = LK.ticks; self.directionChangeInterval = 5; self.speed *= 1.5; } } if (self.hunger > 50 && !self.isMating && LK.ticks - self.lastMateTime > self.mateInterval) { var potentialMates = self.getNearbyFish().filter(function (fish) { return fish.constructor === self.constructor && fish !== self && fish.hunger > 50; }); if (potentialMates.length > 0) { var mate = potentialMates[Math.floor(Math.random() * potentialMates.length)]; self.matingDance(mate); self.isMating = true; mate.isMating = true; self.lastMateTime = LK.ticks; mate.lastMateTime = LK.ticks; self.mateInterval = Math.random() * 5000 + 3000; mate.mateInterval = Math.random() * 5000 + 3000; } } else if (self.isMating && LK.ticks - self.lastMateTime > 200) { self.isMating = false; } if (!self.isResting && LK.ticks - self.lastRestTime > self.restInterval) { self.isResting = true; self.lastRestTime = LK.ticks; self.restInterval = Math.random() * 3000 + 2000; self.restPosition = { x: self.x, y: self.getWaterBounds().bottom - 50 }; self.targetRotation = Math.atan2(self.restPosition.y - self.y, self.restPosition.x - self.x); self.directionChangeTime = LK.ticks; self.directionChangeInterval = 20; } else if (self.isResting && LK.ticks - self.lastRestTime > 200) { self.isResting = false; } if (Math.random() < 0.01 && self.canJump) { self.isJumping = true; self.jumpStartTime = LK.ticks; self.jumpDuration = 60; self.jumpHeight = Math.random() * 100 + 50; self.canJump = false; } else if (self.isJumping) { var jumpProgress = (LK.ticks - self.jumpStartTime) / self.jumpDuration; if (jumpProgress < 1) { self.y -= self.jumpHeight * (1 - Math.cos(Math.PI * jumpProgress)); } else { self.isJumping = false; self.canJump = true; } } else { if (Math.random() < 0.02) { var bubble = new Bubble(); bubble.x = self.x; bubble.y = self.y; LK.stageContainer.addChild(bubble); } self.x += Math.cos(self.rotation) * self.speed; self.y += Math.sin(self.rotation) * self.speed; } } if (LK.ticks % 1800 === 0) { self.isSleeping = !self.isSleeping; self.directionChangeTime = LK.ticks; self.directionChangeInterval = self.isSleeping ? 300 : Math.random() * 120 + 60; } } if (LK.ticks % 300 === 0) { self.isResting = !self.isResting; self.directionChangeTime = LK.ticks; self.directionChangeInterval = self.isResting ? 120 : Math.random() * 120 + 60; } var waterBounds = self.getWaterBounds(); if (self.x < waterBounds.left || self.x > waterBounds.right) { self.rotation = Math.PI - self.rotation; } if (self.y < waterBounds.top || self.y > waterBounds.bottom) { self.rotation = -self.rotation; } self.rotation = self.rotation % (Math.PI * 2); if (Math.cos(self.rotation) < 0) { fishGraphics.scale.x = -1; } else { fishGraphics.scale.x = 1; } fishGraphics.rotation = self.rotation; }; }); var Goldfish = Fish.expand(function () { var self = Fish.call(this) || this; var fishGraphics = self.createAsset('goldfish', 'Goldfish Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = Math.random() * 0.2 + 0.4; self.move = function () { if (self.targetRotation === undefined || LK.ticks - self.rotationStartTime >= self.rotationDuration) { self.targetRotation = Math.random() * Math.PI * 2; self.rotationStartTime = LK.ticks; self.rotationDuration = Math.random() * 140 + 80; } var progress = (LK.ticks - self.rotationStartTime) / self.rotationDuration; if (progress < 1) { var deltaRotation = (self.targetRotation - self.rotation) * progress; self.rotation += deltaRotation; } else { self.rotation = self.targetRotation; } self.x += Math.cos(self.rotation) * self.speed; self.y += Math.sin(self.rotation) * self.speed; var waterBounds = self.getWaterBounds(); if (self.x < waterBounds.left || self.x > waterBounds.right) { self.rotation = Math.PI - self.rotation; } if (self.y < waterBounds.top || self.y > waterBounds.bottom) { self.rotation = -self.rotation; } self.rotation = self.rotation % (Math.PI * 2); if (Math.cos(self.rotation) < 0) { fishGraphics.scale.x = -1; } else { fishGraphics.scale.x = 1; } fishGraphics.rotation = self.rotation; }; }); var GuppyFish = Fish.expand(function () { var self = Fish.call(this) || this; var fishGraphics = self.createAsset('guppyFish', 'Guppy Fish Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = Math.random() * 0.2 + 0.35; self.move = function () { if (self.targetRotation === undefined || LK.ticks - self.rotationStartTime >= self.rotationDuration) { self.targetRotation = Math.random() * Math.PI * 2; self.rotationStartTime = LK.ticks; self.rotationDuration = Math.random() * 100 + 50; } var progress = (LK.ticks - self.rotationStartTime) / self.rotationDuration; if (progress < 1) { var deltaRotation = (self.targetRotation - self.rotation) * progress; self.rotation += deltaRotation; } else { self.rotation = self.targetRotation; } self.x += Math.cos(self.rotation) * self.speed; self.y += Math.sin(self.rotation) * self.speed; var waterBounds = self.getWaterBounds(); if (self.x < waterBounds.left || self.x > waterBounds.right) { self.rotation = Math.PI - self.rotation; } if (self.y < waterBounds.top || self.y > waterBounds.bottom) { self.rotation = -self.rotation; } self.rotation = self.rotation % (Math.PI * 2); if (Math.cos(self.rotation) < 0) { fishGraphics.scale.x = -1; } else { fishGraphics.scale.x = 1; } fishGraphics.rotation = self.rotation; }; }); var BettaFish = Fish.expand(function () { var self = Fish.call(this) || this; var fishGraphics = self.createAsset('bettaFish', 'Betta Fish Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = Math.random() * 0.2 + 0.5; self.move = function () { if (self.targetRotation === undefined || LK.ticks - self.rotationStartTime >= self.rotationDuration) { self.targetRotation = Math.random() * Math.PI * 2; self.rotationStartTime = LK.ticks; self.rotationDuration = Math.random() * 150 + 100; } var progress = (LK.ticks - self.rotationStartTime) / self.rotationDuration; if (progress < 1) { var deltaRotation = (self.targetRotation - self.rotation) * progress; self.rotation += deltaRotation; } else { self.rotation = self.targetRotation; } self.x += Math.cos(self.rotation) * self.speed; self.y += Math.sin(self.rotation) * self.speed; var waterBounds = self.getWaterBounds(); if (self.x < waterBounds.left || self.x > waterBounds.right) { self.rotation = Math.PI - self.rotation; } if (self.y < waterBounds.top || self.y > waterBounds.bottom) { self.rotation = -self.rotation; } self.rotation = self.rotation % (Math.PI * 2); if (Math.cos(self.rotation) < 0) { fishGraphics.scale.x = -1; } else { fishGraphics.scale.x = 1; } fishGraphics.rotation = self.rotation; }; }); var Game = Container.expand(function () { var self = Container.call(this); var aquarium = self.addChild(new Aquarium()); LK.stageContainer.setBackgroundColor(0x008080); var fishes = []; var fishTypes = [Fish, KoiFish, Goldfish, GuppyFish, BettaFish, Angelfish, Clownfish, Pufferfish, Surgeonfish]; for (var i = 0; i < fishTypes.length; i++) { for (var j = 0; j < 1; j++) { var fish = new fishTypes[i](); if (typeof fish.move === 'function') { var waterBounds = aquarium.getWaterBounds(); var waterWidth = waterBounds.right - waterBounds.left; var waterHeight = waterBounds.bottom - waterBounds.top; var waterCenterX = waterBounds.left + waterWidth / 2; var waterCenterY = waterBounds.top + waterHeight / 2; var maxDistanceX = waterWidth / 2 * 0.8; var maxDistanceY = waterHeight / 2 * 0.8; var angle = Math.random() * Math.PI * 2; var distanceX = Math.random() * maxDistanceX; var distanceY = Math.random() * maxDistanceY; fish.x = waterCenterX + distanceX * Math.cos(angle); fish.y = waterCenterY + distanceY * Math.sin(angle); fishes.push(fish); self.addChild(fish); } } } LK.on('tick', function () { for (var i = 0; i < fishes.length; i++) { fishes[i].move(); } }); });
===================================================================
--- original.js
+++ change.js
@@ -45,8 +45,9 @@
self.eatFood = function (food) {
if (self.distanceTo(food) < 50) {
self.hunger = Math.min(self.hunger + food.nutrition, 100);
food.consume();
+ self.triggerFeedingFrenzy();
}
};
self.updateHunger = function () {
self.hunger -= self.hungerDecayRate;
@@ -262,18 +263,16 @@
var newX = self.x + Math.cos(self.rotation) * self.speed;
var newY = self.y + Math.sin(self.rotation) * self.speed;
var obstacles = self.getNearbyObstacles();
var nearbyFish = self.getNearbyFish();
- if (nearbyFish.length > 1) {
- var closestFish = nearbyFish.reduce(function (prev, curr) {
- return self.distanceTo(prev) < self.distanceTo(curr) ? prev : curr;
- });
- if (self.distanceTo(closestFish) < self.radius * 2) {
- self.targetRotation = Math.atan2(self.y - closestFish.y, self.x - closestFish.x);
+ nearbyFish.forEach(function (otherFish) {
+ if (self.distanceTo(otherFish) < self.radius + otherFish.radius) {
+ var angleBetween = Math.atan2(otherFish.y - self.y, otherFish.x - self.x);
+ self.targetRotation = angleBetween + Math.PI;
self.directionChangeTime = LK.ticks;
self.directionChangeInterval = 10;
}
- }
+ });
if (self.isPathBlocked(newX, newY, obstacles)) {
var leaderFish = self.findLeaderFish(nearbyFish);
if (leaderFish) {
self.followLeader(leaderFish);
@@ -288,16 +287,21 @@
self.rememberObject(predator);
});
self.evadePredators(predators);
if (self.isFleeing) {
- var hidingSpots = self.getNearbyObstacles().filter(function (obstacle) {
- return self.distanceTo(obstacle) < 200;
+ var predators = self.getNearbyFish().filter(function (fish) {
+ return fish.size > self.size;
});
- if (hidingSpots.length > 0) {
- var hidingSpot = hidingSpots[Math.floor(Math.random() * hidingSpots.length)];
- self.targetRotation = Math.atan2(hidingSpot.y - self.y, hidingSpot.x - self.x);
- self.directionChangeTime = LK.ticks;
- self.directionChangeInterval = 20;
+ if (predators.length > 0) {
+ var hidingSpots = self.getNearbyObjects().filter(function (obj) {
+ return obj instanceof Plant;
+ });
+ if (hidingSpots.length > 0) {
+ var hidingSpot = hidingSpots[Math.floor(Math.random() * hidingSpots.length)];
+ self.targetRotation = Math.atan2(hidingSpot.y - self.y, hidingSpot.x - self.x);
+ self.directionChangeTime = LK.ticks;
+ self.directionChangeInterval = 20;
+ }
}
}
} else {
if (self.isFleeing && LK.ticks - self.directionChangeTime > 300) {
@@ -309,24 +313,17 @@
}
} else if (nearbyFish.length > 0) {
var similarFish = nearbyFish.filter(fish => fish.constructor === self.constructor);
if (similarFish.length > 0) {
- similarFish.forEach(function (fish) {
- self.greetFish(fish);
- });
- if (Math.random() < 0.05) {
- var potentialMates = similarFish.filter(function (fish) {
- return fish.constructor === self.constructor && fish !== self;
- });
- if (potentialMates.length > 0) {
- var mate = potentialMates[Math.floor(Math.random() * potentialMates.length)];
- self.targetRotation = Math.atan2(mate.y - self.y, mate.x - self.x);
- self.directionChangeTime = LK.ticks;
- self.directionChangeInterval = 20;
- }
- } else {
- self.formSchool(similarFish);
- }
+ var schoolCenterX = similarFish.reduce(function (sum, fish) {
+ return sum + fish.x;
+ }, 0) / similarFish.length;
+ var schoolCenterY = similarFish.reduce(function (sum, fish) {
+ return sum + fish.y;
+ }, 0) / similarFish.length;
+ self.targetRotation = Math.atan2(schoolCenterY - self.y, schoolCenterX - self.x);
+ self.directionChangeTime = LK.ticks;
+ self.directionChangeInterval = 30;
}
} else if (self.curiosityTarget && self.distanceTo(self.curiosityTarget) < 100) {
self.playWithObject(self.curiosityTarget);
self.rememberObject(self.curiosityTarget);
@@ -346,9 +343,14 @@
var toy = toys[Math.floor(Math.random() * toys.length)];
self.playWithObject(toy);
}
} else {
- self.findCuriosityTarget();
+ if (Math.random() < 0.1) {
+ self.findCuriosityTarget();
+ if (self.curiosityTarget) {
+ self.investigateCuriosity(self.curiosityTarget);
+ }
+ }
}
}
} else {
self.findCuriosityTarget();
@@ -360,8 +362,15 @@
}
if (self.y < waterBounds.top || self.y > waterBounds.bottom) {
self.rotation = -self.rotation;
}
+ if (self.isMating) {
+ fishGraphics.tint = 0xFF69B4;
+ } else if (self.isResting) {
+ fishGraphics.tint = 0xADD8E6;
+ } else {
+ fishGraphics.tint = 0xFFFFFF;
+ }
fishGraphics.scale.x = Math.cos(self.rotation) < 0 ? -1 : 1;
fishGraphics.rotation = self.rotation;
};
});
@@ -577,11 +586,9 @@
return fish.constructor === self.constructor && fish !== self && fish.hunger > 50;
});
if (potentialMates.length > 0) {
var mate = potentialMates[Math.floor(Math.random() * potentialMates.length)];
- self.targetRotation = Math.atan2(mate.y - self.y, mate.x - self.x);
- self.directionChangeTime = LK.ticks;
- self.directionChangeInterval = 20;
+ self.matingDance(mate);
self.isMating = true;
mate.isMating = true;
self.lastMateTime = LK.ticks;
mate.lastMateTime = LK.ticks;
@@ -594,16 +601,42 @@
if (!self.isResting && LK.ticks - self.lastRestTime > self.restInterval) {
self.isResting = true;
self.lastRestTime = LK.ticks;
self.restInterval = Math.random() * 3000 + 2000;
- self.targetRotation = Math.PI / 2;
+ self.restPosition = {
+ x: self.x,
+ y: self.getWaterBounds().bottom - 50
+ };
+ self.targetRotation = Math.atan2(self.restPosition.y - self.y, self.restPosition.x - self.x);
self.directionChangeTime = LK.ticks;
self.directionChangeInterval = 20;
} else if (self.isResting && LK.ticks - self.lastRestTime > 200) {
self.isResting = false;
}
- self.x += Math.cos(self.rotation) * self.speed;
- self.y += Math.sin(self.rotation) * self.speed;
+ if (Math.random() < 0.01 && self.canJump) {
+ self.isJumping = true;
+ self.jumpStartTime = LK.ticks;
+ self.jumpDuration = 60;
+ self.jumpHeight = Math.random() * 100 + 50;
+ self.canJump = false;
+ } else if (self.isJumping) {
+ var jumpProgress = (LK.ticks - self.jumpStartTime) / self.jumpDuration;
+ if (jumpProgress < 1) {
+ self.y -= self.jumpHeight * (1 - Math.cos(Math.PI * jumpProgress));
+ } else {
+ self.isJumping = false;
+ self.canJump = true;
+ }
+ } else {
+ if (Math.random() < 0.02) {
+ var bubble = new Bubble();
+ bubble.x = self.x;
+ bubble.y = self.y;
+ LK.stageContainer.addChild(bubble);
+ }
+ self.x += Math.cos(self.rotation) * self.speed;
+ self.y += Math.sin(self.rotation) * self.speed;
+ }
}
if (LK.ticks % 1800 === 0) {
self.isSleeping = !self.isSleeping;
self.directionChangeTime = LK.ticks;
An aquarium with no fish on a sheel in a photorealistic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A realistic goldfish. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A realistic Angelfish. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A realistic koyfish swiming to the right. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A realistic gupyfish swiming to the right. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A realistic bettafish swiming to the right. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A realistic clownfish swiming to the right. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A realistic pufferfish swiming to the right. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A realistic surgeonfish swiming to the right. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A realistic buble of water. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A realistic fish egg. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A realistic celestial pearl danio. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A realistic Parrotfish. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A realistic dartfish. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A realistic moorishidol. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A realistic tangfish. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A realistic bannerfish. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A realistic butterflyfish. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A realistic mandarinfish. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a realistic lionfish. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a realistic emperorFish. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a realistic sunfish. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a realistic discusFish. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a realistic neonTetra. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a realistic oscarFish. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a cardinal tetra. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a tang fish. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a clown fish. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.