User prompt
refresh the shop price to N.A. after an item is bought
User prompt
if the max for an item has been reached change the price to N.A.
User prompt
add a max of 1 to each items
User prompt
add a maximum amount that an item can be bought, add it for each individual item
User prompt
where has the shop icon gone, add it back
User prompt
Fix Bug: 'Uncaught TypeError: Cannot set properties of undefined (setting 'maxPurchases')' in or related to this line: 'self.maxPurchases = maxPurchases;' Line Number: 70
User prompt
add a maximum amount that an item can be bought, add it for each individual item
User prompt
add a maximum amount that an item can be bought
User prompt
make the flashes milder
User prompt
if the mouse is clicked anywhere else than the shop background or icon put the shop away
User prompt
on the bottom side of the screen display what items are activated
User prompt
add a function for how to earn coins, in this case it should be a button that adds 50 coins
User prompt
subtract the cost of the item with the total coins
User prompt
if the player clicks on an item, check if he can afford that item. if not flash the screen red. if it can afford it then flash the screen green and execute the funtion the belongs to that item
User prompt
display the amount of coins in the top middle
User prompt
add objects for each seperate item and display them in the shop
User prompt
make an object for each seperate item in the code
User prompt
fix the color not changing like stated above
User prompt
when the shop window gets opened check the current coins and change the color of the text accordingly
User prompt
add a score on the top middle that displays the amount of coins you have
User prompt
if the item is unaffordable make the text red, if it is affordable make it white
User prompt
replace the current objects that display the affortability by text boxes that indicate the price and change color if it is affortable
User prompt
Fix Bug: 'Uncaught ReferenceError: ShopItem is not defined' in or related to this line: 'var Item1 = ShopItem.expand(function (price) {' Line Number: 12
User prompt
make each item have their own object
User prompt
make the items display in rows of 3
/**** * Classes ****/ var CoinButton = Container.expand(function () { var self = Container.call(this); self.buttonGraphic = self.attachAsset('coinButton', { anchorX: 0.5, anchorY: 0.5 }); self.on('down', function () { playerCoins += 50; // Add 50 coins to the player's total LK.effects.flashScreen(0x00ff00, 300); }); }); var ShopItem = Container.expand(function (id, price, maxPurchase) { var self = Container.call(this); self.id = id; self.price = price; self.maxPurchase = maxPurchase; self.purchaseCount = 0; self.itemGraphic = self.attachAsset(id, { anchorX: 0.5, anchorY: 0.5 }); self.priceText = new Text2(self.price.toString(), { size: 50, fill: '#ffffff' }); self.addChild(self.itemGraphic); self.addChild(self.priceText); self.updateAffordability = function (playerCoins) { if (self.purchaseCount >= self.maxPurchase) { self.priceText.setText('N.A.'); self.priceText.fill = '#ff0000'; } else if (playerCoins >= self.price) { self.priceText.setText(self.price.toString()); self.priceText.fill = '#1eff00'; } else { self.priceText.setText(self.price.toString()); self.priceText.fill = '#ff0000'; } }; self.itemFunction = function () { // Add the item to the activated items display activatedItems.push(self.id); activatedItemDisplay.updateItems(activatedItems); }; self.on('down', function () { if (playerCoins >= self.price && self.purchaseCount < self.maxPurchase) { playerCoins -= self.price; // Subtract item cost from player's coins self.purchaseCount++; LK.effects.flashScreen(0x00ff00, 300); // Execute the function that belongs to this item // This is a placeholder for the actual function self.itemFunction(); // Update the price text to N.A. if the item has been bought if (self.purchaseCount >= self.maxPurchase) { self.priceText.setText('N.A.'); } } else { LK.effects.flashScreen(0xff0000, 300); } }); }); var Item1 = ShopItem.expand(function () { var self = ShopItem.call(this, 'item1', 100, 1); }); var Item2 = ShopItem.expand(function () { var self = ShopItem.call(this, 'item2', 200, 1); }); var Item3 = ShopItem.expand(function () { var self = ShopItem.call(this, 'item3', 300, 1); }); var Item4 = ShopItem.expand(function () { var self = ShopItem.call(this, 'item4', 400, 1); }); var Item5 = ShopItem.expand(function () { var self = ShopItem.call(this, 'item5', 500, 1); }); var Item6 = ShopItem.expand(function () { var self = ShopItem.call(this, 'item6', 600, 1); }); var Item7 = ShopItem.expand(function () { var self = ShopItem.call(this, 'item7', 700, 1); }); var Item8 = ShopItem.expand(function () { var self = ShopItem.call(this, 'item8', 800, 1); }); var ShopMenu = Container.expand(function () { var self = Container.call(this); self.visible = false; self.items = []; self.background = self.attachAsset('shopBackground', { anchorX: 0.5, anchorY: 0.5 }); self.toggleVisibility = function () { self.visible = !self.visible; self.background.visible = self.visible; // Show/hide background with the menu }; self.addItem = function (item) { self.items.push(item); self.addChild(item); }; self.updateItemsAffordability = function (playerCoins) { self.items.forEach(function (item) { item.updateAffordability(playerCoins); }); }; }); var ActivatedItemDisplay = Container.expand(function () { var self = Container.call(this); self.items = []; self.updateItems = function (activatedItems) { // Remove all current item graphics self.items.forEach(function (item) { item.destroy(); }); self.items = []; // Add new activated item graphics activatedItems.forEach(function (itemId, index) { var itemGraphic = self.attachAsset(itemId, { anchorX: 0.5, anchorY: 0.5, x: index * 150 + 75, // Position items with a fixed offset y: 50 // Position items at a fixed height from the bottom }); self.items.push(itemGraphic); }); }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ var activatedItemDisplay = game.addChild(new ActivatedItemDisplay()); activatedItemDisplay.y = 2732 - 100; // Position at the bottom of the screen var activatedItems = []; // Array to keep track of activated items var shopButton = game.addChild(LK.getAsset('shopIcon', { anchorX: 1, anchorY: 0, x: 2048, y: 0 })); var shopMenu = game.addChild(new ShopMenu()); shopMenu.x = 1024; // Center of the screen shopMenu.y = 1366; // Middle of the screen // Sample items for the shop shopMenu.addItem(new Item1(100)); shopMenu.addItem(new Item2(200)); shopMenu.addItem(new Item3(300)); shopMenu.addItem(new Item4(400)); shopMenu.addItem(new Item5(500)); shopMenu.addItem(new Item6(600)); shopMenu.addItem(new Item7(700)); shopMenu.addItem(new Item8(800)); // Position shop items in rows of 3 var itemOffsetX = 200; var itemOffsetY = 200; var itemsPerRow = 3; shopMenu.items.forEach(function (item, index) { item.x = index % itemsPerRow * itemOffsetX - (itemsPerRow - 1) * itemOffsetX / 2; item.y = Math.floor(index / itemsPerRow) * itemOffsetY - (shopMenu.items.length / itemsPerRow - 1) * itemOffsetY / 2; }); var coinButton = game.addChild(new CoinButton()); coinButton.x = 1024; // Center of the screen horizontally coinButton.y = 2732 - 150; // Near the bottom of the screen // Player's coins var playerCoins = 150; // Example starting coins // Display player's coins var coinDisplay = new Text2(playerCoins.toString(), { size: 100, fill: '#ffffff' }); LK.gui.top.addChild(coinDisplay); // Shop button event listener shopButton.on('down', function () { shopMenu.toggleVisibility(); shopMenu.updateItemsAffordability(playerCoins); }); // Main game loop LK.on('tick', function () { // Game logic goes here // For example, earning coins or spending them in the shop // This is just a placeholder for the actual game logic // Update coin display coinDisplay.setText(playerCoins.toString()); }); // Hide the shop menu initially shopMenu.visible = false; // Update the shop menu's visibility based on the shop button game.on('tick', function () { shopMenu.visible = shopMenu.visible; });
===================================================================
--- original.js
+++ change.js
@@ -52,8 +52,12 @@
LK.effects.flashScreen(0x00ff00, 300);
// Execute the function that belongs to this item
// This is a placeholder for the actual function
self.itemFunction();
+ // Update the price text to N.A. if the item has been bought
+ if (self.purchaseCount >= self.maxPurchase) {
+ self.priceText.setText('N.A.');
+ }
} else {
LK.effects.flashScreen(0xff0000, 300);
}
});