User prompt
Please fix the bug: 'Uncaught ReferenceError: collectionText is not defined' in or related to this line: 'collectionText.setText('Collection: ' + Object.keys(collection).length);' Line Number: 384
User prompt
"Collection Statistics" yerinde arka plan siyah renk, aynı yerde(Collection Statistics) "Common" yazısını beyaz yap.
User prompt
Please fix the bug: 'Uncaught ReferenceError: collectionText is not defined' in or related to this line: 'collectionText.setText('Collection: ' + Object.keys(collection).length);' Line Number: 383
User prompt
"Collection" adlı düğmeye tıkladığımızda bize hangi nadirlikten kaç tane çıkardığımızı göstersin.
User prompt
Please fix the bug: 'Uncaught RangeError: Maximum call stack size exceeded' in or related to this line: 'openButton.up();' Line Number: 385
User prompt
Please fix the bug: 'Uncaught RangeError: Maximum call stack size exceeded' in or related to this line: 'openButton.down();' Line Number: 380
Code edit (1 edits merged)
Please save this source code
User prompt
Mystery Box Opener
Initial prompt
bana kasa açma simulasyon oyunu yaparmısın?
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var CheatPanel = Container.expand(function () { var self = Container.call(this); var background = self.attachAsset('cheatPanel', { anchorX: 0.5, anchorY: 0.5, scaleX: 2, scaleY: 2 }); background.tint = 0x000000; var titleText = new Text2('Cheat Panel', { size: 60, fill: 0xFFFFFF }); titleText.anchor.set(0.5, 0.5); titleText.y = -150; self.addChild(titleText); var moneyButton = self.attachAsset('moneyCheatButton', { anchorX: 0.5, anchorY: 0.5 }); moneyButton.y = 0; var moneyButtonText = new Text2('99999 Coins', { size: 40, fill: 0xFFFFFF }); moneyButtonText.anchor.set(0.5, 0.5); moneyButton.addChild(moneyButtonText); moneyButton.interactive = true; moneyButton.buttonMode = true; var resetButton = self.attachAsset('resetMoneyButton', { anchorX: 0.5, anchorY: 0.5 }); resetButton.y = 100; var resetButtonText = new Text2('Reset Money', { size: 40, fill: 0xFFFFFF }); resetButtonText.anchor.set(0.5, 0.5); resetButton.addChild(resetButtonText); resetButton.interactive = true; resetButton.buttonMode = true; var closeButton = new Text2('X', { size: 80, fill: 0xFF0000 }); closeButton.anchor.set(0.5, 0.5); closeButton.x = 250; closeButton.y = -150; closeButton.interactive = true; closeButton.buttonMode = true; self.addChild(closeButton); moneyButton.up = function () { coins += 99999; storage.coins = coins; coinsText.setText('Coins: ' + coins); }; resetButton.up = function () { coins = 0; storage.coins = coins; coinsText.setText('Coins: ' + coins); // Reset boxes to basic box currentBoxIndex = 0; unlockedBoxes = ['basic']; storage.unlockedBoxes = unlockedBoxes; createNewBox(); }; closeButton.up = function () { self.destroy(); }; return self; }); var CollectionView = Container.expand(function () { var self = Container.call(this); var background = self.attachAsset('openButton', { anchorX: 0.5, anchorY: 0.5, scaleX: 5, scaleY: 14 }); background.tint = 0x000000; self.addChild(background); var titleText = new Text2('Collection Statistics', { size: 80, fill: 0xFFFFFF }); titleText.anchor.set(0.5, 0.5); titleText.y = -700; self.addChild(titleText); var closeButton = new Text2('X', { size: 100, fill: 0xFF0000 }); closeButton.anchor.set(0.5, 0.5); closeButton.x = 500; closeButton.y = -700; closeButton.interactive = true; closeButton.buttonMode = true; self.addChild(closeButton); self.setup = function (collectionData) { var rarities = ['common', 'uncommon', 'rare', 'epic', 'legendary']; var rarityColors = { common: 0x808080, uncommon: 0x32cd32, rare: 0x0000ff, epic: 0x8b008b, legendary: 0xff8c00 }; var rarityCounts = {}; for (var i = 0; i < rarities.length; i++) { rarityCounts[rarities[i]] = 0; } for (var key in collectionData) { var parts = key.split('_'); if (parts.length === 2) { var rarity = parts[1]; if (rarityCounts[rarity] !== undefined) { rarityCounts[rarity] += collectionData[key]; } } } // Get current box weights for percentage calculation var currentBoxType = boxConfigs[currentBoxIndex].type; var weights = {}; if (typeof MysteryBox !== 'undefined') { var tempBox = new MysteryBox(); if (tempBox.rarityWeights && tempBox.rarityWeights[currentBoxType]) { weights = tempBox.rarityWeights[currentBoxType]; } tempBox.destroy(); } for (var i = 0; i < rarities.length; i++) { var rarity = rarities[i]; var count = rarityCounts[rarity]; var textColor = rarity === 'common' ? 0xFFFFFF : rarityColors[rarity]; var percentage = weights[rarity] ? weights[rarity] + '%' : '0%'; var rarityText = new Text2(rarity.toUpperCase() + ': ' + count + ' (' + percentage + ')', { size: 60, fill: textColor }); rarityText.anchor.set(0.5, 0.5); rarityText.y = -400 + i * 120; self.addChild(rarityText); } }; closeButton.down = function () { tween(closeButton, { scaleX: 0.9, scaleY: 0.9 }, { duration: 100 }); }; closeButton.up = function () { tween(closeButton, { scaleX: 1, scaleY: 1 }, { duration: 100 }); self.destroy(); }; return self; }); var Market = Container.expand(function () { var self = Container.call(this); var background = self.attachAsset('cheatPanel', { anchorX: 0.5, anchorY: 0.5, scaleX: 4, scaleY: 3 }); background.tint = 0x000000; var titleText = new Text2('Market', { size: 80, fill: 0xFFFFFF }); titleText.anchor.set(0.5, 0.5); titleText.y = -350; self.addChild(titleText); // Add section buttons var sellSectionButton = self.attachAsset('resetMoneyButton', { anchorX: 0.5, anchorY: 0.5 }); sellSectionButton.x = -200; sellSectionButton.y = -250; sellSectionButton.scaleX = 1.2; sellSectionButton.scaleY = 0.8; var sellSectionText = new Text2('SELL', { size: 40, fill: 0xFFFFFF }); sellSectionText.anchor.set(0.5, 0.5); sellSectionButton.addChild(sellSectionText); sellSectionButton.interactive = true; sellSectionButton.buttonMode = true; var buySectionButton = self.attachAsset('resetMoneyButton', { anchorX: 0.5, anchorY: 0.5 }); buySectionButton.x = 200; buySectionButton.y = -250; buySectionButton.scaleX = 1.2; buySectionButton.scaleY = 0.8; buySectionButton.tint = 0x666666; var buySectionText = new Text2('BUY', { size: 40, fill: 0xFFFFFF }); buySectionText.anchor.set(0.5, 0.5); buySectionButton.addChild(buySectionText); buySectionButton.interactive = true; buySectionButton.buttonMode = true; self.currentSection = 'sell'; var closeButton = new Text2('X', { size: 80, fill: 0xFF0000 }); closeButton.anchor.set(0.5, 0.5); closeButton.x = 500; closeButton.y = -350; closeButton.interactive = true; closeButton.buttonMode = true; self.addChild(closeButton); var sellAllButton = self.attachAsset('resetMoneyButton', { anchorX: 0.5, anchorY: 0.5 }); sellAllButton.y = 300; var sellAllText = new Text2('Sell All', { size: 40, fill: 0xFFFFFF }); sellAllText.anchor.set(0.5, 0.5); sellAllButton.addChild(sellAllText); sellAllButton.interactive = true; sellAllButton.buttonMode = true; var itemsList = []; self.setup = function (collectionData) { collection = collectionData; // Initialize with sell section self.currentSection = 'sell'; sellSectionButton.tint = 0xFFFFFF; buySectionButton.tint = 0x666666; self.showSellSection(); }; sellSectionButton.up = function () { self.currentSection = 'sell'; sellSectionButton.tint = 0xFFFFFF; buySectionButton.tint = 0x666666; self.showSellSection(); }; buySectionButton.up = function () { self.currentSection = 'buy'; sellSectionButton.tint = 0x666666; buySectionButton.tint = 0xFFFFFF; self.showBuySection(); }; self.showSellSection = function () { // Clear existing items for (var i = 0; i < itemsList.length; i++) { itemsList[i].destroy(); } itemsList = []; sellAllButton.visible = true; self.setupSellItems(); }; self.showBuySection = function () { // Clear existing items for (var i = 0; i < itemsList.length; i++) { itemsList[i].destroy(); } itemsList = []; sellAllButton.visible = false; // Add 10x luck boost item var luckBoostContainer = new Container(); luckBoostContainer.y = -100; var luckBoostText = new Text2('10x LUCK BOOST (1 minute)', { size: 60, fill: 0xFFD700 }); luckBoostText.anchor.set(0, 0.5); luckBoostText.x = -400; luckBoostContainer.addChild(luckBoostText); var priceText = new Text2('2500 Coins', { size: 50, fill: 0x00FF00 }); priceText.anchor.set(0, 0.5); priceText.x = -400; priceText.y = 60; luckBoostContainer.addChild(priceText); var buyLuckButton = self.attachAsset('numberButton', { anchorX: 0.5, anchorY: 0.5 }); buyLuckButton.x = 350; buyLuckButton.scaleX = 1.5; buyLuckButton.scaleY = 0.8; buyLuckButton.tint = 0x00AA00; var buyLuckButtonText = new Text2('Buy', { size: 35, fill: 0xFFFFFF }); buyLuckButtonText.anchor.set(0.5, 0.5); buyLuckButton.addChild(buyLuckButtonText); buyLuckButton.interactive = true; buyLuckButton.buttonMode = true; buyLuckButton.up = function () { if (coins >= 2500) { updateCoins(-2500); // Activate 10x luck boost for 1 minute luckBoostActive = true; luckBoostEndTime = Date.now() + 60000; luckBoostButton.visible = false; // Visual feedback tween(buyLuckButton, { scaleX: 1.2, scaleY: 1.2 }, { duration: 200, onFinish: function onFinish() { tween(buyLuckButton, { scaleX: 1.5, scaleY: 0.8 }, { duration: 200 }); } }); } }; luckBoostContainer.addChild(buyLuckButton); self.addChild(luckBoostContainer); itemsList.push(luckBoostContainer); }; self.setupSellItems = function () { var rarities = ['common', 'uncommon', 'rare', 'epic', 'legendary']; var sellPrices = { common: 5, uncommon: 15, rare: 50, epic: 250, legendary: 1000 }; var yPos = -200; var totalValue = 0; for (var i = 0; i < rarities.length; i++) { var rarity = rarities[i]; var totalCount = 0; // Count all items of this rarity for (var key in collection) { var parts = key.split('_'); if (parts.length === 2 && parts[1] === rarity) { totalCount += collection[key]; } } if (totalCount > 0) { var itemContainer = new Container(); itemContainer.y = yPos; var itemText = new Text2(rarity.toUpperCase() + ': ' + totalCount + ' x ' + sellPrices[rarity] + ' = ' + totalCount * sellPrices[rarity], { size: 50, fill: 0xFFFFFF }); itemText.anchor.set(0, 0.5); itemText.x = -400; itemContainer.addChild(itemText); var sellButton = self.attachAsset('numberButton', { anchorX: 0.5, anchorY: 0.5 }); sellButton.x = 350; sellButton.scaleX = 1.5; sellButton.scaleY = 0.8; var sellButtonText = new Text2('Sell', { size: 35, fill: 0xFFFFFF }); sellButtonText.anchor.set(0.5, 0.5); sellButton.addChild(sellButtonText); sellButton.interactive = true; sellButton.buttonMode = true; sellButton.rarity = rarity; sellButton.count = totalCount; sellButton.price = sellPrices[rarity]; sellButton.up = function () { var soldValue = this.count * this.price; updateCoins(soldValue); // Remove all items of this rarity from collection for (var key in collection) { var parts = key.split('_'); if (parts.length === 2 && parts[1] === this.rarity) { delete collection[key]; } } storage.collection = collection; collectionText.setText('Collection: ' + Object.keys(collection).length); // Refresh market view if (self.currentSection === 'sell') { self.showSellSection(); } }; itemContainer.addChild(sellButton); self.addChild(itemContainer); itemsList.push(itemContainer); totalValue += totalCount * sellPrices[rarity]; yPos += 80; } } sellAllText.setText('Sell All (' + totalValue + ')'); }; sellAllButton.up = function () { var totalValue = 0; var rarities = ['common', 'uncommon', 'rare', 'epic', 'legendary']; var sellPrices = { common: 5, uncommon: 15, rare: 50, epic: 250, legendary: 1000 }; // Calculate total value and clear collection for (var key in collection) { var parts = key.split('_'); if (parts.length === 2) { var rarity = parts[1]; var count = collection[key]; if (sellPrices[rarity]) { totalValue += count * sellPrices[rarity]; } } } if (totalValue > 0) { updateCoins(totalValue); collection = {}; storage.collection = collection; collectionText.setText('Collection: ' + Object.keys(collection).length); if (self.currentSection === 'sell') { self.showSellSection(); } } }; closeButton.up = function () { self.destroy(); }; return self; }); var MysteryBox = Container.expand(function () { var self = Container.call(this); self.boxType = 'basic'; self.cost = 0; self.isOpening = false; self.rarityWeights = { basic: { common: 70, uncommon: 25, rare: 4, epic: 0.9, legendary: 0.1 }, silver: { common: 45, uncommon: 35, rare: 15, epic: 4.5, legendary: 0.5 }, gold: { common: 25, uncommon: 35, rare: 25, epic: 12, legendary: 3 }, diamond: { common: 5, uncommon: 25, rare: 35, epic: 25, legendary: 10 }, legendary: { common: 0, uncommon: 15, rare: 35, epic: 35, legendary: 15 } }; self.itemValues = { common: 10, uncommon: 25, rare: 100, epic: 500, legendary: 2000 }; self.setup = function (type, cost) { self.boxType = type; self.cost = cost; var boxGraphics = self.attachAsset(type + 'Box', { anchorX: 0.5, anchorY: 0.5 }); self.interactive = true; self.buttonMode = true; }; self.getRarity = function () { var weights = self.rarityWeights[self.boxType]; var modifiedWeights = {}; // Apply luck boost if active if (luckBoostActive) { // 10x boost for rare items when purchased from market modifiedWeights.common = weights.common * 0.1; modifiedWeights.uncommon = weights.uncommon * 0.3; modifiedWeights.rare = weights.rare * 10; modifiedWeights.epic = weights.epic * 10; modifiedWeights.legendary = weights.legendary * 10; } else { modifiedWeights = weights; } var random = Math.random() * 100; var cumulative = 0; for (var rarity in modifiedWeights) { cumulative += modifiedWeights[rarity]; if (random <= cumulative) { return rarity; } } return 'common'; }; self.open = function () { if (self.isOpening) return null; self.isOpening = true; var rarity = self.getRarity(); var value = self.itemValues[rarity]; LK.getSound('boxOpen').play(); // Phase 1: Initial shake and anticipation tween(self, { rotation: 0.2 }, { duration: 150, easing: tween.easeInOut, onFinish: function onFinish() { // Phase 2: Shake back tween(self, { rotation: -0.2 }, { duration: 150, easing: tween.easeInOut, onFinish: function onFinish() { // Phase 3: Return to center and scale up tween(self, { rotation: 0, scaleX: 1.3, scaleY: 1.3 }, { duration: 200, easing: tween.bounceOut, onFinish: function onFinish() { // Phase 4: Flash effect for rare items if (rarity === 'epic' || rarity === 'legendary') { tween(self, { alpha: 0.3 }, { duration: 100, easing: tween.easeInOut, onFinish: function onFinish() { tween(self, { alpha: 1 }, { duration: 100, easing: tween.easeInOut, onFinish: function onFinish() { // Phase 5: Final opening - spin and shrink tween(self, { rotation: Math.PI * 4, scaleX: 0, scaleY: 0, alpha: 0 }, { duration: 800, easing: tween.easeIn }); } }); } }); } else { // Phase 5: Simple opening for common items tween(self, { rotation: Math.PI * 2, scaleX: 0, scaleY: 0, alpha: 0 }, { duration: 600, easing: tween.easeIn }); } } }); } }); } }); return { rarity: rarity, value: value }; }; return self; }); var NumberPad = Container.expand(function () { var self = Container.call(this); var background = self.attachAsset('cheatPanel', { anchorX: 0.5, anchorY: 0.5 }); var enteredCode = ''; var targetCode = '4154'; var codeText = new Text2('', { size: 60, fill: 0xFFFFFF }); codeText.anchor.set(0.5, 0.5); codeText.y = -150; self.addChild(codeText); var closeButton = new Text2('X', { size: 80, fill: 0xFF0000 }); closeButton.anchor.set(0.5, 0.5); closeButton.x = 250; closeButton.y = -150; closeButton.interactive = true; closeButton.buttonMode = true; self.addChild(closeButton); // Create number buttons 0-9 var numberButtons = []; for (var i = 0; i <= 9; i++) { var button = self.attachAsset('numberButton', { anchorX: 0.5, anchorY: 0.5 }); var col = i % 3; var row = Math.floor(i / 3); if (i === 0) { col = 1; row = 3; } button.x = (col - 1) * 120; button.y = row * 80 - 40; var buttonText = new Text2(i.toString(), { size: 40, fill: 0xFFFFFF }); buttonText.anchor.set(0.5, 0.5); button.addChild(buttonText); button.interactive = true; button.buttonMode = true; button.number = i; button.up = function () { enteredCode += this.number.toString(); codeText.setText(enteredCode); if (enteredCode.length >= 4) { if (enteredCode === targetCode) { // Show cheat panel var cheatPanel = new CheatPanel(); cheatPanel.x = 1024; cheatPanel.y = 1366; game.addChild(cheatPanel); } enteredCode = ''; codeText.setText(''); self.destroy(); } }; numberButtons.push(button); } closeButton.up = function () { self.destroy(); }; return self; }); var OpenButton = Container.expand(function () { var self = Container.call(this); self.cost = 0; var buttonGraphics = self.attachAsset('openButton', { anchorX: 0.5, anchorY: 0.5 }); self.buttonText = new Text2('OPEN', { size: 60, fill: 0xFFFFFF }); self.buttonText.anchor.set(0.5, 0.5); self.addChild(self.buttonText); self.interactive = true; self.buttonMode = true; self.updateCost = function (cost) { self.cost = cost; if (cost === 0) { self.buttonText.setText('OPEN FREE'); } else { self.buttonText.setText('OPEN - ' + cost); } }; self.down = function () { tween(self, { scaleX: 0.95, scaleY: 0.95 }, { duration: 100 }); }; self.up = function () { tween(self, { scaleX: 1, scaleY: 1 }, { duration: 100 }); }; return self; }); var RewardItem = Container.expand(function () { var self = Container.call(this); self.setup = function (rarity, value) { var itemGraphics = self.attachAsset(rarity + 'Item', { anchorX: 0.5, anchorY: 0.5 }); self.scaleX = 0; self.scaleY = 0; tween(self, { scaleX: 1, scaleY: 1 }, { duration: 500, easing: tween.bounceOut }); if (rarity === 'epic' || rarity === 'legendary') { LK.getSound('rareFind').play(); LK.effects.flashScreen(0xFFD700, 500); } var rarityText = new Text2(rarity.toUpperCase(), { size: 50, fill: 0xFFFFFF }); rarityText.anchor.set(0.5, 0.5); rarityText.y = 80; self.addChild(rarityText); var valueText = new Text2('+' + value, { size: 60, fill: 0xFFD700 }); valueText.anchor.set(0.5, 0.5); valueText.y = -150; self.addChild(valueText); tween(valueText, { y: -250, alpha: 0 }, { duration: 1500, easing: tween.easeOut }); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x1a1a1a }); /**** * Game Code ****/ var coins = storage.coins || 100; var collection = storage.collection || {}; var unlockedBoxes = storage.unlockedBoxes || ['basic']; var luckBoostActive = false; var luckBoostEndTime = 0; var luckBoostCost = 500; var luckBoostDuration = 60000; // 1 minute var currentBoxIndex = 0; var boxes = []; var boxConfigs = [{ type: 'basic', cost: 0 }, { type: 'silver', cost: 50 }, { type: 'gold', cost: 200 }, { type: 'diamond', cost: 800 }, { type: 'legendary', cost: 3000 }]; var coinsText = new Text2('Coins: ' + coins, { size: 80, fill: 0xFFD700 }); coinsText.anchor.set(0.5, 0); LK.gui.top.addChild(coinsText); var collectionButton = new Text2('Collection', { size: 60, fill: 0xFFFFFF }); collectionButton.anchor.set(1, 0); collectionButton.x = -20; collectionButton.interactive = true; collectionButton.buttonMode = true; LK.gui.topRight.addChild(collectionButton); var marketButton = new Text2('Market', { size: 60, fill: 0x00FF00 }); marketButton.anchor.set(1, 0); marketButton.x = -20; marketButton.y = 80; marketButton.interactive = true; marketButton.buttonMode = true; LK.gui.topRight.addChild(marketButton); var collectionText = new Text2('Collection: ' + Object.keys(collection).length, { size: 60, fill: 0xFFFFFF }); collectionText.anchor.set(0, 0); collectionText.x = 20; collectionText.y = 100; LK.gui.topLeft.addChild(collectionText); var luckBoostButton = new Text2('Luck Boost: 500 Coins', { size: 50, fill: 0xFFD700 }); luckBoostButton.anchor.set(0.5, 0); luckBoostButton.y = 200; luckBoostButton.interactive = true; luckBoostButton.buttonMode = true; LK.gui.top.addChild(luckBoostButton); var luckBoostStatusText = new Text2('', { size: 40, fill: 0x00FF00 }); luckBoostStatusText.anchor.set(0.5, 0); luckBoostStatusText.y = 270; LK.gui.top.addChild(luckBoostStatusText); var currentBox = null; var openButton = new OpenButton(); openButton.x = 1024; openButton.y = 2200; game.addChild(openButton); var prevButton = new Text2('<', { size: 120, fill: 0xFFFFFF }); prevButton.anchor.set(0.5, 0.5); prevButton.x = 200; prevButton.y = 1366; prevButton.interactive = true; prevButton.buttonMode = true; game.addChild(prevButton); var nextButton = new Text2('>', { size: 120, fill: 0xFFFFFF }); nextButton.anchor.set(0.5, 0.5); nextButton.x = 1848; nextButton.y = 1366; nextButton.interactive = true; nextButton.buttonMode = true; game.addChild(nextButton); var boxNameText = new Text2('', { size: 80, fill: 0xFFFFFF }); boxNameText.anchor.set(0.5, 0.5); boxNameText.x = 1024; boxNameText.y = 800; game.addChild(boxNameText); function updateCoins(amount) { coins += amount; storage.coins = coins; coinsText.setText('Coins: ' + coins); LK.getSound('coinCollect').play(); } ; luckBoostButton.down = function () { tween(luckBoostButton, { scaleX: 0.9, scaleY: 0.9 }, { duration: 100 }); }; luckBoostButton.up = function () { tween(luckBoostButton, { scaleX: 1, scaleY: 1 }, { duration: 100 }); if (!luckBoostActive && coins >= luckBoostCost) { updateCoins(-luckBoostCost); luckBoostActive = true; luckBoostEndTime = Date.now() + luckBoostDuration; luckBoostButton.visible = false; } ; }; function updateCollection(rarity) { var key = currentBox.boxType + '_' + rarity; if (!collection[key]) { collection[key] = 0; } collection[key]++; storage.collection = collection; collectionText.setText('Collection: ' + Object.keys(collection).length); } function createNewBox() { if (currentBox) { currentBox.destroy(); } var config = boxConfigs[currentBoxIndex]; currentBox = new MysteryBox(); currentBox.setup(config.type, config.cost); currentBox.x = 1024; currentBox.y = 1366; game.addChild(currentBox); boxNameText.setText(config.type.toUpperCase() + ' BOX'); openButton.updateCost(config.cost); var isUnlocked = unlockedBoxes.indexOf(config.type) !== -1; if (!isUnlocked) { currentBox.alpha = 0.3; openButton.visible = false; boxNameText.setText('LOCKED - Need ' + currentBoxIndex * 1000 + ' coins'); } else { currentBox.alpha = 1; openButton.visible = true; } } function checkUnlocks() { for (var i = 0; i < boxConfigs.length; i++) { var boxType = boxConfigs[i].type; if (unlockedBoxes.indexOf(boxType) === -1) { if (coins >= i * 1000) { unlockedBoxes.push(boxType); storage.unlockedBoxes = unlockedBoxes; if (i === currentBoxIndex) { createNewBox(); } } } } } prevButton.down = function () { tween(prevButton, { scaleX: 0.9, scaleY: 0.9 }, { duration: 100 }); }; prevButton.up = function () { tween(prevButton, { scaleX: 1, scaleY: 1 }, { duration: 100 }); if (currentBoxIndex > 0) { currentBoxIndex--; createNewBox(); } }; nextButton.down = function () { tween(nextButton, { scaleX: 0.9, scaleY: 0.9 }, { duration: 100 }); }; nextButton.up = function () { tween(nextButton, { scaleX: 1, scaleY: 1 }, { duration: 100 }); if (currentBoxIndex < boxConfigs.length - 1) { currentBoxIndex++; createNewBox(); } }; openButton.down = function () { if (openButton.down.__super__) { openButton.down.__super__.call(openButton); } }; collectionButton.down = function () { tween(collectionButton, { scaleX: 0.9, scaleY: 0.9 }, { duration: 100 }); }; collectionButton.up = function () { tween(collectionButton, { scaleX: 1, scaleY: 1 }, { duration: 100 }); var collectionView = new CollectionView(); collectionView.setup(collection); collectionView.x = 1024; collectionView.y = 1366; game.addChild(collectionView); }; marketButton.down = function () { tween(marketButton, { scaleX: 0.9, scaleY: 0.9 }, { duration: 100 }); }; marketButton.up = function () { tween(marketButton, { scaleX: 1, scaleY: 1 }, { duration: 100 }); var market = new Market(); market.setup(collection); market.x = 1024; market.y = 1366; game.addChild(market); }; openButton.up = function () { if (openButton.up.__super__) { openButton.up.__super__.call(openButton); } if (currentBox && !currentBox.isOpening) { var cost = boxConfigs[currentBoxIndex].cost; if (coins >= cost) { if (cost > 0) { updateCoins(-cost); } var result = currentBox.open(); if (result) { var reward = new RewardItem(); reward.setup(result.rarity, result.value); reward.x = 1024; reward.y = 1366; game.addChild(reward); updateCoins(result.value); updateCollection(result.rarity); LK.setTimeout(function () { createNewBox(); reward.destroy(); }, 1000); } } } }; game.update = function () { checkUnlocks(); // Update luck boost status if (luckBoostActive) { var timeLeft = Math.max(0, luckBoostEndTime - Date.now()); if (timeLeft > 0) { var secondsLeft = Math.ceil(timeLeft / 1000); luckBoostStatusText.setText('10x Luck: ' + secondsLeft + 's'); } else { luckBoostActive = false; luckBoostStatusText.setText(''); luckBoostButton.visible = true; } } else { luckBoostStatusText.setText(''); } }; var cheatButton = new Text2('Cheat', { size: 40, fill: 0xFF0000 }); cheatButton.anchor.set(0.5, 1); cheatButton.x = 1024; cheatButton.y = 2700; cheatButton.interactive = true; cheatButton.buttonMode = true; game.addChild(cheatButton); cheatButton.up = function () { var numberPad = new NumberPad(); numberPad.x = 1024; numberPad.y = 1366; game.addChild(numberPad); }; createNewBox(); LK.playMusic('bgmusic'); ;
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var CheatPanel = Container.expand(function () {
var self = Container.call(this);
var background = self.attachAsset('cheatPanel', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
scaleY: 2
});
background.tint = 0x000000;
var titleText = new Text2('Cheat Panel', {
size: 60,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0.5);
titleText.y = -150;
self.addChild(titleText);
var moneyButton = self.attachAsset('moneyCheatButton', {
anchorX: 0.5,
anchorY: 0.5
});
moneyButton.y = 0;
var moneyButtonText = new Text2('99999 Coins', {
size: 40,
fill: 0xFFFFFF
});
moneyButtonText.anchor.set(0.5, 0.5);
moneyButton.addChild(moneyButtonText);
moneyButton.interactive = true;
moneyButton.buttonMode = true;
var resetButton = self.attachAsset('resetMoneyButton', {
anchorX: 0.5,
anchorY: 0.5
});
resetButton.y = 100;
var resetButtonText = new Text2('Reset Money', {
size: 40,
fill: 0xFFFFFF
});
resetButtonText.anchor.set(0.5, 0.5);
resetButton.addChild(resetButtonText);
resetButton.interactive = true;
resetButton.buttonMode = true;
var closeButton = new Text2('X', {
size: 80,
fill: 0xFF0000
});
closeButton.anchor.set(0.5, 0.5);
closeButton.x = 250;
closeButton.y = -150;
closeButton.interactive = true;
closeButton.buttonMode = true;
self.addChild(closeButton);
moneyButton.up = function () {
coins += 99999;
storage.coins = coins;
coinsText.setText('Coins: ' + coins);
};
resetButton.up = function () {
coins = 0;
storage.coins = coins;
coinsText.setText('Coins: ' + coins);
// Reset boxes to basic box
currentBoxIndex = 0;
unlockedBoxes = ['basic'];
storage.unlockedBoxes = unlockedBoxes;
createNewBox();
};
closeButton.up = function () {
self.destroy();
};
return self;
});
var CollectionView = Container.expand(function () {
var self = Container.call(this);
var background = self.attachAsset('openButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 5,
scaleY: 14
});
background.tint = 0x000000;
self.addChild(background);
var titleText = new Text2('Collection Statistics', {
size: 80,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0.5);
titleText.y = -700;
self.addChild(titleText);
var closeButton = new Text2('X', {
size: 100,
fill: 0xFF0000
});
closeButton.anchor.set(0.5, 0.5);
closeButton.x = 500;
closeButton.y = -700;
closeButton.interactive = true;
closeButton.buttonMode = true;
self.addChild(closeButton);
self.setup = function (collectionData) {
var rarities = ['common', 'uncommon', 'rare', 'epic', 'legendary'];
var rarityColors = {
common: 0x808080,
uncommon: 0x32cd32,
rare: 0x0000ff,
epic: 0x8b008b,
legendary: 0xff8c00
};
var rarityCounts = {};
for (var i = 0; i < rarities.length; i++) {
rarityCounts[rarities[i]] = 0;
}
for (var key in collectionData) {
var parts = key.split('_');
if (parts.length === 2) {
var rarity = parts[1];
if (rarityCounts[rarity] !== undefined) {
rarityCounts[rarity] += collectionData[key];
}
}
}
// Get current box weights for percentage calculation
var currentBoxType = boxConfigs[currentBoxIndex].type;
var weights = {};
if (typeof MysteryBox !== 'undefined') {
var tempBox = new MysteryBox();
if (tempBox.rarityWeights && tempBox.rarityWeights[currentBoxType]) {
weights = tempBox.rarityWeights[currentBoxType];
}
tempBox.destroy();
}
for (var i = 0; i < rarities.length; i++) {
var rarity = rarities[i];
var count = rarityCounts[rarity];
var textColor = rarity === 'common' ? 0xFFFFFF : rarityColors[rarity];
var percentage = weights[rarity] ? weights[rarity] + '%' : '0%';
var rarityText = new Text2(rarity.toUpperCase() + ': ' + count + ' (' + percentage + ')', {
size: 60,
fill: textColor
});
rarityText.anchor.set(0.5, 0.5);
rarityText.y = -400 + i * 120;
self.addChild(rarityText);
}
};
closeButton.down = function () {
tween(closeButton, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100
});
};
closeButton.up = function () {
tween(closeButton, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
self.destroy();
};
return self;
});
var Market = Container.expand(function () {
var self = Container.call(this);
var background = self.attachAsset('cheatPanel', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 3
});
background.tint = 0x000000;
var titleText = new Text2('Market', {
size: 80,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0.5);
titleText.y = -350;
self.addChild(titleText);
// Add section buttons
var sellSectionButton = self.attachAsset('resetMoneyButton', {
anchorX: 0.5,
anchorY: 0.5
});
sellSectionButton.x = -200;
sellSectionButton.y = -250;
sellSectionButton.scaleX = 1.2;
sellSectionButton.scaleY = 0.8;
var sellSectionText = new Text2('SELL', {
size: 40,
fill: 0xFFFFFF
});
sellSectionText.anchor.set(0.5, 0.5);
sellSectionButton.addChild(sellSectionText);
sellSectionButton.interactive = true;
sellSectionButton.buttonMode = true;
var buySectionButton = self.attachAsset('resetMoneyButton', {
anchorX: 0.5,
anchorY: 0.5
});
buySectionButton.x = 200;
buySectionButton.y = -250;
buySectionButton.scaleX = 1.2;
buySectionButton.scaleY = 0.8;
buySectionButton.tint = 0x666666;
var buySectionText = new Text2('BUY', {
size: 40,
fill: 0xFFFFFF
});
buySectionText.anchor.set(0.5, 0.5);
buySectionButton.addChild(buySectionText);
buySectionButton.interactive = true;
buySectionButton.buttonMode = true;
self.currentSection = 'sell';
var closeButton = new Text2('X', {
size: 80,
fill: 0xFF0000
});
closeButton.anchor.set(0.5, 0.5);
closeButton.x = 500;
closeButton.y = -350;
closeButton.interactive = true;
closeButton.buttonMode = true;
self.addChild(closeButton);
var sellAllButton = self.attachAsset('resetMoneyButton', {
anchorX: 0.5,
anchorY: 0.5
});
sellAllButton.y = 300;
var sellAllText = new Text2('Sell All', {
size: 40,
fill: 0xFFFFFF
});
sellAllText.anchor.set(0.5, 0.5);
sellAllButton.addChild(sellAllText);
sellAllButton.interactive = true;
sellAllButton.buttonMode = true;
var itemsList = [];
self.setup = function (collectionData) {
collection = collectionData;
// Initialize with sell section
self.currentSection = 'sell';
sellSectionButton.tint = 0xFFFFFF;
buySectionButton.tint = 0x666666;
self.showSellSection();
};
sellSectionButton.up = function () {
self.currentSection = 'sell';
sellSectionButton.tint = 0xFFFFFF;
buySectionButton.tint = 0x666666;
self.showSellSection();
};
buySectionButton.up = function () {
self.currentSection = 'buy';
sellSectionButton.tint = 0x666666;
buySectionButton.tint = 0xFFFFFF;
self.showBuySection();
};
self.showSellSection = function () {
// Clear existing items
for (var i = 0; i < itemsList.length; i++) {
itemsList[i].destroy();
}
itemsList = [];
sellAllButton.visible = true;
self.setupSellItems();
};
self.showBuySection = function () {
// Clear existing items
for (var i = 0; i < itemsList.length; i++) {
itemsList[i].destroy();
}
itemsList = [];
sellAllButton.visible = false;
// Add 10x luck boost item
var luckBoostContainer = new Container();
luckBoostContainer.y = -100;
var luckBoostText = new Text2('10x LUCK BOOST (1 minute)', {
size: 60,
fill: 0xFFD700
});
luckBoostText.anchor.set(0, 0.5);
luckBoostText.x = -400;
luckBoostContainer.addChild(luckBoostText);
var priceText = new Text2('2500 Coins', {
size: 50,
fill: 0x00FF00
});
priceText.anchor.set(0, 0.5);
priceText.x = -400;
priceText.y = 60;
luckBoostContainer.addChild(priceText);
var buyLuckButton = self.attachAsset('numberButton', {
anchorX: 0.5,
anchorY: 0.5
});
buyLuckButton.x = 350;
buyLuckButton.scaleX = 1.5;
buyLuckButton.scaleY = 0.8;
buyLuckButton.tint = 0x00AA00;
var buyLuckButtonText = new Text2('Buy', {
size: 35,
fill: 0xFFFFFF
});
buyLuckButtonText.anchor.set(0.5, 0.5);
buyLuckButton.addChild(buyLuckButtonText);
buyLuckButton.interactive = true;
buyLuckButton.buttonMode = true;
buyLuckButton.up = function () {
if (coins >= 2500) {
updateCoins(-2500);
// Activate 10x luck boost for 1 minute
luckBoostActive = true;
luckBoostEndTime = Date.now() + 60000;
luckBoostButton.visible = false;
// Visual feedback
tween(buyLuckButton, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 200,
onFinish: function onFinish() {
tween(buyLuckButton, {
scaleX: 1.5,
scaleY: 0.8
}, {
duration: 200
});
}
});
}
};
luckBoostContainer.addChild(buyLuckButton);
self.addChild(luckBoostContainer);
itemsList.push(luckBoostContainer);
};
self.setupSellItems = function () {
var rarities = ['common', 'uncommon', 'rare', 'epic', 'legendary'];
var sellPrices = {
common: 5,
uncommon: 15,
rare: 50,
epic: 250,
legendary: 1000
};
var yPos = -200;
var totalValue = 0;
for (var i = 0; i < rarities.length; i++) {
var rarity = rarities[i];
var totalCount = 0;
// Count all items of this rarity
for (var key in collection) {
var parts = key.split('_');
if (parts.length === 2 && parts[1] === rarity) {
totalCount += collection[key];
}
}
if (totalCount > 0) {
var itemContainer = new Container();
itemContainer.y = yPos;
var itemText = new Text2(rarity.toUpperCase() + ': ' + totalCount + ' x ' + sellPrices[rarity] + ' = ' + totalCount * sellPrices[rarity], {
size: 50,
fill: 0xFFFFFF
});
itemText.anchor.set(0, 0.5);
itemText.x = -400;
itemContainer.addChild(itemText);
var sellButton = self.attachAsset('numberButton', {
anchorX: 0.5,
anchorY: 0.5
});
sellButton.x = 350;
sellButton.scaleX = 1.5;
sellButton.scaleY = 0.8;
var sellButtonText = new Text2('Sell', {
size: 35,
fill: 0xFFFFFF
});
sellButtonText.anchor.set(0.5, 0.5);
sellButton.addChild(sellButtonText);
sellButton.interactive = true;
sellButton.buttonMode = true;
sellButton.rarity = rarity;
sellButton.count = totalCount;
sellButton.price = sellPrices[rarity];
sellButton.up = function () {
var soldValue = this.count * this.price;
updateCoins(soldValue);
// Remove all items of this rarity from collection
for (var key in collection) {
var parts = key.split('_');
if (parts.length === 2 && parts[1] === this.rarity) {
delete collection[key];
}
}
storage.collection = collection;
collectionText.setText('Collection: ' + Object.keys(collection).length);
// Refresh market view
if (self.currentSection === 'sell') {
self.showSellSection();
}
};
itemContainer.addChild(sellButton);
self.addChild(itemContainer);
itemsList.push(itemContainer);
totalValue += totalCount * sellPrices[rarity];
yPos += 80;
}
}
sellAllText.setText('Sell All (' + totalValue + ')');
};
sellAllButton.up = function () {
var totalValue = 0;
var rarities = ['common', 'uncommon', 'rare', 'epic', 'legendary'];
var sellPrices = {
common: 5,
uncommon: 15,
rare: 50,
epic: 250,
legendary: 1000
};
// Calculate total value and clear collection
for (var key in collection) {
var parts = key.split('_');
if (parts.length === 2) {
var rarity = parts[1];
var count = collection[key];
if (sellPrices[rarity]) {
totalValue += count * sellPrices[rarity];
}
}
}
if (totalValue > 0) {
updateCoins(totalValue);
collection = {};
storage.collection = collection;
collectionText.setText('Collection: ' + Object.keys(collection).length);
if (self.currentSection === 'sell') {
self.showSellSection();
}
}
};
closeButton.up = function () {
self.destroy();
};
return self;
});
var MysteryBox = Container.expand(function () {
var self = Container.call(this);
self.boxType = 'basic';
self.cost = 0;
self.isOpening = false;
self.rarityWeights = {
basic: {
common: 70,
uncommon: 25,
rare: 4,
epic: 0.9,
legendary: 0.1
},
silver: {
common: 45,
uncommon: 35,
rare: 15,
epic: 4.5,
legendary: 0.5
},
gold: {
common: 25,
uncommon: 35,
rare: 25,
epic: 12,
legendary: 3
},
diamond: {
common: 5,
uncommon: 25,
rare: 35,
epic: 25,
legendary: 10
},
legendary: {
common: 0,
uncommon: 15,
rare: 35,
epic: 35,
legendary: 15
}
};
self.itemValues = {
common: 10,
uncommon: 25,
rare: 100,
epic: 500,
legendary: 2000
};
self.setup = function (type, cost) {
self.boxType = type;
self.cost = cost;
var boxGraphics = self.attachAsset(type + 'Box', {
anchorX: 0.5,
anchorY: 0.5
});
self.interactive = true;
self.buttonMode = true;
};
self.getRarity = function () {
var weights = self.rarityWeights[self.boxType];
var modifiedWeights = {};
// Apply luck boost if active
if (luckBoostActive) {
// 10x boost for rare items when purchased from market
modifiedWeights.common = weights.common * 0.1;
modifiedWeights.uncommon = weights.uncommon * 0.3;
modifiedWeights.rare = weights.rare * 10;
modifiedWeights.epic = weights.epic * 10;
modifiedWeights.legendary = weights.legendary * 10;
} else {
modifiedWeights = weights;
}
var random = Math.random() * 100;
var cumulative = 0;
for (var rarity in modifiedWeights) {
cumulative += modifiedWeights[rarity];
if (random <= cumulative) {
return rarity;
}
}
return 'common';
};
self.open = function () {
if (self.isOpening) return null;
self.isOpening = true;
var rarity = self.getRarity();
var value = self.itemValues[rarity];
LK.getSound('boxOpen').play();
// Phase 1: Initial shake and anticipation
tween(self, {
rotation: 0.2
}, {
duration: 150,
easing: tween.easeInOut,
onFinish: function onFinish() {
// Phase 2: Shake back
tween(self, {
rotation: -0.2
}, {
duration: 150,
easing: tween.easeInOut,
onFinish: function onFinish() {
// Phase 3: Return to center and scale up
tween(self, {
rotation: 0,
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 200,
easing: tween.bounceOut,
onFinish: function onFinish() {
// Phase 4: Flash effect for rare items
if (rarity === 'epic' || rarity === 'legendary') {
tween(self, {
alpha: 0.3
}, {
duration: 100,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(self, {
alpha: 1
}, {
duration: 100,
easing: tween.easeInOut,
onFinish: function onFinish() {
// Phase 5: Final opening - spin and shrink
tween(self, {
rotation: Math.PI * 4,
scaleX: 0,
scaleY: 0,
alpha: 0
}, {
duration: 800,
easing: tween.easeIn
});
}
});
}
});
} else {
// Phase 5: Simple opening for common items
tween(self, {
rotation: Math.PI * 2,
scaleX: 0,
scaleY: 0,
alpha: 0
}, {
duration: 600,
easing: tween.easeIn
});
}
}
});
}
});
}
});
return {
rarity: rarity,
value: value
};
};
return self;
});
var NumberPad = Container.expand(function () {
var self = Container.call(this);
var background = self.attachAsset('cheatPanel', {
anchorX: 0.5,
anchorY: 0.5
});
var enteredCode = '';
var targetCode = '4154';
var codeText = new Text2('', {
size: 60,
fill: 0xFFFFFF
});
codeText.anchor.set(0.5, 0.5);
codeText.y = -150;
self.addChild(codeText);
var closeButton = new Text2('X', {
size: 80,
fill: 0xFF0000
});
closeButton.anchor.set(0.5, 0.5);
closeButton.x = 250;
closeButton.y = -150;
closeButton.interactive = true;
closeButton.buttonMode = true;
self.addChild(closeButton);
// Create number buttons 0-9
var numberButtons = [];
for (var i = 0; i <= 9; i++) {
var button = self.attachAsset('numberButton', {
anchorX: 0.5,
anchorY: 0.5
});
var col = i % 3;
var row = Math.floor(i / 3);
if (i === 0) {
col = 1;
row = 3;
}
button.x = (col - 1) * 120;
button.y = row * 80 - 40;
var buttonText = new Text2(i.toString(), {
size: 40,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
button.addChild(buttonText);
button.interactive = true;
button.buttonMode = true;
button.number = i;
button.up = function () {
enteredCode += this.number.toString();
codeText.setText(enteredCode);
if (enteredCode.length >= 4) {
if (enteredCode === targetCode) {
// Show cheat panel
var cheatPanel = new CheatPanel();
cheatPanel.x = 1024;
cheatPanel.y = 1366;
game.addChild(cheatPanel);
}
enteredCode = '';
codeText.setText('');
self.destroy();
}
};
numberButtons.push(button);
}
closeButton.up = function () {
self.destroy();
};
return self;
});
var OpenButton = Container.expand(function () {
var self = Container.call(this);
self.cost = 0;
var buttonGraphics = self.attachAsset('openButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.buttonText = new Text2('OPEN', {
size: 60,
fill: 0xFFFFFF
});
self.buttonText.anchor.set(0.5, 0.5);
self.addChild(self.buttonText);
self.interactive = true;
self.buttonMode = true;
self.updateCost = function (cost) {
self.cost = cost;
if (cost === 0) {
self.buttonText.setText('OPEN FREE');
} else {
self.buttonText.setText('OPEN - ' + cost);
}
};
self.down = function () {
tween(self, {
scaleX: 0.95,
scaleY: 0.95
}, {
duration: 100
});
};
self.up = function () {
tween(self, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
};
return self;
});
var RewardItem = Container.expand(function () {
var self = Container.call(this);
self.setup = function (rarity, value) {
var itemGraphics = self.attachAsset(rarity + 'Item', {
anchorX: 0.5,
anchorY: 0.5
});
self.scaleX = 0;
self.scaleY = 0;
tween(self, {
scaleX: 1,
scaleY: 1
}, {
duration: 500,
easing: tween.bounceOut
});
if (rarity === 'epic' || rarity === 'legendary') {
LK.getSound('rareFind').play();
LK.effects.flashScreen(0xFFD700, 500);
}
var rarityText = new Text2(rarity.toUpperCase(), {
size: 50,
fill: 0xFFFFFF
});
rarityText.anchor.set(0.5, 0.5);
rarityText.y = 80;
self.addChild(rarityText);
var valueText = new Text2('+' + value, {
size: 60,
fill: 0xFFD700
});
valueText.anchor.set(0.5, 0.5);
valueText.y = -150;
self.addChild(valueText);
tween(valueText, {
y: -250,
alpha: 0
}, {
duration: 1500,
easing: tween.easeOut
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a1a
});
/****
* Game Code
****/
var coins = storage.coins || 100;
var collection = storage.collection || {};
var unlockedBoxes = storage.unlockedBoxes || ['basic'];
var luckBoostActive = false;
var luckBoostEndTime = 0;
var luckBoostCost = 500;
var luckBoostDuration = 60000; // 1 minute
var currentBoxIndex = 0;
var boxes = [];
var boxConfigs = [{
type: 'basic',
cost: 0
}, {
type: 'silver',
cost: 50
}, {
type: 'gold',
cost: 200
}, {
type: 'diamond',
cost: 800
}, {
type: 'legendary',
cost: 3000
}];
var coinsText = new Text2('Coins: ' + coins, {
size: 80,
fill: 0xFFD700
});
coinsText.anchor.set(0.5, 0);
LK.gui.top.addChild(coinsText);
var collectionButton = new Text2('Collection', {
size: 60,
fill: 0xFFFFFF
});
collectionButton.anchor.set(1, 0);
collectionButton.x = -20;
collectionButton.interactive = true;
collectionButton.buttonMode = true;
LK.gui.topRight.addChild(collectionButton);
var marketButton = new Text2('Market', {
size: 60,
fill: 0x00FF00
});
marketButton.anchor.set(1, 0);
marketButton.x = -20;
marketButton.y = 80;
marketButton.interactive = true;
marketButton.buttonMode = true;
LK.gui.topRight.addChild(marketButton);
var collectionText = new Text2('Collection: ' + Object.keys(collection).length, {
size: 60,
fill: 0xFFFFFF
});
collectionText.anchor.set(0, 0);
collectionText.x = 20;
collectionText.y = 100;
LK.gui.topLeft.addChild(collectionText);
var luckBoostButton = new Text2('Luck Boost: 500 Coins', {
size: 50,
fill: 0xFFD700
});
luckBoostButton.anchor.set(0.5, 0);
luckBoostButton.y = 200;
luckBoostButton.interactive = true;
luckBoostButton.buttonMode = true;
LK.gui.top.addChild(luckBoostButton);
var luckBoostStatusText = new Text2('', {
size: 40,
fill: 0x00FF00
});
luckBoostStatusText.anchor.set(0.5, 0);
luckBoostStatusText.y = 270;
LK.gui.top.addChild(luckBoostStatusText);
var currentBox = null;
var openButton = new OpenButton();
openButton.x = 1024;
openButton.y = 2200;
game.addChild(openButton);
var prevButton = new Text2('<', {
size: 120,
fill: 0xFFFFFF
});
prevButton.anchor.set(0.5, 0.5);
prevButton.x = 200;
prevButton.y = 1366;
prevButton.interactive = true;
prevButton.buttonMode = true;
game.addChild(prevButton);
var nextButton = new Text2('>', {
size: 120,
fill: 0xFFFFFF
});
nextButton.anchor.set(0.5, 0.5);
nextButton.x = 1848;
nextButton.y = 1366;
nextButton.interactive = true;
nextButton.buttonMode = true;
game.addChild(nextButton);
var boxNameText = new Text2('', {
size: 80,
fill: 0xFFFFFF
});
boxNameText.anchor.set(0.5, 0.5);
boxNameText.x = 1024;
boxNameText.y = 800;
game.addChild(boxNameText);
function updateCoins(amount) {
coins += amount;
storage.coins = coins;
coinsText.setText('Coins: ' + coins);
LK.getSound('coinCollect').play();
}
;
luckBoostButton.down = function () {
tween(luckBoostButton, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100
});
};
luckBoostButton.up = function () {
tween(luckBoostButton, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
if (!luckBoostActive && coins >= luckBoostCost) {
updateCoins(-luckBoostCost);
luckBoostActive = true;
luckBoostEndTime = Date.now() + luckBoostDuration;
luckBoostButton.visible = false;
}
;
};
function updateCollection(rarity) {
var key = currentBox.boxType + '_' + rarity;
if (!collection[key]) {
collection[key] = 0;
}
collection[key]++;
storage.collection = collection;
collectionText.setText('Collection: ' + Object.keys(collection).length);
}
function createNewBox() {
if (currentBox) {
currentBox.destroy();
}
var config = boxConfigs[currentBoxIndex];
currentBox = new MysteryBox();
currentBox.setup(config.type, config.cost);
currentBox.x = 1024;
currentBox.y = 1366;
game.addChild(currentBox);
boxNameText.setText(config.type.toUpperCase() + ' BOX');
openButton.updateCost(config.cost);
var isUnlocked = unlockedBoxes.indexOf(config.type) !== -1;
if (!isUnlocked) {
currentBox.alpha = 0.3;
openButton.visible = false;
boxNameText.setText('LOCKED - Need ' + currentBoxIndex * 1000 + ' coins');
} else {
currentBox.alpha = 1;
openButton.visible = true;
}
}
function checkUnlocks() {
for (var i = 0; i < boxConfigs.length; i++) {
var boxType = boxConfigs[i].type;
if (unlockedBoxes.indexOf(boxType) === -1) {
if (coins >= i * 1000) {
unlockedBoxes.push(boxType);
storage.unlockedBoxes = unlockedBoxes;
if (i === currentBoxIndex) {
createNewBox();
}
}
}
}
}
prevButton.down = function () {
tween(prevButton, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100
});
};
prevButton.up = function () {
tween(prevButton, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
if (currentBoxIndex > 0) {
currentBoxIndex--;
createNewBox();
}
};
nextButton.down = function () {
tween(nextButton, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100
});
};
nextButton.up = function () {
tween(nextButton, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
if (currentBoxIndex < boxConfigs.length - 1) {
currentBoxIndex++;
createNewBox();
}
};
openButton.down = function () {
if (openButton.down.__super__) {
openButton.down.__super__.call(openButton);
}
};
collectionButton.down = function () {
tween(collectionButton, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100
});
};
collectionButton.up = function () {
tween(collectionButton, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
var collectionView = new CollectionView();
collectionView.setup(collection);
collectionView.x = 1024;
collectionView.y = 1366;
game.addChild(collectionView);
};
marketButton.down = function () {
tween(marketButton, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100
});
};
marketButton.up = function () {
tween(marketButton, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
var market = new Market();
market.setup(collection);
market.x = 1024;
market.y = 1366;
game.addChild(market);
};
openButton.up = function () {
if (openButton.up.__super__) {
openButton.up.__super__.call(openButton);
}
if (currentBox && !currentBox.isOpening) {
var cost = boxConfigs[currentBoxIndex].cost;
if (coins >= cost) {
if (cost > 0) {
updateCoins(-cost);
}
var result = currentBox.open();
if (result) {
var reward = new RewardItem();
reward.setup(result.rarity, result.value);
reward.x = 1024;
reward.y = 1366;
game.addChild(reward);
updateCoins(result.value);
updateCollection(result.rarity);
LK.setTimeout(function () {
createNewBox();
reward.destroy();
}, 1000);
}
}
}
};
game.update = function () {
checkUnlocks();
// Update luck boost status
if (luckBoostActive) {
var timeLeft = Math.max(0, luckBoostEndTime - Date.now());
if (timeLeft > 0) {
var secondsLeft = Math.ceil(timeLeft / 1000);
luckBoostStatusText.setText('10x Luck: ' + secondsLeft + 's');
} else {
luckBoostActive = false;
luckBoostStatusText.setText('');
luckBoostButton.visible = true;
}
} else {
luckBoostStatusText.setText('');
}
};
var cheatButton = new Text2('Cheat', {
size: 40,
fill: 0xFF0000
});
cheatButton.anchor.set(0.5, 1);
cheatButton.x = 1024;
cheatButton.y = 2700;
cheatButton.interactive = true;
cheatButton.buttonMode = true;
game.addChild(cheatButton);
cheatButton.up = function () {
var numberPad = new NumberPad();
numberPad.x = 1024;
numberPad.y = 1366;
game.addChild(numberPad);
};
createNewBox();
LK.playMusic('bgmusic');
;
pixel tahta bir hazine kutusu. In-Game asset. 2d. High contrast. No shadows
pixel bir coin, üstünde dolar($) işareti var. In-Game asset. 2d. High contrast. No shadows
pixel bir hurda parçası. In-Game asset. 2d. High contrast. No shadows
2d pixel bir külçe altın. In-Game asset. 2d. High contrast. No shadows
2d pixel bir elmas. In-Game asset. 2d. High contrast. No shadows
2d pixel bir elmas ama ortadan ikiye ayrılmış. In-Game asset. 2d. High contrast. No shadows
2d pixel bir demir hazine kutusu. In-Game asset. 2d. High contrast. No shadows
2d pixel bir altından hazine kutusu. In-Game asset. 2d. High contrast. No shadows
2d pixel kırmızı gizemli bir hazine sandığı. In-Game asset. 2d. High contrast. No shadows
2d pixel bir kömür. In-Game asset. 2d. High contrast. No shadows