User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'expand')' in this line: 'var HealingBubble = Bubble.expand(function () {' Line Number: 20
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'expand')' in this line: 'var GrowingPlant = Decoration.expand(function () {' Line Number: 1
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'expand')' in this line: 'var CastleHidingFish = Fish.expand(function () {' Line Number: 1
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'expand')' in this line: 'var CleanerFish = Fish.expand(function () {' Line Number: 1
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'expand')' in this line: 'var JumpingFish = Fish.expand(function () {' Line Number: 1
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'expand')' in this line: 'var CamouflageFish = Fish.expand(function () {' Line Number: 1
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'expand')' in this line: 'var SchoolingFish = Fish.expand(function () {' Line Number: 1
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'expand')' in this line: 'var PlayfulFish = Fish.expand(function () {' Line Number: 1
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'expand')' in this line: 'var BreedingFish = Fish.expand(function () {' Line Number: 1
User prompt
Improve the entire code with 10 new functionality
User prompt
Fix Bug: 'TypeError: self.getNearbyFishWithinRange is not a function' in this line: 'var nearbyPredators = self.getNearbyFishWithinRange(200).filter(function (fish) {' Line Number: 942
User prompt
Fix Bug: 'TypeError: self.getNearbyFishWithinRange is not a function' in this line: 'var nearbyPredators = self.getNearbyFishWithinRange(200).filter(function (fish) {' Line Number: 942
User prompt
Fix Bug: 'TypeError: self.getNearbyFish is not a function' in this line: 'var nearbyPredators = self.getNearbyFish().filter(function (fish) {' Line Number: 942
User prompt
Fix Bug: 'Uncaught ReferenceError: Fish is not defined' in this line: 'var PeacefulFish = Fish.expand(function () {' Line Number: 54
User prompt
Add 50 new line of code
User prompt
Improve the entire code with two new functionality
User prompt
Improve the entire code with two new functionality
User prompt
Fix Bug: 'Uncaught TypeError: self.getWaterBounds is not a function' in this line: 'var waterBounds = self.getWaterBounds();' Line Number: 1438
User prompt
Fix Bug: 'Uncaught TypeError: self.getWaterBounds is not a function' in this line: 'var waterBounds = self.getWaterBounds();' Line Number: 1438
User prompt
Fix Bug: 'Uncaught TypeError: self.getWaterBounds is not a function' in this line: 'var waterBounds = self.getWaterBounds();' Line Number: 1438
User prompt
Fix Bug: 'Uncaught TypeError: self.getWaterBounds is not a function' in this line: 'var waterBounds = self.getWaterBounds();' Line Number: 1438
User prompt
Fix Bug: 'Uncaught ReferenceError: aquarium is not defined' in this line: 'var waterBounds = aquarium.getWaterBounds();' Line Number: 1447
User prompt
Improve the entire code with two new functionality
User prompt
Improve the entire code with a new functionality
User prompt
Fix Bug: 'Uncaught TypeError: this.addChild is not a function' in this line: 'self.cleanObject = function (obj, rate) {' Line Number: 272
===================================================================
--- original.js
+++ change.js
@@ -1,4 +1,20 @@
+var FishFeeder = Container.expand(function () {
+ var self = Container.call(this);
+ var feederGraphics = self.createAsset('fishFeeder', 'Fish Feeder Graphics', 0.5, 0.5);
+ self.foodReleaseRate = 5;
+ self.releaseFood = function () {
+ var food = new Food();
+ food.x = self.x;
+ food.y = self.y - feederGraphics.height;
+ LK.stageContainer.addChild(food);
+ var nearbyFish = self.getNearbyFishWithinRange(500);
+ nearbyFish.forEach(function (fish) {
+ fish.rushToFood(food);
+ });
+ };
+ LK.setInterval(self.releaseFood, 10000);
+});
var InteractiveElement = Container.expand(function () {
var self = Container.call(this);
self.interact = function () {};
self.performInteraction = function () {
@@ -36,8 +52,13 @@
};
});
var Fish = Container.expand(function () {
var self = Container.call(this);
+ self.rushToFood = function (food) {
+ self.targetRotation = Math.atan2(food.y - self.y, food.x - self.x);
+ self.directionChangeTime = LK.ticks;
+ self.directionChangeInterval = 5;
+ };
self.hunger = 100;
Fish.prototype.restingBehavior = new RestingBehavior();
Fish.prototype.reproductionBehavior = new ReproductionBehavior();
self.hungerDecayRate = 0.1;
@@ -250,14 +271,24 @@
var Cleaner = Container.expand(function () {
var self = Container.call(this);
self.clean = function () {};
});
-var AquariumCleanerFish = Fish.expand(function () {
- var self = Fish.call(this) || this;
- var cleanerGraphics = self.createAsset('aquariumCleanerFish', 'Aquarium Cleaner Fish Graphics', 0.5, 0.5);
+var AquariumCleaner = Cleaner.expand(function () {
+ var self = Cleaner.call(this) || this;
+ var cleanerGraphics = self.createAsset('aquariumCleaner', 'Aquarium Cleaner Graphics', 0.5, 0.5);
self.speed = 0.2;
self.cleaningRate = 1;
self.cleaningBehavior = new CleaningBehavior();
+ self.update = function () {
+ var dirtyObjects = self.cleaningBehavior.findDirtyObjects();
+ dirtyObjects.forEach(function (obj) {
+ self.x += (obj.x - self.x) * self.speed;
+ self.y += (obj.y - self.y) * self.speed;
+ if (self.distanceTo(obj) < 50) {
+ self.cleaningBehavior.cleanObject(obj, self.cleaningRate);
+ }
+ });
+ };
});
var CleaningBehavior = Container.expand(function () {
var self = Container.call(this);
self.findDirtyObjects = function () {
@@ -272,65 +303,53 @@
self.cleanObject = function (obj, rate) {
obj.clean(rate);
};
});
-var AquariumDecorations = Container.expand(function () {
+var AquariumDecorator = Container.expand(function () {
var self = Container.call(this);
- this.decorators = [];
- this.addDecoration = function (decorationType, x, y) {
- var decoration = new decorationType();
- decoration.x = x;
- decoration.y = y;
- self.addChild(decoration);
- this.decorators.push(decoration);
+ self.decorators = [];
+ self.addDecorator = function (decorator) {
+ self.decorators.push(decorator);
+ self.addChild(decorator);
};
- this.updateDecorations = function () {
- this.decorators.forEach(function (decoration) {
- if (typeof decoration.interact === 'function') {
- decoration.interact();
+ self.removeDecorator = function (decorator) {
+ var index = self.decorators.indexOf(decorator);
+ if (index !== -1) {
+ self.decorators.splice(index, 1);
+ decorator.destroy();
+ }
+ };
+ self.updateDecorators = function () {
+ for (var i = 0; i < self.decorators.length; i++) {
+ if (typeof self.decorators[i].update === 'function') {
+ self.decorators[i].update();
}
- });
+ }
};
- LK.on('tick', this.updateDecorations);
});
var InteractiveDecoration = InteractiveElement.expand(function () {
var self = InteractiveElement.call(this) || this;
});
-var InteractiveFeeder = InteractiveDecoration.expand(function () {
- var self = InteractiveDecoration.call(this) || this;
- var feederGraphics = self.createAsset('interactiveFeeder', 'Interactive Feeder Graphics', 0.5, 0.5);
- self.foodReleaseRate = 5;
- self.interactWithFish = function (fish) {
- if (fish.size < self.size && self.distanceTo(fish) < 100) {
- var food = new Food();
- food.x = self.x;
- food.y = self.y - feederGraphics.height;
- LK.stageContainer.addChild(food);
+var AquariumPlant = Decoration.expand(function () {
+ var self = Decoration.call(this) || this;
+ self.growthRate = 0.01;
+ self.nutritionValue = 5;
+ var plantGraphics = self.createAsset('aquariumPlant', 'Aquarium Plant Graphics', 0.5, 1);
+ self.on('tick', function () {
+ plantGraphics.scale.x += self.growthRate;
+ plantGraphics.scale.y += self.growthRate;
+ if (plantGraphics.scale.x > 3) {
+ plantGraphics.scale.x = 3;
+ plantGraphics.scale.y = 3;
}
+ });
+ self.consume = function (fish) {
+ if (self.distanceTo(fish) < 100) {
+ fish.hunger = Math.min(fish.hunger + self.nutritionValue, 100);
+ self.destroy();
+ }
};
- LK.setInterval(self.interactWithFish, 10000);
});
-var AquariumPlantLife = Container.expand(function () {
- var self = Container.call(this);
- this.growthRate = 0.01;
- this.nutritionValue = 5;
- this.plants = [];
- this.addPlant = function (plantType, x, y) {
- var plant = new plantType();
- plant.x = x;
- plant.y = y;
- self.addChild(plant);
- this.plants.push(plant);
- };
- this.updatePlants = function () {
- this.plants.forEach(function (plant) {
- if (typeof plant.grow === 'function') {
- plant.grow();
- }
- });
- };
- LK.on('tick', this.updatePlants);
-});
var HealingPlant = Decoration.expand(function () {
var self = Decoration.call(this);
var plantGraphics = self.createAsset('healingPlant', 'Healing Plant Graphics', 0.5, 1);
self.healingRate = 0.1;
@@ -1002,24 +1021,8 @@
fishGraphics.scale.x = Math.cos(self.rotation) < 0 ? -1 : 1;
fishGraphics.rotation = self.rotation;
};
});
-var AquariumEnvironment = Container.expand(function () {
- var self = Container.call(this);
- 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.7;
- self.addChild(waterGraphics);
-});
var Aquarium = Container.expand(function () {
var self = Container.call(this);
self.getWaterBounds = function () {
var waterGraphics = LK.getAsset('water', 'Water Graphics', 0, 0);
@@ -1029,9 +1032,24 @@
top: (2732 - waterGraphics.height) / 2 - 150,
bottom: (2732 + waterGraphics.height) / 2 - 150
};
};
- var aquariumEnvironment = self.addChild(new AquariumEnvironment());
+ self.initializeEnvironment = function () {
+ 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.7;
+ self.addChild(waterGraphics);
+ };
+ self.initializeEnvironment();
});
var KoiFish = Fish.expand(function () {
var self = Fish.call(this) || this;
var fishGraphics = self.createAsset('koiFish', 'Koi Fish Graphics', .5, .5);
@@ -1382,18 +1400,18 @@
}
fishGraphics.rotation = self.rotation;
};
});
-var BubbleManager = Container.expand(function () {
+var BubbleGenerator = Container.expand(function () {
var self = Container.call(this);
- this.bubbleRate = 500;
- this.createBubble = function () {
+ self.bubbleRate = 500;
+ self.createBubble = function () {
var bubble = new Bubble();
bubble.x = Math.random() * 2048;
bubble.y = 2732;
- self.addChild(bubble);
+ LK.stageContainer.addChild(bubble);
};
- LK.setInterval(this.createBubble, this.bubbleRate);
+ LK.setInterval(self.createBubble, self.bubbleRate);
});
var Bubble = Container.expand(function () {
var self = Container.call(this);
var bubbleGraphics = self.createAsset('bubble', 'Bubble Graphics', 0.5, 0.5);
@@ -1420,60 +1438,35 @@
});
return nearbyPredators.length > 0;
};
});
-var FishSpawner = Container.expand(function () {
- var self = Container.call(this);
- var fishTypes = [Fish, KoiFish, Goldfish, GuppyFish, BettaFish, Angelfish, Clownfish, Pufferfish, Surgeonfish];
- this.spawnFish = function (aquarium) {
- var fishes = [];
- 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);
- }
- }
- }
- return fishes;
- };
-});
-var aquariumCleanerFish = this.addChild(new AquariumCleanerFish());
-var aquariumDecorations = self.addChild(new AquariumDecorations());
-aquariumDecorations.addDecoration(TreasureChest, 1500, 2500);
-var aquariumPlantLife = self.addChild(new AquariumPlantLife());
-aquariumPlantLife.addPlant(AquariumPlant, 500, 2000);
-var bubbleManager = self.addChild(new BubbleManager());
var Game = Container.expand(function () {
var self = Container.call(this);
- self.updateAquariumCleanerFish = function (aquariumCleanerFish) {
- var dirtyObjects = aquariumCleanerFish.cleaningBehavior.findDirtyObjects();
- dirtyObjects.forEach(function (obj) {
- aquariumCleanerFish.x += (obj.x - aquariumCleanerFish.x) * aquariumCleanerFish.speed;
- aquariumCleanerFish.y += (obj.y - aquariumCleanerFish.y) * aquariumCleanerFish.speed;
- if (aquariumCleanerFish.distanceTo(obj) < 50) {
- aquariumCleanerFish.cleaningBehavior.cleanObject(obj, aquariumCleanerFish.cleaningRate);
- }
- });
- LK.stageContainer.addChild(aquariumCleanerFish);
- };
var aquarium = self.addChild(new Aquarium());
LK.stageContainer.setBackgroundColor(0x008080);
- var fishSpawner = self.addChild(new FishSpawner());
- var fishes = fishSpawner.spawnFish(aquarium);
+ 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();
}
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.