User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'attachAsset')' in or related to this line: 'var fishGraphics = self.attachAsset('zebraDanio', {' Line Number: 116
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'attachAsset')' in or related to this line: 'var fishGraphics = self.attachAsset('zebraDanio', {' Line Number: 111
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'attachAsset')' in or related to this line: 'var fishGraphics = self.attachAsset('zebraDanio', {' Line Number: 106
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'attachAsset')' in or related to this line: 'var fishGraphics = self.attachAsset('zebraDanio', {' Line Number: 109
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'attachAsset')' in or related to this line: 'self.fishGraphics = self.attachAsset('zebraDanio', {' Line Number: 106
User prompt
Migrate to the latest version of LK
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'attachAsset')' in or related to this line: 'var fishGraphics = self.attachAsset('zebraDanio', {' Line Number: 106
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'attachAsset')' in or related to this line: 'self.fishGraphics = self.attachAsset('zebraDanio', {' Line Number: 106
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'attachAsset')' in or related to this line: 'var fishGraphics = self.attachAsset('zebraDanio', {' Line Number: 106
User prompt
Migrate to the latest version of LK
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'createAsset')' in this line: 'var fishGraphics = self.createAsset('zebraDanio', 'Zebra Danio Graphics', .5, .5);' Line Number: 25
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'createAsset')' in this line: 'self.fishGraphics = self.createAsset('zebraDanio', 'Zebra Danio Graphics', .5, .5);' Line Number: 25
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'createAsset')' in this line: 'self.fishGraphics = self.createAsset('zebraDanio', 'Zebra Danio Graphics', .5, .5);' Line Number: 25
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'createAsset')' in this line: 'self.fishGraphics = self.createAsset('zebraDanio', 'Zebra Danio Graphics', .5, .5);' Line Number: 52
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'createAsset')' in this line: 'var fishGraphics = self.createAsset('zebraDanio', 'Zebra Danio Graphics', .5, .5);' Line Number: 169
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'createAsset')' in this line: 'self.fishGraphics = self.createAsset('zebraDanio', 'Zebra Danio Graphics', .5, .5);' Line Number: 169
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'createAsset')' in this line: 'var fishGraphics = self.createAsset('zebraDanio', 'Zebra Danio Graphics', .5, .5);' Line Number: 169
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'createAsset')' in this line: 'var fishGraphics = self.createAsset('zebraDanio', 'Zebra Danio Graphics', .5, .5);' Line Number: 168
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'createAsset')' in this line: 'var fishGraphics = self.createAsset('zebraDanio', 'Zebra Danio Graphics', .5, .5);' Line Number: 168
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'createAsset')' in this line: 'var fishGraphics = self.createAsset('zebraDanio', 'Zebra Danio Graphics', .5, .5);' Line Number: 168
User prompt
Improve the fluidity
User prompt
Make décoration 600 pixel up
User prompt
Move the décoration in the aquarium
User prompt
Fix Bug: 'Uncaught ReferenceError: aquarium is not defined' in this line: 'var waterBounds = aquarium.getWaterBounds();' Line Number: 1351
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'getWaterBounds')' in this line: 'var waterBounds = self.aquarium.getWaterBounds();' Line Number: 1255
/**** * Classes ****/ var Fish = Container.expand(function () { var self = Container.call(this); self.move = function () { if (!self.directionChangeTime || LK.ticks - self.directionChangeTime > self.directionChangeInterval) { self.directionChangeTime = LK.ticks; self.directionChangeInterval = Math.random() * (self.maxChangeInterval - self.minChangeInterval) + self.minChangeInterval; 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 + 50, Math.min(tentativeX, waterBounds.right - 50)); tentativeY = Math.max(waterBounds.top + 50, Math.min(tentativeY, waterBounds.bottom - 50)); if (!self.isPathBlocked(tentativeX, tentativeY, self.getNearbyObstacles())) { self.x = tentativeX; self.y = tentativeY; } else { self.avoidObstacles(self.getNearbyObstacles()); } self.rotation = self.rotation % (Math.PI * 2); self.fishGraphics.scale.x = Math.cos(self.rotation) < 0 ? -1 : 1; self.fishGraphics.rotation = self.rotation; }; self.avoidObstacles = function (obstacles) {}; self.isPathBlocked = function (newX, newY, obstacles) { return false; }; self.getNearbyObstacles = function () { return []; }; 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 ZebraDanio = Fish.expand(function () { var self = Fish.call(this); self.fishGraphics = self.createAsset('zebraDanio', 'Zebra Danio 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() * 90 + 45; 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(); if (tentativeX < waterBounds.left || tentativeX > waterBounds.right || tentativeY < waterBounds.top || tentativeY > waterBounds.bottom) { self.x = Math.max(waterBounds.left, Math.min(centerX + Math.cos(angle) * distance, waterBounds.right)); self.y = Math.max(waterBounds.top, Math.min(centerY + Math.sin(angle) * distance, waterBounds.bottom)); } else { if (tentativeX < waterBounds.left || tentativeX > waterBounds.right || tentativeY < waterBounds.top || tentativeY > waterBounds.bottom) { self.x = centerX + Math.cos(angle) * distance; self.y = centerY + Math.sin(angle) * distance; } else { if (!self.isPathBlocked(tentativeX, tentativeY, self.getNearbyObstacles())) { self.x = Math.max(waterBounds.left, Math.min(tentativeX, waterBounds.right)); self.y = Math.max(waterBounds.top, Math.min(tentativeY, waterBounds.bottom)); } else { self.avoidObstacles(self.getNearbyObstacles()); } } } var waterBounds = self.getWaterBounds(); if (tentativeX < waterBounds.left) { self.rotation = Math.PI - self.rotation; tentativeX = waterBounds.left; } if (tentativeX > waterBounds.right) { self.rotation = Math.PI - self.rotation; tentativeX = waterBounds.right; } if (tentativeY < waterBounds.top) { self.rotation = -self.rotation; tentativeY = waterBounds.top; } if (tentativeY > waterBounds.bottom) { self.rotation = -self.rotation; tentativeY = waterBounds.bottom; } self.rotation = self.rotation % (Math.PI * 2); fishGraphics.scale.x = Math.cos(self.rotation) < 0 ? -1 : 1; fishGraphics.rotation = self.rotation; }; }); var CelestialPearlDanio = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('celestialPearlDanio', 'Celestial Pearl Danio Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = (Math.random() * 0.2 + 0.35) * 2; self.move = function () { if (!self.directionChangeTime || LK.ticks - self.directionChangeTime > self.directionChangeInterval) { self.directionChangeTime = LK.ticks; self.directionChangeInterval = Math.random() * 80 + 40; 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(); self.x = Math.max(waterBounds.left, Math.min(self.x, waterBounds.right)); self.y = Math.max(waterBounds.top, Math.min(self.y, waterBounds.bottom)); var waterBounds = self.getWaterBounds(); if (self.x <= waterBounds.left) { self.rotation = Math.PI - self.rotation; self.x = waterBounds.left; } if (self.x >= waterBounds.right) { self.rotation = Math.PI - self.rotation; self.x = waterBounds.right; } if (self.y <= waterBounds.top) { self.rotation = -self.rotation; self.y = waterBounds.top; } if (self.y >= waterBounds.bottom) { self.rotation = -self.rotation; self.y = waterBounds.bottom; } self.rotation = self.rotation % (Math.PI * 2); fishGraphics.scale.x = Math.cos(self.rotation) < 0 ? -1 : 1; fishGraphics.rotation = self.rotation; }; }); var Wrasses = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('wrasses', 'Wrasses Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = Math.random() * 0.2 + 0.42; self.move = function () {}; }); var Parrotfish = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('parrotfish', 'Parrotfish Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = Math.random() * 0.2 + 0.50; self.move = function () {}; }); var Dartfish = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('dartfish', 'Dartfish Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = Math.random() * 0.2 + 0.45; self.move = function () {}; }); var MoorishIdol = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('moorishidol', 'Moorish Idol Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = Math.random() * 0.2 + 0.43; self.move = function () {}; }); var Tangfish = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('tangfish', 'Tangfish Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = Math.random() * 0.2 + 0.47; self.move = function () {}; }); var Bannerfish = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('bannerfish', 'Bannerfish Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = Math.random() * 0.2 + 0.46; self.move = function () {}; }); var Butterflyfish = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('butterflyfish', 'Butterflyfish Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = Math.random() * 0.2 + 0.45; self.move = function () {}; }); var Mandarinfish = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('mandarinfish', 'Mandarinfish Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = (Math.random() * 0.2 + 0.4) * 2; self.move = function () {}; }); var Lionfish = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('lionfish', 'Lionfish Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = Math.random() * 0.2 + 0.5; self.move = function () {}; }); var Surgeonfish = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('surgeonfish', 'Surgeonfish Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = (Math.random() * 0.2 + 0.5) * 2 * 2 * 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) { self.rotation += (self.targetRotation - self.rotation) * progress; } 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(); if (self.isPathBlocked(newX, newY, obstacles)) { self.avoidObstacles(obstacles); } else { self.x = newX; self.y = newY; } var waterBounds = self.getWaterBounds(); var centerX = (waterBounds.left + waterBounds.right) / 2; var centerY = (waterBounds.top + waterBounds.bottom) / 2; if (self.x < waterBounds.left || self.x > waterBounds.right || self.y < waterBounds.top || self.y > waterBounds.bottom) { self.x = centerX; self.y = centerY; } fishGraphics.scale.x = Math.cos(self.rotation) < 0 ? -1 : 1; fishGraphics.rotation = self.rotation; }; }); var Pufferfish = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('pufferfish', 'Pufferfish Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = (Math.random() * 0.2 + 0.4) * 2 * 2; 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(); self.x = Math.max(waterBounds.left, Math.min(tentativeX, waterBounds.right)); self.y = Math.max(waterBounds.top, Math.min(tentativeY, waterBounds.bottom)); 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); var fishGraphics = self.createAsset('clownfish', 'Clownfish Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = (Math.random() * 0.2 + 0.4) * 2; 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); 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; } 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; } 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 * 1.1; waterGraphics.height = 2732 / 3 * 1.26 * 1.1; waterGraphics.x = (2048 - waterGraphics.width) / 2; waterGraphics.y = (2732 - waterGraphics.height) / 2 - 150; waterGraphics.alpha = 0.3; self.addChild(waterGraphics); }); var KoiFish = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('koiFish', 'Koi Fish Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = (Math.random() * 0.2 + 0.48) * 2; 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; } 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 EmperorFish = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('emperorFish', 'Emperor Fish Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = Math.random() * 0.2 + 0.5; self.move = function () {}; }); var Goldfish = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('goldfish', 'Goldfish Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = (Math.random() * 0.2 + 0.4) * 2 * 2; 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 Sunfish = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('sunfish', 'Sunfish Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = Math.random() * 0.2 + 0.6; self.move = function () { if (!self.directionChangeTime || LK.ticks - self.directionChangeTime > self.directionChangeInterval) { self.directionChangeTime = LK.ticks; self.directionChangeInterval = Math.random() * 200 + 100; 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; } 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); fishGraphics.scale.x = Math.cos(self.rotation) < 0 ? -1 : 1; fishGraphics.rotation = self.rotation; }; }); var GuppyFish = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('guppyFish', 'Guppy Fish Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = (Math.random() * 0.2 + 0.35) * 2 * 2; 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); 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 DiscusFish = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('discusFish', 'Discus Fish Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = (Math.random() * 0.2 + 0.45) * 2; 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() * 120 + 60; } 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 NeonTetra = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('neonTetra', 'Neon Tetra Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = Math.random() * 0.2 + 0.3; 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 OscarFish = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('oscarFish', 'Oscar 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 ElectricCatfish = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('electricCatfish', 'Electric Catfish Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = Math.random() * 0.2 + 0.58; self.move = function () { if (!self.directionChangeTime || LK.ticks - self.directionChangeTime > self.directionChangeInterval) { self.directionChangeTime = LK.ticks; self.directionChangeInterval = Math.random() * 190 + 130; 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; } 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); fishGraphics.scale.x = Math.cos(self.rotation) < 0 ? -1 : 1; fishGraphics.rotation = self.rotation; }; }); var RainbowTrout = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('rainbowTrout', 'Rainbow Trout Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = Math.random() * 0.2 + 0.53; self.move = function () { if (!self.directionChangeTime || LK.ticks - self.directionChangeTime > self.directionChangeInterval) { self.directionChangeTime = LK.ticks; self.directionChangeInterval = Math.random() * 160 + 120; 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; } 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); fishGraphics.scale.x = Math.cos(self.rotation) < 0 ? -1 : 1; fishGraphics.rotation = self.rotation; }; }); var PsychedelicFrogfish = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('psychedelicFrogfish', 'Psychedelic Frogfish Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = (Math.random() * 0.2 + 0.4) * 2 * 2; self.move = function () {}; }); var FlameScallop = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('flameScallop', 'Flame Scallop Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = Math.random() * 0.2 + 0.3; self.move = function () {}; }); var RibbonEel = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('ribbonEel', 'Ribbon Eel Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = (Math.random() * 0.2 + 0.6) * 2; self.move = function () {}; }); var LeafySeaDragon = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('leafySeaDragon', 'Leafy Sea Dragon Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = (Math.random() * 0.2 + 0.4) * 2; self.move = function () {}; }); var ClownTriggerfish = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('clownTriggerfish', 'Clown Triggerfish Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = Math.random() * 0.2 + 0.5; self.move = function () {}; }); var ElectricBlueDamsel = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('electricBlueDamsel', 'Electric Blue Damsel Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = (Math.random() * 0.2 + 0.45) * 2; self.move = function () {}; }); var YellowTang = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('yellowTang', 'Yellow Tang Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = Math.random() * 0.2 + 0.5; self.move = function () {}; }); var FlameHawkfish = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('flameHawkfish', 'Flame Hawkfish Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = (Math.random() * 0.2 + 0.48) * 2; self.move = function () {}; }); var RoyalGramma = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('royalGramma', 'Royal Gramma Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = Math.random() * 0.2 + 0.5; self.move = function () { if (!self.directionChangeTime || LK.ticks - self.directionChangeTime > self.directionChangeInterval) { self.directionChangeTime = LK.ticks; self.directionChangeInterval = Math.random() * 160 + 100; 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; } 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); fishGraphics.scale.x = Math.cos(self.rotation) < 0 ? -1 : 1; fishGraphics.rotation = self.rotation; }; }); var FlameAngel = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('flameAngel', 'Flame Angel Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = Math.random() * 0.2 + 0.55; self.move = function () { if (!self.directionChangeTime || LK.ticks - self.directionChangeTime > self.directionChangeInterval) { self.directionChangeTime = LK.ticks; self.directionChangeInterval = Math.random() * 170 + 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; } 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); fishGraphics.scale.x = Math.cos(self.rotation) < 0 ? -1 : 1; fishGraphics.rotation = self.rotation; }; }); var BlueTang = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('blueTang', 'Blue Tang Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = Math.random() * 0.2 + 0.52; self.move = function () { if (!self.directionChangeTime || LK.ticks - self.directionChangeTime > self.directionChangeInterval) { self.directionChangeTime = LK.ticks; self.directionChangeInterval = Math.random() * 150 + 110; 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; } 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); fishGraphics.scale.x = Math.cos(self.rotation) < 0 ? -1 : 1; fishGraphics.rotation = self.rotation; }; }); var Moonfish = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('moonfish', 'Moonfish Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = Math.random() * 0.2 + 0.55; self.move = function () { self.x += Math.cos(LK.ticks / 60) * self.speed; self.y += Math.sin(LK.ticks / 60) * self.speed; var waterBounds = self.getWaterBounds(); if (self.x < waterBounds.left || self.x > waterBounds.right || self.y < waterBounds.top || self.y > waterBounds.bottom) { self.x = Math.max(waterBounds.left, Math.min(self.x, waterBounds.right)); self.y = Math.max(waterBounds.top, Math.min(self.y, waterBounds.bottom)); } fishGraphics.rotation = Math.atan2(Math.sin(LK.ticks / 60), Math.cos(LK.ticks / 60)); }; }); var Starfish = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('starfish', 'Starfish Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = Math.random() * 0.2 + 0.5; self.move = function () { self.x += Math.sin(LK.ticks / 30) * self.speed; self.y += Math.cos(LK.ticks / 30) * self.speed; var waterBounds = self.getWaterBounds(); if (self.x < waterBounds.left || self.x > waterBounds.right || self.y < waterBounds.top || self.y > waterBounds.bottom) { self.x = Math.max(waterBounds.left, Math.min(self.x, waterBounds.right)); self.y = Math.max(waterBounds.top, Math.min(self.y, waterBounds.bottom)); } fishGraphics.rotation = LK.ticks / 30; }; }); var GlassCatfish = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('glassCatfish', 'Glass Catfish Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = Math.random() * 0.2 + 0.45; self.move = function () { self.x += Math.cos(LK.ticks / 100) * self.speed; self.y += Math.sin(LK.ticks / 100) * self.speed; var waterBounds = self.getWaterBounds(); if (self.x < waterBounds.left || self.x > waterBounds.right || self.y < waterBounds.top || self.y > waterBounds.bottom) { self.x = Math.max(waterBounds.left, Math.min(self.x, waterBounds.right)); self.y = Math.max(waterBounds.top, Math.min(self.y, waterBounds.bottom)); } fishGraphics.rotation = Math.atan2(Math.sin(LK.ticks / 100), Math.cos(LK.ticks / 100)); }; }); var DiamondTetra = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('diamondTetra', 'Diamond Tetra 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() * 100 + 50; 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; } 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); fishGraphics.scale.x = Math.cos(self.rotation) < 0 ? -1 : 1; fishGraphics.rotation = self.rotation; }; }); var PeacockBass = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('peacockBass', 'Peacock Bass Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = Math.random() * 0.2 + 0.65; self.move = function () { if (!self.directionChangeTime || LK.ticks - self.directionChangeTime > self.directionChangeInterval) { self.directionChangeTime = LK.ticks; self.directionChangeInterval = Math.random() * 220 + 160; 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; } self.x += Math.cos(self.rotation) * self.speed * 1.6; self.y += Math.sin(self.rotation) * self.speed * 1.6; 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); fishGraphics.scale.x = Math.cos(self.rotation) < 0 ? -1 : 1; fishGraphics.rotation = self.rotation; }; }); var CrimsonSnapper = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('crimsonSnapper', 'Crimson Snapper Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = Math.random() * 0.2 + 0.57; self.move = function () { if (!self.directionChangeTime || LK.ticks - self.directionChangeTime > self.directionChangeInterval) { self.directionChangeTime = LK.ticks; self.directionChangeInterval = Math.random() * 130 + 65; 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; } 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); fishGraphics.scale.x = Math.cos(self.rotation) < 0 ? -1 : 1; fishGraphics.rotation = self.rotation; }; }); var CardinalTetra = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('cardinalTetra', 'Cardinal Tetra Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = Math.random() * 0.2 + 0.3; self.move = function () { if (!self.directionChangeTime || LK.ticks - self.directionChangeTime > self.directionChangeInterval) { self.directionChangeTime = LK.ticks; self.directionChangeInterval = Math.random() * 90 + 60; 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; } 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); fishGraphics.scale.x = Math.cos(self.rotation) < 0 ? -1 : 1; fishGraphics.rotation = self.rotation; }; }); var CometFish = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('cometFish', 'Comet Fish Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = (Math.random() * 0.2 + 0.6) * 2; self.move = function () { self.x += Math.cos(LK.ticks / 70) * self.speed; self.y += Math.sin(LK.ticks / 70) * self.speed; var waterBounds = self.getWaterBounds(); if (self.x < waterBounds.left || self.x > waterBounds.right || self.y < waterBounds.top || self.y > waterBounds.bottom) { self.x = Math.max(waterBounds.left, Math.min(self.x, waterBounds.right)); self.y = Math.max(waterBounds.top, Math.min(self.y, waterBounds.bottom)); } fishGraphics.rotation = Math.atan2(Math.sin(LK.ticks / 70), Math.cos(LK.ticks / 70)); }; }); var EmeraldGoby = Fish.expand(function () { var self = Fish.call(this); var fishGraphics = self.createAsset('emeraldGoby', 'Emerald Goby Graphics', .5, .5); fishGraphics.scale.set(1, 1); self.speed = Math.random() * 0.2 + 0.42; self.move = function () { if (!self.directionChangeTime || LK.ticks - self.directionChangeTime > self.directionChangeInterval) { self.directionChangeTime = LK.ticks; self.directionChangeInterval = Math.random() * 110 + 55; 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; } 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); fishGraphics.scale.x = Math.cos(self.rotation) < 0 ? -1 : 1; fishGraphics.rotation = self.rotation; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ var aquarium = game.addChild(new Aquarium()); game.setBackgroundColor(0x008080); var fishes = []; var fishTypes = [Wrasses, Parrotfish, Dartfish, MoorishIdol, Tangfish, Bannerfish, Butterflyfish, Mandarinfish, Lionfish, Surgeonfish, Pufferfish, Clownfish, Angelfish, KoiFish, EmperorFish, Goldfish, Sunfish, GuppyFish, BettaFish, DiscusFish, NeonTetra, OscarFish, PsychedelicFrogfish, FlameScallop, RibbonEel, LeafySeaDragon, ClownTriggerfish, ElectricBlueDamsel, YellowTang, FlameHawkfish, RoyalGramma, FlameAngel, BlueTang, Moonfish, Starfish, CardinalTetra]; var fishTypes = [ZebraDanio, CelestialPearlDanio, Wrasses, Parrotfish, Dartfish, MoorishIdol, Tangfish, Bannerfish, Butterflyfish, Mandarinfish, Lionfish, Surgeonfish, Pufferfish, Clownfish, Angelfish, KoiFish, EmperorFish, Goldfish, Sunfish, GuppyFish, BettaFish, DiscusFish, NeonTetra, OscarFish, ElectricCatfish, RainbowTrout, PsychedelicFrogfish, FlameScallop, RibbonEel, LeafySeaDragon, ClownTriggerfish, ElectricBlueDamsel, YellowTang, FlameHawkfish, RoyalGramma, FlameAngel, BlueTang, Moonfish, Starfish, GlassCatfish, DiamondTetra, PeacockBass, CrimsonSnapper, CardinalTetra, CometFish, EmeraldGoby]; fishTypes.forEach(function (fishType) { var fish = new fishType(); if (typeof fish.move === 'function') { var waterBounds = aquarium.getWaterBounds(); var centerX = waterBounds.left + (waterBounds.right - waterBounds.left) / 2; var centerY = waterBounds.top + (waterBounds.bottom - waterBounds.top) / 2; var maxDistance = 500; var angle = Math.random() * Math.PI * 2; var distance = Math.random() * maxDistance; fish.x = centerX + Math.cos(angle) * distance; fish.y = centerY + Math.sin(angle) * distance; fishes.push(fish); game.addChild(fish); } }); LK.on('tick', function () { for (var i = 0; i < fishes.length; i++) { fishes[i].move(); } });
===================================================================
--- original.js
+++ change.js
@@ -1,76 +1,21 @@
/****
* Classes
****/
-var DecorativePlant = Container.expand(function () {
- var self = Container.call(this);
- var plantGraphics = self.createAsset('decorativePlant', 'Decorative Plant Graphics', .5, 1);
- var swayDirection = 1;
- self.sway = function () {
- plantGraphics.rotation += swayDirection * 0.01;
- if (Math.abs(plantGraphics.rotation) > 0.2) {
- swayDirection *= -1;
- }
- };
- self.move = function () {
- self.x += 1;
- if (self.x > 2048) {
- self.x = 0;
- }
- };
-});
-var TreasureChest = Container.expand(function () {
- var self = Container.call(this);
- var chestClosedGraphics = self.createAsset('chestClosed', 'Closed Chest Graphics', .5, .5);
- var chestOpenGraphics = self.createAsset('chestOpen', 'Open Chest Graphics', .5, .5);
- chestOpenGraphics.visible = false;
- var isOpen = false;
- self.toggleChest = function () {
- isOpen = !isOpen;
- chestClosedGraphics.visible = !isOpen;
- chestOpenGraphics.visible = isOpen;
- };
- LK.setInterval(self.toggleChest, 5000);
-});
-var FishFood = Container.expand(function () {
- var self = Container.call(this);
- var foodGraphics = self.createAsset('fishFood', 'Fish Food Graphics', .5, .5);
- self.speed = 1;
- self.move = function () {
- self.y += self.speed;
- if (self.y > 2732) {
- self.destroy();
- }
- };
-});
-var Bubble = Container.expand(function () {
- var self = Container.call(this);
- var bubbleGraphics = self.createAsset('bubble', 'Bubble Graphics', .5, .5);
- self.speed = -0.5;
- self.move = function () {
- self.y += self.speed;
- if (self.y < -50) {
- self.destroy();
- }
- };
- bubbleGraphics.on('down', function () {
- LK.effects.flashObject(self, 0xFFFFFF, 300);
- self.destroy();
- });
-});
var Fish = Container.expand(function () {
var self = Container.call(this);
- self.fishGraphics = self.createAsset('fish', 'Fish Graphics', .5, .5);
self.move = function () {
if (!self.directionChangeTime || LK.ticks - self.directionChangeTime > self.directionChangeInterval) {
self.directionChangeTime = LK.ticks;
self.directionChangeInterval = Math.random() * (self.maxChangeInterval - self.minChangeInterval) + self.minChangeInterval;
self.targetRotation = Math.random() * Math.PI * 2;
}
- var progress = Math.min(1, (LK.ticks - self.directionChangeTime) / self.directionChangeInterval);
- var rotationDifference = (self.targetRotation - self.rotation + Math.PI) % (2 * Math.PI) - Math.PI;
- self.rotation += rotationDifference * progress * 0.1;
- self.rotation = (self.rotation + Math.PI * 2) % (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 + 50, Math.min(tentativeX, waterBounds.right - 50));
@@ -80,80 +25,18 @@
self.y = tentativeY;
} else {
self.avoidObstacles(self.getNearbyObstacles());
}
- var nearbyFish = self.getNearbyObstacles();
- var alignmentRotation = 0;
- var alignmentCount = 0;
- for (var i = 0; i < nearbyFish.length; i++) {
- var fish = nearbyFish[i];
- var dx = self.x - fish.x;
- var dy = self.y - fish.y;
- var distance = Math.sqrt(dx * dx + dy * dy);
- if (distance < 200) {
- alignmentRotation += fish.rotation;
- alignmentCount++;
- }
- }
- if (alignmentCount > 0) {
- alignmentRotation /= alignmentCount;
- self.rotation = (self.rotation + alignmentRotation) / 2;
- }
- if (Math.random() < 0.02) {
- self.speed *= 0.5;
- }
self.rotation = self.rotation % (Math.PI * 2);
- if (Math.random() < 0.005) {
- LK.effects.splash(self.x, self.y, 0x1CA3EC, 500);
- }
- var isFishClose = self.getNearbyObstacles().some(function (obstacle) {
- var dx = self.x - obstacle.x;
- var dy = self.y - obstacle.y;
- return Math.sqrt(dx * dx + dy * dy) < 150;
- });
- if (isFishClose) {
- fishGraphics.tint = 0x88FFFF;
- } else {
- fishGraphics.tint = 0xFFFFFF;
- }
- fishGraphics.scale.x = Math.cos(self.rotation) < 0 ? -1 : 1;
- if (Math.random() < 0.01) {
- fishGraphics.blink();
- }
- fishGraphics.rotation = self.rotation;
+ self.fishGraphics.scale.x = Math.cos(self.rotation) < 0 ? -1 : 1;
+ self.fishGraphics.rotation = self.rotation;
};
- self.avoidObstacles = function (obstacles) {
- for (var i = 0; i < obstacles.length; i++) {
- var obstacle = obstacles[i];
- var dx = self.x - obstacle.x;
- var dy = self.y - obstacle.y;
- var distance = Math.sqrt(dx * dx + dy * dy);
- if (distance < 100) {
- self.targetRotation = Math.atan2(dy, dx) + Math.PI;
- break;
- }
- }
- };
+ self.avoidObstacles = function (obstacles) {};
self.isPathBlocked = function (newX, newY, obstacles) {
- for (var i = 0; i < obstacles.length; i++) {
- var obstacle = obstacles[i];
- var dx = newX - obstacle.x;
- var dy = newY - obstacle.y;
- var distance = Math.sqrt(dx * dx + dy * dy);
- if (distance < 50) {
- return true;
- }
- }
return false;
};
self.getNearbyObstacles = function () {
- var nearbyObstacles = [];
- for (var i = 0; i < self.fishes.length; i++) {
- if (fishes[i] !== self) {
- nearbyObstacles.push(fishes[i]);
- }
- }
- return nearbyObstacles;
+ return [];
};
this.getWaterBounds = function () {
var waterGraphics = LK.getAsset('water', 'Water Graphics', 0, 0);
return {
@@ -165,9 +48,9 @@
};
});
var ZebraDanio = Fish.expand(function () {
var self = Fish.call(this);
- var fishGraphics = self.createAsset('zebraDanio', 'Zebra Danio Graphics', .5, .5);
+ self.fishGraphics = self.createAsset('zebraDanio', 'Zebra Danio 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) {
@@ -276,29 +159,9 @@
var self = Fish.call(this);
var fishGraphics = self.createAsset('wrasses', 'Wrasses Graphics', .5, .5);
fishGraphics.scale.set(1, 1);
self.speed = Math.random() * 0.2 + 0.42;
- self.move = function () {
- if (!self.directionChangeTime || LK.ticks - self.directionChangeTime > self.directionChangeInterval) {
- self.directionChangeTime = LK.ticks;
- self.directionChangeInterval = Math.random() * (self.maxChangeInterval - self.minChangeInterval) + self.minChangeInterval;
- 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;
- }
- self.x += Math.cos(self.rotation) * self.speed;
- self.y += Math.sin(self.rotation) * self.speed;
- var waterBounds = self.getWaterBounds();
- self.x = Math.max(waterBounds.left, Math.min(self.x, waterBounds.right));
- self.y = Math.max(waterBounds.top, Math.min(self.y, waterBounds.bottom));
- self.rotation = self.rotation % (Math.PI * 2);
- fishGraphics.scale.x = Math.cos(self.rotation) < 0 ? -1 : 1;
- fishGraphics.rotation = self.rotation;
- };
+ self.move = function () {};
});
var Parrotfish = Fish.expand(function () {
var self = Fish.call(this);
var fishGraphics = self.createAsset('parrotfish', 'Parrotfish Graphics', .5, .5);
@@ -352,11 +215,9 @@
var self = Fish.call(this);
var fishGraphics = self.createAsset('lionfish', 'Lionfish Graphics', .5, .5);
fishGraphics.scale.set(1, 1);
self.speed = Math.random() * 0.2 + 0.5;
- self.move = function () {
- fishGraphics.rotation = self.rotation;
- };
+ self.move = function () {};
});
var Surgeonfish = Fish.expand(function () {
var self = Fish.call(this);
var fishGraphics = self.createAsset('surgeonfish', 'Surgeonfish Graphics', .5, .5);
@@ -1250,133 +1111,29 @@
/****
* Game Code
****/
-game.updateElements = function () {
- game.fishes = [];
- var children = game.children.slice();
- for (var i = 0; i < children.length; i++) {
- if (children[i] instanceof Bubble || children[i] instanceof FishFood) {
- children[i].move();
- }
- if (children[i] instanceof DecorativePlant) {
- children[i].sway();
- children[i].move();
- }
- }
-};
-LK.on('tick', game.updateElements);
-for (var i = 0; i < 5; i++) {
- var plant = new DecorativePlant();
- game.aquarium = game.addChild(new Aquarium());
- var waterBounds = game.aquarium.getWaterBounds();
- plant.x = waterBounds.left + i * ((waterBounds.right - waterBounds.left) / 5);
- plant.y = waterBounds.bottom - plant.height / 2 - 600;
- game.addChild(plant);
-}
-var treasureChest = new TreasureChest();
-treasureChest.x = 2048 / 2;
-treasureChest.y = 2732 - 100;
-game.addChild(treasureChest);
-var feedButton = new Text2('Feed Fish', {
- size: 100,
- fill: '#ffffff'
-});
-feedButton.anchor.set(.5, 0);
-feedButton.x = 2048 / 2;
-feedButton.y = 50;
-LK.gui.topCenter.addChild(feedButton);
-feedButton.on('down', game.feedFish);
-game.feedFish = function () {
- var food = new FishFood();
- food.x = 2048 / 2;
- food.y = 0;
- game.addChild(food);
-};
-game.spawnBubble = function () {
- var bubble = new Bubble();
- bubble.x = Math.random() * 2048;
- bubble.y = 2732;
- game.addChild(bubble);
-};
-var bubbleSpawnTimer = LK.setInterval(game.spawnBubble, 2000);
-game.spawnBubble = function () {
- var bubble = new Bubble();
- bubble.x = Math.random() * 2048;
- bubble.y = 2732;
- game.addChild(bubble);
-};
-game.aquarium = game.addChild(new Aquarium());
+var aquarium = game.addChild(new Aquarium());
game.setBackgroundColor(0x008080);
-game.fishes = [];
-LK.on('tick', function () {
- for (var i = 0; i < game.fishes.length; i++) {
- game.fishes[i].move();
- }
-});
-LK.on('tick', function () {
- if (game.fishes) {
- for (var i = 0; i < game.fishes.length; i++) {
- game.fishes[i].move();
- }
- }
-});
-LK.on('tick', function () {
- for (var i = 0; i < game.fishes.length; i++) {
- game.fishes[i].move();
- }
-});
-for (var i = 0; i < 5; i++) {
- var plant = new DecorativePlant();
- plant.x = i * (2048 / 5);
- plant.y = 2732 - 50;
- game.addChild(plant);
-}
-LK.on('tick', function () {
- if (game.fishes && game.fishes.length) {
- for (var i = 0; i < game.fishes.length; i++) {
- game.fishes[i].move();
- }
- }
-});
-LK.on('tick', function () {
- for (var i = 0; i < game.fishes.length; i++) {
- game.fishes[i].move();
- }
-});
-LK.on('tick', function () {
- for (var i = 0; i < game.fishes.length; i++) {
- game.fishes[i].move();
- }
-});
-LK.on('tick', function () {
- for (var i = 0; i < game.fishes.length; i++) {
- game.fishes[i].move();
- }
-});
-LK.on('tick', function () {
- for (var i = 0; i < game.fishes.length; i++) {
- game.fishes[i].move();
- }
-});
+var fishes = [];
+var fishTypes = [Wrasses, Parrotfish, Dartfish, MoorishIdol, Tangfish, Bannerfish, Butterflyfish, Mandarinfish, Lionfish, Surgeonfish, Pufferfish, Clownfish, Angelfish, KoiFish, EmperorFish, Goldfish, Sunfish, GuppyFish, BettaFish, DiscusFish, NeonTetra, OscarFish, PsychedelicFrogfish, FlameScallop, RibbonEel, LeafySeaDragon, ClownTriggerfish, ElectricBlueDamsel, YellowTang, FlameHawkfish, RoyalGramma, FlameAngel, BlueTang, Moonfish, Starfish, CardinalTetra];
var fishTypes = [ZebraDanio, CelestialPearlDanio, Wrasses, Parrotfish, Dartfish, MoorishIdol, Tangfish, Bannerfish, Butterflyfish, Mandarinfish, Lionfish, Surgeonfish, Pufferfish, Clownfish, Angelfish, KoiFish, EmperorFish, Goldfish, Sunfish, GuppyFish, BettaFish, DiscusFish, NeonTetra, OscarFish, ElectricCatfish, RainbowTrout, PsychedelicFrogfish, FlameScallop, RibbonEel, LeafySeaDragon, ClownTriggerfish, ElectricBlueDamsel, YellowTang, FlameHawkfish, RoyalGramma, FlameAngel, BlueTang, Moonfish, Starfish, GlassCatfish, DiamondTetra, PeacockBass, CrimsonSnapper, CardinalTetra, CometFish, EmeraldGoby];
-var that = void 0;
fishTypes.forEach(function (fishType) {
var fish = new fishType();
if (typeof fish.move === 'function') {
- var waterBounds = game.aquarium.getWaterBounds();
+ var waterBounds = aquarium.getWaterBounds();
var centerX = waterBounds.left + (waterBounds.right - waterBounds.left) / 2;
var centerY = waterBounds.top + (waterBounds.bottom - waterBounds.top) / 2;
var maxDistance = 500;
var angle = Math.random() * Math.PI * 2;
var distance = Math.random() * maxDistance;
fish.x = centerX + Math.cos(angle) * distance;
fish.y = centerY + Math.sin(angle) * distance;
- that.fishes.push(fish);
+ fishes.push(fish);
game.addChild(fish);
}
});
LK.on('tick', function () {
- for (var i = 0; i < game.fishes.length; i++) {
- game.fishes[i].move();
+ for (var i = 0; i < fishes.length; i++) {
+ fishes[i].move();
}
});
\ No newline at end of file
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.