/**** * Classes ****/ // Bubble class to represent the bubbles in the game var Bubble = Container.expand(function () { var self = Container.call(this); self.speed = 1; // Default speed // Attach bubble asset var scaleX = Math.random() * 0.5 + 0.5; var bubbleGraphics = self.attachAsset('bubble', { anchorX: 0.5, anchorY: 0.5, scaleX: scaleX, // Random scale between 0.5 and 1.0 scaleY: scaleX // Ensure scaleY matches scaleX for a perfect circle }); bubbleGraphics.alpha = 0.5; // Update function to move bubble self.update = function () { if (self.lastY === undefined) { self.lastY = self.y; } // Initialize lastY for tracking changes on Y self.y -= self.speed; self.lastY = self.y; // Update lastY after movement self.x += Math.sin(self.y / 50) * 1; // Reduce gentle swaying motion if (self.y < 500) { self.destroy(); // Destroy the bubble if it reaches a certain height } }; }); // Bullet class to represent the bullets shot by the player var Bullet = Container.expand(function () { var self = Container.call(this); self.speed = 10; // Default speed // Attach bullet asset var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); bulletGraphics.scale.set(0.5, 0.5); // Decrease the size of the bullet bulletGraphics.rotation = -Math.PI / 2; // Rotate the bullet to point upwards // Update function to move bullet self.update = function () { if (game.mouse) { self.rotation = Math.atan2(game.mouse.y - self.y, game.mouse.x - self.x); } if (self.lastX === undefined) { self.lastX = self.x; } // Initialize lastX for tracking changes on X if (self.lastY === undefined) { self.lastY = self.y; } // Initialize lastY for tracking changes on Y self.x += self.speed * Math.cos(self.rotation); self.y += self.speed * Math.sin(self.rotation); self.lastX = self.x; // Update lastX after movement self.lastY = self.y; // Update lastY after movement if (self.y < 0) { self.destroy(); // Destroy the bullet if it goes off screen } }; }); // Fake class to represent the fake in the game var Fake = Container.expand(function () { var self = Container.call(this); self.speed = 1; // Default speed // Attach fake asset var fakeGraphics = self.attachAsset('fake', { anchorX: 0.5, anchorY: 0.5 }); fakeGraphics.alpha = 0.5; // Update function to move fake self.update = function () { if (self.lastY === undefined) { self.lastY = self.y; } // Initialize lastY for tracking changes on Y self.y -= self.speed; self.lastY = self.y; // Update lastY after movement if (self.y < 500) { self.destroy(); // Destroy the fake if it reaches a certain height } }; }); //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Fish class to represent different types of fish var Fish = Container.expand(function () { var self = Container.call(this); self.size = 1; // Default size multiplier self.points = 1; // Default points self.speed = 2; // Default speed // Attach fish asset var fishGraphics = self.attachAsset('fish', { anchorX: 0.5, anchorY: 0.5 }); // Update function to move fish self.update = function () { if (self.lastX === undefined) { self.lastX = self.x; } // Initialize lastX for tracking changes on X if (self.lastY === undefined) { self.lastY = self.y; } // Initialize lastY for tracking changes on Y self.x += self.speed; // Move fish based on speed direction self.y += Math.sin(self.x / 50) * 0.5; // Further reduce gentle swaying motion to fish self.lastX = self.x; // Update lastX after movement self.lastY = self.y; // Update lastY after movement // Removed rotation animation from fish // Ensure fish face the correct direction based on speed fishGraphics.scale.x = self.speed > 0 ? 1 : -1; fishGraphics.scale.y = 1; // Ensure fish are always facing forward // Check for nearby bullets and change direction if close game.children.forEach(function (child) { if (child instanceof Bullet) { var distance = Math.sqrt(Math.pow(child.x - self.x, 2) + Math.pow(child.y - self.y, 2)); if (distance < 200) { // If bullet is within 200 pixels self.speed = -self.speed; // Reverse direction } } }); // Reset position if fish goes off screen if (self.speed > 0 && self.x > 2048) { self.x = -fishGraphics.width; } else if (self.speed < 0 && self.x < -fishGraphics.width) { self.x = 2048; } }; // Method to set fish properties based on level self.setProperties = function () { self.size = 1; // Set size to a constant value self.points = 50; // Fixed points for each fish self.speed = 2; // Constant speed fishGraphics.scale.set(self.size * 6.0, self.size * 6.0); if (Math.random() > 0.5) { self.speed = -self.speed; } }; // Method to shoot a bullet self.shoot = function () { var bullet = new Bullet(); bullet.x = self.x; bullet.y = self.y; game.addChild(bullet); }; }); var Fish2 = Container.expand(function () { var self = Container.call(this); self.size = 1; self.points = 1; self.speed = 2; var fishGraphics = self.attachAsset('fish2', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { if (self.lastX === undefined) { self.lastX = self.x; } // Initialize lastX for tracking changes on X if (self.lastY === undefined) { self.lastY = self.y; } // Initialize lastY for tracking changes on Y self.x += self.speed; self.y += Math.sin(self.x / 50) * 0.5; self.lastX = self.x; // Update lastX after movement self.lastY = self.y; // Update lastY after movement fishGraphics.scale.x = self.speed > 0 ? 1 : -1; fishGraphics.scale.y = 1; game.children.forEach(function (child) { if (child instanceof Bullet) { var distance = Math.sqrt(Math.pow(child.x - self.x, 2) + Math.pow(child.y - self.y, 2)); if (distance < 200) { self.speed = -self.speed; } } }); if (self.speed > 0 && self.x > 2048) { self.x = -fishGraphics.width; } else if (self.speed < 0 && self.x < -fishGraphics.width) { self.x = 2048; } }; self.setProperties = function () { self.size = 1; self.points = 50; // Fixed points for each fish self.speed = 2; // Constant speed fishGraphics.scale.set(self.size * 6.0, self.size * 6.0); if (Math.random() > 0.5) { self.speed = -self.speed; } }; self.shoot = function () { var bullet = new Bullet(); bullet.x = self.x; bullet.y = self.y; game.addChild(bullet); }; }); var Fish3 = Container.expand(function () { var self = Container.call(this); self.size = 1; self.points = 1; self.speed = 2; var fishGraphics = self.attachAsset('fish3', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { if (self.lastX === undefined) { self.lastX = self.x; } // Initialize lastX for tracking changes on X if (self.lastY === undefined) { self.lastY = self.y; } // Initialize lastY for tracking changes on Y self.x += self.speed; self.y += Math.sin(self.x / 50) * 0.5; self.lastX = self.x; // Update lastX after movement self.lastY = self.y; // Update lastY after movement fishGraphics.scale.x = self.speed > 0 ? 1 : -1; fishGraphics.scale.y = 1; game.children.forEach(function (child) { if (child instanceof Bullet) { var distance = Math.sqrt(Math.pow(child.x - self.x, 2) + Math.pow(child.y - self.y, 2)); if (distance < 200) { self.speed = -self.speed; } } }); if (self.speed > 0 && self.x > 2048) { self.x = -fishGraphics.width; } else if (self.speed < 0 && self.x < -fishGraphics.width) { self.x = 2048; } }; self.setProperties = function () { self.size = 1; self.points = 50; // Fixed points for each fish self.speed = 2; // Constant speed fishGraphics.scale.set(self.size * 6.0, self.size * 6.0); if (Math.random() > 0.5) { self.speed = -self.speed; } }; self.shoot = function () { var bullet = new Bullet(); bullet.x = self.x; bullet.y = self.y; game.addChild(bullet); }; }); var Fish4 = Container.expand(function () { var self = Container.call(this); self.size = 1; self.points = 1; self.speed = 2; var fishGraphics = self.attachAsset('fish4', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { if (self.lastX === undefined) { self.lastX = self.x; } // Initialize lastX for tracking changes on X if (self.lastY === undefined) { self.lastY = self.y; } // Initialize lastY for tracking changes on Y self.x += self.speed; self.y += Math.sin(self.x / 50) * 0.5; self.lastX = self.x; // Update lastX after movement self.lastY = self.y; // Update lastY after movement fishGraphics.scale.x = self.speed > 0 ? 1 : -1; fishGraphics.scale.y = 1; game.children.forEach(function (child) { if (child instanceof Bullet) { var distance = Math.sqrt(Math.pow(child.x - self.x, 2) + Math.pow(child.y - self.y, 2)); if (distance < 200) { self.speed = -self.speed; } } }); if (self.speed > 0 && self.x > 2048) { self.x = -fishGraphics.width; } else if (self.speed < 0 && self.x < -fishGraphics.width) { self.x = 2048; } }; self.setProperties = function () { self.size = 1; self.points = 50; // Fixed points for each fish self.speed = 2; // Constant speed fishGraphics.scale.set(self.size * 6.0, self.size * 6.0); if (Math.random() > 0.5) { self.speed = -self.speed; } }; self.shoot = function () { var bullet = new Bullet(); bullet.x = self.x; bullet.y = self.y; game.addChild(bullet); }; }); // Spear class to represent the spear shot by the player var Spear = Container.expand(function () { var self = Container.call(this); self.speed = 10; // Default speed // Attach spear asset var spearGraphics = self.attachAsset('spear', { anchorX: 0.5, anchorY: 1.0 }); // Update function to move spear self.update = function () { self.y -= self.speed; if (self.y < 0) { self.destroy(); // Destroy the spear if it goes off screen } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x0000FF // Change background color to blue to simulate water }); /**** * Game Code ****/ var backgrounds = ['background', 'background2', 'background3', 'background4']; // Initialize backgrounds array var currentBackgroundIndex = 0; // Track the current background index var currentBackground = null; // Track the current background object function changeBackground() { // Remove the current background if it exists if (currentBackground) { game.removeChild(currentBackground); } // Update the background index currentBackgroundIndex = (currentBackgroundIndex + 1) % backgrounds.length; // Get the new background asset currentBackground = LK.getAsset(backgrounds[currentBackgroundIndex], { anchorX: 0.5, anchorY: 0.5, scaleX: 2048 / 4096, scaleY: 2732 / 5464, x: 2048 / 2, y: 2732 / 2 }); // Add the new background to the game game.addChild(currentBackground); // Schedule the next background change LK.setTimeout(changeBackground, 60000); // Change background every 60 seconds } // Start the background change cycle changeBackground(); function showRestartButton() { // Logic to display the restart button console.log("Restart button displayed"); } // Initialize variables var backgrounds = ['background', 'background2', 'background3']; // Initialize backgrounds array var initialBackground = LK.getAsset('background2', { anchorX: 0.5, anchorY: 0.5, scaleX: 2048 / 4096, // Adjust scale to fit screen width scaleY: 2732 / 5464, // Adjust scale to fit screen height x: 2048 / 2, y: 2732 / 2 }); game.addChild(initialBackground); // Initialize variables var timerTxt = new Text2('Time: 0', { size: 80, fill: 0xFFFFFF, font: "'Bubbleboddy Neue Trial Regular', Impact, 'Arial Black', Tahoma" }); timerTxt.anchor.set(0.5, 0); timerTxt.y = 200; // Position below the bullet count LK.gui.top.addChild(timerTxt); var timeRemaining = 300; // Initialize timeRemaining to 300 seconds (5 minutes) var score = 0; var fishArray = []; var bulletCount = 100; // Maximum number of bullets available var reloadTime = 3000; // 3 seconds reload time in milliseconds var isReloading = false; // Flag to check if reloading is in progress var scoreTxt = new Text2('Score: 0', { size: 100, fill: 0xFFFFFF, font: "'Bubbleboddy Neue Trial Regular', Impact, 'Arial Black', Tahoma" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Display bullet count and reloading status var bulletTxt = new Text2('Bullets: ' + bulletCount, { size: 80, // Increased size from 50 to 80 fill: 0xFFFFFF, font: "'Bubbleboddy Neue Trial Regular', Impact, 'Arial Black', Tahoma" }); bulletTxt.anchor.set(0.5, 0); bulletTxt.y = 100; // Position below the score LK.gui.top.addChild(bulletTxt); var reloadCountdown = reloadTime / 1000; // Reload time in seconds var bulletInterval = LK.setInterval(function () { if (isReloading) { if (bulletTxt) { bulletTxt.setText('Bullets: ' + bulletCount + ' (Reloading in ' + reloadCountdown + 's)'); if (bulletTxt.style) { bulletTxt.style.fill = 0xFF0000; // Set text color to red } } reloadCountdown--; if (reloadCountdown < 0) { reloadCountdown = reloadTime / 1000; // Reset countdown } } else { if (bulletTxt) { bulletTxt.setText('Bullets: ' + bulletCount); if (bulletTxt.style) { bulletTxt.style.fill = 0xFFFFFF; // Reset text color to white } } } }, 1000); // Function to initialize fish function initializeFish() { for (var i = 0; i < 20; i++) { var fishType = Math.floor(Math.random() * 4) + 1; // Randomly select fish type var fish; switch (fishType) { case 1: fish = new Fish(); break; case 2: fish = new Fish2(); break; case 3: fish = new Fish3(); break; case 4: fish = new Fish4(); break; } fish.setProperties(); fish.x = Math.random() * 2048; fish.y = Math.random() * 2732; fish.speed = (Math.random() > 0.5 ? 1 : -1) * (Math.random() * 2 + 1); // Randomize speed and direction fishArray.push(fish); game.addChild(fish); } var randomBackground = backgrounds[Math.floor(Math.random() * backgrounds.length)]; var newBackground = LK.getAsset(randomBackground, { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 }); game.addChild(newBackground); score = 0; scoreTxt.setText('Score: ' + score); timerTxt.setText('Time: ' + timeRemaining); // Initialize fish after background to ensure they are rendered above fishArray.forEach(function (fish) { game.addChild(fish); }); // Removed redundant fish initialization to prevent maximum call stack size exceeded error // Removed redundant fish initialization to prevent maximum call stack size exceeded error } // Function to handle fish click function handleFishClick(fish) { score += fish.points; // Add points based on fish properties scoreTxt.setText('Score: ' + score); // Display points earned at the fish's position var pointsTxt = new Text2('+' + fish.points, { size: 100, // Increased font size fill: 0xFFFF00, // Yellow color for visibility font: "'Bubbleboddy Neue Trial Regular', Impact, 'Arial Black', Tahoma" }); pointsTxt.anchor.set(0.5, 0.5); pointsTxt.x = fish.x; pointsTxt.y = fish.y; game.addChild(pointsTxt); // Animate the points text to move upwards and fade out LK.setTimeout(function () { pointsTxt.y -= 50; // Move up by 50 pixels pointsTxt.alpha = 0; // Fade out LK.setTimeout(function () { pointsTxt.destroy(); // Remove the text after animation }, 1000); // Duration of the fade out }, 1000); // Duration before starting the fade out fish.destroy(); fishArray.splice(fishArray.indexOf(fish), 1); // Check if all fish are caught if (fishArray.length === 0) { initializeFish(); // Reinitialize fish when all are caught } } // Add event listeners for fish fishArray.forEach(function (fish) { fish.down = function (x, y, obj) { handleFishClick(fish); }; }); // Game update function game.update = function () { fishArray.forEach(function (fish, index) { return fish.update(); }); // Update timeRemaining and timerTxt if (timeRemaining > 0) { timeRemaining -= 1 / 60; // Decrease timeRemaining by 1 second every 60 frames timerTxt.setText('Time: ' + Math.ceil(timeRemaining)); } else { // Handle time out logic if needed } game.children.forEach(function (child) { if (child instanceof Spear || child instanceof Bullet) { child.update(); // Check for collision with fish fishArray.forEach(function (fish) { if (child.intersects(fish)) { handleFishClick(fish); child.destroy(); LK.getSound('saplanma').play(); // Play 'saplanma' sound } }); } // Create bubbles at random intervals if (Math.random() < 0.0005) { var bubble = new Bubble(); bubble.x = Math.random() * 2048; bubble.y = 2732; // Start from the bottom of the screen game.addChild(bubble); } }); }; // Initialize the fake var fake = new Fake(); fake.x = 2048 / 2; fake.y = 2732 / 2; game.addChild(fake); initializeFish(); // Initialize fish after background and fake to ensure they are rendered above // Mouse or touch down on the game game.down = function (x, y, obj) { if (bulletCount > 0 && !isReloading) { var bullet = new Bullet(); bullet.x = 2048 / 2; // Set the bullet's starting x position to the center of the screen bullet.y = 2732; // Set the bullet's starting y position to the bottom of the screen bullet.rotation = Math.atan2(y - bullet.y, x - bullet.x); game.addChild(bullet); bulletCount--; // Decrease bullet count console.log("Bullets left: " + bulletCount); } else if (bulletCount === 0 && !isReloading) { isReloading = true; console.log("Reloading bullets..."); LK.setTimeout(function () { bulletCount = 20; // Reset bullet count isReloading = false; console.log("Bullets reloaded: " + bulletCount); reloadCountdown = reloadTime / 1000; // Reset countdown }, reloadTime); } }; // Play background music LK.playMusic('bgmusic', { loop: true });
/****
* Classes
****/
// Bubble class to represent the bubbles in the game
var Bubble = Container.expand(function () {
var self = Container.call(this);
self.speed = 1; // Default speed
// Attach bubble asset
var scaleX = Math.random() * 0.5 + 0.5;
var bubbleGraphics = self.attachAsset('bubble', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: scaleX,
// Random scale between 0.5 and 1.0
scaleY: scaleX // Ensure scaleY matches scaleX for a perfect circle
});
bubbleGraphics.alpha = 0.5;
// Update function to move bubble
self.update = function () {
if (self.lastY === undefined) {
self.lastY = self.y;
} // Initialize lastY for tracking changes on Y
self.y -= self.speed;
self.lastY = self.y; // Update lastY after movement
self.x += Math.sin(self.y / 50) * 1; // Reduce gentle swaying motion
if (self.y < 500) {
self.destroy(); // Destroy the bubble if it reaches a certain height
}
};
});
// Bullet class to represent the bullets shot by the player
var Bullet = Container.expand(function () {
var self = Container.call(this);
self.speed = 10; // Default speed
// Attach bullet asset
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
bulletGraphics.scale.set(0.5, 0.5); // Decrease the size of the bullet
bulletGraphics.rotation = -Math.PI / 2; // Rotate the bullet to point upwards
// Update function to move bullet
self.update = function () {
if (game.mouse) {
self.rotation = Math.atan2(game.mouse.y - self.y, game.mouse.x - self.x);
}
if (self.lastX === undefined) {
self.lastX = self.x;
} // Initialize lastX for tracking changes on X
if (self.lastY === undefined) {
self.lastY = self.y;
} // Initialize lastY for tracking changes on Y
self.x += self.speed * Math.cos(self.rotation);
self.y += self.speed * Math.sin(self.rotation);
self.lastX = self.x; // Update lastX after movement
self.lastY = self.y; // Update lastY after movement
if (self.y < 0) {
self.destroy(); // Destroy the bullet if it goes off screen
}
};
});
// Fake class to represent the fake in the game
var Fake = Container.expand(function () {
var self = Container.call(this);
self.speed = 1; // Default speed
// Attach fake asset
var fakeGraphics = self.attachAsset('fake', {
anchorX: 0.5,
anchorY: 0.5
});
fakeGraphics.alpha = 0.5;
// Update function to move fake
self.update = function () {
if (self.lastY === undefined) {
self.lastY = self.y;
} // Initialize lastY for tracking changes on Y
self.y -= self.speed;
self.lastY = self.y; // Update lastY after movement
if (self.y < 500) {
self.destroy(); // Destroy the fake if it reaches a certain height
}
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Fish class to represent different types of fish
var Fish = Container.expand(function () {
var self = Container.call(this);
self.size = 1; // Default size multiplier
self.points = 1; // Default points
self.speed = 2; // Default speed
// Attach fish asset
var fishGraphics = self.attachAsset('fish', {
anchorX: 0.5,
anchorY: 0.5
});
// Update function to move fish
self.update = function () {
if (self.lastX === undefined) {
self.lastX = self.x;
} // Initialize lastX for tracking changes on X
if (self.lastY === undefined) {
self.lastY = self.y;
} // Initialize lastY for tracking changes on Y
self.x += self.speed; // Move fish based on speed direction
self.y += Math.sin(self.x / 50) * 0.5; // Further reduce gentle swaying motion to fish
self.lastX = self.x; // Update lastX after movement
self.lastY = self.y; // Update lastY after movement
// Removed rotation animation from fish
// Ensure fish face the correct direction based on speed
fishGraphics.scale.x = self.speed > 0 ? 1 : -1;
fishGraphics.scale.y = 1; // Ensure fish are always facing forward
// Check for nearby bullets and change direction if close
game.children.forEach(function (child) {
if (child instanceof Bullet) {
var distance = Math.sqrt(Math.pow(child.x - self.x, 2) + Math.pow(child.y - self.y, 2));
if (distance < 200) {
// If bullet is within 200 pixels
self.speed = -self.speed; // Reverse direction
}
}
});
// Reset position if fish goes off screen
if (self.speed > 0 && self.x > 2048) {
self.x = -fishGraphics.width;
} else if (self.speed < 0 && self.x < -fishGraphics.width) {
self.x = 2048;
}
};
// Method to set fish properties based on level
self.setProperties = function () {
self.size = 1; // Set size to a constant value
self.points = 50; // Fixed points for each fish
self.speed = 2; // Constant speed
fishGraphics.scale.set(self.size * 6.0, self.size * 6.0);
if (Math.random() > 0.5) {
self.speed = -self.speed;
}
};
// Method to shoot a bullet
self.shoot = function () {
var bullet = new Bullet();
bullet.x = self.x;
bullet.y = self.y;
game.addChild(bullet);
};
});
var Fish2 = Container.expand(function () {
var self = Container.call(this);
self.size = 1;
self.points = 1;
self.speed = 2;
var fishGraphics = self.attachAsset('fish2', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
if (self.lastX === undefined) {
self.lastX = self.x;
} // Initialize lastX for tracking changes on X
if (self.lastY === undefined) {
self.lastY = self.y;
} // Initialize lastY for tracking changes on Y
self.x += self.speed;
self.y += Math.sin(self.x / 50) * 0.5;
self.lastX = self.x; // Update lastX after movement
self.lastY = self.y; // Update lastY after movement
fishGraphics.scale.x = self.speed > 0 ? 1 : -1;
fishGraphics.scale.y = 1;
game.children.forEach(function (child) {
if (child instanceof Bullet) {
var distance = Math.sqrt(Math.pow(child.x - self.x, 2) + Math.pow(child.y - self.y, 2));
if (distance < 200) {
self.speed = -self.speed;
}
}
});
if (self.speed > 0 && self.x > 2048) {
self.x = -fishGraphics.width;
} else if (self.speed < 0 && self.x < -fishGraphics.width) {
self.x = 2048;
}
};
self.setProperties = function () {
self.size = 1;
self.points = 50; // Fixed points for each fish
self.speed = 2; // Constant speed
fishGraphics.scale.set(self.size * 6.0, self.size * 6.0);
if (Math.random() > 0.5) {
self.speed = -self.speed;
}
};
self.shoot = function () {
var bullet = new Bullet();
bullet.x = self.x;
bullet.y = self.y;
game.addChild(bullet);
};
});
var Fish3 = Container.expand(function () {
var self = Container.call(this);
self.size = 1;
self.points = 1;
self.speed = 2;
var fishGraphics = self.attachAsset('fish3', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
if (self.lastX === undefined) {
self.lastX = self.x;
} // Initialize lastX for tracking changes on X
if (self.lastY === undefined) {
self.lastY = self.y;
} // Initialize lastY for tracking changes on Y
self.x += self.speed;
self.y += Math.sin(self.x / 50) * 0.5;
self.lastX = self.x; // Update lastX after movement
self.lastY = self.y; // Update lastY after movement
fishGraphics.scale.x = self.speed > 0 ? 1 : -1;
fishGraphics.scale.y = 1;
game.children.forEach(function (child) {
if (child instanceof Bullet) {
var distance = Math.sqrt(Math.pow(child.x - self.x, 2) + Math.pow(child.y - self.y, 2));
if (distance < 200) {
self.speed = -self.speed;
}
}
});
if (self.speed > 0 && self.x > 2048) {
self.x = -fishGraphics.width;
} else if (self.speed < 0 && self.x < -fishGraphics.width) {
self.x = 2048;
}
};
self.setProperties = function () {
self.size = 1;
self.points = 50; // Fixed points for each fish
self.speed = 2; // Constant speed
fishGraphics.scale.set(self.size * 6.0, self.size * 6.0);
if (Math.random() > 0.5) {
self.speed = -self.speed;
}
};
self.shoot = function () {
var bullet = new Bullet();
bullet.x = self.x;
bullet.y = self.y;
game.addChild(bullet);
};
});
var Fish4 = Container.expand(function () {
var self = Container.call(this);
self.size = 1;
self.points = 1;
self.speed = 2;
var fishGraphics = self.attachAsset('fish4', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
if (self.lastX === undefined) {
self.lastX = self.x;
} // Initialize lastX for tracking changes on X
if (self.lastY === undefined) {
self.lastY = self.y;
} // Initialize lastY for tracking changes on Y
self.x += self.speed;
self.y += Math.sin(self.x / 50) * 0.5;
self.lastX = self.x; // Update lastX after movement
self.lastY = self.y; // Update lastY after movement
fishGraphics.scale.x = self.speed > 0 ? 1 : -1;
fishGraphics.scale.y = 1;
game.children.forEach(function (child) {
if (child instanceof Bullet) {
var distance = Math.sqrt(Math.pow(child.x - self.x, 2) + Math.pow(child.y - self.y, 2));
if (distance < 200) {
self.speed = -self.speed;
}
}
});
if (self.speed > 0 && self.x > 2048) {
self.x = -fishGraphics.width;
} else if (self.speed < 0 && self.x < -fishGraphics.width) {
self.x = 2048;
}
};
self.setProperties = function () {
self.size = 1;
self.points = 50; // Fixed points for each fish
self.speed = 2; // Constant speed
fishGraphics.scale.set(self.size * 6.0, self.size * 6.0);
if (Math.random() > 0.5) {
self.speed = -self.speed;
}
};
self.shoot = function () {
var bullet = new Bullet();
bullet.x = self.x;
bullet.y = self.y;
game.addChild(bullet);
};
});
// Spear class to represent the spear shot by the player
var Spear = Container.expand(function () {
var self = Container.call(this);
self.speed = 10; // Default speed
// Attach spear asset
var spearGraphics = self.attachAsset('spear', {
anchorX: 0.5,
anchorY: 1.0
});
// Update function to move spear
self.update = function () {
self.y -= self.speed;
if (self.y < 0) {
self.destroy(); // Destroy the spear if it goes off screen
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x0000FF // Change background color to blue to simulate water
});
/****
* Game Code
****/
var backgrounds = ['background', 'background2', 'background3', 'background4']; // Initialize backgrounds array
var currentBackgroundIndex = 0; // Track the current background index
var currentBackground = null; // Track the current background object
function changeBackground() {
// Remove the current background if it exists
if (currentBackground) {
game.removeChild(currentBackground);
}
// Update the background index
currentBackgroundIndex = (currentBackgroundIndex + 1) % backgrounds.length;
// Get the new background asset
currentBackground = LK.getAsset(backgrounds[currentBackgroundIndex], {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2048 / 4096,
scaleY: 2732 / 5464,
x: 2048 / 2,
y: 2732 / 2
});
// Add the new background to the game
game.addChild(currentBackground);
// Schedule the next background change
LK.setTimeout(changeBackground, 60000); // Change background every 60 seconds
}
// Start the background change cycle
changeBackground();
function showRestartButton() {
// Logic to display the restart button
console.log("Restart button displayed");
}
// Initialize variables
var backgrounds = ['background', 'background2', 'background3']; // Initialize backgrounds array
var initialBackground = LK.getAsset('background2', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2048 / 4096,
// Adjust scale to fit screen width
scaleY: 2732 / 5464,
// Adjust scale to fit screen height
x: 2048 / 2,
y: 2732 / 2
});
game.addChild(initialBackground);
// Initialize variables
var timerTxt = new Text2('Time: 0', {
size: 80,
fill: 0xFFFFFF,
font: "'Bubbleboddy Neue Trial Regular', Impact, 'Arial Black', Tahoma"
});
timerTxt.anchor.set(0.5, 0);
timerTxt.y = 200; // Position below the bullet count
LK.gui.top.addChild(timerTxt);
var timeRemaining = 300; // Initialize timeRemaining to 300 seconds (5 minutes)
var score = 0;
var fishArray = [];
var bulletCount = 100; // Maximum number of bullets available
var reloadTime = 3000; // 3 seconds reload time in milliseconds
var isReloading = false; // Flag to check if reloading is in progress
var scoreTxt = new Text2('Score: 0', {
size: 100,
fill: 0xFFFFFF,
font: "'Bubbleboddy Neue Trial Regular', Impact, 'Arial Black', Tahoma"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Display bullet count and reloading status
var bulletTxt = new Text2('Bullets: ' + bulletCount, {
size: 80,
// Increased size from 50 to 80
fill: 0xFFFFFF,
font: "'Bubbleboddy Neue Trial Regular', Impact, 'Arial Black', Tahoma"
});
bulletTxt.anchor.set(0.5, 0);
bulletTxt.y = 100; // Position below the score
LK.gui.top.addChild(bulletTxt);
var reloadCountdown = reloadTime / 1000; // Reload time in seconds
var bulletInterval = LK.setInterval(function () {
if (isReloading) {
if (bulletTxt) {
bulletTxt.setText('Bullets: ' + bulletCount + ' (Reloading in ' + reloadCountdown + 's)');
if (bulletTxt.style) {
bulletTxt.style.fill = 0xFF0000; // Set text color to red
}
}
reloadCountdown--;
if (reloadCountdown < 0) {
reloadCountdown = reloadTime / 1000; // Reset countdown
}
} else {
if (bulletTxt) {
bulletTxt.setText('Bullets: ' + bulletCount);
if (bulletTxt.style) {
bulletTxt.style.fill = 0xFFFFFF; // Reset text color to white
}
}
}
}, 1000);
// Function to initialize fish
function initializeFish() {
for (var i = 0; i < 20; i++) {
var fishType = Math.floor(Math.random() * 4) + 1; // Randomly select fish type
var fish;
switch (fishType) {
case 1:
fish = new Fish();
break;
case 2:
fish = new Fish2();
break;
case 3:
fish = new Fish3();
break;
case 4:
fish = new Fish4();
break;
}
fish.setProperties();
fish.x = Math.random() * 2048;
fish.y = Math.random() * 2732;
fish.speed = (Math.random() > 0.5 ? 1 : -1) * (Math.random() * 2 + 1); // Randomize speed and direction
fishArray.push(fish);
game.addChild(fish);
}
var randomBackground = backgrounds[Math.floor(Math.random() * backgrounds.length)];
var newBackground = LK.getAsset(randomBackground, {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
game.addChild(newBackground);
score = 0;
scoreTxt.setText('Score: ' + score);
timerTxt.setText('Time: ' + timeRemaining);
// Initialize fish after background to ensure they are rendered above
fishArray.forEach(function (fish) {
game.addChild(fish);
});
// Removed redundant fish initialization to prevent maximum call stack size exceeded error
// Removed redundant fish initialization to prevent maximum call stack size exceeded error
}
// Function to handle fish click
function handleFishClick(fish) {
score += fish.points; // Add points based on fish properties
scoreTxt.setText('Score: ' + score);
// Display points earned at the fish's position
var pointsTxt = new Text2('+' + fish.points, {
size: 100,
// Increased font size
fill: 0xFFFF00,
// Yellow color for visibility
font: "'Bubbleboddy Neue Trial Regular', Impact, 'Arial Black', Tahoma"
});
pointsTxt.anchor.set(0.5, 0.5);
pointsTxt.x = fish.x;
pointsTxt.y = fish.y;
game.addChild(pointsTxt);
// Animate the points text to move upwards and fade out
LK.setTimeout(function () {
pointsTxt.y -= 50; // Move up by 50 pixels
pointsTxt.alpha = 0; // Fade out
LK.setTimeout(function () {
pointsTxt.destroy(); // Remove the text after animation
}, 1000); // Duration of the fade out
}, 1000); // Duration before starting the fade out
fish.destroy();
fishArray.splice(fishArray.indexOf(fish), 1);
// Check if all fish are caught
if (fishArray.length === 0) {
initializeFish(); // Reinitialize fish when all are caught
}
}
// Add event listeners for fish
fishArray.forEach(function (fish) {
fish.down = function (x, y, obj) {
handleFishClick(fish);
};
});
// Game update function
game.update = function () {
fishArray.forEach(function (fish, index) {
return fish.update();
});
// Update timeRemaining and timerTxt
if (timeRemaining > 0) {
timeRemaining -= 1 / 60; // Decrease timeRemaining by 1 second every 60 frames
timerTxt.setText('Time: ' + Math.ceil(timeRemaining));
} else {
// Handle time out logic if needed
}
game.children.forEach(function (child) {
if (child instanceof Spear || child instanceof Bullet) {
child.update();
// Check for collision with fish
fishArray.forEach(function (fish) {
if (child.intersects(fish)) {
handleFishClick(fish);
child.destroy();
LK.getSound('saplanma').play(); // Play 'saplanma' sound
}
});
}
// Create bubbles at random intervals
if (Math.random() < 0.0005) {
var bubble = new Bubble();
bubble.x = Math.random() * 2048;
bubble.y = 2732; // Start from the bottom of the screen
game.addChild(bubble);
}
});
};
// Initialize the fake
var fake = new Fake();
fake.x = 2048 / 2;
fake.y = 2732 / 2;
game.addChild(fake);
initializeFish(); // Initialize fish after background and fake to ensure they are rendered above
// Mouse or touch down on the game
game.down = function (x, y, obj) {
if (bulletCount > 0 && !isReloading) {
var bullet = new Bullet();
bullet.x = 2048 / 2; // Set the bullet's starting x position to the center of the screen
bullet.y = 2732; // Set the bullet's starting y position to the bottom of the screen
bullet.rotation = Math.atan2(y - bullet.y, x - bullet.x);
game.addChild(bullet);
bulletCount--; // Decrease bullet count
console.log("Bullets left: " + bulletCount);
} else if (bulletCount === 0 && !isReloading) {
isReloading = true;
console.log("Reloading bullets...");
LK.setTimeout(function () {
bulletCount = 20; // Reset bullet count
isReloading = false;
console.log("Bullets reloaded: " + bulletCount);
reloadCountdown = reloadTime / 1000; // Reset countdown
}, reloadTime);
}
};
// Play background music
LK.playMusic('bgmusic', {
loop: true
});
Red pot fish. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
spear. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
palyaço balığı. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
japon balığı. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Guppy fish. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
undersea olants rocks etc but no fish. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.