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 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: 50,
uncommon: 35,
rare: 10,
epic: 4,
legendary: 1
},
gold: {
common: 30,
uncommon: 40,
rare: 20,
epic: 8,
legendary: 2
},
diamond: {
common: 10,
uncommon: 30,
rare: 35,
epic: 20,
legendary: 5
},
legendary: {
common: 0,
uncommon: 20,
rare: 40,
epic: 30,
legendary: 10
}
};
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 random = Math.random() * 100;
var cumulative = 0;
for (var rarity in weights) {
cumulative += weights[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();
tween(self, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self, {
scaleX: 0,
scaleY: 0
}, {
duration: 300,
easing: tween.easeIn
});
}
});
return {
rarity: rarity,
value: value
};
};
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 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 currentBoxIndex = 0;
var boxes = [];
var boxConfigs = [{
type: 'basic',
cost: 0
}, {
type: 'silver',
cost: 100
}, {
type: 'gold',
cost: 500
}, {
type: 'diamond',
cost: 2000
}, {
type: 'legendary',
cost: 10000
}];
var coinsText = new Text2('Coins: ' + coins, {
size: 80,
fill: 0xFFD700
});
coinsText.anchor.set(0.5, 0);
LK.gui.top.addChild(coinsText);
var collectionText = new Text2('Collection: ' + Object.keys(collection).length, {
size: 60,
fill: 0xFFFFFF
});
collectionText.anchor.set(1, 0);
collectionText.x = -20;
LK.gui.topRight.addChild(collectionText);
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();
}
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 () {
openButton.down();
};
openButton.up = function () {
openButton.up();
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();
};
createNewBox();
LK.playMusic('bgmusic'); ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,389 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+var storage = LK.import("@upit/storage.v1");
+
+/****
+* Classes
+****/
+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: 50,
+ uncommon: 35,
+ rare: 10,
+ epic: 4,
+ legendary: 1
+ },
+ gold: {
+ common: 30,
+ uncommon: 40,
+ rare: 20,
+ epic: 8,
+ legendary: 2
+ },
+ diamond: {
+ common: 10,
+ uncommon: 30,
+ rare: 35,
+ epic: 20,
+ legendary: 5
+ },
+ legendary: {
+ common: 0,
+ uncommon: 20,
+ rare: 40,
+ epic: 30,
+ legendary: 10
+ }
+ };
+ 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 random = Math.random() * 100;
+ var cumulative = 0;
+ for (var rarity in weights) {
+ cumulative += weights[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();
+ tween(self, {
+ scaleX: 1.2,
+ scaleY: 1.2
+ }, {
+ duration: 200,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ tween(self, {
+ scaleX: 0,
+ scaleY: 0
+ }, {
+ duration: 300,
+ easing: tween.easeIn
+ });
+ }
+ });
+ return {
+ rarity: rarity,
+ value: value
+ };
+ };
+ 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 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: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x1a1a1a
+});
+
+/****
+* Game Code
+****/
+var coins = storage.coins || 100;
+var collection = storage.collection || {};
+var unlockedBoxes = storage.unlockedBoxes || ['basic'];
+var currentBoxIndex = 0;
+var boxes = [];
+var boxConfigs = [{
+ type: 'basic',
+ cost: 0
+}, {
+ type: 'silver',
+ cost: 100
+}, {
+ type: 'gold',
+ cost: 500
+}, {
+ type: 'diamond',
+ cost: 2000
+}, {
+ type: 'legendary',
+ cost: 10000
+}];
+var coinsText = new Text2('Coins: ' + coins, {
+ size: 80,
+ fill: 0xFFD700
+});
+coinsText.anchor.set(0.5, 0);
+LK.gui.top.addChild(coinsText);
+var collectionText = new Text2('Collection: ' + Object.keys(collection).length, {
+ size: 60,
+ fill: 0xFFFFFF
+});
+collectionText.anchor.set(1, 0);
+collectionText.x = -20;
+LK.gui.topRight.addChild(collectionText);
+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();
+}
+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 () {
+ openButton.down();
+};
+openButton.up = function () {
+ openButton.up();
+ 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();
+};
+createNewBox();
+LK.playMusic('bgmusic');
\ No newline at end of file
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