User prompt
добавь картинку pearl над текстом pearl
User prompt
jgecnb brjyre yf 600
User prompt
добавь иконку pearl
User prompt
размести иконку pearl на уровне баланса
User prompt
убери надпись pearls
User prompt
значек pearl привязан к тексту? Ты можешь картинку опустить а текст оставить на месте? Отвечай по русски
User prompt
ты опускаешь значек вместе с счетчиком не надо так делать. Верни счетчик туда где он был.
User prompt
да нет же просто сам значек пониже а счетчик оставь на томже уровне
User prompt
опусти значек пониже на 30
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'x')' in or related to this line: 'var pearlIcon = LK.getAsset('pearl', {' Line Number: 1663
User prompt
сделай значек по центру наверху счетчика
User prompt
убери надпись pearls и вместо нее поставь иконку pt=earl
User prompt
хочу добавить еще один счетчик справа от баланса. Это счетчик жемчуга со значком pearl справа
User prompt
для акул сделай 1000 а для монстров 3000
User prompt
теперь снова попробуй добавить пульсацию текста баланса при увеличении но другим методом ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
удали все что связано с пульсацией текста баланса. Так как слишком много не нужного и не рабочего кода
User prompt
Не помогло ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
все равно нет. Может нужно переписать заного и что-то сделать по другому?
User prompt
я не вижу никакого эффекта пульсации ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
опять небыло ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
и снова небыло эффекта ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
я не увидел эффекта пульсации ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
сделай эффект пульсации ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
увеличь скорость с которой монеты летят к балансу в 1.5 раз
User prompt
правее на 50 и ниже на 50
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
leaderboard: []
});
/****
* Classes
****/
// Akula class representing a shark in the aquarium
var Akula = Container.expand(function () {
var self = Container.call(this);
var akulaGraphics = self.attachAsset('akula', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = Math.random() * 2 + 1; // Random speed for each Akula
self.direction = 1; // Akula always swim to the right when they appear
self.health = 15; // Initial health for Akula
// Update function to move the Akula
self.update = function () {
// Check if Akula's health is 0 or less
if (self.health <= 0) {
// Spawn Sunduk at Akula's position
var sunduk = new Sunduk();
sunduk.x = self.x;
sunduk.y = self.y;
game.addChild(sunduk);
coins.push(sunduk);
self.destroy(); // Remove Akula from the game
return; // Exit update function to prevent further processing
}
// Initialize lastApproachTime if not already set
if (self.lastApproachTime === undefined) {
self.lastApproachTime = LK.ticks;
}
// Find the nearest fish to approach
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 && (self.lastEatTime === undefined || LK.ticks - self.lastEatTime >= 300)) {
// Ensure at least 5 seconds have passed since last eat
var angleToFish = Math.atan2(nearestFish.y - self.y, nearestFish.x - self.x);
self.x += Math.cos(angleToFish) * 4; // Move towards the fish
self.y += Math.sin(angleToFish) * 4;
akulaGraphics.scaleX = Math.cos(angleToFish) < 0 ? -1 : 1; // Flip the Akula based on direction
// Check if Akula intersects with the fish
if (self.intersects(nearestFish)) {
var index = fishes.indexOf(nearestFish);
if (index !== -1) {
nearestFish.destroy(); // Ensure fish is destroyed immediately upon consumption
fishes.splice(index, 1);
LK.getSound('emyakula').play(); // Play sound when Akula eats a fish
self.lastEatTime = LK.ticks; // Update last eat time
}
}
}
if (self.x < aquarium.x - aquarium.width / 2 + 100) {
self.direction = 1; // Move right
akulaGraphics.scaleX = 1; // Ensure Akula is facing right
} else if (self.x > aquarium.x + aquarium.width / 2 - 100) {
self.direction = -1; // Move left
akulaGraphics.scaleX = -1; // Ensure Akula is facing left
}
self.x += self.speed * self.direction;
self.y += Math.sin(LK.ticks / 100) * self.speed; // Smooth vertical movement
// Ensure Akula stays within aquarium bounds
if (self.y < aquarium.y - aquarium.height / 2 + 550) {
self.y = aquarium.y - aquarium.height / 2 + 550; // Prevent Akula from swimming above 600 units from the top boundary
} else if (self.y > aquarium.y + aquarium.height / 2 - 100) {
self.y = aquarium.y + aquarium.height / 2 - 100; // Prevent Akula from swimming below the bottom boundary
}
// Randomly change direction and speed
if (Math.random() < 0.0033) {
self.direction *= -1; // Change horizontal direction
self.speed = Math.random() * 2 + 1; // Randomize speed
akulaGraphics.scaleX = self.direction < 0 ? -1 : 1; // Flip the Akula based on direction
}
};
});
// 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 - 200; // Adjust position to accommodate icons at the bottom
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);
}
};
});
var BonusBubble = Container.expand(function () {
var self = Container.call(this);
var bonusBubbleGraphics = self.attachAsset('bonus1', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.9,
scaleX: 0.5,
scaleY: 0.5
});
// Add visual representation of food inside the bonus bubble
var hasBigFish = fishes.some(function (fish) {
return fish.hasGrown;
});
var randomValue = Math.random() * 100;
if (randomValue < 35) {
self.level = 1; // 35% chance for level 1
} else if (randomValue < 70) {
self.level = 2; // 35% chance for level 2
} else if (randomValue < 80) {
self.level = 3; // 10% chance for level 3
} else if (randomValue < 90) {
self.level = 4; // 10% chance for level 4
} else {
self.level = 5; // 10% chance for level 5
}
var foodGraphics = [];
if (self.level === 1) {
var additionalItems = Math.floor(LK.getScore() / 200); // Calculate additional items based on score
var foodCount = Math.floor(Math.random() * 6) + 5 + additionalItems; // Level 1 contains 5 to 10 regular food plus additional items
for (var i = 0; i < foodCount; i++) {
var food = self.attachAsset('corm', {
anchorX: 0.5,
anchorY: 0.5,
x: (Math.random() - 0.5) * 100,
y: (Math.random() - 0.5) * 100,
scaleX: 1,
scaleY: 1
});
foodGraphics.push(food);
}
} else if (self.level === 2) {
var additionalItems = Math.floor(LK.getScore() / 200); // Calculate additional items based on score
var foodCount = Math.floor(Math.random() * 6) + 5 + additionalItems; // Level 2 contains 5 to 10 big food plus additional items
for (var i = 0; i < foodCount; i++) {
var food = self.attachAsset('bigcorm', {
anchorX: 0.5,
anchorY: 0.5,
x: (Math.random() - 0.5) * 100,
y: (Math.random() - 0.5) * 100,
scaleX: 1,
scaleY: 1
});
foodGraphics.push(food);
}
} else if (self.level === 3) {
var additionalItems = Math.floor(LK.getScore() / 200); // Calculate additional items based on score
var fishCount = Math.floor(Math.random() * 3) + 3; // Level 3 contains 3 to 5 small fish
for (var i = 0; i < fishCount; i++) {
var smallFish = self.attachAsset('fish', {
anchorX: 0.5,
anchorY: 0.5,
x: (Math.random() - 0.5) * 100,
y: (Math.random() - 0.5) * 100,
scaleX: 1,
scaleY: 1
});
foodGraphics.push(smallFish);
}
} else if (self.level === 4) {
var piranhaCount = Math.floor(Math.random() * 3) + 1; // Level 4 contains 1 to 3 piranhas
for (var i = 0; i < piranhaCount; i++) {
var piranha = self.attachAsset('piran', {
anchorX: 0.5,
anchorY: 0.5,
x: (Math.random() - 0.5) * 100,
y: (Math.random() - 0.5) * 100,
scaleX: 1,
scaleY: 1
});
foodGraphics.push(piranha);
}
} else if (self.level === 5) {
var osmin = self.attachAsset('osmin', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 0,
scaleX: 1,
scaleY: 1
});
foodGraphics.push(osmin);
}
self.health = 3 + (self.level - 1) * 2; // Increase health by 2 for each level above 1
self.speed = Math.random() * 0.5 + 0.5; // Random speed for each bonus bubble
// Update function to move the bonus bubble upwards
self.update = function () {
self.x -= self.speed * 4; // Move left
self.y += Math.sin(LK.ticks / 20) * 2; // Oscillate vertically
if (self.x < -self.width / 2) {
// Check if off-screen to the left
self.destroy();
bonusBubbles.splice(bonusBubbles.indexOf(self), 1);
}
};
// Function to pop the bonus bubble
self.pop = function () {
LK.getSound('Lop').play();
// Spawn random amount of food
// Use the existing food graphics to spawn food at the position of BonusBubble
foodGraphics.forEach(function (food) {
if (self.level === 1) {
var corm = new Corm();
corm.x = self.x + food.x; // Use the same relative position
corm.y = self.y + food.y;
game.addChild(corm);
corms.push(corm);
} else if (self.level === 2) {
var bigCorm = new BigCorm();
bigCorm.x = self.x + food.x; // Use the same relative position
bigCorm.y = self.y + food.y;
game.addChild(bigCorm);
bigCorns.push(bigCorm);
} else if (self.level === 3) {
var fish = new Fish();
fish.x = self.x + food.x; // Use the same relative position
fish.y = self.y + food.y;
fish.scaleX = 1; // Normal size for fish
fish.scaleY = 1;
game.addChild(fish);
fishes.push(fish);
} else if (self.level === 4) {
var piranha = new Piranha();
piranha.x = self.x + food.x; // Use the same relative position
piranha.y = self.y + food.y;
piranha.scaleX = 1; // Normal size for piranha
piranha.scaleY = 1;
game.addChild(piranha);
piranhas.push(piranha);
} else if (self.level === 5) {
var osmin = new Osmin();
osmin.x = self.x + food.x; // Use the same relative position
osmin.y = self.y + food.y;
game.addChild(osmin);
}
});
// Spawn 5 regular bubbles at the position of the BonusBubble
for (var i = 0; i < 5; 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
game.addChild(bubble);
bubbles.push(bubble);
// Add explosion effect to bubbles
var randomDirection = Math.random() * Math.PI * 2;
tween(bubble, {
x: bubble.x + Math.cos(randomDirection) * 150,
y: bubble.y + Math.sin(randomDirection) * 150
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
// After explosion effect, make bubbles float upwards as usual
bubble.update = function () {
bubble.y -= bubble.speed * 4;
bubble.x += Math.sin(LK.ticks / 20) * 0.5;
if (bubble.y < 580) {
bubble.pop();
}
};
}
});
}
self.destroy();
bonusBubbles.splice(bonusBubbles.indexOf(self), 1);
};
// Function to handle tap on bonus bubble
self.down = function (x, y, obj) {
self.health -= 1;
// Apply a quick shrink and expand animation
tween(bonusBubbleGraphics, {
scaleX: 0.4,
scaleY: 0.4
}, {
duration: 50,
onFinish: function onFinish() {
tween(bonusBubbleGraphics, {
scaleX: 0.5,
scaleY: 0.5
}, {
duration: 50
});
}
});
if (self.health > 2) {
LK.getSound('udarbonus').play();
} else if (self.health === 2) {
LK.getSound('udarbonus2').play();
} else if (self.health === 1) {
LK.getSound('udarbonus3').play();
self.pop();
}
};
});
// 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 < 580) {
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 += 4 / 1.5;
if (self.y > aquarium.y + aquarium.height / 2 - 100) {
self.y = aquarium.y + aquarium.height / 2 - 100;
// Start the timer for coin disappearance
if (!self.disappearanceTimer) {
self.disappearanceTimer = 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) {
if (self.isFlying) {
return;
} // Prevent multiple clicks while flying
self.isFlying = true; // Set flying state
// Play sound when coin is clicked
LK.getSound('MonetaUp').play();
// Create a tween to animate the coin flying to the balance
tween(self, {
x: balanceText.x + balanceText.width / 2 + 950,
y: balanceText.y + balanceText.height / 2 + 130,
scaleX: 0.5,
scaleY: 0.5
}, {
duration: 1000,
onFinish: function onFinish() {
if (typeof LK.setScore === 'function') {
LK.setScore(LK.getScore() + 1); // Increment score by 1
scoreText.setText('Score: ' + LK.getScore()); // Update score display
}
balance += 10;
balanceText.setText('$' + balance);
fishCostText.setText('$' + calculateFishCost());
// Animate balance text
tween(balanceText, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 100,
onFinish: function onFinish() {
tween(balanceText, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
}
});
self.destroy();
if (coins.includes(self)) {
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 += 4 / 1.5;
if (self.y > aquarium.y + aquarium.height / 2 - 100) {
self.y = aquarium.y + aquarium.height / 2 - 100;
// Start the timer for coin disappearance
if (!self.disappearanceTimer) {
self.disappearanceTimer = 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) {
if (self.isFlying) {
return;
} // Prevent multiple clicks while flying
self.isFlying = true; // Set flying state
// Play sound when coin is clicked
LK.getSound('MonetaUp').play();
// Create a tween to animate the coin flying to the balance
tween(self, {
x: balanceText.x + balanceText.width / 2 + 950,
y: balanceText.y + balanceText.height / 2 + 130,
scaleX: 0.5,
scaleY: 0.5
}, {
duration: 1000,
onFinish: function onFinish() {
if (typeof LK.setScore === 'function') {
LK.setScore(LK.getScore() + 3); // Increment score by 3
scoreText.setText('Score: ' + LK.getScore()); // Update score display
}
balance += 30; // Increase balance by 30
balanceText.setText('$' + balance);
self.destroy();
if (coins.includes(self)) {
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)) {
// Check if Akula is nearby and make fish flee towards the boundaries
if (game.children.some(function (child) {
return child instanceof Akula;
})) {
var nearestAkula = null;
var minDistanceToAkula = Infinity;
game.children.forEach(function (child) {
if (child instanceof Akula) {
var distance = Math.sqrt(Math.pow(child.x - self.x, 2) + Math.pow(child.y - self.y, 2));
if (distance < minDistanceToAkula) {
minDistanceToAkula = distance;
nearestAkula = child;
}
}
});
if (nearestAkula && minDistanceToAkula < 500) {
var angleAwayFromAkula = Math.atan2(self.y - nearestAkula.y, self.x - nearestAkula.x);
var newX = self.x + Math.cos(angleAwayFromAkula) * 4;
var newY = self.y + Math.sin(angleAwayFromAkula) * 4;
// Ensure fish do not move outside the aquarium boundaries
if (newX > aquarium.x - aquarium.width / 2 + 50 && newX < aquarium.x + aquarium.width / 2 - 50) {
self.x = newX;
}
if (newY > aquarium.y - aquarium.height / 2 + 50 && newY < aquarium.y + aquarium.height / 2 - 50) {
self.y = newY;
}
fishGraphics.scaleX = Math.cos(angleAwayFromAkula) < 0 ? -1 : 1; // Flip the fish based on direction
}
}
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 - 100) {
self.y = aquarium.y + aquarium.height / 2 - 100; // 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 5 corms to grow
if (!self.hasGrown && self.cormsEaten >= 5) {
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 * 10) {
// Increase frequency by 1.5 times
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 = 1; // Set bubble size to normal
bubble.scaleY = 1; // Set bubble size to normal
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 - 100) {
self.y = aquarium.y + aquarium.height / 2 - 100;
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);
fishCostText.setText('$' + calculateFishCost());
};
// Event listener for adding fish
// Create a fish icon
self.fishIcon = self.attachAsset('iconFish', {
anchorX: 0.5,
anchorY: 0.5,
x: 200,
y: 2732 - 300,
// Move to the bottom of the screen
alpha: 2
});
// Add cost display under fish icon
fishCostText = new Text2('$' + calculateFishCost(), {
size: 80,
fill: 0x00FF00
});
fishCostText.anchor.set(0.5, 0);
fishCostText.x = self.fishIcon.x;
fishCostText.y = self.fishIcon.y + 150;
self.addChild(fishCostText);
// Create a corm icon
var cormIcon = self.attachAsset('iconcorm', {
anchorX: 0.5,
anchorY: 0.5,
x: 610,
y: 2732 - 300,
// Move to the bottom of the screen
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 + 150;
self.addChild(cormCostText);
// Create a bigcorm icon
bigCormIcon = self.attachAsset('iconbigcorm', {
anchorX: 0.5,
anchorY: 0.5,
x: 1020,
y: 2732 - 300,
// Move to the bottom of the screen
alpha: 0.3
});
// Create a piranha icon
var piranhaIcon = self.attachAsset('iconpiran', {
anchorX: 0.5,
anchorY: 0.5,
x: 1430,
y: 2732 - 300,
// Move to the bottom of the screen
alpha: 2
});
// Add cost display under piranha icon
var piranhaCostText = new Text2('$250', {
size: 80,
fill: 0x00FF00
});
piranhaCostText.anchor.set(0.5, 0);
piranhaCostText.x = piranhaIcon.x;
piranhaCostText.y = piranhaIcon.y + 150;
self.addChild(piranhaCostText);
// 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 + 150;
self.addChild(bigCormCostText);
// Create a krab icon
var krabIcon = self.attachAsset('iconkrab', {
anchorX: 0.5,
anchorY: 0.5,
x: 1840,
y: 2732 - 300,
// Move to the bottom of the screen
alpha: 2
});
// Add cost display under krab icon
var krabCostText = new Text2('$500', {
size: 80,
fill: 0x00FF00
});
krabCostText.anchor.set(0.5, 0);
krabCostText.x = krabIcon.x;
krabCostText.y = krabIcon.y + 150;
self.addChild(krabCostText);
// Event listener for krab icon
krabIcon.down = function (x, y, obj) {
if (balance >= 500) {
balance -= 500;
balanceText.setText('$' + balance);
var krab = new Krab();
krab.x = aquarium.x;
krab.y = aquarium.y + aquarium.height / 2 - 100; // Position at the bottom
game.addChild(krab);
LK.getSound('click').play();
}
tween(krabIcon, {
scaleX: 0.8,
scaleY: 0.8
}, {
duration: 100,
onFinish: function onFinish() {
tween(krabIcon, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
}
});
};
// 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
self.fishIcon.down = function (x, y, obj) {
var fishCost = calculateFishCost();
if (balance >= fishCost) {
balance -= fishCost;
balanceText.setText('$' + balance);
self.addFish();
LK.getSound('click').play();
}
tween(self.fishIcon, {
scaleX: 0.8,
scaleY: 0.8
}, {
duration: 100,
onFinish: function onFinish() {
tween(self.fishIcon, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
}
});
};
// Event listener for adding piranha
piranhaIcon.down = function (x, y, obj) {
if (balance >= 250) {
balance -= 250;
balanceText.setText('$' + balance);
var piranha = new Piranha();
var angle = Math.random() * Math.PI * 2;
var radius = Math.random() * 600;
piranha.x = aquarium.x + radius * Math.cos(angle);
piranha.y = aquarium.y + radius * Math.sin(angle);
piranhas.push(piranha);
game.addChild(piranha);
LK.getSound('click').play();
}
tween(piranhaIcon, {
scaleX: 0.8,
scaleY: 0.8
}, {
duration: 100,
onFinish: function onFinish() {
tween(piranhaIcon, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
}
});
};
});
// Krab class representing a crab that collects coins and chests
var Krab = Container.expand(function () {
var self = Container.call(this);
var krabGraphics = self.attachAsset('krab', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2; // Set speed for the crab
self.direction = 1; // Initial direction to the right
// Update function to move the crab
self.update = function () {
// Randomly pause or change direction
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
}
// Move the crab left and right
if (self.x < aquarium.x - aquarium.width / 2 + 100) {
self.direction = 1; // Move right
krabGraphics.scaleX = 1; // Ensure crab is facing right
} else if (self.x > aquarium.x + aquarium.width / 2 - 100) {
self.direction = -1; // Move left
krabGraphics.scaleX = -1; // Ensure crab is facing left
}
self.x += self.speed * self.direction;
// Move towards the nearest coin or sunduk
var nearestCoin = null;
var minDistance = Infinity;
coins.forEach(function (coin) {
var distance = Math.sqrt(Math.pow(coin.x - self.x, 2) + Math.pow(coin.y - self.y, 2));
if (distance < minDistance) {
minDistance = distance;
nearestCoin = coin;
}
});
if (nearestCoin) {
var angle = Math.atan2(nearestCoin.y - self.y, nearestCoin.x - self.x); // Move towards the coin
self.x += Math.cos(angle) * 1; // Reduce speed when moving towards a coin or sunduk
krabGraphics.scaleX = Math.cos(angle) < 0 ? -1 : 1; // Flip the crab based on direction
// Check if crab intersects with the coin
if (self.intersects(nearestCoin)) {
if (typeof nearestCoin.down === 'function') {
nearestCoin.down(); // Trigger the coin's collection logic
}
coins.splice(coins.indexOf(nearestCoin), 1); // Remove the coin from the array
}
}
};
});
// Monstr class representing a monster in the aquarium
var Monstr = Container.expand(function () {
var self = Container.call(this);
var monstrGraphics = self.attachAsset('Monstr', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 18; // Monstr has 3 times more health than Akula
// Create a text display for Monstr's health
self.health = 18; // Monstr has 3 times more health than Akula
self.speed = Math.random() * 2 + 1; // Random speed for each monster
self.direction = 1; // Monster always swim to the right when they appear
// Update function to move the monster
self.update = function () {
// Increase Monstr health by 1 for every 200 points scored
if (self.lastScore === undefined) {
self.lastScore = 0;
}
if (LK.getScore() >= self.lastScore + 500) {
self.health += 1;
self.lastScore += 500; // Increment lastScore by 500 to ensure health increases correctly
}
if (self.x < aquarium.x - aquarium.width / 2 + 100) {
self.direction = 1; // Move right
monstrGraphics.scaleX = 1; // Ensure monster is facing right
} else if (self.x > aquarium.x + aquarium.width / 2 - 100) {
self.direction = -1; // Move left
monstrGraphics.scaleX = -1; // Ensure monster is facing left
}
self.x += self.speed * self.direction;
if (self.x < -self.width / 2 || self.x > 2048 + self.width / 2 || self.health <= 0) {
self.destroy();
game.monstr = null;
// Spawn Sunduk at Monstr's position
var sunduk = new Sunduk2();
sunduk.x = self.x;
sunduk.y = self.y;
game.addChild(sunduk);
coins.push(sunduk);
}
// Find the nearest small fish
var nearestFish = null;
var minDistance = Infinity;
var targetFishes = fishes.filter(function (fish) {
return true; // Allow Monstr to target both small and big fish
});
targetFishes.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 && (self.lastEatTime === undefined || LK.ticks - self.lastEatTime >= 300)) {
// Move towards the nearest fish
var angle = Math.atan2(nearestFish.y - self.y, nearestFish.x - self.x);
self.x += Math.cos(angle) * 4;
self.y += Math.sin(angle) * 4;
monstrGraphics.scaleX = Math.cos(angle) < 0 ? -1 : 1; // Flip the monster based on direction
// Check if Monstr intersects with the fish
if (self.intersects(nearestFish)) {
if (self.lastEatTime === undefined || LK.ticks - self.lastEatTime >= 120) {
// Check if 2 seconds have passed
var index = fishes.indexOf(nearestFish);
if (index !== -1) {
nearestFish.destroy(); // Ensure fish is destroyed immediately upon consumption
fishes.splice(index, 1);
}
LK.getSound('emyakula').play(); // Play 'emyakula' sound when Monstr eats a fish
self.lastEatTime = LK.ticks; // Update last eat time
}
}
}
// Ensure Monstr stays within aquarium bounds
if (self.y < aquarium.y - aquarium.height / 2 + 550) {
self.y = aquarium.y - aquarium.height / 2 + 550; // Prevent Monstr 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 Monstr from swimming below the bottom boundary
}
// Randomly change direction and speed
if (Math.random() < 0.0033) {
self.direction *= -1; // Change horizontal direction
self.speed = Math.random() * 2 + 1; // Randomize speed
monstrGraphics.scaleX = self.direction < 0 ? -1 : 1; // Flip the monster based on direction
}
};
});
// Osmin class representing a new type of fish that swims like a regular fish but has no satiety
var Osmin = Container.expand(function () {
var self = Container.call(this);
var osminGraphics = self.attachAsset('osmin', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = Math.random() * 2 + 1; // Random speed for each Osmin
self.direction = 1; // Osmin always swim to the right when they appear
// Update function to move the Osmin
self.update = function () {
// Initialize lastFoodCreationTime if not already set
if (self.lastFoodCreationTime === undefined) {
self.lastFoodCreationTime = LK.ticks;
}
// Check if 4 seconds have passed since the last food creation
if (LK.ticks - self.lastFoodCreationTime >= 240) {
// Create food for 2 seconds
if (LK.ticks - self.lastFoodCreationTime < 360) {
if (LK.ticks % 30 === 0) {
LK.getSound('osmincorm').play(); // Play 'osmincorm' sound when Osmin creates food
var food; // Declare food variable
if (Math.random() < 0.5) {
// 50% chance to create big food
food = new BigCorm(); // Create big food
bigCorns.push(food); // Add to bigCorns array
} else {
food = new Corm(); // Create regular food
corms.push(food); // Add to corms array
}
food.x = self.x + (Math.random() - 0.5) * 100; // Slightly randomize x position
food.y = self.y + (Math.random() - 0.5) * 100; // Slightly randomize y position
game.addChild(food);
}
} else {
// Reset lastFoodCreationTime after 2 seconds of food creation
self.lastFoodCreationTime = LK.ticks;
}
}
if (self.x < aquarium.x - aquarium.width / 2 + 100) {
self.direction = 1; // Move right
osminGraphics.scaleX = 1; // Ensure Osmin is facing right
} else if (self.x > aquarium.x + aquarium.width / 2 - 100) {
self.direction = -1; // Move left
osminGraphics.scaleX = -1; // Ensure Osmin is facing left
}
self.x += self.speed * self.direction;
self.y += Math.sin(LK.ticks / 100) * self.speed; // Smooth vertical movement
if (self.y < aquarium.y - aquarium.height / 2 + 550) {
self.y = aquarium.y - aquarium.height / 2 + 550; // Prevent Osmin from swimming above 600 units from the top boundary
} else if (self.y > aquarium.y + aquarium.height / 2 - 100) {
self.y = aquarium.y + aquarium.height / 2 - 100; // Prevent Osmin from swimming below the bottom boundary
}
// Randomly change direction and speed
if (Math.random() < 0.0033) {
self.direction *= -1; // Change horizontal direction
self.speed = Math.random() * 2 + 1; // Randomize speed
osminGraphics.scaleX = self.direction < 0 ? -1 : 1; // Flip the Osmin based on direction
}
};
});
// Pirand class representing a piranha skeleton
var Pirand = Container.expand(function () {
var self = Container.call(this);
var pirandGraphics = self.attachAsset('pirand', {
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 piranha skeleton downwards
self.update = function () {
self.y += self.speed;
if (self.y >= aquarium.y + aquarium.height / 2 - 100) {
self.y = aquarium.y + aquarium.height / 2 - 100;
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);
}
});
}
};
});
// Piranha class representing a piranha in the aquarium
var Piranha = Container.expand(function () {
var self = Container.call(this);
var piranhaGraphics = self.attachAsset('piran', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 3
});
self.satiety = 160; // Initialize satiety variable
// Add satiety display above piranha's head
self.speed = Math.random() * 2 + 1; // Random speed for each piranha
self.direction = 1; // Piranha always swim to the right when they appear
self.satiety = 270; // Initialize satiety variable
self.verticalInterval = Math.random() * 100 + 50; // Random interval for vertical movement
// Update function to move the piranha
self.update = function () {
var targetFishes = fishes.filter(function (fish) {
return !fish.hasGrown;
});
if (self.satiety > 30 || self.satiety <= 30 && targetFishes.length === 0) {
// Check if Akula is nearby and attack if not hungry
var nearestTarget = null;
var minDistanceToTarget = Infinity;
game.children.forEach(function (child) {
if (child instanceof Akula || child instanceof Monstr) {
var distance = Math.sqrt(Math.pow(child.x - self.x, 2) + Math.pow(child.y - self.y, 2));
if (distance < minDistanceToTarget) {
minDistanceToTarget = distance;
nearestTarget = child;
}
}
});
if (nearestTarget) {
var distanceToTarget = minDistanceToTarget;
if (distanceToTarget < 200 && nearestTarget.x > aquarium.x - aquarium.width / 2 && nearestTarget.x < aquarium.x + aquarium.width / 2) {
// If target is within 200 units and fully inside the aquarium
if (self.lastAttackTime === undefined || LK.ticks - self.lastAttackTime >= 180) {
// Attack every 2 seconds
if (nearestTarget instanceof Akula || nearestTarget instanceof Monstr) {
nearestTarget.health -= 1; // Reduce target's health by 1
}
// Create ssd1 and ssd2 objects when target loses health
var ssd1 = new Container();
var ssd1Graphics = ssd1.attachAsset('ssd1', {
anchorX: 0.5,
anchorY: 0.5
});
ssd1.x = nearestTarget.x;
ssd1.y = nearestTarget.y;
game.addChild(ssd1);
var randomDirection1 = Math.random() * Math.PI * 2;
tween(ssd1, {
x: ssd1.x + Math.cos(randomDirection1) * 100,
y: ssd1.y + Math.sin(randomDirection1) * 100,
scaleX: 0.1,
scaleY: 0.1
}, {
duration: 1000,
onFinish: function onFinish() {
ssd1.destroy();
}
});
var ssd2 = new Container();
var ssd2Graphics = ssd2.attachAsset('ssd2', {
anchorX: 0.5,
anchorY: 0.5
});
ssd2.x = nearestTarget.x;
ssd2.y = nearestTarget.y;
game.addChild(ssd2);
var randomDirection2 = Math.random() * Math.PI * 2;
tween(ssd2, {
x: ssd2.x + Math.cos(randomDirection2) * 100,
y: ssd2.y + Math.sin(randomDirection2) * 100,
scaleX: 0.1,
scaleY: 0.1
}, {
duration: 1000,
onFinish: function onFinish() {
ssd2.destroy();
}
});
var ssd3 = new Container();
var ssd3Graphics = ssd3.attachAsset('ssd3', {
anchorX: 0.5,
anchorY: 0.5
});
ssd3.x = nearestTarget.x;
ssd3.y = nearestTarget.y;
game.addChild(ssd3);
var randomDirection3 = Math.random() * Math.PI * 2;
tween(ssd3, {
x: ssd3.x + Math.cos(randomDirection3) * 100,
y: ssd3.y + Math.sin(randomDirection3) * 100,
scaleX: 0.1,
scaleY: 0.1
}, {
duration: 1000,
onFinish: function onFinish() {
ssd3.destroy();
}
});
LK.getSound('ataka').play(); // Play attack sound
self.lastAttackTime = LK.ticks; // Update last attack time
}
} else {
// Move towards target
if (nearestTarget) {
var angleToTarget = Math.atan2(nearestTarget.y - self.y, nearestTarget.x - self.x);
self.x += Math.cos(angleToTarget) * 4; // Move towards target faster
self.y += Math.sin(angleToTarget) * 4;
piranhaGraphics.scaleX = Math.cos(angleToTarget) < 0 ? -1 : 1; // Flip the piranha based on direction
}
self.x += Math.cos(angleToTarget) * 4; // Move towards target faster
self.y += Math.sin(angleToTarget) * 4;
piranhaGraphics.scaleX = Math.cos(angleToTarget) < 0 ? -1 : 1; // Flip the piranha based on direction
if (Math.random() < 0.001) {}
}
self.speed = 0; // Random pause
self.pauseDuration = Math.random() * 50 + 25; // Reduced random pause duration between 25 and 75 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
}
if (self.x < aquarium.x - aquarium.width / 2 + 100) {
self.direction = 1; // Move right
piranhaGraphics.scaleX = 1; // Ensure piranha is facing right
} else if (self.x > aquarium.x + aquarium.width / 2 - 100) {
self.direction = -1; // Move left
piranhaGraphics.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
if (Math.random() < 0.0033) {
self.direction *= -1; // Change horizontal direction
self.speed = Math.random() * 2 + 1; // Randomize speed
piranhaGraphics.scaleX = self.direction < 0 ? -1 : 1; // Flip the piranha based on direction
}
} else {
// Move towards the nearest small fish only
var nearestFish = null;
var minDistance = Infinity;
var targetFishes = fishes.filter(function (fish) {
return !fish.hasGrown;
});
targetFishes.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;
piranhaGraphics.scaleX = Math.cos(angle) < 0 ? -1 : 1; // Flip the piranha based on direction
if (nearestFish && self.intersects(nearestFish)) {
if (self.lastEatTime === undefined || LK.ticks - self.lastEatTime >= 240) {
// Check if 4 seconds have passed
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(270, self.satiety + 240); // Increase satiety by 240, max 270
LK.getSound('Emy').play(); // Play sound when piranha eats a fish
self.lastEatTime = LK.ticks; // Update last eat time
self.direction *= -1; // Change direction
piranhaGraphics.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
piranhaGraphics.scaleX = self.direction < 0 ? -1 : 1; // Flip the piranha based on direction
}, 500);
}
}
nearestFish = null;
}
}
}
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
piranhaGraphics.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 - 100) {
self.y = aquarium.y + aquarium.height / 2 - 100; // Prevent piranha from swimming below the bottom boundary
}
if (self.satiety <= 10) {
piranhaGraphics.tint = 0xFFFF00; // Change color to yellow
if (self.satiety <= 0) {
var pirand = new Pirand();
pirand.x = self.x;
pirand.y = self.y;
pirand.scaleX = piranhaGraphics.scaleX;
pirand.scaleY = piranhaGraphics.scaleY;
game.addChild(pirand);
fishDs.push(pirand);
LK.getSound('Deadfish').play(); // Play sound when piranha dies
self.destroy(); // Remove piranha if satiety is 0 or less
piranhas.splice(piranhas.indexOf(self), 1);
// Removed game over condition related to piranhas
return; // Exit update function to prevent further processing
}
} else {
piranhaGraphics.tint = 0xFFFFFF; // Reset to original color
}
};
});
// Sunduk class representing a treasure chest dropped by Akula
var Sunduk = Container.expand(function () {
var self = Container.call(this);
var sundukGraphics = self.attachAsset('sunduk', {
anchorX: 0.5,
anchorY: 0.5
});
// Update function to move the sunduk downwards
self.update = function () {
self.y += 4 / 1.5;
if (self.y > aquarium.y + aquarium.height / 2 - 200) {
self.y = aquarium.y + aquarium.height / 2 - 200;
// Start the timer for sunduk disappearance
if (!self.disappearanceTimer) {
self.disappearanceTimer = LK.setTimeout(function () {
if (coins.includes(self)) {
self.destroy();
coins.splice(coins.indexOf(self), 1);
}
}, 5000);
}
}
};
// Add click event to sunduk
self.down = function (x, y, obj) {
if (self.isFlying) {
return;
} // Prevent multiple clicks while flying
self.isFlying = true; // Set flying state
// Play sound when sunduk is clicked
LK.getSound('sundukup').play();
// Create a tween to animate the sunduk flying to the balance
tween(self, {
x: balanceText.x + balanceText.width / 2 + 950,
y: balanceText.y + balanceText.height / 2 + 130,
scaleX: 0.5,
scaleY: 0.5
}, {
duration: 1000,
onFinish: function onFinish() {
if (typeof LK.setScore === 'function') {
LK.setScore(LK.getScore() + 10); // Increment score by 10
scoreText.setText('Score: ' + LK.getScore()); // Update score display
}
balance += 250;
balanceText.setText('$' + balance);
self.destroy();
if (coins.includes(self)) {
coins.splice(coins.indexOf(self), 1);
}
}
});
};
});
// Sunduk2 class representing a treasure chest dropped by Monstr
var Sunduk2 = Container.expand(function () {
var self = Container.call(this);
var sunduk2Graphics = self.attachAsset('sunduk2', {
anchorX: 0.5,
anchorY: 0.5
});
// Update function to move the sunduk2 downwards
self.update = function () {
self.y += 4 / 1.5;
if (self.y > aquarium.y + aquarium.height / 2 - 200) {
self.y = aquarium.y + aquarium.height / 2 - 200;
// Start the timer for sunduk2 disappearance
if (!self.disappearanceTimer) {
self.disappearanceTimer = LK.setTimeout(function () {
if (coins.includes(self)) {
self.destroy();
coins.splice(coins.indexOf(self), 1);
}
}, 5000);
}
}
};
// Add click event to sunduk2
self.down = function (x, y, obj) {
if (self.isFlying) {
return;
} // Prevent multiple clicks while flying
self.isFlying = true; // Set flying state
// Play sound when sunduk2 is clicked
LK.getSound('sundukup').play();
// Create a tween to animate the sunduk2 flying to the balance
tween(self, {
x: balanceText.x + balanceText.width / 2 + 950,
y: balanceText.y + balanceText.height / 2 + 130,
scaleX: 0.5,
scaleY: 0.5
}, {
duration: 1000,
onFinish: function onFinish() {
if (typeof LK.setScore === 'function') {
LK.setScore(LK.getScore() + 15); // Increment score by 15
scoreText.setText('Score: ' + LK.getScore()); // Update score display
}
balance += 500; // Increase balance by 500
balanceText.setText('$' + balance);
self.destroy();
if (coins.includes(self)) {
coins.splice(coins.indexOf(self), 1);
}
}
});
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
function calculateFishCost() {
var baseCost = 75;
var additionalCostPerFish = 5;
return baseCost + fishes.length * additionalCostPerFish;
}
// Initialize arrays and variables
var fishCostText; // Declare fishCostText in the global scope
var bigCormIcon; // Define bigCormIcon in the global scope
// Removed unnecessary global declaration of fishIcon
var bigCormCostText; // Declare bigCormCostText in the global scope
var balance = 100;
var balanceText = new Text2('$' + balance, {
size: 100,
fill: 0x00FF00,
font: "'Tahoma', sans-serif" // Set font to Tahoma
});
var scoreText = new Text2('Score: ' + LK.getScore(), {
size: 100,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
// Add countdown timer below the score display
var countdown = 240; // Initial countdown value set to 4 minutes (240 seconds)
var akulaCount = 0; // Initialize shark count to zero
var countdownText = new Text2(countdown.toString(), {
size: 80,
fill: 0xFFFF00 // Yellow color
});
countdownText.anchor.set(0.5, 0);
countdownText.x = scoreText.x + 500; // Move 400 units to the right
countdownText.y = scoreText.y + 400; // Position below the score text
countdownText.visible = false; // Hide the countdown timer
LK.gui.top.addChild(countdownText);
// Add balance text below the countdown timer
var balanceText; // Declare balanceText in the global scope
balanceText = new Text2('$' + balance, {
size: 100,
fill: 0x00FF00
});
balanceText.anchor.set(0.5, 0);
balanceText.y = countdownText.y - 200; // Move 400 units higher than before
LK.gui.top.addChild(balanceText);
// Update countdown every second
LK.setInterval(function () {
if (countdown > 0) {
countdown--;
countdownText.setText(countdown.toString());
if (countdown <= 5) {
// Play 'akulaspawn' sound once when warning appears
LK.getSound('akulaspawn').play(); // Play 'akulaspawn' sound when warning appears
var warning = LK.getAsset('warning', {
// Create warning asset
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2 + 750,
// Center horizontally
y: 2732 / 2 + 150 // Center vertically and shift down by 150 units
});
game.addChild(warning); // Add warning to the game
// Show the warning for 1 second
LK.setTimeout(function () {
// Remove warning after 1 second
warning.destroy();
}, 500);
}
} else if (countdown === 0) {
countdown += 90; // Extend the countdown by 90 seconds
var akulaToSpawn = Math.floor(LK.getScore() / 750) + 1; // Calculate number of Akula to spawn based on score
for (var i = 0; i < akulaToSpawn; i++) {
var akula = new Akula();
akula.x = 2048 + akula.width / 2; // Position on the right side of the screen
akula.y = Math.random() * (2732 - 200) + 100; // Random y position within screen bounds
game.addChild(akula);
}
}
}, 1000);
var fishes = [];
var coins = [];
var corms = [];
var bubbles = [];
var bonusBubbles = [];
var bonusTimer = 70; // Start bonus timer at 70 seconds
var fishDs = [];
var bigCorns = [];
var piranhas = [];
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.5); // Decrease by 1.5 if satiety is 10 or less
} else {
fishes[i].satiety = Math.max(0, fishes[i].satiety - 3); // Decrease by 3 otherwise
}
//fishes[i].updateSatietyDisplay();
}
for (var i = 0; i < piranhas.length; i++) {
if (piranhas[i].satiety <= 10) {
piranhas[i].satiety = Math.max(0, piranhas[i].satiety - 1); // Decrease by 1 if satiety is 10 or less
} else {
piranhas[i].satiety = Math.max(0, piranhas[i].satiety - 3); // Decrease by 3 otherwise
}
}
}, 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 () {
// Check if no peaceful fish are left
if (fishes.length === 0) {
// Save current score to leaderboard
storage.leaderboard.push(LK.getScore());
storage.leaderboard.sort(function (a, b) {
return b - a;
}); // Sort leaderboard in descending order
storage.leaderboard = storage.leaderboard.slice(0, 5); // Keep top 5 scores
// Display leaderboard
var leaderboardText = new Text2('Leaderboard:\n' + storage.leaderboard.join('\n'), {
size: 80,
fill: 0xFFFFFF // White color
});
leaderboardText.anchor.set(0.5, 0);
leaderboardText.x = 2048 / 2;
leaderboardText.y = 2732 / 2;
LK.gui.top.addChild(leaderboardText);
LK.showGameOver(); // Trigger game over immediately
}
// Check if there is at least one shark in the game
var monstrCount = Math.floor(LK.getScore() / 1000);
var existingMonstrCount = game.children.filter(function (child) {
return child instanceof Monstr;
}).length;
if (countdown === 0 && monstrCount > existingMonstrCount) {
for (var i = existingMonstrCount; i < monstrCount; i++) {
var monstr = new Monstr();
monstr.x = 2048 + monstr.width / 2; // Position on the right side of the screen
monstr.y = Math.random() * (2732 - 200) + 100; // Random y position within screen bounds
game.addChild(monstr);
}
}
var hasMonstr = game.children.some(function (child) {
return child instanceof Monstr;
});
// Update fish icon alpha and interactivity based on Monstr presence
if (hasMonstr) {
interfacePanel.fishIcon.alpha = 0.3;
interfacePanel.fishIcon.interactive = false;
} else {
interfacePanel.fishIcon.alpha = 2;
interfacePanel.fishIcon.interactive = true;
}
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
}
// Bonus timer logic
if (bonusTimer <= 0) {
var bonusBubble = new BonusBubble();
bonusBubble.x = 2048 + bonusBubble.width / 2; // Start from the right edge
bonusBubble.y = bonusBubble.height / 2 + 670; // Start 670 units lower from the top edge
game.addChild(bonusBubble);
bonusBubbles.push(bonusBubble);
LK.getSound('startbonus').play(); // Play 'startbonus' sound when a bonus bubble appears
bonusTimer = Math.floor(Math.random() * 21) + 25; // Reset bonus timer to a random value between 25 and 45 seconds
} else {
bonusTimer -= 1 / 60; // Decrease bonus timer by 1 second every 60 frames
}
// Update all bonus bubbles
for (var b = 0; b < bonusBubbles.length; b++) {
bonusBubbles[b].update();
}
};
прозрачный пузырь воздуха. 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