/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var Fish = Container.expand(function (fishType) { var self = Container.call(this); var fishTypes = { 'common': { asset: 'commonFish', value: 5, name: 'Sardine' }, 'uncommon': { asset: 'uncommonFish', value: 15, name: 'Bass' }, 'rare': { asset: 'rareFish', value: 50, name: 'Tuna' }, 'legendary': { asset: 'legendaryFish', value: 200, name: 'Golden Fish' } }; self.fishData = fishTypes[fishType] || fishTypes['common']; self.fishType = fishType || 'common'; var fishGraphics = self.attachAsset(self.fishData.asset, { anchorX: 0.5, anchorY: 0.5 }); self.getValue = function () { // Progressive multiplier that grows more reasonably for 100 levels // Levels 1-10: 10% bonus per level // Levels 11-50: 5% bonus per level // Levels 51-100: 2% bonus per level var multiplier = 1; if (rodLevel <= 10) { multiplier = 1 + (rodLevel - 1) * 0.1; } else if (rodLevel <= 50) { multiplier = 2 + (rodLevel - 10) * 0.05; // Start at 2x (level 10 bonus) + additional } else { multiplier = 4 + (rodLevel - 50) * 0.02; // Start at 4x (level 50 bonus) + additional } return Math.floor(self.fishData.value * multiplier); }; self.getName = function () { return self.fishData.name; }; return self; }); var FishingRod = Container.expand(function () { var self = Container.call(this); var rodGraphics = self.attachAsset('fishingRod', { anchorX: 0.5, anchorY: 0 }); var lineGraphics = self.attachAsset('fishingLine', { anchorX: 0.5, anchorY: 0 }); lineGraphics.y = 300; lineGraphics.visible = false; var hookGraphics = self.attachAsset('hook', { anchorX: 0.5, anchorY: 0 }); hookGraphics.y = 700; hookGraphics.visible = false; self.isCasting = false; self.castProgress = 0; self.cast = function () { if (self.isCasting) return; self.isCasting = true; self.castProgress = 0; lineGraphics.visible = true; hookGraphics.visible = true; tween(self, { castProgress: 1 }, { duration: 1000, easing: tween.easeOut, onFinish: function onFinish() { self.pullUp(); } }); }; self.pullUp = function () { tween(self, { castProgress: 0 }, { duration: 800, easing: tween.easeIn, onFinish: function onFinish() { lineGraphics.visible = false; hookGraphics.visible = false; self.isCasting = false; } }); }; self.update = function () { if (self.isCasting) { lineGraphics.height = 400 + self.castProgress * 300; hookGraphics.y = 700 + self.castProgress * 300; } }; return self; }); var UpgradeButton = Container.expand(function (upgradeType, cost, description) { var self = Container.call(this); var buttonGraphics = self.attachAsset('upgradeButton', { anchorX: 0.5, anchorY: 0.5 }); var buttonText = new Text2(description + '\n$' + cost, { size: 32, fill: 0xFFFFFF }); buttonText.anchor.set(0.5, 0.5); self.addChild(buttonText); self.upgradeType = upgradeType; self.cost = cost; self.description = description; self.updateText = function (newCost) { self.cost = newCost; buttonText.setText(self.description + '\n$' + newCost); }; self.down = function (x, y, obj) { if (coins >= self.cost) { coins -= self.cost; LK.getSound('upgrade').play(); if (self.upgradeType === 'rod') { rodLevel++; // Reset to level 1 when reaching level 100 if (rodLevel > 100) { rodLevel = 1; } self.updateText(Math.floor(self.cost * 1.5)); updateRodAppearance(); // Update rod color when upgraded } updateUI(); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB }); /**** * Game Code ****/ // Game state variables var coins = storage.coins || 0; var rodLevel = storage.rodLevel || 1; // Reconstruct inventory from flattened storage var inventory = []; var storedTypes = storage.inventoryTypes || []; var storedValues = storage.inventoryValues || []; var storedNames = storage.inventoryNames || []; for (var i = 0; i < storedTypes.length; i++) { inventory.push({ type: storedTypes[i], value: storedValues[i], name: storedNames[i] }); } var totalFishCaught = storage.totalFishCaught || 0; // Create water background var water = game.attachAsset('water', { anchorX: 0, anchorY: 0, x: 0, y: 0 }); // Create fishing rod var fishingRod = game.addChild(new FishingRod()); fishingRod.x = 1024; fishingRod.y = 200; // Function to update rod appearance based on level function updateRodAppearance() { var rodColors = [0x8b4513, 0x4a90e2, 0x9b59b6, 0xe74c3c, 0xf39c12, // Levels 1-5: Brown, Blue, Purple, Red, Orange 0x1abc9c, 0x34495e, 0xe67e22, 0x9c88ff, 0xff6b6b, // Levels 6-10: Turquoise, Dark Gray, Orange, Light Purple, Light Red 0x4ecdc4, 0x45b7d1, 0x96ceb4, 0xfeca57, 0xff9ff3, // Levels 11-15: Mint, Sky Blue, Sage, Yellow, Pink 0x54a0ff, 0x5f27cd, 0x00d2d3, 0xff9f43, 0xc44569, // Levels 16-20: Blue, Deep Purple, Cyan, Peach, Maroon 0x3d5a80, 0x98ddca, 0xd63031, 0x6c5ce7, 0xa29bfe // Levels 21-25: Navy, Mint Green, Crimson, Violet, Periwinkle ]; var rodGraphics = fishingRod.children[0]; // First child is the rod graphics if (rodGraphics) { var colorIndex; if (rodLevel <= 25) { colorIndex = rodLevel - 1; } else { // For levels 26-100, cycle through colors with slight variations var baseColorIndex = (rodLevel - 26) % 25; var variation = Math.floor((rodLevel - 26) / 25); var baseColor = rodColors[baseColorIndex]; // Add brightness variation for higher levels var brightnessFactor = 1 + variation * 0.15; var r = Math.min(255, Math.floor((baseColor >> 16 & 0xFF) * brightnessFactor)); var g = Math.min(255, Math.floor((baseColor >> 8 & 0xFF) * brightnessFactor)); var b = Math.min(255, Math.floor((baseColor & 0xFF) * brightnessFactor)); var finalColor = r << 16 | g << 8 | b; tween(rodGraphics, { tint: finalColor }, { duration: 500, easing: tween.easeOut }); return; } tween(rodGraphics, { tint: rodColors[colorIndex] }, { duration: 500, easing: tween.easeOut }); } } // Set initial rod color updateRodAppearance(); // Create UI elements var coinsText = new Text2('Coins: $' + coins, { size: 48, fill: 0xFFFFFF }); coinsText.anchor.set(0, 0); coinsText.x = 120; // Position away from top-left menu icon LK.gui.topLeft.addChild(coinsText); var rodLevelDisplayText = new Text2('Rod Level: ' + rodLevel, { size: 36, fill: 0xFFFFFF }); rodLevelDisplayText.anchor.set(0, 0); rodLevelDisplayText.x = 120; // Position away from top-left menu icon rodLevelDisplayText.y = 60; // Position below coins text LK.gui.topLeft.addChild(rodLevelDisplayText); var rodLevelText = new Text2('Rod Level: ' + rodLevel, { size: 36, fill: 0xFFFFFF }); rodLevelText.anchor.set(0, 0); LK.gui.topRight.addChild(rodLevelText); rodLevelText.y = 60; var inventoryText = new Text2('Fish Caught: ' + inventory.length, { size: 36, fill: 0xFFFFFF }); inventoryText.anchor.set(0, 0); LK.gui.topRight.addChild(inventoryText); inventoryText.y = 110; // Create upgrade button var rodUpgrade = game.addChild(new UpgradeButton('rod', 100, 'Upgrade Rod')); rodUpgrade.x = 1024; rodUpgrade.y = 2500; // Create sell button var sellButtonGraphics = game.attachAsset('sellButton', { anchorX: 0.5, anchorY: 0.5, x: 300, y: 2500 }); var sellButtonText = new Text2('Sell All Fish', { size: 32, fill: 0xFFFFFF }); sellButtonText.anchor.set(0.5, 0.5); sellButtonGraphics.addChild(sellButtonText); // Create inventory GUI button var inventoryButton = game.attachAsset('upgradeButton', { anchorX: 0.5, anchorY: 0.5, x: 700, y: 2500 }); var inventoryButtonText = new Text2('View Inventory', { size: 32, fill: 0xFFFFFF }); inventoryButtonText.anchor.set(0.5, 0.5); inventoryButton.addChild(inventoryButtonText); // Create inventory display container (initially hidden) var inventoryContainer = new Container(); inventoryContainer.visible = false; game.addChild(inventoryContainer); // Inventory background var inventoryBg = inventoryContainer.attachAsset('water', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1366, scaleX: 0.8, scaleY: 0.6 }); inventoryBg.tint = 0x333333; inventoryBg.alpha = 0.9; // Inventory title var inventoryTitle = new Text2('Fish Inventory', { size: 48, fill: 0xFFFFFF }); inventoryTitle.anchor.set(0.5, 0.5); inventoryTitle.x = 1024; inventoryTitle.y = 900; inventoryContainer.addChild(inventoryTitle); // Close button for inventory var closeButton = inventoryContainer.attachAsset('sellButton', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1800 }); var closeButtonText = new Text2('Close', { size: 32, fill: 0xFFFFFF }); closeButtonText.anchor.set(0.5, 0.5); closeButton.addChild(closeButtonText); var isInventoryOpen = false; var inventoryFishDisplays = []; // Fish spawn area var fishSpawnArea = { x: 400, y: 1400, width: 1200, height: 800 }; // Arrays to track game objects var caughtFish = []; var fishingTimer = 0; function updateUI() { coinsText.setText('Coins: $' + coins); rodLevelText.setText('Rod Level: ' + rodLevel); rodLevelDisplayText.setText('Rod Level: ' + rodLevel); inventoryText.setText('Fish Caught: ' + inventory.length); // Save to storage - flatten inventory for storage compatibility storage.coins = coins; storage.rodLevel = rodLevel; // Store inventory as separate arrays var inventoryTypes = []; var inventoryValues = []; var inventoryNames = []; for (var i = 0; i < inventory.length; i++) { inventoryTypes.push(inventory[i].type); inventoryValues.push(inventory[i].value); inventoryNames.push(inventory[i].name); } storage.inventoryTypes = inventoryTypes; storage.inventoryValues = inventoryValues; storage.inventoryNames = inventoryNames; storage.totalFishCaught = totalFishCaught; } function updateInventoryDisplay() { // Clear existing fish displays for (var i = 0; i < inventoryFishDisplays.length; i++) { if (inventoryFishDisplays[i] && inventoryFishDisplays[i].destroy) { inventoryFishDisplays[i].destroy(); } } inventoryFishDisplays = []; // Count fish by type var fishCounts = {}; for (var i = 0; i < inventory.length; i++) { var fish = inventory[i]; if (!fishCounts[fish.type]) { fishCounts[fish.type] = { count: 0, value: fish.value, name: fish.name, type: fish.type }; } fishCounts[fish.type].count++; } // Display fish groups var fishTypes = Object.keys(fishCounts); var startX = 600; var startY = 1000; var columns = 3; for (var i = 0; i < fishTypes.length; i++) { var fishType = fishTypes[i]; var fishData = fishCounts[fishType]; var row = Math.floor(i / columns); var col = i % columns; var x = startX + col * 300; var y = startY + row * 200; // Create fish display container var fishDisplay = new Container(); fishDisplay.x = x; fishDisplay.y = y; inventoryContainer.addChild(fishDisplay); inventoryFishDisplays.push(fishDisplay); // Fish icon var fishIcon = new Fish(fishType); fishIcon.scaleX = 1.5; fishIcon.scaleY = 1.5; fishDisplay.addChild(fishIcon); // Fish info text var fishInfo = new Text2(fishData.name + '\nCount: ' + fishData.count + '\nValue: $' + fishData.value, { size: 24, fill: 0xFFFFFF }); fishInfo.anchor.set(0.5, 0); fishInfo.y = 50; fishDisplay.addChild(fishInfo); } } function getFishTypeByRodLevel() { var random = Math.random(); // Progressive legendary fish chance (starts at level 10, max 25% at level 100) var legendaryChance = Math.max(0, (rodLevel - 10) * 0.0025); legendaryChance = Math.min(0.25, legendaryChance); // Progressive rare fish chance (starts at level 5, max 40% at level 100) var rareChance = Math.max(0, (rodLevel - 5) * 0.004); rareChance = Math.min(0.4, rareChance); // Progressive uncommon fish chance (starts at level 2, max 50% at level 100) var uncommonChance = Math.max(0, (rodLevel - 2) * 0.005); uncommonChance = Math.min(0.5, uncommonChance); if (random < legendaryChance) return 'legendary'; if (random < legendaryChance + rareChance) return 'rare'; if (random < legendaryChance + rareChance + uncommonChance) return 'uncommon'; return 'common'; } function spawnFish() { var fishType = getFishTypeByRodLevel(); var fish = new Fish(fishType); fish.x = fishSpawnArea.x + Math.random() * fishSpawnArea.width; fish.y = fishSpawnArea.y + Math.random() * fishSpawnArea.height; game.addChild(fish); caughtFish.push(fish); inventory.push({ type: fishType, value: fish.getValue(), name: fish.getName() }); totalFishCaught++; // Animate fish jump var originalY = fish.y; tween(fish, { y: originalY - 100 }, { duration: 500, easing: tween.easeOut, onFinish: function onFinish() { tween(fish, { y: originalY }, { duration: 500, easing: tween.easeIn, onFinish: function onFinish() { tween(fish, { alpha: 0 }, { duration: 1000, onFinish: function onFinish() { fish.destroy(); var index = caughtFish.indexOf(fish); if (index > -1) { caughtFish.splice(index, 1); } } }); } }); } }); LK.getSound('catch').play(); updateUI(); if (isInventoryOpen) { updateInventoryDisplay(); } } // Game tap handler game.down = function (x, y, obj) { if (!fishingRod.isCasting) { fishingRod.cast(); LK.getSound('splash').play(); // Chance to catch fish based on rod level (scales to 100 levels, max 95%) var catchChance = 0.3 + Math.min(0.65, rodLevel * 0.0065); if (Math.random() < catchChance) { LK.setTimeout(function () { spawnFish(); }, 1200); } } }; // Sell button handler sellButtonGraphics.down = function (x, y, obj) { // Button press effect tween(sellButtonGraphics, { scaleX: 0.9, scaleY: 0.9 }, { duration: 100, easing: tween.easeOut, onFinish: function onFinish() { tween(sellButtonGraphics, { scaleX: 1, scaleY: 1 }, { duration: 100, easing: tween.easeOut }); } }); if (inventory.length > 0) { var totalValue = 0; for (var i = 0; i < inventory.length; i++) { totalValue += inventory[i].value; } coins += totalValue; inventory = []; // Clear visible fish for (var j = 0; j < caughtFish.length; j++) { if (caughtFish[j] && caughtFish[j].destroy) { caughtFish[j].destroy(); } } caughtFish = []; updateUI(); updateInventoryDisplay(); LK.effects.flashScreen(0x00FF00, 500); } }; // Inventory button handler inventoryButton.down = function (x, y, obj) { // Button press effect tween(inventoryButton, { scaleX: 0.9, scaleY: 0.9 }, { duration: 100, easing: tween.easeOut, onFinish: function onFinish() { tween(inventoryButton, { scaleX: 1, scaleY: 1 }, { duration: 100, easing: tween.easeOut }); } }); isInventoryOpen = !isInventoryOpen; inventoryContainer.visible = isInventoryOpen; if (isInventoryOpen) { updateInventoryDisplay(); } }; // Close inventory button handler closeButton.down = function (x, y, obj) { // Button press effect tween(closeButton, { scaleX: 0.9, scaleY: 0.9 }, { duration: 100, easing: tween.easeOut, onFinish: function onFinish() { tween(closeButton, { scaleX: 1, scaleY: 1 }, { duration: 100, easing: tween.easeOut }); } }); isInventoryOpen = false; inventoryContainer.visible = false; }; // Auto-save every 5 seconds var autoSaveTimer = LK.setInterval(function () { storage.coins = coins; storage.rodLevel = rodLevel; // Store inventory as separate arrays var inventoryTypes = []; var inventoryValues = []; var inventoryNames = []; for (var i = 0; i < inventory.length; i++) { inventoryTypes.push(inventory[i].type); inventoryValues.push(inventory[i].value); inventoryNames.push(inventory[i].name); } storage.inventoryTypes = inventoryTypes; storage.inventoryValues = inventoryValues; storage.inventoryNames = inventoryNames; storage.totalFishCaught = totalFishCaught; }, 5000); // Add hover effects for buttons sellButtonGraphics.move = function (x, y, obj) { tween(sellButtonGraphics, { tint: 0xffcc00 }, { duration: 200, easing: tween.easeOut }); }; inventoryButton.move = function (x, y, obj) { tween(inventoryButton, { tint: 0x66bb6a }, { duration: 200, easing: tween.easeOut }); }; closeButton.move = function (x, y, obj) { tween(closeButton, { tint: 0xff7043 }, { duration: 200, easing: tween.easeOut }); }; // Reset button colors when not hovering game.move = function (x, y, obj) { // Reset sell button color if not hovering if (!sellButtonGraphics.getBounds().contains(x, y)) { tween(sellButtonGraphics, { tint: 0xff9800 }, { duration: 200, easing: tween.easeOut }); } // Reset inventory button color if not hovering if (!inventoryButton.getBounds().contains(x, y)) { tween(inventoryButton, { tint: 0x4caf50 }, { duration: 200, easing: tween.easeOut }); } // Reset close button color if not hovering and inventory is open if (isInventoryOpen && !closeButton.getBounds().contains(x, y)) { tween(closeButton, { tint: 0xff9800 }, { duration: 200, easing: tween.easeOut }); } }; game.update = function () { // Update fishing rod animation if (fishingRod && fishingRod.update) { fishingRod.update(); } // Update upgrade button cost display with progressive scaling for 100 levels var targetCost; // Hide upgrade button at level 100 since it will reset if (rodLevel >= 100) { targetCost = Math.floor(100 * Math.pow(1.5, 99)); // Cost for level 100 } else if (rodLevel <= 10) { targetCost = Math.floor(100 * Math.pow(1.5, rodLevel - 1)); } else if (rodLevel <= 50) { var baseCost = Math.floor(100 * Math.pow(1.5, 9)); // Cost at level 10 targetCost = Math.floor(baseCost * Math.pow(1.3, rodLevel - 10)); } else { var baseCost10 = Math.floor(100 * Math.pow(1.5, 9)); var baseCost50 = Math.floor(baseCost10 * Math.pow(1.3, 40)); targetCost = Math.floor(baseCost50 * Math.pow(1.2, rodLevel - 50)); } if (rodUpgrade && rodUpgrade.cost !== targetCost) { rodUpgrade.updateText(targetCost); } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Fish = Container.expand(function (fishType) {
var self = Container.call(this);
var fishTypes = {
'common': {
asset: 'commonFish',
value: 5,
name: 'Sardine'
},
'uncommon': {
asset: 'uncommonFish',
value: 15,
name: 'Bass'
},
'rare': {
asset: 'rareFish',
value: 50,
name: 'Tuna'
},
'legendary': {
asset: 'legendaryFish',
value: 200,
name: 'Golden Fish'
}
};
self.fishData = fishTypes[fishType] || fishTypes['common'];
self.fishType = fishType || 'common';
var fishGraphics = self.attachAsset(self.fishData.asset, {
anchorX: 0.5,
anchorY: 0.5
});
self.getValue = function () {
// Progressive multiplier that grows more reasonably for 100 levels
// Levels 1-10: 10% bonus per level
// Levels 11-50: 5% bonus per level
// Levels 51-100: 2% bonus per level
var multiplier = 1;
if (rodLevel <= 10) {
multiplier = 1 + (rodLevel - 1) * 0.1;
} else if (rodLevel <= 50) {
multiplier = 2 + (rodLevel - 10) * 0.05; // Start at 2x (level 10 bonus) + additional
} else {
multiplier = 4 + (rodLevel - 50) * 0.02; // Start at 4x (level 50 bonus) + additional
}
return Math.floor(self.fishData.value * multiplier);
};
self.getName = function () {
return self.fishData.name;
};
return self;
});
var FishingRod = Container.expand(function () {
var self = Container.call(this);
var rodGraphics = self.attachAsset('fishingRod', {
anchorX: 0.5,
anchorY: 0
});
var lineGraphics = self.attachAsset('fishingLine', {
anchorX: 0.5,
anchorY: 0
});
lineGraphics.y = 300;
lineGraphics.visible = false;
var hookGraphics = self.attachAsset('hook', {
anchorX: 0.5,
anchorY: 0
});
hookGraphics.y = 700;
hookGraphics.visible = false;
self.isCasting = false;
self.castProgress = 0;
self.cast = function () {
if (self.isCasting) return;
self.isCasting = true;
self.castProgress = 0;
lineGraphics.visible = true;
hookGraphics.visible = true;
tween(self, {
castProgress: 1
}, {
duration: 1000,
easing: tween.easeOut,
onFinish: function onFinish() {
self.pullUp();
}
});
};
self.pullUp = function () {
tween(self, {
castProgress: 0
}, {
duration: 800,
easing: tween.easeIn,
onFinish: function onFinish() {
lineGraphics.visible = false;
hookGraphics.visible = false;
self.isCasting = false;
}
});
};
self.update = function () {
if (self.isCasting) {
lineGraphics.height = 400 + self.castProgress * 300;
hookGraphics.y = 700 + self.castProgress * 300;
}
};
return self;
});
var UpgradeButton = Container.expand(function (upgradeType, cost, description) {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('upgradeButton', {
anchorX: 0.5,
anchorY: 0.5
});
var buttonText = new Text2(description + '\n$' + cost, {
size: 32,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.upgradeType = upgradeType;
self.cost = cost;
self.description = description;
self.updateText = function (newCost) {
self.cost = newCost;
buttonText.setText(self.description + '\n$' + newCost);
};
self.down = function (x, y, obj) {
if (coins >= self.cost) {
coins -= self.cost;
LK.getSound('upgrade').play();
if (self.upgradeType === 'rod') {
rodLevel++;
// Reset to level 1 when reaching level 100
if (rodLevel > 100) {
rodLevel = 1;
}
self.updateText(Math.floor(self.cost * 1.5));
updateRodAppearance(); // Update rod color when upgraded
}
updateUI();
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Game state variables
var coins = storage.coins || 0;
var rodLevel = storage.rodLevel || 1;
// Reconstruct inventory from flattened storage
var inventory = [];
var storedTypes = storage.inventoryTypes || [];
var storedValues = storage.inventoryValues || [];
var storedNames = storage.inventoryNames || [];
for (var i = 0; i < storedTypes.length; i++) {
inventory.push({
type: storedTypes[i],
value: storedValues[i],
name: storedNames[i]
});
}
var totalFishCaught = storage.totalFishCaught || 0;
// Create water background
var water = game.attachAsset('water', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
// Create fishing rod
var fishingRod = game.addChild(new FishingRod());
fishingRod.x = 1024;
fishingRod.y = 200;
// Function to update rod appearance based on level
function updateRodAppearance() {
var rodColors = [0x8b4513, 0x4a90e2, 0x9b59b6, 0xe74c3c, 0xf39c12,
// Levels 1-5: Brown, Blue, Purple, Red, Orange
0x1abc9c, 0x34495e, 0xe67e22, 0x9c88ff, 0xff6b6b,
// Levels 6-10: Turquoise, Dark Gray, Orange, Light Purple, Light Red
0x4ecdc4, 0x45b7d1, 0x96ceb4, 0xfeca57, 0xff9ff3,
// Levels 11-15: Mint, Sky Blue, Sage, Yellow, Pink
0x54a0ff, 0x5f27cd, 0x00d2d3, 0xff9f43, 0xc44569,
// Levels 16-20: Blue, Deep Purple, Cyan, Peach, Maroon
0x3d5a80, 0x98ddca, 0xd63031, 0x6c5ce7, 0xa29bfe // Levels 21-25: Navy, Mint Green, Crimson, Violet, Periwinkle
];
var rodGraphics = fishingRod.children[0]; // First child is the rod graphics
if (rodGraphics) {
var colorIndex;
if (rodLevel <= 25) {
colorIndex = rodLevel - 1;
} else {
// For levels 26-100, cycle through colors with slight variations
var baseColorIndex = (rodLevel - 26) % 25;
var variation = Math.floor((rodLevel - 26) / 25);
var baseColor = rodColors[baseColorIndex];
// Add brightness variation for higher levels
var brightnessFactor = 1 + variation * 0.15;
var r = Math.min(255, Math.floor((baseColor >> 16 & 0xFF) * brightnessFactor));
var g = Math.min(255, Math.floor((baseColor >> 8 & 0xFF) * brightnessFactor));
var b = Math.min(255, Math.floor((baseColor & 0xFF) * brightnessFactor));
var finalColor = r << 16 | g << 8 | b;
tween(rodGraphics, {
tint: finalColor
}, {
duration: 500,
easing: tween.easeOut
});
return;
}
tween(rodGraphics, {
tint: rodColors[colorIndex]
}, {
duration: 500,
easing: tween.easeOut
});
}
}
// Set initial rod color
updateRodAppearance();
// Create UI elements
var coinsText = new Text2('Coins: $' + coins, {
size: 48,
fill: 0xFFFFFF
});
coinsText.anchor.set(0, 0);
coinsText.x = 120; // Position away from top-left menu icon
LK.gui.topLeft.addChild(coinsText);
var rodLevelDisplayText = new Text2('Rod Level: ' + rodLevel, {
size: 36,
fill: 0xFFFFFF
});
rodLevelDisplayText.anchor.set(0, 0);
rodLevelDisplayText.x = 120; // Position away from top-left menu icon
rodLevelDisplayText.y = 60; // Position below coins text
LK.gui.topLeft.addChild(rodLevelDisplayText);
var rodLevelText = new Text2('Rod Level: ' + rodLevel, {
size: 36,
fill: 0xFFFFFF
});
rodLevelText.anchor.set(0, 0);
LK.gui.topRight.addChild(rodLevelText);
rodLevelText.y = 60;
var inventoryText = new Text2('Fish Caught: ' + inventory.length, {
size: 36,
fill: 0xFFFFFF
});
inventoryText.anchor.set(0, 0);
LK.gui.topRight.addChild(inventoryText);
inventoryText.y = 110;
// Create upgrade button
var rodUpgrade = game.addChild(new UpgradeButton('rod', 100, 'Upgrade Rod'));
rodUpgrade.x = 1024;
rodUpgrade.y = 2500;
// Create sell button
var sellButtonGraphics = game.attachAsset('sellButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 300,
y: 2500
});
var sellButtonText = new Text2('Sell All Fish', {
size: 32,
fill: 0xFFFFFF
});
sellButtonText.anchor.set(0.5, 0.5);
sellButtonGraphics.addChild(sellButtonText);
// Create inventory GUI button
var inventoryButton = game.attachAsset('upgradeButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 700,
y: 2500
});
var inventoryButtonText = new Text2('View Inventory', {
size: 32,
fill: 0xFFFFFF
});
inventoryButtonText.anchor.set(0.5, 0.5);
inventoryButton.addChild(inventoryButtonText);
// Create inventory display container (initially hidden)
var inventoryContainer = new Container();
inventoryContainer.visible = false;
game.addChild(inventoryContainer);
// Inventory background
var inventoryBg = inventoryContainer.attachAsset('water', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366,
scaleX: 0.8,
scaleY: 0.6
});
inventoryBg.tint = 0x333333;
inventoryBg.alpha = 0.9;
// Inventory title
var inventoryTitle = new Text2('Fish Inventory', {
size: 48,
fill: 0xFFFFFF
});
inventoryTitle.anchor.set(0.5, 0.5);
inventoryTitle.x = 1024;
inventoryTitle.y = 900;
inventoryContainer.addChild(inventoryTitle);
// Close button for inventory
var closeButton = inventoryContainer.attachAsset('sellButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1800
});
var closeButtonText = new Text2('Close', {
size: 32,
fill: 0xFFFFFF
});
closeButtonText.anchor.set(0.5, 0.5);
closeButton.addChild(closeButtonText);
var isInventoryOpen = false;
var inventoryFishDisplays = [];
// Fish spawn area
var fishSpawnArea = {
x: 400,
y: 1400,
width: 1200,
height: 800
};
// Arrays to track game objects
var caughtFish = [];
var fishingTimer = 0;
function updateUI() {
coinsText.setText('Coins: $' + coins);
rodLevelText.setText('Rod Level: ' + rodLevel);
rodLevelDisplayText.setText('Rod Level: ' + rodLevel);
inventoryText.setText('Fish Caught: ' + inventory.length);
// Save to storage - flatten inventory for storage compatibility
storage.coins = coins;
storage.rodLevel = rodLevel;
// Store inventory as separate arrays
var inventoryTypes = [];
var inventoryValues = [];
var inventoryNames = [];
for (var i = 0; i < inventory.length; i++) {
inventoryTypes.push(inventory[i].type);
inventoryValues.push(inventory[i].value);
inventoryNames.push(inventory[i].name);
}
storage.inventoryTypes = inventoryTypes;
storage.inventoryValues = inventoryValues;
storage.inventoryNames = inventoryNames;
storage.totalFishCaught = totalFishCaught;
}
function updateInventoryDisplay() {
// Clear existing fish displays
for (var i = 0; i < inventoryFishDisplays.length; i++) {
if (inventoryFishDisplays[i] && inventoryFishDisplays[i].destroy) {
inventoryFishDisplays[i].destroy();
}
}
inventoryFishDisplays = [];
// Count fish by type
var fishCounts = {};
for (var i = 0; i < inventory.length; i++) {
var fish = inventory[i];
if (!fishCounts[fish.type]) {
fishCounts[fish.type] = {
count: 0,
value: fish.value,
name: fish.name,
type: fish.type
};
}
fishCounts[fish.type].count++;
}
// Display fish groups
var fishTypes = Object.keys(fishCounts);
var startX = 600;
var startY = 1000;
var columns = 3;
for (var i = 0; i < fishTypes.length; i++) {
var fishType = fishTypes[i];
var fishData = fishCounts[fishType];
var row = Math.floor(i / columns);
var col = i % columns;
var x = startX + col * 300;
var y = startY + row * 200;
// Create fish display container
var fishDisplay = new Container();
fishDisplay.x = x;
fishDisplay.y = y;
inventoryContainer.addChild(fishDisplay);
inventoryFishDisplays.push(fishDisplay);
// Fish icon
var fishIcon = new Fish(fishType);
fishIcon.scaleX = 1.5;
fishIcon.scaleY = 1.5;
fishDisplay.addChild(fishIcon);
// Fish info text
var fishInfo = new Text2(fishData.name + '\nCount: ' + fishData.count + '\nValue: $' + fishData.value, {
size: 24,
fill: 0xFFFFFF
});
fishInfo.anchor.set(0.5, 0);
fishInfo.y = 50;
fishDisplay.addChild(fishInfo);
}
}
function getFishTypeByRodLevel() {
var random = Math.random();
// Progressive legendary fish chance (starts at level 10, max 25% at level 100)
var legendaryChance = Math.max(0, (rodLevel - 10) * 0.0025);
legendaryChance = Math.min(0.25, legendaryChance);
// Progressive rare fish chance (starts at level 5, max 40% at level 100)
var rareChance = Math.max(0, (rodLevel - 5) * 0.004);
rareChance = Math.min(0.4, rareChance);
// Progressive uncommon fish chance (starts at level 2, max 50% at level 100)
var uncommonChance = Math.max(0, (rodLevel - 2) * 0.005);
uncommonChance = Math.min(0.5, uncommonChance);
if (random < legendaryChance) return 'legendary';
if (random < legendaryChance + rareChance) return 'rare';
if (random < legendaryChance + rareChance + uncommonChance) return 'uncommon';
return 'common';
}
function spawnFish() {
var fishType = getFishTypeByRodLevel();
var fish = new Fish(fishType);
fish.x = fishSpawnArea.x + Math.random() * fishSpawnArea.width;
fish.y = fishSpawnArea.y + Math.random() * fishSpawnArea.height;
game.addChild(fish);
caughtFish.push(fish);
inventory.push({
type: fishType,
value: fish.getValue(),
name: fish.getName()
});
totalFishCaught++;
// Animate fish jump
var originalY = fish.y;
tween(fish, {
y: originalY - 100
}, {
duration: 500,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(fish, {
y: originalY
}, {
duration: 500,
easing: tween.easeIn,
onFinish: function onFinish() {
tween(fish, {
alpha: 0
}, {
duration: 1000,
onFinish: function onFinish() {
fish.destroy();
var index = caughtFish.indexOf(fish);
if (index > -1) {
caughtFish.splice(index, 1);
}
}
});
}
});
}
});
LK.getSound('catch').play();
updateUI();
if (isInventoryOpen) {
updateInventoryDisplay();
}
}
// Game tap handler
game.down = function (x, y, obj) {
if (!fishingRod.isCasting) {
fishingRod.cast();
LK.getSound('splash').play();
// Chance to catch fish based on rod level (scales to 100 levels, max 95%)
var catchChance = 0.3 + Math.min(0.65, rodLevel * 0.0065);
if (Math.random() < catchChance) {
LK.setTimeout(function () {
spawnFish();
}, 1200);
}
}
};
// Sell button handler
sellButtonGraphics.down = function (x, y, obj) {
// Button press effect
tween(sellButtonGraphics, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(sellButtonGraphics, {
scaleX: 1,
scaleY: 1
}, {
duration: 100,
easing: tween.easeOut
});
}
});
if (inventory.length > 0) {
var totalValue = 0;
for (var i = 0; i < inventory.length; i++) {
totalValue += inventory[i].value;
}
coins += totalValue;
inventory = [];
// Clear visible fish
for (var j = 0; j < caughtFish.length; j++) {
if (caughtFish[j] && caughtFish[j].destroy) {
caughtFish[j].destroy();
}
}
caughtFish = [];
updateUI();
updateInventoryDisplay();
LK.effects.flashScreen(0x00FF00, 500);
}
};
// Inventory button handler
inventoryButton.down = function (x, y, obj) {
// Button press effect
tween(inventoryButton, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(inventoryButton, {
scaleX: 1,
scaleY: 1
}, {
duration: 100,
easing: tween.easeOut
});
}
});
isInventoryOpen = !isInventoryOpen;
inventoryContainer.visible = isInventoryOpen;
if (isInventoryOpen) {
updateInventoryDisplay();
}
};
// Close inventory button handler
closeButton.down = function (x, y, obj) {
// Button press effect
tween(closeButton, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(closeButton, {
scaleX: 1,
scaleY: 1
}, {
duration: 100,
easing: tween.easeOut
});
}
});
isInventoryOpen = false;
inventoryContainer.visible = false;
};
// Auto-save every 5 seconds
var autoSaveTimer = LK.setInterval(function () {
storage.coins = coins;
storage.rodLevel = rodLevel;
// Store inventory as separate arrays
var inventoryTypes = [];
var inventoryValues = [];
var inventoryNames = [];
for (var i = 0; i < inventory.length; i++) {
inventoryTypes.push(inventory[i].type);
inventoryValues.push(inventory[i].value);
inventoryNames.push(inventory[i].name);
}
storage.inventoryTypes = inventoryTypes;
storage.inventoryValues = inventoryValues;
storage.inventoryNames = inventoryNames;
storage.totalFishCaught = totalFishCaught;
}, 5000);
// Add hover effects for buttons
sellButtonGraphics.move = function (x, y, obj) {
tween(sellButtonGraphics, {
tint: 0xffcc00
}, {
duration: 200,
easing: tween.easeOut
});
};
inventoryButton.move = function (x, y, obj) {
tween(inventoryButton, {
tint: 0x66bb6a
}, {
duration: 200,
easing: tween.easeOut
});
};
closeButton.move = function (x, y, obj) {
tween(closeButton, {
tint: 0xff7043
}, {
duration: 200,
easing: tween.easeOut
});
};
// Reset button colors when not hovering
game.move = function (x, y, obj) {
// Reset sell button color if not hovering
if (!sellButtonGraphics.getBounds().contains(x, y)) {
tween(sellButtonGraphics, {
tint: 0xff9800
}, {
duration: 200,
easing: tween.easeOut
});
}
// Reset inventory button color if not hovering
if (!inventoryButton.getBounds().contains(x, y)) {
tween(inventoryButton, {
tint: 0x4caf50
}, {
duration: 200,
easing: tween.easeOut
});
}
// Reset close button color if not hovering and inventory is open
if (isInventoryOpen && !closeButton.getBounds().contains(x, y)) {
tween(closeButton, {
tint: 0xff9800
}, {
duration: 200,
easing: tween.easeOut
});
}
};
game.update = function () {
// Update fishing rod animation
if (fishingRod && fishingRod.update) {
fishingRod.update();
}
// Update upgrade button cost display with progressive scaling for 100 levels
var targetCost;
// Hide upgrade button at level 100 since it will reset
if (rodLevel >= 100) {
targetCost = Math.floor(100 * Math.pow(1.5, 99)); // Cost for level 100
} else if (rodLevel <= 10) {
targetCost = Math.floor(100 * Math.pow(1.5, rodLevel - 1));
} else if (rodLevel <= 50) {
var baseCost = Math.floor(100 * Math.pow(1.5, 9)); // Cost at level 10
targetCost = Math.floor(baseCost * Math.pow(1.3, rodLevel - 10));
} else {
var baseCost10 = Math.floor(100 * Math.pow(1.5, 9));
var baseCost50 = Math.floor(baseCost10 * Math.pow(1.3, 40));
targetCost = Math.floor(baseCost50 * Math.pow(1.2, rodLevel - 50));
}
if (rodUpgrade && rodUpgrade.cost !== targetCost) {
rodUpgrade.updateText(targetCost);
}
};