User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'toString')' in or related to this line: 'self.satietyText = new Text2(self.satiety.toString(), {' Line Number: 649
User prompt
отобрази сытость над головой пираньи
User prompt
сделай баланс 500
User prompt
я хочу добаввить новую рыбу. Это пиранья. У меня уже готова иконка и модель рыбы. Добавь их. Стоимость пираньи 200. Пиранья ведет себя точно также как и все рыбы кроме того что она не ест корм. Она ест fish.
User prompt
пиранья стоит на месте исправь это
User prompt
движенье пираньи такоеже как и обычной рыбы. Она почему-то стоит на месте
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'call')' in or related to this line: 'Piran.prototype.update.call(piran);' Line Number: 623
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'call')' in or related to this line: 'self.update.call(piran);' Line Number: 623
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'call')' in or related to this line: 'Piran.prototype.update.call(piran);' Line Number: 623
User prompt
полностью проверь весь код на наличие ошибки 3
User prompt
пираньи не появляются их что-то съедает судя по звуку. Исправь это
User prompt
стоимость пираньи 200 и отобрази ее под иконкой. Пираньи не питаются обычным кормом они едят маленьких рыб (fish)
Code edit (1 edits merged)
Please save this source code
User prompt
почему пока я не нажму iconfish я не вижу iconpiran исправь это
User prompt
я не вижу иконки сразу
User prompt
Исправь и сделай так что бы было видно иконку сразу
User prompt
добавь iconpiran справа от последней иконки. при нажатии Iconpiran создаются рыбы piran.
User prompt
piran должны есть fish когда у них сытость 30 или меньше
User prompt
что-то съедает piran когда у них сытость 30. Так бфть не должно.
User prompt
найди в чем проблем и исправь
User prompt
piran должна есть fish а не наоборот
User prompt
покажи сытость piran над ее головой
Code edit (1 edits merged)
Please save this source code
User prompt
иконку почему то видно не сразу
User prompt
добавь iconpiran справа от последней иконки. при нажатии Iconpiran создаются рыбы piran. У них такоеже поведение как и у обычных рыб, но у них сытость 120 и питаются они обычными рыбами (fish) которые восстанавливают 90 сытости. А стоят они 200.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Aquarium class representing the aquarium var Aquarium = Container.expand(function () { var self = Container.call(this); var aquariumGraphics = self.attachAsset('Aquarium', { anchorX: 0.5, anchorY: 0.5 }); self.x = 2048 / 2; self.y = 2732 / 2; var scale = Math.min(2048 / aquariumGraphics.width, 2732 / aquariumGraphics.height); self.scaleX = scale; self.scaleY = scale; }); // BigCorm class representing a falling bigcorm var BigCorm = Container.expand(function () { var self = Container.call(this); var bigCormGraphics = self.attachAsset('bigcorm', { anchorX: 0.5, anchorY: 0.5 }); // Set initial falling speed self.fallingSpeed = 2 / 1.5; // Update function to move the bigcorm downwards self.update = function () { self.y += self.fallingSpeed; if (self.y > aquarium.y + aquarium.height / 2 - 100) { self.y = aquarium.y + aquarium.height / 2 - 100; self.update = null; // Stop updating position // Start the timer for bigcorm disappearance LK.setTimeout(function () { if (bigCorns.includes(self)) { self.destroy(); bigCorns.splice(bigCorns.indexOf(self), 1); } }, 1000); } }; }); // Bubble class representing a bubble created by fish var Bubble = Container.expand(function () { var self = Container.call(this); var randomScale = Math.random() * 0.5 + 0.75; // Random scale between 0.75 and 1.25 var bubbleGraphics = self.attachAsset('bubble', { anchorX: 0.5, anchorY: 0.5, alpha: 0.7, // Set transparency to 50% scaleX: randomScale, scaleY: randomScale }); // Initialize bubble position and speed self.speed = Math.random() * 0.5 + 0.5; // Random speed for each bubble // Update function to move the bubble upwards self.update = function () { self.y -= self.speed * 4; self.x += Math.sin(LK.ticks / 20) * 0.5; // Oscillate horizontally if (self.y < 730) { self.pop(); } }; // Function to pop the bubble self.pop = function () { // Add pop animation or effect here if needed LK.getSound('Lop').play(); self.destroy(); bubbles.splice(bubbles.indexOf(self), 1); }; }); // Coin class representing a coin dropped by a fish var Coin = Container.expand(function () { var self = Container.call(this); var coinGraphics = self.attachAsset('coin', { anchorX: 0.5, anchorY: 0.5 }); // Update function to move the coin downwards self.update = function () { self.y += 2 / 1.5; if (self.y > aquarium.y + aquarium.height / 2 - 100) { self.y = aquarium.y + aquarium.height / 2 - 100; self.update = null; // Stop updating position // Start the timer for coin disappearance LK.setTimeout(function () { if (coins.includes(self)) { self.destroy(); coins.splice(coins.indexOf(self), 1); } }, 5000); } // Add click event to coin self.down = function (x, y, obj) { // Play sound when coin is clicked LK.getSound('MonetaUp').play(); // Create a tween to animate the coin flying to the balance tween(self, { x: 2048 / 2, y: 0, scaleX: 0.5, scaleY: 0.5 }, { duration: 1000, onFinish: function onFinish() { balance += 10; balanceText.setText('$' + balance); self.destroy(); coins.splice(coins.indexOf(self), 1); } }); }; }; }); // Coin2 class representing a new type of coin dropped by big fish var Coin2 = Container.expand(function () { var self = Container.call(this); var coinGraphics = self.attachAsset('coin2', { anchorX: 0.5, anchorY: 0.5 }); // Update function to move the coin downwards self.update = function () { self.y += 2 / 1.5; if (self.y > aquarium.y + aquarium.height / 2 - 100) { self.y = aquarium.y + aquarium.height / 2 - 100; self.update = null; // Stop updating position // Start the timer for coin disappearance LK.setTimeout(function () { if (coins.includes(self)) { self.destroy(); coins.splice(coins.indexOf(self), 1); } }, 5000); } }; // Add click event to coin self.down = function (x, y, obj) { // Play sound when coin is clicked LK.getSound('MonetaUp').play(); // Create a tween to animate the coin flying to the balance tween(self, { x: 2048 / 2, y: 0, scaleX: 0.5, scaleY: 0.5 }, { duration: 1000, onFinish: function onFinish() { balance += 30; // Increase balance by 30 balanceText.setText('$' + balance); self.destroy(); coins.splice(coins.indexOf(self), 1); } }); }; }); // Corm class representing a falling corm var Corm = Container.expand(function () { var self = Container.call(this); var cormGraphics = self.attachAsset('corm', { anchorX: 0.5, anchorY: 0.5 }); // Set initial falling speed self.fallingSpeed = 2 / 1.5; // Update function to move the corm downwards self.update = function () { self.y += self.fallingSpeed; if (self.y > aquarium.y + aquarium.height / 2 - 100) { self.y = aquarium.y + aquarium.height / 2 - 100; self.update = null; // Stop updating position // Start the timer for corm disappearance LK.setTimeout(function () { if (corms.includes(self)) { self.destroy(); corms.splice(corms.indexOf(self), 1); } }, 1000); } }; }); // Fish class representing a fish in the aquarium var Fish = Container.expand(function () { var self = Container.call(this); var fishGraphics = self.attachAsset('fish', { anchorX: 0.5, anchorY: 0.5, alpha: 3 }); self.speed = Math.random() * 2 + 1; // Random speed for each fish self.direction = 1; // Fish always swim to the right when they appear // Initialize satiety variable self.satiety = 60; // Update function to move the fish self.verticalInterval = Math.random() * 100 + 50; // Random interval for vertical movement self.update = function () { if (self.satiety > 30 || self.satiety <= 30 && (self.hasGrown ? bigCorns.length === 0 : corms.length === 0)) { if (Math.random() < 0.002) { // Reduce the chance of pausing self.speed = 0; // Random pause self.pauseDuration = Math.random() * 100 + 50; // Random pause duration between 50 and 150 ticks } else if (self.speed === 0 && self.pauseDuration > 0) { self.pauseDuration--; // Decrease pause duration } else { self.speed = Math.random() * 2 + 1; // Randomize speed again after pause } // Check if fish is too close to the left or right edge and adjust direction if (self.x < aquarium.x - aquarium.width / 2 + 100) { self.direction = 1; // Move right fishGraphics.scaleX = 1; // Ensure fish is facing right } else if (self.x > aquarium.x + aquarium.width / 2 - 100) { self.direction = -1; // Move left fishGraphics.scaleX = -1; // Ensure fish is facing left } self.x += self.speed * self.direction; self.y += Math.sin(LK.ticks / self.verticalInterval) * self.speed; // Smooth vertical movement based on unique interval // Randomly change direction and speed if (Math.random() < 0.0033) { self.direction *= -1; // Change horizontal direction self.speed = Math.random() * 2 + 1; // Randomize speed fishGraphics.scaleX = self.direction < 0 ? -1 : 1; // Flip the fish based on direction } } else { // Move towards the nearest corm var nearestCorm = null; var minDistance = Infinity; var availableCorns = self.hasGrown ? bigCorns : corms; availableCorns.forEach(function (corm) { var distance = Math.sqrt(Math.pow(corm.x - self.x, 2) + Math.pow(corm.y - self.y, 2)); if (distance < minDistance) { minDistance = distance; nearestCorm = corm; } }); if (nearestCorm) { var angle = Math.atan2(nearestCorm.y - self.y, nearestCorm.x - self.x); self.x += Math.cos(angle) * 4; self.y += Math.sin(angle) * 4; fishGraphics.scaleX = Math.cos(angle) < 0 ? -1 : 1; // Flip the fish based on direction // Check if fish intersects with the corm if (nearestCorm && self.intersects(nearestCorm)) { var index = availableCorns.indexOf(nearestCorm); if (index !== -1) { nearestCorm.destroy(); // Ensure corm is destroyed immediately upon consumption availableCorns.splice(index, 1); self.satiety = Math.min(100, self.satiety + 30); // Increase satiety by 30, max 100 self.cormsEaten += 1; // Increment cormsEaten counter LK.getSound('Emy').play(); // Play sound when fish eats a corm // Make fish turn around and swim in the opposite direction for 0.5 seconds self.direction *= -1; // Change direction fishGraphics.scaleX = self.direction < 0 ? -1 : 1; // Flip the fish based on direction self.speed = Math.random() * 2 + 1; // Randomize speed var originalDirection = self.direction; LK.setTimeout(function () { self.direction = originalDirection; // Restore original direction after 0.5 seconds fishGraphics.scaleX = self.direction < 0 ? -1 : 1; // Flip the fish based on direction }, 500); } // Reset nearestCorm to ensure fish targets a new corm nearestCorm = null; } } } // Ensure fish stays within aquarium bounds if (self.x < aquarium.x - aquarium.width / 2 || self.x > aquarium.x + aquarium.width / 2) { self.direction *= -1; // Change direction if fish hits the aquarium edge fishGraphics.scaleX = self.direction < 0 ? -1 : 1; // Flip the fish based on direction } if (self.y < aquarium.y - aquarium.height / 2 + 550) { self.y = aquarium.y - aquarium.height / 2 + 550; // Prevent fish from swimming above 600 units from the top boundary } else if (self.y > aquarium.y + aquarium.height / 2 - 50) { self.y = aquarium.y + aquarium.height / 2 - 50; // Prevent fish from swimming below the bottom boundary } // Update satiety display if (self.satiety <= 10) { fishGraphics.tint = 0xFFFF00; // Change color to yellow if (self.satiety <= 0) { // Spawn FishD at the fish's position var fishD = new FishD(); fishD.x = self.x; fishD.y = self.y; fishD.scaleX = fishGraphics.scaleX; fishD.scaleY = fishGraphics.scaleY; game.addChild(fishD); fishDs.push(fishD); LK.getSound('Deadfish').play(); // Play sound when fish dies self.destroy(); // Remove fish if satiety is 0 or less fishes.splice(fishes.indexOf(self), 1); // Check if no fish are left if (fishes.length === 0) { LK.setTimeout(function () { LK.showGameOver(); // Trigger game over after 3 seconds }, 3000); } return; // Exit update function to prevent further processing } } else { fishGraphics.tint = 0xFFFFFF; // Reset to original color } // Initialize individual coin drop timer if (self.lastCoinDropTime === undefined) { self.lastCoinDropTime = LK.ticks; } // Initialize cormsEaten counter for fish growth if (self.cormsEaten === undefined) { self.cormsEaten = 0; } // Check if fish has eaten 8 corms to grow if (!self.hasGrown && self.cormsEaten >= 8) { self.grow(); self.hasGrown = true; // Mark the fish as grown } // Drop a coin every 15 seconds for each fish if (LK.ticks - self.lastCoinDropTime >= 60 * 15) { self.dropCoin(); self.lastCoinDropTime = LK.ticks; } }; // Function to grow the fish self.grow = function () { // Change fish texture to bigfish fishGraphics.texture = LK.getAsset('bigfish', {}).texture; // Play growth sound LK.getSound('rost').play(); tween(fishGraphics, { width: LK.getAsset('bigfish', {}).width, height: LK.getAsset('bigfish', {}).height }, { duration: 2000, easing: tween.easeInOut }); // Override dropCoin function to drop coin2 self.dropCoin = function () { var coin = new Coin2(); coin.x = self.x; coin.y = self.y; game.addChild(coin); coins.push(coin); LK.getSound('MonetaSpawn').play(); // Create 3 bubbles when a coin is created for (var i = 0; i < 3; i++) { var bubble = new Bubble(); bubble.x = self.x + (Math.random() - 0.5) * 50; // Slightly randomize x position bubble.y = self.y + (Math.random() - 0.5) * 50; // Slightly randomize y position bubble.scaleX = 0.5; // Set bubble size to half bubble.scaleY = 0.5; // Set bubble size to half game.addChild(bubble); bubbles.push(bubble); } LK.getSound('spawnpuzir').play(); // Play sound when bubbles are created }; }; // Function to drop a coin self.dropCoin = function () { var coin = new Coin(); coin.x = self.x; coin.y = self.y; game.addChild(coin); coins.push(coin); LK.getSound('MonetaSpawn').play(); // Create 3 bubbles when a coin is created for (var i = 0; i < 3; i++) { var bubble = new Bubble(); bubble.x = self.x + (Math.random() - 0.5) * 50; // Slightly randomize x position bubble.y = self.y + (Math.random() - 0.5) * 50; // Slightly randomize y position bubble.scaleX = 0.5; // Set bubble size to half bubble.scaleY = 0.5; // Set bubble size to half game.addChild(bubble); bubbles.push(bubble); } LK.getSound('spawnpuzir').play(); // Play sound when bubbles are created }; }); // FishD class representing a fish skeleton var FishD = Container.expand(function () { var self = Container.call(this); var fishDGraphics = self.attachAsset('FishD', { anchorX: 0.5, anchorY: 0.5, tint: 0xFFFF00 // Change color to yellow }); // Initialize position and speed self.speed = 2 / 1.5; // Update function to move the fish skeleton downwards self.update = function () { self.y += self.speed; if (self.y >= aquarium.y + aquarium.height / 2 - 50) { self.y = aquarium.y + aquarium.height / 2 - 50; self.update = null; // Stop updating position // Start shrinking after reaching the bottom tween(self, { scaleX: 0.1, scaleY: 0.1 }, { duration: 3000, onFinish: function onFinish() { self.destroy(); fishDs.splice(fishDs.indexOf(self), 1); } }); } }; }); // InterfacePanel class representing the interface panel var InterfacePanel = Container.expand(function () { var self = Container.call(this); self.width = 2048; self.height = 200; self.y = 0; self.x = 0; self.color = 0x000000; self.alpha = 1; // Function to add a fish to the aquarium self.addFish = function () { var fish = new Fish(); var angle = Math.random() * Math.PI * 2; var radius = Math.random() * 600; fish.x = aquarium.x + radius * Math.cos(angle); fish.y = aquarium.y + radius * Math.sin(angle); fishes.push(fish); game.addChild(fish); }; // Event listener for adding fish // Create a fish icon var fishIcon = self.attachAsset('iconFish', { anchorX: 0.5, anchorY: 0.5, x: 200, y: 500, alpha: 2 }); // Add cost display under fish icon var fishCostText = new Text2('$50', { size: 80, fill: 0x00FF00 }); fishCostText.anchor.set(0.5, 0); fishCostText.x = fishIcon.x; fishCostText.y = fishIcon.y + 100; self.addChild(fishCostText); // Create a corm icon var cormIcon = self.attachAsset('iconcorm', { anchorX: 0.5, anchorY: 0.5, x: 450, y: 500, alpha: 2 }); // Add cost display under corm icon var cormCostText = new Text2('$5', { size: 80, fill: 0x00FF00 }); cormCostText.anchor.set(0.5, 0); cormCostText.x = cormIcon.x; cormCostText.y = cormIcon.y + 100; self.addChild(cormCostText); // Create a bigcorm icon bigCormIcon = self.attachAsset('iconbigcorm', { anchorX: 0.5, anchorY: 0.5, x: 700, y: 500, alpha: 0.3 }); // Add cost display under bigcorm icon bigCormCostText = new Text2('$15', { size: 80, fill: 0x00FF00 }); bigCormCostText.anchor.set(0.5, 0); bigCormCostText.visible = bigCormIcon.alpha === 2; // Hide cost if alpha is not 2 bigCormCostText.x = bigCormIcon.x; bigCormCostText.y = bigCormIcon.y + 100; self.addChild(bigCormCostText); // Event listener for bigcorm icon bigCormIcon.down = function (x, y, obj) { if (bigCormIcon.alpha !== 2) { return; } // Prevent interaction if alpha is not 2 LK.getSound('clickkorm').play(); tween(bigCormIcon, { scaleX: 0.8, scaleY: 0.8 }, { duration: 100, onFinish: function onFinish() { tween(bigCormIcon, { scaleX: 1, scaleY: 1 }, { duration: 100 }); } }); // Create and drop a new bigcorm from the top if (balance >= 15) { balance -= 15; balanceText.setText('$' + balance); var bigCorm = new BigCorm(); bigCorm.x = Math.random() * (2048 - 500) + 200; // Random x position within 200 units from both edges bigCorm.y = 750; // Start from a slightly lower position game.addChild(bigCorm); bigCorns.push(bigCorm); } }; // Event listener for corm icon cormIcon.down = function (x, y, obj) { LK.getSound('clickkorm').play(); tween(cormIcon, { scaleX: 0.8, scaleY: 0.8 }, { duration: 100, onFinish: function onFinish() { tween(cormIcon, { scaleX: 1, scaleY: 1 }, { duration: 100 }); } }); // Create and drop a new corm from the top if (balance >= 5) { balance -= 5; balanceText.setText('$' + balance); var corm = new Corm(); corm.x = Math.random() * (2048 - 500) + 200; // Random x position within 200 units from both edges corm.y = 750; // Start from a slightly lower position game.addChild(corm); corms.push(corm); } }; // Event listener for adding fish fishIcon.down = function (x, y, obj) { if (balance >= 50) { balance -= 50; balanceText.setText('$' + balance); self.addFish(); LK.getSound('click').play(); } tween(fishIcon, { scaleX: 0.8, scaleY: 0.8 }, { duration: 100, onFinish: function onFinish() { tween(fishIcon, { scaleX: 1, scaleY: 1 }, { duration: 100 }); } }); // Create a piranha icon var piranIcon = self.attachAsset('iconpiran', { anchorX: 0.5, anchorY: 0.5, x: 950, y: 500, alpha: 2 }); // Add cost display under piranha icon var piranCostText = new Text2('$200', { size: 80, fill: 0x00FF00 }); piranCostText.anchor.set(0.5, 0); piranCostText.x = piranIcon.x; piranCostText.y = piranIcon.y + 100; self.addChild(piranCostText); // Event listener for piranha icon piranIcon.down = function (x, y, obj) { if (balance >= 200) { balance -= 200; balanceText.setText('$' + balance); var piran = new Piran(); var angle = Math.random() * Math.PI * 2; var radius = Math.random() * 600; piran.x = aquarium.x + radius * Math.cos(angle); piran.y = aquarium.y + radius * Math.sin(angle); game.addChild(piran); fishes.push(piran); // Add piranha to fishes array for update LK.getSound('click').play(); } tween(piranIcon, { scaleX: 0.8, scaleY: 0.8 }, { duration: 100, onFinish: function onFinish() { tween(piranIcon, { scaleX: 1, scaleY: 1 }, { duration: 100 }); } }); }; }; }); // Piran class representing a piranha in the aquarium var Piran = Container.expand(function () { var self = Container.call(this); var piranGraphics = self.attachAsset('piran', { anchorX: 0.5, anchorY: 0.5, alpha: 3 }); self.speed = Math.random() * 2 + 1; // Random speed for each piranha self.direction = 1; // Piranha always swim to the right when they appear // Initialize satiety variable self.satiety = 120; // Update function to move the piranha self.verticalInterval = Math.random() * 100 + 50; // Random interval for vertical movement self.update = function () { if (self.satiety > 30 || fishes.length === 0) { if (Math.random() < 0.002) { self.speed = 0; // Random pause self.pauseDuration = Math.random() * 100 + 50; // Random pause duration between 50 and 150 ticks } else if (self.speed === 0 && self.pauseDuration > 0) { self.pauseDuration--; // Decrease pause duration } else { self.speed = Math.random() * 2 + 1; // Randomize speed again after pause } // Check if piranha is too close to the left or right edge and adjust direction if (self.x < aquarium.x - aquarium.width / 2 + 100) { self.direction = 1; // Move right piranGraphics.scaleX = 1; // Ensure piranha is facing right } else if (self.x > aquarium.x + aquarium.width / 2 - 100) { self.direction = -1; // Move left piranGraphics.scaleX = -1; // Ensure piranha is facing left } self.x += self.speed * self.direction; self.y += Math.sin(LK.ticks / self.verticalInterval) * self.speed; // Smooth vertical movement based on unique interval // Randomly change direction and speed if (Math.random() < 0.0033) { self.direction *= -1; // Change horizontal direction self.speed = Math.random() * 2 + 1; // Randomize speed piranGraphics.scaleX = self.direction < 0 ? -1 : 1; // Flip the piranha based on direction } } else { // Move towards the nearest fish var nearestFish = null; var minDistance = Infinity; fishes.forEach(function (fish) { var distance = Math.sqrt(Math.pow(fish.x - self.x, 2) + Math.pow(fish.y - self.y, 2)); if (distance < minDistance) { minDistance = distance; nearestFish = fish; } }); if (nearestFish) { var angle = Math.atan2(nearestFish.y - self.y, nearestFish.x - self.x); self.x += Math.cos(angle) * 4; self.y += Math.sin(angle) * 4; piranGraphics.scaleX = Math.cos(angle) < 0 ? -1 : 1; // Flip the piranha based on direction // Check if piranha intersects with the fish if (nearestFish && self.intersects(nearestFish)) { var index = fishes.indexOf(nearestFish); if (index !== -1) { nearestFish.destroy(); // Ensure fish is destroyed immediately upon consumption fishes.splice(index, 1); self.satiety = Math.min(120, self.satiety + 90); // Increase satiety by 90, max 120 LK.getSound('Emy').play(); // Play sound when piranha eats a fish // Make piranha turn around and swim in the opposite direction for 0.5 seconds self.direction *= -1; // Change direction piranGraphics.scaleX = self.direction < 0 ? -1 : 1; // Flip the piranha based on direction self.speed = Math.random() * 2 + 1; // Randomize speed var originalDirection = self.direction; LK.setTimeout(function () { self.direction = originalDirection; // Restore original direction after 0.5 seconds piranGraphics.scaleX = self.direction < 0 ? -1 : 1; // Flip the piranha based on direction }, 500); } // Reset nearestFish to ensure piranha targets a new fish nearestFish = null; } } } // Ensure piranha stays within aquarium bounds if (self.x < aquarium.x - aquarium.width / 2 || self.x > aquarium.x + aquarium.width / 2) { self.direction *= -1; // Change direction if piranha hits the aquarium edge piranGraphics.scaleX = self.direction < 0 ? -1 : 1; // Flip the piranha based on direction } if (self.y < aquarium.y - aquarium.height / 2 + 550) { self.y = aquarium.y - aquarium.height / 2 + 550; // Prevent piranha from swimming above 600 units from the top boundary } else if (self.y > aquarium.y + aquarium.height / 2 - 50) { self.y = aquarium.y + aquarium.height / 2 - 50; // Prevent piranha from swimming below the bottom boundary } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize arrays and variables var bigCormIcon; // Define bigCormIcon in the global scope var bigCormCostText; // Declare bigCormCostText in the global scope var balance = 50; var balanceText = new Text2('$' + balance, { size: 100, fill: 0x00FF00 }); balanceText.anchor.set(0.5, 0); LK.gui.top.addChild(balanceText); var fishes = []; var coins = []; var corms = []; var bubbles = []; var fishDs = []; var bigCorns = []; var lastFeedTime = 0; // Decrease satiety of each fish every second LK.setInterval(function () { for (var i = 0; i < fishes.length; i++) { if (fishes[i].satiety <= 10) { fishes[i].satiety = Math.max(0, fishes[i].satiety - 1); // Decrease by 1 if satiety is 10 or less } else { fishes[i].satiety = Math.max(0, fishes[i].satiety - 2); // Decrease by 2 otherwise } //fishes[i].updateSatietyDisplay(); } }, 1000); // Create the aquarium var aquarium = new Aquarium(); game.addChild(aquarium); // Add a fish to the aquarium at the start of the game var initialFish = new Fish(); initialFish.x = aquarium.x; initialFish.y = aquarium.y; fishes.push(initialFish); game.addChild(initialFish); // Function to create bubbles function createBubbles() { if (bubbles.length < 6) { var bubbleCount = Math.random() < 0.5 ? 1 : 3; // Randomly decide to create 1 or 3 bubbles if (bubbleCount === 1) { var bubble = new Bubble(); bubble.x = Math.random() * (aquarium.width - 50) + aquarium.x - aquarium.width / 2 + 25; // Random x position within the aquarium bubble.y = aquarium.y + aquarium.height / 2 - 50; // Start from the bottom of the aquarium game.addChild(bubble); bubbles.push(bubble); LK.getSound('spawnpuzir').play(); // Play sound when a bubble is created } else { var baseX = Math.random() * (aquarium.width - 50) + aquarium.x - aquarium.width / 2 + 25; // Random x position within the aquarium var baseY = aquarium.y + aquarium.height / 2 - 50; // Start from the bottom of the aquarium for (var i = 0; i < bubbleCount; i++) { LK.setTimeout(function () { var bubble = new Bubble(); bubble.x = baseX; bubble.y = baseY; game.addChild(bubble); bubbles.push(bubble); LK.getSound('spawnpuzir').play(); // Play sound when a bubble is created }, i * 500); // Cascade with 0.5 second interval } } } // Set a new random interval between 10 to 20 seconds LK.setTimeout(createBubbles, Math.random() * 10000 + 10000); } // Start the first bubble creation createBubbles(); // Create the interface panel var interfacePanel = new InterfacePanel(); game.addChild(interfacePanel); // Game update function game.update = function () { // Update all coins for (var j = 0; j < coins.length; j++) { if (coins[j] && typeof coins[j].update === 'function') { coins[j].update(); } } ; // Update all bubbles for (var l = 0; l < bubbles.length; l++) { bubbles[l].update(); } // Update all corms for (var k = 0; k < corms.length; k++) { if (corms[k] && typeof corms[k].update === 'function') { corms[k].update(); } } // Update all bigCorns for (var n = 0; n < bigCorns.length; n++) { if (bigCorns[n] && typeof bigCorns[n].update === 'function') { bigCorns[n].update(); } } // Update all FishD instances for (var m = 0; m < fishDs.length; m++) { if (typeof fishDs[m].update === 'function') { fishDs[m].update(); } } // Check if at least one fish has grown if (fishes.some(function (fish) { return fish.hasGrown; })) { bigCormIcon.alpha = 2; bigCormCostText.visible = true; // Ensure cost text is visible when alpha is 2 } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Aquarium class representing the aquarium
var Aquarium = Container.expand(function () {
var self = Container.call(this);
var aquariumGraphics = self.attachAsset('Aquarium', {
anchorX: 0.5,
anchorY: 0.5
});
self.x = 2048 / 2;
self.y = 2732 / 2;
var scale = Math.min(2048 / aquariumGraphics.width, 2732 / aquariumGraphics.height);
self.scaleX = scale;
self.scaleY = scale;
});
// BigCorm class representing a falling bigcorm
var BigCorm = Container.expand(function () {
var self = Container.call(this);
var bigCormGraphics = self.attachAsset('bigcorm', {
anchorX: 0.5,
anchorY: 0.5
});
// Set initial falling speed
self.fallingSpeed = 2 / 1.5;
// Update function to move the bigcorm downwards
self.update = function () {
self.y += self.fallingSpeed;
if (self.y > aquarium.y + aquarium.height / 2 - 100) {
self.y = aquarium.y + aquarium.height / 2 - 100;
self.update = null; // Stop updating position
// Start the timer for bigcorm disappearance
LK.setTimeout(function () {
if (bigCorns.includes(self)) {
self.destroy();
bigCorns.splice(bigCorns.indexOf(self), 1);
}
}, 1000);
}
};
});
// Bubble class representing a bubble created by fish
var Bubble = Container.expand(function () {
var self = Container.call(this);
var randomScale = Math.random() * 0.5 + 0.75; // Random scale between 0.75 and 1.25
var bubbleGraphics = self.attachAsset('bubble', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.7,
// Set transparency to 50%
scaleX: randomScale,
scaleY: randomScale
});
// Initialize bubble position and speed
self.speed = Math.random() * 0.5 + 0.5; // Random speed for each bubble
// Update function to move the bubble upwards
self.update = function () {
self.y -= self.speed * 4;
self.x += Math.sin(LK.ticks / 20) * 0.5; // Oscillate horizontally
if (self.y < 730) {
self.pop();
}
};
// Function to pop the bubble
self.pop = function () {
// Add pop animation or effect here if needed
LK.getSound('Lop').play();
self.destroy();
bubbles.splice(bubbles.indexOf(self), 1);
};
});
// Coin class representing a coin dropped by a fish
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
// Update function to move the coin downwards
self.update = function () {
self.y += 2 / 1.5;
if (self.y > aquarium.y + aquarium.height / 2 - 100) {
self.y = aquarium.y + aquarium.height / 2 - 100;
self.update = null; // Stop updating position
// Start the timer for coin disappearance
LK.setTimeout(function () {
if (coins.includes(self)) {
self.destroy();
coins.splice(coins.indexOf(self), 1);
}
}, 5000);
}
// Add click event to coin
self.down = function (x, y, obj) {
// Play sound when coin is clicked
LK.getSound('MonetaUp').play();
// Create a tween to animate the coin flying to the balance
tween(self, {
x: 2048 / 2,
y: 0,
scaleX: 0.5,
scaleY: 0.5
}, {
duration: 1000,
onFinish: function onFinish() {
balance += 10;
balanceText.setText('$' + balance);
self.destroy();
coins.splice(coins.indexOf(self), 1);
}
});
};
};
});
// Coin2 class representing a new type of coin dropped by big fish
var Coin2 = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin2', {
anchorX: 0.5,
anchorY: 0.5
});
// Update function to move the coin downwards
self.update = function () {
self.y += 2 / 1.5;
if (self.y > aquarium.y + aquarium.height / 2 - 100) {
self.y = aquarium.y + aquarium.height / 2 - 100;
self.update = null; // Stop updating position
// Start the timer for coin disappearance
LK.setTimeout(function () {
if (coins.includes(self)) {
self.destroy();
coins.splice(coins.indexOf(self), 1);
}
}, 5000);
}
};
// Add click event to coin
self.down = function (x, y, obj) {
// Play sound when coin is clicked
LK.getSound('MonetaUp').play();
// Create a tween to animate the coin flying to the balance
tween(self, {
x: 2048 / 2,
y: 0,
scaleX: 0.5,
scaleY: 0.5
}, {
duration: 1000,
onFinish: function onFinish() {
balance += 30; // Increase balance by 30
balanceText.setText('$' + balance);
self.destroy();
coins.splice(coins.indexOf(self), 1);
}
});
};
});
// Corm class representing a falling corm
var Corm = Container.expand(function () {
var self = Container.call(this);
var cormGraphics = self.attachAsset('corm', {
anchorX: 0.5,
anchorY: 0.5
});
// Set initial falling speed
self.fallingSpeed = 2 / 1.5;
// Update function to move the corm downwards
self.update = function () {
self.y += self.fallingSpeed;
if (self.y > aquarium.y + aquarium.height / 2 - 100) {
self.y = aquarium.y + aquarium.height / 2 - 100;
self.update = null; // Stop updating position
// Start the timer for corm disappearance
LK.setTimeout(function () {
if (corms.includes(self)) {
self.destroy();
corms.splice(corms.indexOf(self), 1);
}
}, 1000);
}
};
});
// Fish class representing a fish in the aquarium
var Fish = Container.expand(function () {
var self = Container.call(this);
var fishGraphics = self.attachAsset('fish', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 3
});
self.speed = Math.random() * 2 + 1; // Random speed for each fish
self.direction = 1; // Fish always swim to the right when they appear
// Initialize satiety variable
self.satiety = 60;
// Update function to move the fish
self.verticalInterval = Math.random() * 100 + 50; // Random interval for vertical movement
self.update = function () {
if (self.satiety > 30 || self.satiety <= 30 && (self.hasGrown ? bigCorns.length === 0 : corms.length === 0)) {
if (Math.random() < 0.002) {
// Reduce the chance of pausing
self.speed = 0; // Random pause
self.pauseDuration = Math.random() * 100 + 50; // Random pause duration between 50 and 150 ticks
} else if (self.speed === 0 && self.pauseDuration > 0) {
self.pauseDuration--; // Decrease pause duration
} else {
self.speed = Math.random() * 2 + 1; // Randomize speed again after pause
}
// Check if fish is too close to the left or right edge and adjust direction
if (self.x < aquarium.x - aquarium.width / 2 + 100) {
self.direction = 1; // Move right
fishGraphics.scaleX = 1; // Ensure fish is facing right
} else if (self.x > aquarium.x + aquarium.width / 2 - 100) {
self.direction = -1; // Move left
fishGraphics.scaleX = -1; // Ensure fish is facing left
}
self.x += self.speed * self.direction;
self.y += Math.sin(LK.ticks / self.verticalInterval) * self.speed; // Smooth vertical movement based on unique interval
// Randomly change direction and speed
if (Math.random() < 0.0033) {
self.direction *= -1; // Change horizontal direction
self.speed = Math.random() * 2 + 1; // Randomize speed
fishGraphics.scaleX = self.direction < 0 ? -1 : 1; // Flip the fish based on direction
}
} else {
// Move towards the nearest corm
var nearestCorm = null;
var minDistance = Infinity;
var availableCorns = self.hasGrown ? bigCorns : corms;
availableCorns.forEach(function (corm) {
var distance = Math.sqrt(Math.pow(corm.x - self.x, 2) + Math.pow(corm.y - self.y, 2));
if (distance < minDistance) {
minDistance = distance;
nearestCorm = corm;
}
});
if (nearestCorm) {
var angle = Math.atan2(nearestCorm.y - self.y, nearestCorm.x - self.x);
self.x += Math.cos(angle) * 4;
self.y += Math.sin(angle) * 4;
fishGraphics.scaleX = Math.cos(angle) < 0 ? -1 : 1; // Flip the fish based on direction
// Check if fish intersects with the corm
if (nearestCorm && self.intersects(nearestCorm)) {
var index = availableCorns.indexOf(nearestCorm);
if (index !== -1) {
nearestCorm.destroy(); // Ensure corm is destroyed immediately upon consumption
availableCorns.splice(index, 1);
self.satiety = Math.min(100, self.satiety + 30); // Increase satiety by 30, max 100
self.cormsEaten += 1; // Increment cormsEaten counter
LK.getSound('Emy').play(); // Play sound when fish eats a corm
// Make fish turn around and swim in the opposite direction for 0.5 seconds
self.direction *= -1; // Change direction
fishGraphics.scaleX = self.direction < 0 ? -1 : 1; // Flip the fish based on direction
self.speed = Math.random() * 2 + 1; // Randomize speed
var originalDirection = self.direction;
LK.setTimeout(function () {
self.direction = originalDirection; // Restore original direction after 0.5 seconds
fishGraphics.scaleX = self.direction < 0 ? -1 : 1; // Flip the fish based on direction
}, 500);
}
// Reset nearestCorm to ensure fish targets a new corm
nearestCorm = null;
}
}
}
// Ensure fish stays within aquarium bounds
if (self.x < aquarium.x - aquarium.width / 2 || self.x > aquarium.x + aquarium.width / 2) {
self.direction *= -1; // Change direction if fish hits the aquarium edge
fishGraphics.scaleX = self.direction < 0 ? -1 : 1; // Flip the fish based on direction
}
if (self.y < aquarium.y - aquarium.height / 2 + 550) {
self.y = aquarium.y - aquarium.height / 2 + 550; // Prevent fish from swimming above 600 units from the top boundary
} else if (self.y > aquarium.y + aquarium.height / 2 - 50) {
self.y = aquarium.y + aquarium.height / 2 - 50; // Prevent fish from swimming below the bottom boundary
}
// Update satiety display
if (self.satiety <= 10) {
fishGraphics.tint = 0xFFFF00; // Change color to yellow
if (self.satiety <= 0) {
// Spawn FishD at the fish's position
var fishD = new FishD();
fishD.x = self.x;
fishD.y = self.y;
fishD.scaleX = fishGraphics.scaleX;
fishD.scaleY = fishGraphics.scaleY;
game.addChild(fishD);
fishDs.push(fishD);
LK.getSound('Deadfish').play(); // Play sound when fish dies
self.destroy(); // Remove fish if satiety is 0 or less
fishes.splice(fishes.indexOf(self), 1);
// Check if no fish are left
if (fishes.length === 0) {
LK.setTimeout(function () {
LK.showGameOver(); // Trigger game over after 3 seconds
}, 3000);
}
return; // Exit update function to prevent further processing
}
} else {
fishGraphics.tint = 0xFFFFFF; // Reset to original color
}
// Initialize individual coin drop timer
if (self.lastCoinDropTime === undefined) {
self.lastCoinDropTime = LK.ticks;
}
// Initialize cormsEaten counter for fish growth
if (self.cormsEaten === undefined) {
self.cormsEaten = 0;
}
// Check if fish has eaten 8 corms to grow
if (!self.hasGrown && self.cormsEaten >= 8) {
self.grow();
self.hasGrown = true; // Mark the fish as grown
}
// Drop a coin every 15 seconds for each fish
if (LK.ticks - self.lastCoinDropTime >= 60 * 15) {
self.dropCoin();
self.lastCoinDropTime = LK.ticks;
}
};
// Function to grow the fish
self.grow = function () {
// Change fish texture to bigfish
fishGraphics.texture = LK.getAsset('bigfish', {}).texture;
// Play growth sound
LK.getSound('rost').play();
tween(fishGraphics, {
width: LK.getAsset('bigfish', {}).width,
height: LK.getAsset('bigfish', {}).height
}, {
duration: 2000,
easing: tween.easeInOut
});
// Override dropCoin function to drop coin2
self.dropCoin = function () {
var coin = new Coin2();
coin.x = self.x;
coin.y = self.y;
game.addChild(coin);
coins.push(coin);
LK.getSound('MonetaSpawn').play();
// Create 3 bubbles when a coin is created
for (var i = 0; i < 3; i++) {
var bubble = new Bubble();
bubble.x = self.x + (Math.random() - 0.5) * 50; // Slightly randomize x position
bubble.y = self.y + (Math.random() - 0.5) * 50; // Slightly randomize y position
bubble.scaleX = 0.5; // Set bubble size to half
bubble.scaleY = 0.5; // Set bubble size to half
game.addChild(bubble);
bubbles.push(bubble);
}
LK.getSound('spawnpuzir').play(); // Play sound when bubbles are created
};
};
// Function to drop a coin
self.dropCoin = function () {
var coin = new Coin();
coin.x = self.x;
coin.y = self.y;
game.addChild(coin);
coins.push(coin);
LK.getSound('MonetaSpawn').play();
// Create 3 bubbles when a coin is created
for (var i = 0; i < 3; i++) {
var bubble = new Bubble();
bubble.x = self.x + (Math.random() - 0.5) * 50; // Slightly randomize x position
bubble.y = self.y + (Math.random() - 0.5) * 50; // Slightly randomize y position
bubble.scaleX = 0.5; // Set bubble size to half
bubble.scaleY = 0.5; // Set bubble size to half
game.addChild(bubble);
bubbles.push(bubble);
}
LK.getSound('spawnpuzir').play(); // Play sound when bubbles are created
};
});
// FishD class representing a fish skeleton
var FishD = Container.expand(function () {
var self = Container.call(this);
var fishDGraphics = self.attachAsset('FishD', {
anchorX: 0.5,
anchorY: 0.5,
tint: 0xFFFF00 // Change color to yellow
});
// Initialize position and speed
self.speed = 2 / 1.5;
// Update function to move the fish skeleton downwards
self.update = function () {
self.y += self.speed;
if (self.y >= aquarium.y + aquarium.height / 2 - 50) {
self.y = aquarium.y + aquarium.height / 2 - 50;
self.update = null; // Stop updating position
// Start shrinking after reaching the bottom
tween(self, {
scaleX: 0.1,
scaleY: 0.1
}, {
duration: 3000,
onFinish: function onFinish() {
self.destroy();
fishDs.splice(fishDs.indexOf(self), 1);
}
});
}
};
});
// InterfacePanel class representing the interface panel
var InterfacePanel = Container.expand(function () {
var self = Container.call(this);
self.width = 2048;
self.height = 200;
self.y = 0;
self.x = 0;
self.color = 0x000000;
self.alpha = 1;
// Function to add a fish to the aquarium
self.addFish = function () {
var fish = new Fish();
var angle = Math.random() * Math.PI * 2;
var radius = Math.random() * 600;
fish.x = aquarium.x + radius * Math.cos(angle);
fish.y = aquarium.y + radius * Math.sin(angle);
fishes.push(fish);
game.addChild(fish);
};
// Event listener for adding fish
// Create a fish icon
var fishIcon = self.attachAsset('iconFish', {
anchorX: 0.5,
anchorY: 0.5,
x: 200,
y: 500,
alpha: 2
});
// Add cost display under fish icon
var fishCostText = new Text2('$50', {
size: 80,
fill: 0x00FF00
});
fishCostText.anchor.set(0.5, 0);
fishCostText.x = fishIcon.x;
fishCostText.y = fishIcon.y + 100;
self.addChild(fishCostText);
// Create a corm icon
var cormIcon = self.attachAsset('iconcorm', {
anchorX: 0.5,
anchorY: 0.5,
x: 450,
y: 500,
alpha: 2
});
// Add cost display under corm icon
var cormCostText = new Text2('$5', {
size: 80,
fill: 0x00FF00
});
cormCostText.anchor.set(0.5, 0);
cormCostText.x = cormIcon.x;
cormCostText.y = cormIcon.y + 100;
self.addChild(cormCostText);
// Create a bigcorm icon
bigCormIcon = self.attachAsset('iconbigcorm', {
anchorX: 0.5,
anchorY: 0.5,
x: 700,
y: 500,
alpha: 0.3
});
// Add cost display under bigcorm icon
bigCormCostText = new Text2('$15', {
size: 80,
fill: 0x00FF00
});
bigCormCostText.anchor.set(0.5, 0);
bigCormCostText.visible = bigCormIcon.alpha === 2; // Hide cost if alpha is not 2
bigCormCostText.x = bigCormIcon.x;
bigCormCostText.y = bigCormIcon.y + 100;
self.addChild(bigCormCostText);
// Event listener for bigcorm icon
bigCormIcon.down = function (x, y, obj) {
if (bigCormIcon.alpha !== 2) {
return;
} // Prevent interaction if alpha is not 2
LK.getSound('clickkorm').play();
tween(bigCormIcon, {
scaleX: 0.8,
scaleY: 0.8
}, {
duration: 100,
onFinish: function onFinish() {
tween(bigCormIcon, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
}
});
// Create and drop a new bigcorm from the top
if (balance >= 15) {
balance -= 15;
balanceText.setText('$' + balance);
var bigCorm = new BigCorm();
bigCorm.x = Math.random() * (2048 - 500) + 200; // Random x position within 200 units from both edges
bigCorm.y = 750; // Start from a slightly lower position
game.addChild(bigCorm);
bigCorns.push(bigCorm);
}
};
// Event listener for corm icon
cormIcon.down = function (x, y, obj) {
LK.getSound('clickkorm').play();
tween(cormIcon, {
scaleX: 0.8,
scaleY: 0.8
}, {
duration: 100,
onFinish: function onFinish() {
tween(cormIcon, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
}
});
// Create and drop a new corm from the top
if (balance >= 5) {
balance -= 5;
balanceText.setText('$' + balance);
var corm = new Corm();
corm.x = Math.random() * (2048 - 500) + 200; // Random x position within 200 units from both edges
corm.y = 750; // Start from a slightly lower position
game.addChild(corm);
corms.push(corm);
}
};
// Event listener for adding fish
fishIcon.down = function (x, y, obj) {
if (balance >= 50) {
balance -= 50;
balanceText.setText('$' + balance);
self.addFish();
LK.getSound('click').play();
}
tween(fishIcon, {
scaleX: 0.8,
scaleY: 0.8
}, {
duration: 100,
onFinish: function onFinish() {
tween(fishIcon, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
}
});
// Create a piranha icon
var piranIcon = self.attachAsset('iconpiran', {
anchorX: 0.5,
anchorY: 0.5,
x: 950,
y: 500,
alpha: 2
});
// Add cost display under piranha icon
var piranCostText = new Text2('$200', {
size: 80,
fill: 0x00FF00
});
piranCostText.anchor.set(0.5, 0);
piranCostText.x = piranIcon.x;
piranCostText.y = piranIcon.y + 100;
self.addChild(piranCostText);
// Event listener for piranha icon
piranIcon.down = function (x, y, obj) {
if (balance >= 200) {
balance -= 200;
balanceText.setText('$' + balance);
var piran = new Piran();
var angle = Math.random() * Math.PI * 2;
var radius = Math.random() * 600;
piran.x = aquarium.x + radius * Math.cos(angle);
piran.y = aquarium.y + radius * Math.sin(angle);
game.addChild(piran);
fishes.push(piran); // Add piranha to fishes array for update
LK.getSound('click').play();
}
tween(piranIcon, {
scaleX: 0.8,
scaleY: 0.8
}, {
duration: 100,
onFinish: function onFinish() {
tween(piranIcon, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
}
});
};
};
});
// Piran class representing a piranha in the aquarium
var Piran = Container.expand(function () {
var self = Container.call(this);
var piranGraphics = self.attachAsset('piran', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 3
});
self.speed = Math.random() * 2 + 1; // Random speed for each piranha
self.direction = 1; // Piranha always swim to the right when they appear
// Initialize satiety variable
self.satiety = 120;
// Update function to move the piranha
self.verticalInterval = Math.random() * 100 + 50; // Random interval for vertical movement
self.update = function () {
if (self.satiety > 30 || fishes.length === 0) {
if (Math.random() < 0.002) {
self.speed = 0; // Random pause
self.pauseDuration = Math.random() * 100 + 50; // Random pause duration between 50 and 150 ticks
} else if (self.speed === 0 && self.pauseDuration > 0) {
self.pauseDuration--; // Decrease pause duration
} else {
self.speed = Math.random() * 2 + 1; // Randomize speed again after pause
}
// Check if piranha is too close to the left or right edge and adjust direction
if (self.x < aquarium.x - aquarium.width / 2 + 100) {
self.direction = 1; // Move right
piranGraphics.scaleX = 1; // Ensure piranha is facing right
} else if (self.x > aquarium.x + aquarium.width / 2 - 100) {
self.direction = -1; // Move left
piranGraphics.scaleX = -1; // Ensure piranha is facing left
}
self.x += self.speed * self.direction;
self.y += Math.sin(LK.ticks / self.verticalInterval) * self.speed; // Smooth vertical movement based on unique interval
// Randomly change direction and speed
if (Math.random() < 0.0033) {
self.direction *= -1; // Change horizontal direction
self.speed = Math.random() * 2 + 1; // Randomize speed
piranGraphics.scaleX = self.direction < 0 ? -1 : 1; // Flip the piranha based on direction
}
} else {
// Move towards the nearest fish
var nearestFish = null;
var minDistance = Infinity;
fishes.forEach(function (fish) {
var distance = Math.sqrt(Math.pow(fish.x - self.x, 2) + Math.pow(fish.y - self.y, 2));
if (distance < minDistance) {
minDistance = distance;
nearestFish = fish;
}
});
if (nearestFish) {
var angle = Math.atan2(nearestFish.y - self.y, nearestFish.x - self.x);
self.x += Math.cos(angle) * 4;
self.y += Math.sin(angle) * 4;
piranGraphics.scaleX = Math.cos(angle) < 0 ? -1 : 1; // Flip the piranha based on direction
// Check if piranha intersects with the fish
if (nearestFish && self.intersects(nearestFish)) {
var index = fishes.indexOf(nearestFish);
if (index !== -1) {
nearestFish.destroy(); // Ensure fish is destroyed immediately upon consumption
fishes.splice(index, 1);
self.satiety = Math.min(120, self.satiety + 90); // Increase satiety by 90, max 120
LK.getSound('Emy').play(); // Play sound when piranha eats a fish
// Make piranha turn around and swim in the opposite direction for 0.5 seconds
self.direction *= -1; // Change direction
piranGraphics.scaleX = self.direction < 0 ? -1 : 1; // Flip the piranha based on direction
self.speed = Math.random() * 2 + 1; // Randomize speed
var originalDirection = self.direction;
LK.setTimeout(function () {
self.direction = originalDirection; // Restore original direction after 0.5 seconds
piranGraphics.scaleX = self.direction < 0 ? -1 : 1; // Flip the piranha based on direction
}, 500);
}
// Reset nearestFish to ensure piranha targets a new fish
nearestFish = null;
}
}
}
// Ensure piranha stays within aquarium bounds
if (self.x < aquarium.x - aquarium.width / 2 || self.x > aquarium.x + aquarium.width / 2) {
self.direction *= -1; // Change direction if piranha hits the aquarium edge
piranGraphics.scaleX = self.direction < 0 ? -1 : 1; // Flip the piranha based on direction
}
if (self.y < aquarium.y - aquarium.height / 2 + 550) {
self.y = aquarium.y - aquarium.height / 2 + 550; // Prevent piranha from swimming above 600 units from the top boundary
} else if (self.y > aquarium.y + aquarium.height / 2 - 50) {
self.y = aquarium.y + aquarium.height / 2 - 50; // Prevent piranha from swimming below the bottom boundary
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize arrays and variables
var bigCormIcon; // Define bigCormIcon in the global scope
var bigCormCostText; // Declare bigCormCostText in the global scope
var balance = 50;
var balanceText = new Text2('$' + balance, {
size: 100,
fill: 0x00FF00
});
balanceText.anchor.set(0.5, 0);
LK.gui.top.addChild(balanceText);
var fishes = [];
var coins = [];
var corms = [];
var bubbles = [];
var fishDs = [];
var bigCorns = [];
var lastFeedTime = 0;
// Decrease satiety of each fish every second
LK.setInterval(function () {
for (var i = 0; i < fishes.length; i++) {
if (fishes[i].satiety <= 10) {
fishes[i].satiety = Math.max(0, fishes[i].satiety - 1); // Decrease by 1 if satiety is 10 or less
} else {
fishes[i].satiety = Math.max(0, fishes[i].satiety - 2); // Decrease by 2 otherwise
}
//fishes[i].updateSatietyDisplay();
}
}, 1000);
// Create the aquarium
var aquarium = new Aquarium();
game.addChild(aquarium);
// Add a fish to the aquarium at the start of the game
var initialFish = new Fish();
initialFish.x = aquarium.x;
initialFish.y = aquarium.y;
fishes.push(initialFish);
game.addChild(initialFish);
// Function to create bubbles
function createBubbles() {
if (bubbles.length < 6) {
var bubbleCount = Math.random() < 0.5 ? 1 : 3; // Randomly decide to create 1 or 3 bubbles
if (bubbleCount === 1) {
var bubble = new Bubble();
bubble.x = Math.random() * (aquarium.width - 50) + aquarium.x - aquarium.width / 2 + 25; // Random x position within the aquarium
bubble.y = aquarium.y + aquarium.height / 2 - 50; // Start from the bottom of the aquarium
game.addChild(bubble);
bubbles.push(bubble);
LK.getSound('spawnpuzir').play(); // Play sound when a bubble is created
} else {
var baseX = Math.random() * (aquarium.width - 50) + aquarium.x - aquarium.width / 2 + 25; // Random x position within the aquarium
var baseY = aquarium.y + aquarium.height / 2 - 50; // Start from the bottom of the aquarium
for (var i = 0; i < bubbleCount; i++) {
LK.setTimeout(function () {
var bubble = new Bubble();
bubble.x = baseX;
bubble.y = baseY;
game.addChild(bubble);
bubbles.push(bubble);
LK.getSound('spawnpuzir').play(); // Play sound when a bubble is created
}, i * 500); // Cascade with 0.5 second interval
}
}
}
// Set a new random interval between 10 to 20 seconds
LK.setTimeout(createBubbles, Math.random() * 10000 + 10000);
}
// Start the first bubble creation
createBubbles();
// Create the interface panel
var interfacePanel = new InterfacePanel();
game.addChild(interfacePanel);
// Game update function
game.update = function () {
// Update all coins
for (var j = 0; j < coins.length; j++) {
if (coins[j] && typeof coins[j].update === 'function') {
coins[j].update();
}
}
;
// Update all bubbles
for (var l = 0; l < bubbles.length; l++) {
bubbles[l].update();
}
// Update all corms
for (var k = 0; k < corms.length; k++) {
if (corms[k] && typeof corms[k].update === 'function') {
corms[k].update();
}
}
// Update all bigCorns
for (var n = 0; n < bigCorns.length; n++) {
if (bigCorns[n] && typeof bigCorns[n].update === 'function') {
bigCorns[n].update();
}
}
// Update all FishD instances
for (var m = 0; m < fishDs.length; m++) {
if (typeof fishDs[m].update === 'function') {
fishDs[m].update();
}
}
// Check if at least one fish has grown
if (fishes.some(function (fish) {
return fish.hasGrown;
})) {
bigCormIcon.alpha = 2;
bigCormCostText.visible = true; // Ensure cost text is visible when alpha is 2
}
};
прозрачный пузырь воздуха. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Потрепаная рыбе
древняя Монетка, постэльные цвета. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Потрепаная рыба
сундук с сокровищами с видом спереди, постэльные цвета. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
предупреждение о нападении акул без надписей, постэльные цвета.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Морской Монстр, вид с боку, накаченные мышцы, постэльные цвета.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Большой прозрачный радужный пузырь. пастельные цвета Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
осьминог повар, минимализм, пастельные цвета \. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
spawnpuzir
Sound effect
Lop
Sound effect
click
Sound effect
clickkorm
Sound effect
Emy
Sound effect
MonetaSpawn
Sound effect
MonetaUp
Sound effect
Deadfish
Sound effect
rost
Sound effect
akulaspawn
Sound effect
ataka
Sound effect
emyakula
Sound effect
sundukup
Sound effect
Music
Music
music2
Music
udarbonus
Sound effect
udarbonus2
Sound effect
udarbonus3
Sound effect
startbonus
Sound effect
osmincorm
Sound effect