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) {
var self = Container.call(this);
self.itemType = itemType;
self.rarity = rarity;
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.3
});
var rarityColors = {
common: 0xFFFFFF,
rare: 0x4169E1,
epic: 0x9932CC,
legendary: 0xFFD700
};
itemGraphics.tint = rarityColors[rarity];
self.discover = function () {
if (!self.discovered) {
self.discovered = true;
itemGraphics.alpha = 1.0;
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) {
var self = Container.call(this);
self.itemType = itemType;
self.rarity = rarity;
self.value = getItemValue(itemType, rarity);
var itemGraphics = self.attachAsset('treasure_' + itemType, {
anchorX: 0.5,
anchorY: 0.5
});
// Apply rarity tint
var rarityColors = {
common: 0xFFFFFF,
rare: 0x4169E1,
epic: 0x9932CC,
legendary: 0xFFD700
};
itemGraphics.tint = rarityColors[rarity];
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'];
// Box definitions
var boxTypes = ['common', 'rare', 'epic', 'legendary'];
function getBoxPrice(boxType) {
var prices = {
common: 50,
rare: 150,
epic: 400,
legendary: 1000
};
return prices[boxType];
}
function getItemValue(itemType, rarity) {
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
};
return (baseValues[itemType] || 50) * rarityMultipliers[rarity];
}
function getRarityChance(boxType) {
var chances = {
common: {
common: 0.7,
rare: 0.25,
epic: 0.04,
legendary: 0.01
},
rare: {
common: 0.4,
rare: 0.45,
epic: 0.13,
legendary: 0.02
},
epic: {
common: 0.2,
rare: 0.4,
epic: 0.35,
legendary: 0.05
},
legendary: {
common: 0.1,
rare: 0.3,
epic: 0.4,
legendary: 0.2
}
};
return chances[boxType];
}
function generateRandomItem(boxType) {
var chances = getRarityChance(boxType);
var rand = Math.random();
var rarity = 'common';
if (rand < chances.legendary) {
rarity = 'legendary';
} else if (rand < chances.legendary + chances.epic) {
rarity = 'epic';
} else if (rand < chances.legendary + chances.epic + chances.rare) {
rarity = 'rare';
}
var itemType = treasureTypes[Math.floor(Math.random() * treasureTypes.length)];
return {
type: itemType,
rarity: rarity
};
}
// 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]);
box.x = 200 + i * 400;
box.y = 1000;
shopContainer.addChild(box);
treasureBoxes.push(box);
// Add rarity labels
var rarityLabel = new Text2(boxTypes[i].toUpperCase() + ' BOX', {
size: 45,
fill: '#FFFFFF'
});
rarityLabel.anchor.set(0.5, 0.5);
rarityLabel.x = box.x;
rarityLabel.y = box.y - 150;
shopContainer.addChild(rarityLabel);
// Add legendary chance info
var chanceInfo = getRarityChance(boxTypes[i]);
var legendaryChance = Math.round(chanceInfo.legendary * 100);
var chanceText = new Text2('Legendary: ' + legendaryChance + '%', {
size: 30,
fill: '#FFD700'
});
chanceText.anchor.set(0.5, 0.5);
chanceText.x = box.x;
chanceText.y = box.y + 150;
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);
var slotIndex = 0;
var itemsPerRow = 10;
var slotSpacing = 140;
var startX = 200;
var startY = 500;
for (var r = 0; r < rarityLevels.length; r++) {
var rarityText = new Text2(rarityLevels[r].toUpperCase(), {
size: 50,
fill: '#FFFFFF'
});
rarityText.anchor.set(0.5, 0.5);
rarityText.x = 1024;
rarityText.y = startY + r * 600;
collectionContainer.addChild(rarityText);
for (var t = 0; t < treasureTypes.length; t++) {
var slot = new CollectionSlot(treasureTypes[t], rarityLevels[r]);
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
var itemKey = treasureTypes[t] + '_' + rarityLevels[r];
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;
}
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);
treasure.x = 1024;
treasure.y = 600;
treasure.alpha = 0;
treasure.scaleX = 0.1;
treasure.scaleY = 0.1;
openingContainer.addChild(treasure);
// Rarity text
var rarityText = new Text2(item.rarity.toUpperCase() + '!', {
size: 80,
fill: '#FFFFFF'
});
rarityText.anchor.set(0.5, 0.5);
rarityText.x = 1024;
rarityText.y = 400;
rarityText.alpha = 0;
openingContainer.addChild(rarityText);
// 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 === 'legendary' || item.rarity === 'epic') {
LK.getSound('rare_find').play();
} else {
LK.getSound('coin_sound').play();
}
// Flash effect for rare items
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;
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
@@ -521,8 +521,73 @@
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
@@ -530,6 +595,20 @@
shopContainer.visible = false;
openingContainer.visible = false;
collectionContainer.visible = false;
game.update = function () {
- // Update logic here if needed
+ // 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();
+ }
+ }
};
\ No newline at end of file