User prompt
Please fix the bug: 'Error: Invalid value. Only literals or 1-level deep objects/arrays containing literals are allowed.' in or related to this line: 'storage.leaderboard = leaderboard;' Line Number: 1116 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Poner leaderboard button
User prompt
Que se pueda saber quien a conseguido el más difícil online ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Que sea más posible de qué sea grande
User prompt
Que se pueda salir de la tienda
User prompt
Que con el tamaño sea más grande el número de probabilidad
User prompt
Al conseguirlo no en las dificultades
User prompt
Y que ponga lo raro que es de 1 entre 1 hasta infinito
User prompt
Que no haya límite de tamaño
User prompt
Please fix the bug: 'Error: Invalid value. Only literals or 1-level deep objects/arrays containing literals are allowed.' in or related to this line: 'discoveredItems[itemKey] = {' Line Number: 827 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Hacer que puedan tocar objetos más grandes con menos probabilidad y que sean más valiosos i que no haya máximo de tamaño
User prompt
Poner 5 más cofres i poner de probabilidades mítico cósmico y imposible
User prompt
Poner las indicaciones de probabilidad más grandes
User prompt
Poner las probabilidades más grandes
User prompt
Haz las cosas más grandes
User prompt
Que muestre cuanta probabilidad hay de que te toque común raro epico o legendario
User prompt
Que muestre comun raro epico y legendario
User prompt
Que pongan todas las posibilidades
User prompt
Que aparezcan monedas aleatoria mente i que cada 1 de 5 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Que hayan 50 objetos
User prompt
Poner el botón de tienda
User prompt
Que este eso en un botón de tienda
User prompt
Haz una tienda
Code edit (1 edits merged)
Please save this source code
User prompt
Treasure Box Rush
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var CollectionSlot = Container.expand(function (itemType, rarity, size) {
var self = Container.call(this);
self.itemType = itemType;
self.rarity = rarity;
self.size = size || 1.0;
self.discovered = false;
var slotBg = self.attachAsset('item_slot', {
anchorX: 0.5,
anchorY: 0.5
});
var itemGraphics = self.attachAsset('treasure_' + itemType, {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.6
});
// Scale item to fit in slot while maintaining aspect ratio
var maxScale = Math.min(1.0, 80 / (80 * self.size));
itemGraphics.scaleX = maxScale;
itemGraphics.scaleY = maxScale;
var rarityColors = {
common: 0xFFFFFF,
rare: 0x4169E1,
epic: 0x9932CC,
legendary: 0xFFD700,
mítico: 0xFF0080,
cósmico: 0x00FFFF,
imposible: 0xFF6600
};
itemGraphics.tint = rarityColors[rarity];
// Add item name text
var itemNameText = new Text2(itemType.toUpperCase(), {
size: 16,
fill: '#FFFFFF'
});
itemNameText.anchor.set(0.5, 0.5);
itemNameText.y = 70;
itemNameText.alpha = 0.8;
self.addChild(itemNameText);
// Add discovery indicator
var discoveryIndicator = new Text2('?', {
size: 30,
fill: '#FF0000'
});
discoveryIndicator.anchor.set(0.5, 0.5);
discoveryIndicator.x = 40;
discoveryIndicator.y = -40;
self.addChild(discoveryIndicator);
self.discover = function () {
if (!self.discovered) {
self.discovered = true;
itemGraphics.alpha = 1.0;
itemNameText.alpha = 1.0;
discoveryIndicator.visible = false;
LK.effects.flashObject(self, rarityColors[rarity], 1000);
}
};
return self;
});
var TreasureBox = Container.expand(function (boxType) {
var self = Container.call(this);
self.boxType = boxType;
self.price = getBoxPrice(boxType);
var boxGraphics = self.attachAsset('box_' + boxType, {
anchorX: 0.5,
anchorY: 0.5
});
var priceText = new Text2(self.price + ' coins', {
size: 40,
fill: '#FFFFFF'
});
priceText.anchor.set(0.5, 0.5);
priceText.y = 120;
self.addChild(priceText);
self.down = function (x, y, obj) {
if (playerCoins >= self.price) {
openBox(self.boxType);
} else {
// Visual feedback for insufficient coins
LK.effects.flashObject(self, 0xff0000, 500);
}
};
self.update = function () {
// Update visual state based on affordability
if (playerCoins >= self.price) {
boxGraphics.alpha = 1.0;
priceText.tint = 0x00ff00;
} else {
boxGraphics.alpha = 0.6;
priceText.tint = 0xff0000;
}
};
return self;
});
var TreasureItem = Container.expand(function (itemType, rarity, size) {
var self = Container.call(this);
self.itemType = itemType;
self.rarity = rarity;
self.size = size || 1.0;
self.value = getItemValue(itemType, rarity, size);
var itemGraphics = self.attachAsset('treasure_' + itemType, {
anchorX: 0.5,
anchorY: 0.5
});
// Apply size scaling
itemGraphics.scaleX = self.size;
itemGraphics.scaleY = self.size;
// Apply rarity tint
var rarityColors = {
common: 0xFFFFFF,
rare: 0x4169E1,
epic: 0x9932CC,
legendary: 0xFFD700,
mítico: 0xFF0080,
cósmico: 0x00FFFF,
imposible: 0xFF6600
};
itemGraphics.tint = rarityColors[rarity];
// Add size indicator text if item is larger than normal
if (self.size > 1.5) {
var sizeText = new Text2(self.size.toFixed(1) + 'x', {
size: 30,
fill: '#FFFF00'
});
sizeText.anchor.set(0.5, 0.5);
sizeText.y = itemGraphics.height * self.size / 2 + 20;
self.addChild(sizeText);
}
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a1a
});
/****
* Game Code
****/
// Game state
var playerCoins = storage.coins || 100;
var discoveredItems = storage.discovered || {};
var currentScreen = 'shop'; // 'shop', 'opening', 'collection'
var openingAnimation = false;
// Treasure definitions
var treasureTypes = ['coin', 'gem', 'diamond', 'ruby', 'crown', 'artifact', 'sword', 'shield', 'ring', 'necklace', 'bracelet', 'earring', 'pendant', 'watch', 'staff', 'orb', 'scroll', 'book', 'potion', 'crystal', 'pearl', 'emerald', 'sapphire', 'topaz', 'amethyst', 'opal', 'jade', 'onyx', 'turquoise', 'garnet', 'chalice', 'goblet', 'scepter', 'tiara', 'dagger', 'armor', 'helmet', 'gauntlets', 'boots', 'cloak', 'amulet', 'talisman', 'rune', 'compass', 'telescope', 'hourglass', 'lantern', 'mirror', 'key', 'chest'];
var rarityLevels = ['common', 'rare', 'epic', 'legendary', 'mítico', 'cósmico', 'imposible'];
// Box definitions
var boxTypes = ['common', 'rare', 'epic', 'legendary', 'mítico', 'cósmico', 'imposible'];
function getBoxPrice(boxType) {
var prices = {
common: 50,
rare: 150,
epic: 400,
legendary: 1000,
mítico: 2500,
cósmico: 5000,
imposible: 10000
};
return prices[boxType];
}
function getItemValue(itemType, rarity, size) {
var baseValues = {
coin: 10,
gem: 25,
diamond: 50,
ruby: 100,
crown: 200,
artifact: 500,
sword: 80,
shield: 75,
ring: 60,
necklace: 90,
bracelet: 70,
earring: 65,
pendant: 85,
watch: 120,
staff: 150,
orb: 180,
scroll: 45,
book: 55,
potion: 40,
crystal: 95,
pearl: 110,
emerald: 140,
sapphire: 160,
topaz: 130,
amethyst: 135,
opal: 125,
jade: 145,
onyx: 105,
turquoise: 115,
garnet: 100,
chalice: 220,
goblet: 200,
scepter: 300,
tiara: 250,
dagger: 85,
armor: 400,
helmet: 180,
gauntlets: 120,
boots: 90,
cloak: 110,
amulet: 170,
talisman: 160,
rune: 190,
compass: 100,
telescope: 150,
hourglass: 140,
lantern: 80,
mirror: 90,
key: 75,
chest: 350
};
var rarityMultipliers = {
common: 1,
rare: 3,
epic: 8,
legendary: 20,
mítico: 50,
cósmico: 100,
imposible: 250
};
size = size || 1.0; // Default size if not provided
var sizeMultiplier = size * size; // Quadratic scaling for value
return Math.floor((baseValues[itemType] || 50) * rarityMultipliers[rarity] * sizeMultiplier);
}
function getRarityChance(boxType) {
var chances = {
common: {
common: 0.5,
rare: 0.35,
epic: 0.12,
legendary: 0.03,
mítico: 0,
cósmico: 0,
imposible: 0
},
rare: {
common: 0.25,
rare: 0.5,
epic: 0.2,
legendary: 0.05,
mítico: 0,
cósmico: 0,
imposible: 0
},
epic: {
common: 0.15,
rare: 0.35,
epic: 0.4,
legendary: 0.1,
mítico: 0,
cósmico: 0,
imposible: 0
},
legendary: {
common: 0.05,
rare: 0.25,
epic: 0.45,
legendary: 0.25,
mítico: 0,
cósmico: 0,
imposible: 0
},
mítico: {
common: 0.02,
rare: 0.15,
epic: 0.28,
legendary: 0.35,
mítico: 0.15,
cósmico: 0.04,
imposible: 0.01
},
cósmico: {
common: 0.01,
rare: 0.1,
epic: 0.2,
legendary: 0.35,
mítico: 0.25,
cósmico: 0.08,
imposible: 0.01
},
imposible: {
common: 0.005,
rare: 0.05,
epic: 0.15,
legendary: 0.25,
mítico: 0.35,
cósmico: 0.15,
imposible: 0.095
}
};
return chances[boxType];
}
function generateRandomItem(boxType) {
var chances = getRarityChance(boxType);
var rand = Math.random();
var rarity = 'common';
if (rand < chances.imposible) {
rarity = 'imposible';
} else if (rand < chances.imposible + chances.cósmico) {
rarity = 'cósmico';
} else if (rand < chances.imposible + chances.cósmico + chances.mítico) {
rarity = 'mítico';
} else if (rand < chances.imposible + chances.cósmico + chances.mítico + chances.legendary) {
rarity = 'legendary';
} else if (rand < chances.imposible + chances.cósmico + chances.mítico + chances.legendary + chances.epic) {
rarity = 'epic';
} else if (rand < chances.imposible + chances.cósmico + chances.mítico + chances.legendary + chances.epic + chances.rare) {
rarity = 'rare';
}
var itemType = treasureTypes[Math.floor(Math.random() * treasureTypes.length)];
// Generate item size based on probability - larger items are rarer
var sizeRand = Math.random();
var size = 1.0; // Base size
if (sizeRand < 0.01) {
// 1% chance for massive items
size = 8.0 + Math.random() * 12.0; // 8x to 20x size
} else if (sizeRand < 0.05) {
// 4% chance for huge items
size = 4.0 + Math.random() * 4.0; // 4x to 8x size
} else if (sizeRand < 0.15) {
// 10% chance for large items
size = 2.0 + Math.random() * 2.0; // 2x to 4x size
} else if (sizeRand < 0.35) {
// 20% chance for medium items
size = 1.5 + Math.random() * 0.5; // 1.5x to 2x size
} else if (sizeRand < 0.65) {
// 30% chance for small+ items
size = 1.2 + Math.random() * 0.3; // 1.2x to 1.5x size
}
// 35% chance for normal size (1.0x)
return {
type: itemType,
rarity: rarity,
size: size
};
}
// UI Elements
var coinsDisplay = new Text2('Coins: ' + playerCoins, {
size: 60,
fill: '#FFD700'
});
coinsDisplay.anchor.set(0, 0);
coinsDisplay.x = 150;
coinsDisplay.y = 50;
LK.gui.topLeft.addChild(coinsDisplay);
var shopButton = new Container();
var shopButtonBg = shopButton.attachAsset('button_bg', {
anchorX: 0.5,
anchorY: 0.5
});
var shopButtonText = new Text2('SHOP', {
size: 40,
fill: '#FFFFFF'
});
shopButtonText.anchor.set(0.5, 0.5);
shopButton.addChild(shopButtonText);
shopButton.x = 1024;
shopButton.y = 150;
shopButton.down = function () {
showShop();
};
game.addChild(shopButton);
var collectionButton = new Container();
var collectionButtonBg = collectionButton.attachAsset('button_bg', {
anchorX: 0.5,
anchorY: 0.5
});
var collectionButtonText = new Text2('COLLECTION', {
size: 40,
fill: '#FFFFFF'
});
collectionButtonText.anchor.set(0.5, 0.5);
collectionButton.addChild(collectionButtonText);
collectionButton.x = 1024;
collectionButton.y = 250;
collectionButton.down = function () {
showCollection();
};
LK.gui.top.addChild(collectionButton);
// Game containers
var shopContainer = new Container();
var openingContainer = new Container();
var collectionContainer = new Container();
game.addChild(shopContainer);
game.addChild(openingContainer);
game.addChild(collectionContainer);
// Shop setup
var treasureBoxes = [];
function setupShop() {
shopContainer.removeChildren();
treasureBoxes = [];
// Add shop title
var shopTitle = new Text2('TREASURE SHOP', {
size: 100,
fill: '#FFFFFF'
});
shopTitle.anchor.set(0.5, 0.5);
shopTitle.x = 1024;
shopTitle.y = 300;
shopContainer.addChild(shopTitle);
// Add shop description
var shopDesc = new Text2('Buy mystery boxes to discover treasures!', {
size: 50,
fill: '#CCCCCC'
});
shopDesc.anchor.set(0.5, 0.5);
shopDesc.x = 1024;
shopDesc.y = 400;
shopContainer.addChild(shopDesc);
// Create boxes with better spacing
for (var i = 0; i < boxTypes.length; i++) {
var box = new TreasureBox(boxTypes[i]);
// Create two rows of boxes
if (i < 4) {
box.x = 200 + i * 400;
box.y = 900;
} else {
box.x = 200 + (i - 4) * 400;
box.y = 1400;
}
shopContainer.addChild(box);
treasureBoxes.push(box);
// Add rarity labels with proper colors
var boxRarityColors = {
common: '#FFFFFF',
rare: '#4169E1',
epic: '#9932CC',
legendary: '#FFD700',
mítico: '#FF0080',
cósmico: '#00FFFF',
imposible: '#FF6600'
};
var rarityLabel = new Text2(boxTypes[i].toUpperCase() + ' BOX', {
size: 45,
fill: boxRarityColors[boxTypes[i]]
});
rarityLabel.anchor.set(0.5, 0.5);
rarityLabel.x = box.x;
rarityLabel.y = box.y - 150;
shopContainer.addChild(rarityLabel);
// Add probability display for all rarities
var chanceInfo = getRarityChance(boxTypes[i]);
var probabilities = [{
rarity: 'Common',
chance: chanceInfo.common,
color: '#FFFFFF'
}, {
rarity: 'Rare',
chance: chanceInfo.rare,
color: '#4169E1'
}, {
rarity: 'Epic',
chance: chanceInfo.epic,
color: '#9932CC'
}, {
rarity: 'Legendary',
chance: chanceInfo.legendary,
color: '#FFD700'
}, {
rarity: 'Mítico',
chance: chanceInfo.mítico,
color: '#FF0080'
}, {
rarity: 'Cósmico',
chance: chanceInfo.cósmico,
color: '#00FFFF'
}, {
rarity: 'Imposible',
chance: chanceInfo.imposible,
color: '#FF6600'
}];
for (var p = 0; p < probabilities.length; p++) {
var prob = probabilities[p];
var percentage = Math.round(prob.chance * 100);
var chanceText = new Text2(prob.rarity + ': ' + percentage + '%', {
size: 40,
fill: prob.color
});
chanceText.anchor.set(0.5, 0.5);
chanceText.x = box.x;
chanceText.y = box.y + 150 + p * 35;
shopContainer.addChild(chanceText);
}
}
}
// Collection setup
var collectionSlots = [];
function setupCollection() {
collectionContainer.removeChildren();
collectionSlots = [];
var collectionBg = collectionContainer.attachAsset('collection_bg', {
anchorX: 0.5,
anchorY: 0.5
});
collectionBg.x = 1024;
collectionBg.y = 1366;
var titleText = new Text2('TREASURE COLLECTION', {
size: 80,
fill: '#FFFFFF'
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 1024;
titleText.y = 300;
collectionContainer.addChild(titleText);
// Add collection statistics
var totalItems = treasureTypes.length * rarityLevels.length;
var discoveredCount = 0;
for (var key in discoveredItems) {
if (discoveredItems[key] && !key.endsWith('_size')) {
discoveredCount++;
}
}
var statsText = new Text2('Discovered: ' + discoveredCount + '/' + totalItems, {
size: 40,
fill: '#CCCCCC'
});
statsText.anchor.set(0.5, 0.5);
statsText.x = 1024;
statsText.y = 370;
collectionContainer.addChild(statsText);
var slotIndex = 0;
var itemsPerRow = 10;
var slotSpacing = 140;
var startX = 200;
var startY = 500;
for (var r = 0; r < rarityLevels.length; r++) {
// Rarity color mapping
var rarityColors = {
common: '#FFFFFF',
rare: '#4169E1',
epic: '#9932CC',
legendary: '#FFD700',
mítico: '#FF0080',
cósmico: '#00FFFF',
imposible: '#FF6600'
};
var rarityText = new Text2(rarityLevels[r].toUpperCase(), {
size: 50,
fill: rarityColors[rarityLevels[r]]
});
rarityText.anchor.set(0.5, 0.5);
rarityText.x = 1024;
rarityText.y = startY + r * 600;
collectionContainer.addChild(rarityText);
// Add rarity statistics
var rarityCount = 0;
for (var t = 0; t < treasureTypes.length; t++) {
var itemKey = treasureTypes[t] + '_' + rarityLevels[r];
if (discoveredItems[itemKey]) {
rarityCount++;
}
}
var rarityStats = new Text2(rarityCount + '/' + treasureTypes.length, {
size: 35,
fill: '#CCCCCC'
});
rarityStats.anchor.set(0.5, 0.5);
rarityStats.x = 1024;
rarityStats.y = startY + r * 600 + 30;
collectionContainer.addChild(rarityStats);
for (var t = 0; t < treasureTypes.length; t++) {
var itemKey = treasureTypes[t] + '_' + rarityLevels[r];
var itemSize = 1.0;
if (discoveredItems[itemKey + '_size']) {
itemSize = discoveredItems[itemKey + '_size'];
}
var slot = new CollectionSlot(treasureTypes[t], rarityLevels[r], itemSize);
var row = Math.floor(t / itemsPerRow);
var col = t % itemsPerRow;
slot.x = startX + col * slotSpacing;
slot.y = startY + 80 + r * 600 + row * slotSpacing;
collectionContainer.addChild(slot);
collectionSlots.push(slot);
// Check if already discovered
if (discoveredItems[itemKey]) {
slot.discover();
}
}
}
}
function showShop() {
currentScreen = 'shop';
shopContainer.visible = true;
openingContainer.visible = false;
collectionContainer.visible = false;
}
function showCollection() {
currentScreen = 'collection';
shopContainer.visible = false;
openingContainer.visible = false;
collectionContainer.visible = true;
updateCollectionStats();
}
function updateCollectionStats() {
// Update the collection statistics when shown
var totalItems = treasureTypes.length * rarityLevels.length;
var discoveredCount = 0;
for (var key in discoveredItems) {
if (discoveredItems[key] && !key.endsWith('_size')) {
discoveredCount++;
}
}
// Find and update stats text if it exists
for (var i = 0; i < collectionContainer.children.length; i++) {
var child = collectionContainer.children[i];
if (child.text && child.text.includes('Discovered:')) {
child.setText('Discovered: ' + discoveredCount + '/' + totalItems + ' (' + Math.round(discoveredCount / totalItems * 100) + '%)');
break;
}
}
}
function showOpening() {
currentScreen = 'opening';
shopContainer.visible = false;
openingContainer.visible = true;
collectionContainer.visible = false;
}
function openBox(boxType) {
if (playerCoins < getBoxPrice(boxType)) return;
playerCoins -= getBoxPrice(boxType);
updateCoinsDisplay();
var item = generateRandomItem(boxType);
showOpening();
openingAnimation = true;
openingContainer.removeChildren();
// Create opening animation
var openingBox = new Container();
var boxGraphics = openingBox.attachAsset('box_' + boxType, {
anchorX: 0.5,
anchorY: 0.5
});
openingBox.x = 1024;
openingBox.y = 1000;
openingContainer.addChild(openingBox);
LK.getSound('box_open').play();
// Animate box opening
tween(openingBox, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 500,
easing: tween.easeOut,
onFinish: function onFinish() {
revealTreasure(item, boxType);
}
});
}
function revealTreasure(item, boxType) {
var treasure = new TreasureItem(item.type, item.rarity, item.size);
treasure.x = 1024;
treasure.y = 600;
treasure.alpha = 0;
treasure.scaleX = 0.1;
treasure.scaleY = 0.1;
openingContainer.addChild(treasure);
// Rarity text with proper color
var rarityTextColors = {
common: '#FFFFFF',
rare: '#4169E1',
epic: '#9932CC',
legendary: '#FFD700',
mítico: '#FF0080',
cósmico: '#00FFFF',
imposible: '#FF6600'
};
var rarityText = new Text2(item.rarity.toUpperCase() + '!', {
size: 80,
fill: rarityTextColors[item.rarity]
});
rarityText.anchor.set(0.5, 0.5);
rarityText.x = 1024;
rarityText.y = 400;
rarityText.alpha = 0;
openingContainer.addChild(rarityText);
// Size text for larger items
if (item.size > 1.5) {
var sizeText = new Text2('SIZE: ' + item.size.toFixed(1) + 'x', {
size: 50,
fill: '#FFFF00'
});
sizeText.anchor.set(0.5, 0.5);
sizeText.x = 1024;
sizeText.y = 480;
sizeText.alpha = 0;
openingContainer.addChild(sizeText);
tween(sizeText, {
alpha: 1
}, {
duration: 600,
easing: tween.easeOut
});
}
// Value text
var valueText = new Text2('+' + treasure.value + ' coins', {
size: 60,
fill: '#FFD700'
});
valueText.anchor.set(0.5, 0.5);
valueText.x = 1024;
valueText.y = 800;
valueText.alpha = 0;
openingContainer.addChild(valueText);
// Animate treasure reveal
tween(treasure, {
alpha: 1,
scaleX: 1,
scaleY: 1
}, {
duration: 800,
easing: tween.easeOut
});
tween(rarityText, {
alpha: 1
}, {
duration: 600,
easing: tween.easeOut
});
tween(valueText, {
alpha: 1
}, {
duration: 600,
easing: tween.easeOut
});
// Play appropriate sound
if (item.rarity === 'imposible' || item.rarity === 'cósmico' || item.rarity === 'mítico' || item.rarity === 'legendary' || item.rarity === 'epic') {
LK.getSound('rare_find').play();
} else {
LK.getSound('coin_sound').play();
}
// Flash effect for rare items
if (item.rarity === 'imposible') {
LK.effects.flashScreen(0xFF6600, 1500);
} else if (item.rarity === 'cósmico') {
LK.effects.flashScreen(0x00FFFF, 1200);
} else if (item.rarity === 'mítico') {
LK.effects.flashScreen(0xFF0080, 1000);
} else if (item.rarity === 'legendary') {
LK.effects.flashScreen(0xFFD700, 1000);
} else if (item.rarity === 'epic') {
LK.effects.flashScreen(0x9932CC, 800);
}
// Add to collection
var itemKey = item.type + '_' + item.rarity;
if (!discoveredItems[itemKey]) {
discoveredItems[itemKey] = true;
discoveredItems[itemKey + '_size'] = item.size;
storage.discovered = discoveredItems;
// Update collection display
for (var i = 0; i < collectionSlots.length; i++) {
var slot = collectionSlots[i];
if (slot.itemType === item.type && slot.rarity === item.rarity) {
slot.discover();
break;
}
}
}
// Add coins
playerCoins += treasure.value;
updateCoinsDisplay();
// Auto return to shop after 3 seconds
LK.setTimeout(function () {
openingAnimation = false;
showShop();
}, 3000);
}
function updateCoinsDisplay() {
coinsDisplay.setText('Coins: ' + playerCoins);
storage.coins = playerCoins;
// Update box affordability when coins change
for (var i = 0; i < treasureBoxes.length; i++) {
var box = treasureBoxes[i];
if (box.update) {
box.update();
}
}
}
// Coin spawning system
var spawnedCoins = [];
var coinSpawnTimer = 0;
var coinSpawnInterval = 120; // Spawn every 2 seconds at 60fps
var coinCounter = 0;
function spawnRandomCoin() {
coinCounter++;
var isSpecial = coinCounter % 5 === 0; // Every 5th coin is special
var coin = new Container();
var coinGraphics = coin.attachAsset('treasure_coin', {
anchorX: 0.5,
anchorY: 0.5
});
// Random position at top of screen
coin.x = Math.random() * (2048 - 100) + 50;
coin.y = -50;
coin.speed = 2 + Math.random() * 3; // Random fall speed
coin.value = isSpecial ? 50 : 10;
coin.isSpecial = isSpecial;
coin.lastY = coin.y;
// Special coin effects
if (isSpecial) {
coinGraphics.tint = 0xFFD700; // Gold tint
coinGraphics.scaleX = 1.5;
coinGraphics.scaleY = 1.5;
} else {
coinGraphics.tint = 0xFFA500; // Orange tint
}
coin.down = function (x, y, obj) {
// Collect the coin
playerCoins += coin.value;
updateCoinsDisplay();
// Visual feedback
if (coin.isSpecial) {
LK.effects.flashScreen(0xFFD700, 500);
LK.getSound('rare_find').play();
} else {
LK.getSound('coin_sound').play();
}
// Remove coin from game
coin.destroy();
for (var i = spawnedCoins.length - 1; i >= 0; i--) {
if (spawnedCoins[i] === coin) {
spawnedCoins.splice(i, 1);
break;
}
}
};
coin.update = function () {
coin.y += coin.speed;
// Remove if off screen
if (coin.lastY <= 2800 && coin.y > 2800) {
coin.destroy();
for (var i = spawnedCoins.length - 1; i >= 0; i--) {
if (spawnedCoins[i] === coin) {
spawnedCoins.splice(i, 1);
break;
}
}
}
coin.lastY = coin.y;
};
game.addChild(coin);
spawnedCoins.push(coin);
}
// Initialize game
setupShop();
setupCollection();
// Start with shop hidden, show only when button is pressed
currentScreen = 'menu';
shopContainer.visible = false;
openingContainer.visible = false;
collectionContainer.visible = false;
game.update = function () {
// Coin spawning system
coinSpawnTimer++;
if (coinSpawnTimer >= coinSpawnInterval) {
spawnRandomCoin();
coinSpawnTimer = 0;
// Vary the spawn interval slightly for randomness
coinSpawnInterval = 90 + Math.random() * 60; // Between 1.5 and 2.5 seconds
}
// Update all spawned coins
for (var i = spawnedCoins.length - 1; i >= 0; i--) {
var coin = spawnedCoins[i];
if (coin.update) {
coin.update();
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -518,9 +518,9 @@
// Add collection statistics
var totalItems = treasureTypes.length * rarityLevels.length;
var discoveredCount = 0;
for (var key in discoveredItems) {
- if (discoveredItems[key] && discoveredItems[key].discovered) {
+ if (discoveredItems[key] && !key.endsWith('_size')) {
discoveredCount++;
}
}
var statsText = new Text2('Discovered: ' + discoveredCount + '/' + totalItems, {
@@ -558,9 +558,9 @@
// Add rarity statistics
var rarityCount = 0;
for (var t = 0; t < treasureTypes.length; t++) {
var itemKey = treasureTypes[t] + '_' + rarityLevels[r];
- if (discoveredItems[itemKey] && discoveredItems[itemKey].discovered) {
+ if (discoveredItems[itemKey]) {
rarityCount++;
}
}
var rarityStats = new Text2(rarityCount + '/' + treasureTypes.length, {
@@ -573,10 +573,10 @@
collectionContainer.addChild(rarityStats);
for (var t = 0; t < treasureTypes.length; t++) {
var itemKey = treasureTypes[t] + '_' + rarityLevels[r];
var itemSize = 1.0;
- if (discoveredItems[itemKey] && discoveredItems[itemKey].size) {
- itemSize = discoveredItems[itemKey].size;
+ if (discoveredItems[itemKey + '_size']) {
+ itemSize = discoveredItems[itemKey + '_size'];
}
var slot = new CollectionSlot(treasureTypes[t], rarityLevels[r], itemSize);
var row = Math.floor(t / itemsPerRow);
var col = t % itemsPerRow;
@@ -584,9 +584,9 @@
slot.y = startY + 80 + r * 600 + row * slotSpacing;
collectionContainer.addChild(slot);
collectionSlots.push(slot);
// Check if already discovered
- if (discoveredItems[itemKey] && discoveredItems[itemKey].discovered) {
+ if (discoveredItems[itemKey]) {
slot.discover();
}
}
}
@@ -608,9 +608,9 @@
// Update the collection statistics when shown
var totalItems = treasureTypes.length * rarityLevels.length;
var discoveredCount = 0;
for (var key in discoveredItems) {
- if (discoveredItems[key] && discoveredItems[key].discovered) {
+ if (discoveredItems[key] && !key.endsWith('_size')) {
discoveredCount++;
}
}
// Find and update stats text if it exists
@@ -754,12 +754,10 @@
}
// Add to collection
var itemKey = item.type + '_' + item.rarity;
if (!discoveredItems[itemKey]) {
- discoveredItems[itemKey] = {
- discovered: true,
- size: item.size
- };
+ discoveredItems[itemKey] = true;
+ discoveredItems[itemKey + '_size'] = item.size;
storage.discovered = discoveredItems;
// Update collection display
for (var i = 0; i < collectionSlots.length; i++) {
var slot = collectionSlots[i];