User prompt
son yaptığımız 3 adımları geri al
User prompt
sarı şeyi oyundan sil
User prompt
şu sarı şeyi yediğimde onu yok et ve bana 100 puan ver
User prompt
BU SARI ŞEY BENİ YİYEMEZ BEN DAHA BÜYÜĞÜM BÜYÜK BALIK KÜÇÜK BALIĞI YER DÜZELT
User prompt
Please fix the bug: 'ReferenceError: GoldFish is not defined' in or related to this line: 'if (player.level >= fish.fishLevel) {' Line Number: 591
User prompt
benden kaçabilen hızlı bir nesne yap ve ona elma adını ver elmayı yiyince 100 puan kazanıyorum
User prompt
sarı balığı sil
User prompt
oyun başladığında o sarı balığın doğması gerekiyor onu görünür yap
User prompt
At the beginning of the game, one of the small fish is born yellow and is faster than the others, can run away from us and gives more points when we eat it.
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'tint')' in or related to this line: 'self.children[0].tint = 0xFFFF00; // Assuming the body is the first child' Line Number: 384
User prompt
At the beginning of the game, one of the small fish is born yellow and is faster than the others, can run away from us and gives more points when we eat it.
User prompt
altın balığı sil
User prompt
I can eat the goldfish but it can't eat me. Killing the goldfish gives 100 points.
User prompt
altın balık beni yiyemez düzelt şunu
User prompt
altın balıkta bir küçük balıktır ve onu yiyebilirim sadece 100 puan verir
User prompt
Altın balığa gidince game over yazıyor ? bunu fixle onu yiyeyeceğim sadece bu
User prompt
altın balığa bir kuyruk ekle ve onu yaklaştığımda yememi sağla yalvarırım
User prompt
altın balığı yenilebilir yap ve altın balık kimseyi yiyemez
User prompt
altın balık oyuna başladığımda kesin 1 tane olsun 2. stage e kadar doğmasın
User prompt
altın balığı yiyemiyorum bunu fixle
User prompt
tamam bu kadar iyi kaçamasın biraz
User prompt
biz altın balığı her türlü yiyebiliyoruz ve eğer altın balığa yaklaşırsak bizden kaçsın
User prompt
altın balık bizi yiyemez o en küçük
User prompt
altın balığı göremiyorum görünür yap
User prompt
en küçük balıklardan 1 tanesini kopyala ve altın rengine boya ve aşırı hızlı yap bizden kaçsın eğer yersek 100 puan
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1", { highScore: 0 }); /**** * Classes ****/ var Clam = Container.expand(function () { var self = Container.call(this); // Clam body var body = self.attachAsset('mine', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.5, scaleY: 1.0 }); // Pearl var pearl = LK.getAsset('eyeball', { anchorX: 0.5, anchorY: 0.5, x: 0, y: -body.height / 2 - 10, scaleX: 0.5, scaleY: 0.5, visible: false }); self.addChild(pearl); // Open and release pearl every 10 seconds var releasePearl = function releasePearl() { pearl.visible = true; LK.setTimeout(function () { pearl.visible = false; }, 1000); }; LK.setInterval(releasePearl, 10000); return self; }); var Fish = Container.expand(function (type, level) { var self = Container.call(this); // Setup fish properties based on type self.fishType = type || 'smallFish'; self.fishLevel = level || 1; // Size multiplier based on level var sizeMultiplier = 1; if (self.fishLevel === 2) { sizeMultiplier = 1.5; } if (self.fishLevel === 3) { sizeMultiplier = 2; } // Fish body var assetId = self.fishType; var body = self.attachAsset(assetId, { anchorX: 0.5, anchorY: 0.5, scaleX: sizeMultiplier * (Math.random() * 0.2 + 0.9), // Vary size slightly for realism scaleY: sizeMultiplier * (Math.random() * 0.2 + 0.9), // Vary size slightly for realism tint: 0x8A2BE2 // Add a more realistic purple tint }); // Tail var tailColor = self.fishType === 'smallFish' ? 0xffb967 : self.fishType === 'mediumFish' ? 0xff6c67 : 0xc267ff; var tail = LK.getAsset('tail', { anchorX: 1.0, anchorY: 0.5, x: -body.width / 2, y: 0, scaleX: sizeMultiplier * (Math.random() * 0.3 + 0.8), // Vary size slightly for realism scaleY: sizeMultiplier * (Math.random() * 0.3 + 0.8), // Vary size slightly for realism tint: 0x8A2BE2, // Add a more realistic purple tint texture: 'fishTailTexture' // Add texture for realism }); tail.tint = tailColor; self.addChild(tail); // Mouth var mouth = LK.getAsset('eyeball', { anchorX: 0.5, anchorY: 0.5, x: body.width / 2, y: body.height / 4, scaleX: sizeMultiplier * 0.5, scaleY: sizeMultiplier * 0.2, tint: 0x000000 }); self.addChild(mouth); // Eye var eye = self.attachAsset('eyeball', { anchorX: 0.5, anchorY: 0.5, x: body.width / 4, y: -body.height / 4, scaleX: sizeMultiplier, scaleY: sizeMultiplier }); // Pupil var pupil = self.attachAsset('pupil', { anchorX: 0.5, anchorY: 0.5, x: body.width / 4 + 2, y: -body.height / 4, scaleX: sizeMultiplier, scaleY: sizeMultiplier }); // Movement variables self.speedX = (Math.random() * 2 + 1) * (Math.random() < 0.5 ? 1 : -1); self.speedY = (Math.random() - 0.5) * 1.5; // Animation var _animateTail = function animateTail() { tween(tail, { scaleX: sizeMultiplier * 0.6 }, { duration: 300, easing: tween.easeInOut, onFinish: function onFinish() { tween(tail, { scaleX: sizeMultiplier * 0.8 }, { duration: 300, easing: tween.easeInOut, onFinish: _animateTail }); } }); }; _animateTail(); // Update method called automatically by LK engine self.update = function () { // Move fish self.x += self.speedX; self.y += self.speedY; // Update rotation based on direction if (self.speedX < 0) { self.scale.x = -1; } else { self.scale.x = 1; } // Bounce off edges if (self.x < 0 || self.x > 2048) { self.speedX *= -1; } // Limit vertical movement more subtly if (self.y < 0 || self.y > 2732) { self.speedY *= -1; } // Occasionally change vertical direction if (Math.random() < 0.01) { self.speedY = (Math.random() - 0.5) * 1.5; } }; return self; }); var GoldFish = Container.expand(function () { var self = Container.call(this); // Gold fish body var body = self.attachAsset('goldFish', { anchorX: 0.5, anchorY: 0.5 }); // Movement variables self.speedX = (Math.random() * 4 + 3) * (Math.random() < 0.5 ? 1 : -1); self.speedY = (Math.random() - 0.5) * 3; // Update method called automatically by LK engine self.update = function () { // Move gold fish self.x += self.speedX; self.y += self.speedY; // Bounce off edges if (self.x < 0 || self.x > 2048) { self.speedX *= -1; } if (self.y < 0 || self.y > 2732) { self.speedY *= -1; } }; return self; }); var Mine = Container.expand(function () { var self = Container.call(this); // Mine body var body = self.attachAsset('mine', { anchorX: 0.5, anchorY: 0.5 }); // Add spikes for (var i = 0; i < 8; i++) { var angle = i / 8 * Math.PI * 2; var spike = LK.getAsset('mine', { anchorX: 0.5, anchorY: 0.5, width: 15, height: 3, x: Math.cos(angle) * 25, y: Math.sin(angle) * 25, rotation: angle }); self.addChild(spike); } // Small pulse animation var _animatePulse = function animatePulse() { tween(body, { scaleX: 1.1, scaleY: 1.1 }, { duration: 800, easing: tween.easeInOut, onFinish: function onFinish() { tween(body, { scaleX: 1, scaleY: 1 }, { duration: 800, easing: tween.easeInOut, onFinish: _animatePulse }); } }); }; _animatePulse(); return self; }); var PlayerFish = Container.expand(function () { var self = Container.call(this); // Fish body var body = self.attachAsset('playerFish', { anchorX: 0.5, anchorY: 0.5 }); // Tail var tail = self.attachAsset('tail', { anchorX: 1.0, anchorY: 0.5, x: -body.width / 2, y: 0 }); // Eye var eye = self.attachAsset('eyeball', { anchorX: 0.5, anchorY: 0.5, x: body.width / 4, y: -body.height / 4 }); // Pupil var pupil = self.attachAsset('pupil', { anchorX: 0.5, anchorY: 0.5, x: body.width / 4 + 2, y: -body.height / 4 }); // Size/Level properties self.level = 1; self.initialWidth = body.width; self.initialHeight = body.height; // Movement target self.targetX = null; self.targetY = null; self.speed = 5; // Animation var _animateTail2 = function animateTail() { tween(tail, { scaleX: 0.7 }, { duration: 300, easing: tween.easeInOut, onFinish: function onFinish() { tween(tail, { scaleX: 1 }, { duration: 300, easing: tween.easeInOut, onFinish: _animateTail2 }); } }); }; _animateTail2(); // Growth function self.grow = function () { self.level++; // Calculate new size based on level (capped at level 5) var growthFactor = Math.min(self.level * 0.25 + 1, 2.5); tween(body, { width: self.initialWidth * growthFactor, height: self.initialHeight * growthFactor }, { duration: 500, easing: tween.easeOut }); tween(tail, { width: tail.width * 1.2, height: tail.height * 1.2, x: -(self.initialWidth * growthFactor) / 2 }, { duration: 500, easing: tween.easeOut }); tween(eye, { x: self.initialWidth * growthFactor / 4, y: -(self.initialHeight * growthFactor) / 4 }, { duration: 500, easing: tween.easeOut }); tween(pupil, { x: self.initialWidth * growthFactor / 4 + 2, y: -(self.initialHeight * growthFactor) / 4 }, { duration: 500, easing: tween.easeOut }); // Play level up sound LK.getSound('levelUp').play(); }; // Shield properties self.shieldActive = true; self.shieldDuration = 3000; // 3 seconds // Create a visible blue circular shield var shield = LK.getAsset('eyeball', { anchorX: 0.5, anchorY: 0.5, x: 0, y: 0, scaleX: 15.0, // Make the shield much larger than the player fish scaleY: 15.0, // Make the shield much larger than the player fish tint: 0x0000FF, alpha: 0.3 // Make the shield more transparent }); self.addChild(shield); // Deactivate shield after 3 seconds LK.setTimeout(function () { self.shieldActive = false; shield.visible = false; // Hide the shield after duration }, self.shieldDuration); // Update method called automatically by LK engine self.update = function () { if (self.targetX !== null && self.targetY !== null) { // Calculate direction vector var dx = self.targetX - self.x; var dy = self.targetY - self.y; var distance = Math.sqrt(dx * dx + dy * dy); // If we're close enough to the target, stop moving if (distance < self.speed) { self.x = self.targetX; self.y = self.targetY; self.targetX = null; self.targetY = null; } else { // Move towards target self.x += dx / distance * self.speed; self.y += dy / distance * self.speed; // Rotate fish in the direction of movement var angle = Math.atan2(dy, dx); // Only flip horizontally, no rotation if (dx < 0) { self.scale.x = -1; } else { self.scale.x = 1; } } } // Keep fish in bounds if (self.x < 0) { self.x = 0; } if (self.y < 0) { self.y = 0; } if (self.x > 2048) { self.x = 2048; } if (self.y > 2732) { self.y = 2732; } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x202438 // Dark blue cave background }); /**** * Game Code ****/ function transitionToNewMap() { gameActive = false; LK.getSound('levelUp').play(); LK.effects.flashScreen(0x00FF00, 1000); // Flash screen green to indicate stage transition var stageTxt = new Text2('Stage 2', { size: 100, fill: 0x00FF00 }); stageTxt.anchor.set(0.5, 0.5); LK.gui.center.addChild(stageTxt); LK.setTimeout(function () { LK.gui.center.removeChild(stageTxt); // Clear existing fish and mines fishes.forEach(function (fish) { return fish.destroy(); }); mines.forEach(function (mine) { return mine.destroy(); }); fishes = []; mines = []; // Add new fish types for stage 2 spawnFish(5, 'mediumFish', 2); spawnFish(5, 'largeFish', 3); // Add seaweed var seaweedColors = [0x228B22, 0x2E8B57, 0x006400]; for (var i = 0; i < 5; i++) { var seaweed = LK.getAsset('cave', { anchorX: 0.5, anchorY: 1.0, x: 2048 / 5 * i + 2048 / 10, y: 2732, scaleX: 0.1, scaleY: 0.3, tint: seaweedColors[i % seaweedColors.length] }); game.addChild(seaweed); } gameActive = true; }, 1500); } // Game variables var player = null; var fishes = []; var mines = []; var score = 0; var gameActive = true; var shield = { parent: null }; // Define a shield object with a parent property // Background cave elements var cave = game.addChild(LK.getAsset('cave', { anchorX: 0, anchorY: 0, x: 0, y: 0 })); // Initialize player fish player = new PlayerFish(); player.x = 2048 / 2; player.y = 2732 / 2; game.addChild(player); // UI var scoreTxt = new Text2('Score: 0', { size: 60, fill: 0xFFFFFF }); scoreTxt.anchor.set(1, 0); LK.gui.topRight.addChild(scoreTxt); scoreTxt.x = -20; scoreTxt.y = 20; var levelTxt = new Text2('Level: 1', { size: 60, fill: 0xFFFFFF }); levelTxt.anchor.set(0, 0); LK.gui.topRight.addChild(levelTxt); levelTxt.x = -levelTxt.width - 20; levelTxt.y = 90; var highScoreTxt = new Text2('High Score: ' + storage.highScore, { size: 50, fill: 0xFFDD00 }); highScoreTxt.anchor.set(0, 0); LK.gui.topRight.addChild(highScoreTxt); highScoreTxt.x = -highScoreTxt.width - 20; highScoreTxt.y = 160; // Initialize game elements function initializeGame() { // Add a clam to the game var clam = new Clam(); clam.x = 2048 / 2; clam.y = 2732 - 100; clam.visible = true; // Make the clam visible game.addChild(clam); // Spawn initial fish spawnFish(10, 'smallFish', 1); spawnFish(5, 'mediumFish', 2); // Spawn mines spawnMines(8); // Start playing ambient cave sound LK.playMusic('caveAmbience', { loop: true, fade: { start: 0, end: 0.4, duration: 1000 } }); } // Spawn fish function spawnFish(count, type, level) { for (var i = 0; i < count; i++) { var fish = new Fish(type, level); fish.x = Math.random() * 2048; fish.y = Math.random() * 2732; fishes.push(fish); game.addChild(fish); } } // Spawn mines function spawnMines(count) { for (var i = 0; i < count; i++) { var mine = new Mine(); mine.x = Math.random() * 2048; mine.y = Math.random() * 2732; mines.push(mine); game.addChild(mine); } } // Handle player movement function handleMove(x, y, obj) { if (gameActive) { player.targetX = x; player.targetY = y; } } // Mouse/touch events game.down = function (x, y, obj) { handleMove(x, y, obj); player.speed = 10; // Increase speed when mouse is held down }; game.move = handleMove; game.up = function (x, y, obj) { player.speed = 5; // Reset speed when mouse is released }; // Main game loop game.update = function () { if (!gameActive) { return; } // Change player fish appearance to mine fish at 200 points if (score >= 200 && player.level < 2) { player.level = 2; player.attachAsset('mine', { anchorX: 0.5, anchorY: 0.5 }); } // Check if score reaches 400 to transition to stage 2 if (score >= 400) { transitionToNewMap(); } // Check for collisions with fish for (var i = fishes.length - 1; i >= 0; i--) { var fish = fishes[i]; if (player.intersects(fish) && !player.shieldActive) { // Determine if player can eat the fish if (player.level >= fish.fishLevel) { // Player eats fish LK.getSound('eat').play(); // Add score based on fish type var points = fish instanceof GoldFish ? 100 : fish.fishLevel * 10; score += points; scoreTxt.setText('Score: ' + score); // Remove fish fish.destroy(); fishes.splice(i, 1); // Check if player should level up if (score >= player.level * 50) { player.grow(); levelTxt.setText('Level: ' + player.level); // Spawn a replacement fish if (fish.fishLevel === 1) { spawnFish(1, 'smallFish', 1); } else if (fish.fishLevel === 2) { spawnFish(1, 'mediumFish', 2); } else { spawnFish(1, 'largeFish', 3); } } // Update high score if needed if (score > storage.highScore) { storage.highScore = score; highScoreTxt.setText('High Score: ' + storage.highScore); } } else { // Fish eats player - game over gameActive = false; LK.getSound('explode').play(); // Flash player LK.effects.flashObject(player, 0xFF0000, 1000); // Show game over LK.setTimeout(function () { LK.showGameOver(); }, 1500); } } } // Check for collisions with mines for (var j = mines.length - 1; j >= 0; j--) { var mine = mines[j]; if (player.intersects(mine) && !player.shieldActive) { // Mine explodes - game over gameActive = false; LK.getSound('explode').play(); // Flash screen LK.effects.flashScreen(0xFF0000, 1000); // Show game over LK.setTimeout(function () { LK.showGameOver(); }, 1500); } } // Occasionally spawn a new small fish if (Math.random() < 0.005 && fishes.length < 20) { spawnFish(1, 'smallFish', 1); } // Occasionally spawn a new gold fish if (Math.random() < 0.001 && fishes.length < 20) { var goldFish = new GoldFish(); goldFish.x = Math.random() * 2048; goldFish.y = Math.random() * 2732; fishes.push(goldFish); game.addChild(goldFish); } }; // Initialize the game initializeGame();
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
highScore: 0
});
/****
* Classes
****/
var Clam = Container.expand(function () {
var self = Container.call(this);
// Clam body
var body = self.attachAsset('mine', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1.0
});
// Pearl
var pearl = LK.getAsset('eyeball', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: -body.height / 2 - 10,
scaleX: 0.5,
scaleY: 0.5,
visible: false
});
self.addChild(pearl);
// Open and release pearl every 10 seconds
var releasePearl = function releasePearl() {
pearl.visible = true;
LK.setTimeout(function () {
pearl.visible = false;
}, 1000);
};
LK.setInterval(releasePearl, 10000);
return self;
});
var Fish = Container.expand(function (type, level) {
var self = Container.call(this);
// Setup fish properties based on type
self.fishType = type || 'smallFish';
self.fishLevel = level || 1;
// Size multiplier based on level
var sizeMultiplier = 1;
if (self.fishLevel === 2) {
sizeMultiplier = 1.5;
}
if (self.fishLevel === 3) {
sizeMultiplier = 2;
}
// Fish body
var assetId = self.fishType;
var body = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5,
scaleX: sizeMultiplier * (Math.random() * 0.2 + 0.9),
// Vary size slightly for realism
scaleY: sizeMultiplier * (Math.random() * 0.2 + 0.9),
// Vary size slightly for realism
tint: 0x8A2BE2 // Add a more realistic purple tint
});
// Tail
var tailColor = self.fishType === 'smallFish' ? 0xffb967 : self.fishType === 'mediumFish' ? 0xff6c67 : 0xc267ff;
var tail = LK.getAsset('tail', {
anchorX: 1.0,
anchorY: 0.5,
x: -body.width / 2,
y: 0,
scaleX: sizeMultiplier * (Math.random() * 0.3 + 0.8),
// Vary size slightly for realism
scaleY: sizeMultiplier * (Math.random() * 0.3 + 0.8),
// Vary size slightly for realism
tint: 0x8A2BE2,
// Add a more realistic purple tint
texture: 'fishTailTexture' // Add texture for realism
});
tail.tint = tailColor;
self.addChild(tail);
// Mouth
var mouth = LK.getAsset('eyeball', {
anchorX: 0.5,
anchorY: 0.5,
x: body.width / 2,
y: body.height / 4,
scaleX: sizeMultiplier * 0.5,
scaleY: sizeMultiplier * 0.2,
tint: 0x000000
});
self.addChild(mouth);
// Eye
var eye = self.attachAsset('eyeball', {
anchorX: 0.5,
anchorY: 0.5,
x: body.width / 4,
y: -body.height / 4,
scaleX: sizeMultiplier,
scaleY: sizeMultiplier
});
// Pupil
var pupil = self.attachAsset('pupil', {
anchorX: 0.5,
anchorY: 0.5,
x: body.width / 4 + 2,
y: -body.height / 4,
scaleX: sizeMultiplier,
scaleY: sizeMultiplier
});
// Movement variables
self.speedX = (Math.random() * 2 + 1) * (Math.random() < 0.5 ? 1 : -1);
self.speedY = (Math.random() - 0.5) * 1.5;
// Animation
var _animateTail = function animateTail() {
tween(tail, {
scaleX: sizeMultiplier * 0.6
}, {
duration: 300,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(tail, {
scaleX: sizeMultiplier * 0.8
}, {
duration: 300,
easing: tween.easeInOut,
onFinish: _animateTail
});
}
});
};
_animateTail();
// Update method called automatically by LK engine
self.update = function () {
// Move fish
self.x += self.speedX;
self.y += self.speedY;
// Update rotation based on direction
if (self.speedX < 0) {
self.scale.x = -1;
} else {
self.scale.x = 1;
}
// Bounce off edges
if (self.x < 0 || self.x > 2048) {
self.speedX *= -1;
}
// Limit vertical movement more subtly
if (self.y < 0 || self.y > 2732) {
self.speedY *= -1;
}
// Occasionally change vertical direction
if (Math.random() < 0.01) {
self.speedY = (Math.random() - 0.5) * 1.5;
}
};
return self;
});
var GoldFish = Container.expand(function () {
var self = Container.call(this);
// Gold fish body
var body = self.attachAsset('goldFish', {
anchorX: 0.5,
anchorY: 0.5
});
// Movement variables
self.speedX = (Math.random() * 4 + 3) * (Math.random() < 0.5 ? 1 : -1);
self.speedY = (Math.random() - 0.5) * 3;
// Update method called automatically by LK engine
self.update = function () {
// Move gold fish
self.x += self.speedX;
self.y += self.speedY;
// Bounce off edges
if (self.x < 0 || self.x > 2048) {
self.speedX *= -1;
}
if (self.y < 0 || self.y > 2732) {
self.speedY *= -1;
}
};
return self;
});
var Mine = Container.expand(function () {
var self = Container.call(this);
// Mine body
var body = self.attachAsset('mine', {
anchorX: 0.5,
anchorY: 0.5
});
// Add spikes
for (var i = 0; i < 8; i++) {
var angle = i / 8 * Math.PI * 2;
var spike = LK.getAsset('mine', {
anchorX: 0.5,
anchorY: 0.5,
width: 15,
height: 3,
x: Math.cos(angle) * 25,
y: Math.sin(angle) * 25,
rotation: angle
});
self.addChild(spike);
}
// Small pulse animation
var _animatePulse = function animatePulse() {
tween(body, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 800,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(body, {
scaleX: 1,
scaleY: 1
}, {
duration: 800,
easing: tween.easeInOut,
onFinish: _animatePulse
});
}
});
};
_animatePulse();
return self;
});
var PlayerFish = Container.expand(function () {
var self = Container.call(this);
// Fish body
var body = self.attachAsset('playerFish', {
anchorX: 0.5,
anchorY: 0.5
});
// Tail
var tail = self.attachAsset('tail', {
anchorX: 1.0,
anchorY: 0.5,
x: -body.width / 2,
y: 0
});
// Eye
var eye = self.attachAsset('eyeball', {
anchorX: 0.5,
anchorY: 0.5,
x: body.width / 4,
y: -body.height / 4
});
// Pupil
var pupil = self.attachAsset('pupil', {
anchorX: 0.5,
anchorY: 0.5,
x: body.width / 4 + 2,
y: -body.height / 4
});
// Size/Level properties
self.level = 1;
self.initialWidth = body.width;
self.initialHeight = body.height;
// Movement target
self.targetX = null;
self.targetY = null;
self.speed = 5;
// Animation
var _animateTail2 = function animateTail() {
tween(tail, {
scaleX: 0.7
}, {
duration: 300,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(tail, {
scaleX: 1
}, {
duration: 300,
easing: tween.easeInOut,
onFinish: _animateTail2
});
}
});
};
_animateTail2();
// Growth function
self.grow = function () {
self.level++;
// Calculate new size based on level (capped at level 5)
var growthFactor = Math.min(self.level * 0.25 + 1, 2.5);
tween(body, {
width: self.initialWidth * growthFactor,
height: self.initialHeight * growthFactor
}, {
duration: 500,
easing: tween.easeOut
});
tween(tail, {
width: tail.width * 1.2,
height: tail.height * 1.2,
x: -(self.initialWidth * growthFactor) / 2
}, {
duration: 500,
easing: tween.easeOut
});
tween(eye, {
x: self.initialWidth * growthFactor / 4,
y: -(self.initialHeight * growthFactor) / 4
}, {
duration: 500,
easing: tween.easeOut
});
tween(pupil, {
x: self.initialWidth * growthFactor / 4 + 2,
y: -(self.initialHeight * growthFactor) / 4
}, {
duration: 500,
easing: tween.easeOut
});
// Play level up sound
LK.getSound('levelUp').play();
};
// Shield properties
self.shieldActive = true;
self.shieldDuration = 3000; // 3 seconds
// Create a visible blue circular shield
var shield = LK.getAsset('eyeball', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 0,
scaleX: 15.0,
// Make the shield much larger than the player fish
scaleY: 15.0,
// Make the shield much larger than the player fish
tint: 0x0000FF,
alpha: 0.3 // Make the shield more transparent
});
self.addChild(shield);
// Deactivate shield after 3 seconds
LK.setTimeout(function () {
self.shieldActive = false;
shield.visible = false; // Hide the shield after duration
}, self.shieldDuration);
// Update method called automatically by LK engine
self.update = function () {
if (self.targetX !== null && self.targetY !== null) {
// Calculate direction vector
var dx = self.targetX - self.x;
var dy = self.targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
// If we're close enough to the target, stop moving
if (distance < self.speed) {
self.x = self.targetX;
self.y = self.targetY;
self.targetX = null;
self.targetY = null;
} else {
// Move towards target
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
// Rotate fish in the direction of movement
var angle = Math.atan2(dy, dx);
// Only flip horizontally, no rotation
if (dx < 0) {
self.scale.x = -1;
} else {
self.scale.x = 1;
}
}
}
// Keep fish in bounds
if (self.x < 0) {
self.x = 0;
}
if (self.y < 0) {
self.y = 0;
}
if (self.x > 2048) {
self.x = 2048;
}
if (self.y > 2732) {
self.y = 2732;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x202438 // Dark blue cave background
});
/****
* Game Code
****/
function transitionToNewMap() {
gameActive = false;
LK.getSound('levelUp').play();
LK.effects.flashScreen(0x00FF00, 1000); // Flash screen green to indicate stage transition
var stageTxt = new Text2('Stage 2', {
size: 100,
fill: 0x00FF00
});
stageTxt.anchor.set(0.5, 0.5);
LK.gui.center.addChild(stageTxt);
LK.setTimeout(function () {
LK.gui.center.removeChild(stageTxt);
// Clear existing fish and mines
fishes.forEach(function (fish) {
return fish.destroy();
});
mines.forEach(function (mine) {
return mine.destroy();
});
fishes = [];
mines = [];
// Add new fish types for stage 2
spawnFish(5, 'mediumFish', 2);
spawnFish(5, 'largeFish', 3);
// Add seaweed
var seaweedColors = [0x228B22, 0x2E8B57, 0x006400];
for (var i = 0; i < 5; i++) {
var seaweed = LK.getAsset('cave', {
anchorX: 0.5,
anchorY: 1.0,
x: 2048 / 5 * i + 2048 / 10,
y: 2732,
scaleX: 0.1,
scaleY: 0.3,
tint: seaweedColors[i % seaweedColors.length]
});
game.addChild(seaweed);
}
gameActive = true;
}, 1500);
}
// Game variables
var player = null;
var fishes = [];
var mines = [];
var score = 0;
var gameActive = true;
var shield = {
parent: null
}; // Define a shield object with a parent property
// Background cave elements
var cave = game.addChild(LK.getAsset('cave', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
}));
// Initialize player fish
player = new PlayerFish();
player.x = 2048 / 2;
player.y = 2732 / 2;
game.addChild(player);
// UI
var scoreTxt = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(scoreTxt);
scoreTxt.x = -20;
scoreTxt.y = 20;
var levelTxt = new Text2('Level: 1', {
size: 60,
fill: 0xFFFFFF
});
levelTxt.anchor.set(0, 0);
LK.gui.topRight.addChild(levelTxt);
levelTxt.x = -levelTxt.width - 20;
levelTxt.y = 90;
var highScoreTxt = new Text2('High Score: ' + storage.highScore, {
size: 50,
fill: 0xFFDD00
});
highScoreTxt.anchor.set(0, 0);
LK.gui.topRight.addChild(highScoreTxt);
highScoreTxt.x = -highScoreTxt.width - 20;
highScoreTxt.y = 160;
// Initialize game elements
function initializeGame() {
// Add a clam to the game
var clam = new Clam();
clam.x = 2048 / 2;
clam.y = 2732 - 100;
clam.visible = true; // Make the clam visible
game.addChild(clam);
// Spawn initial fish
spawnFish(10, 'smallFish', 1);
spawnFish(5, 'mediumFish', 2);
// Spawn mines
spawnMines(8);
// Start playing ambient cave sound
LK.playMusic('caveAmbience', {
loop: true,
fade: {
start: 0,
end: 0.4,
duration: 1000
}
});
}
// Spawn fish
function spawnFish(count, type, level) {
for (var i = 0; i < count; i++) {
var fish = new Fish(type, level);
fish.x = Math.random() * 2048;
fish.y = Math.random() * 2732;
fishes.push(fish);
game.addChild(fish);
}
}
// Spawn mines
function spawnMines(count) {
for (var i = 0; i < count; i++) {
var mine = new Mine();
mine.x = Math.random() * 2048;
mine.y = Math.random() * 2732;
mines.push(mine);
game.addChild(mine);
}
}
// Handle player movement
function handleMove(x, y, obj) {
if (gameActive) {
player.targetX = x;
player.targetY = y;
}
}
// Mouse/touch events
game.down = function (x, y, obj) {
handleMove(x, y, obj);
player.speed = 10; // Increase speed when mouse is held down
};
game.move = handleMove;
game.up = function (x, y, obj) {
player.speed = 5; // Reset speed when mouse is released
};
// Main game loop
game.update = function () {
if (!gameActive) {
return;
}
// Change player fish appearance to mine fish at 200 points
if (score >= 200 && player.level < 2) {
player.level = 2;
player.attachAsset('mine', {
anchorX: 0.5,
anchorY: 0.5
});
}
// Check if score reaches 400 to transition to stage 2
if (score >= 400) {
transitionToNewMap();
}
// Check for collisions with fish
for (var i = fishes.length - 1; i >= 0; i--) {
var fish = fishes[i];
if (player.intersects(fish) && !player.shieldActive) {
// Determine if player can eat the fish
if (player.level >= fish.fishLevel) {
// Player eats fish
LK.getSound('eat').play();
// Add score based on fish type
var points = fish instanceof GoldFish ? 100 : fish.fishLevel * 10;
score += points;
scoreTxt.setText('Score: ' + score);
// Remove fish
fish.destroy();
fishes.splice(i, 1);
// Check if player should level up
if (score >= player.level * 50) {
player.grow();
levelTxt.setText('Level: ' + player.level);
// Spawn a replacement fish
if (fish.fishLevel === 1) {
spawnFish(1, 'smallFish', 1);
} else if (fish.fishLevel === 2) {
spawnFish(1, 'mediumFish', 2);
} else {
spawnFish(1, 'largeFish', 3);
}
}
// Update high score if needed
if (score > storage.highScore) {
storage.highScore = score;
highScoreTxt.setText('High Score: ' + storage.highScore);
}
} else {
// Fish eats player - game over
gameActive = false;
LK.getSound('explode').play();
// Flash player
LK.effects.flashObject(player, 0xFF0000, 1000);
// Show game over
LK.setTimeout(function () {
LK.showGameOver();
}, 1500);
}
}
}
// Check for collisions with mines
for (var j = mines.length - 1; j >= 0; j--) {
var mine = mines[j];
if (player.intersects(mine) && !player.shieldActive) {
// Mine explodes - game over
gameActive = false;
LK.getSound('explode').play();
// Flash screen
LK.effects.flashScreen(0xFF0000, 1000);
// Show game over
LK.setTimeout(function () {
LK.showGameOver();
}, 1500);
}
}
// Occasionally spawn a new small fish
if (Math.random() < 0.005 && fishes.length < 20) {
spawnFish(1, 'smallFish', 1);
}
// Occasionally spawn a new gold fish
if (Math.random() < 0.001 && fishes.length < 20) {
var goldFish = new GoldFish();
goldFish.x = Math.random() * 2048;
goldFish.y = Math.random() * 2732;
fishes.push(goldFish);
game.addChild(goldFish);
}
};
// Initialize the game
initializeGame();