User prompt
make a button for the upgrades visible
User prompt
make the upgrades in the top right
User prompt
show the upgrades
User prompt
set money to zero when the game starts
User prompt
add upgrades and when you buy the upgrades they get more expensive and when you buy the upgrades you loose money
User prompt
make the clicking thing in the middle and a bit bigger
User prompt
add something to click on
Code edit (1 edits merged)
Please save this source code
User prompt
Tap Empire: Business Tycoon
User prompt
Please continue polishing my design document.
Initial prompt
make a clicker game
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1", { money: 0, lastSaveTime: "undefined", businesses: [{ id: "lemonade_stand", name: "Lemonade Stand", level: 1, basePrice: 4, baseIncome: 1, owned: 1, manager: false, managerPrice: 1000, upgradeLevel: 1, upgradePrice: 50, lastCollectTime: 0 }, { id: "restaurant", name: "Restaurant", level: 1, basePrice: 60, baseIncome: 20, owned: 0, manager: false, managerPrice: 15000, upgradeLevel: 1, upgradePrice: 500, lastCollectTime: 0 }, { id: "tech_startup", name: "Tech Startup", level: 1, basePrice: 720, baseIncome: 90, owned: 0, manager: false, managerPrice: 100000, upgradeLevel: 1, upgradePrice: 4000, lastCollectTime: 0 }, { id: "real_estate", name: "Real Estate", level: 1, basePrice: 8640, baseIncome: 360, owned: 0, manager: false, managerPrice: 1200000, upgradeLevel: 1, upgradePrice: 20000, lastCollectTime: 0 }] }); /**** * Classes ****/ var Business = Container.expand(function (data) { var self = Container.call(this); self.data = data; var businessGraphics = self.attachAsset(data.id, { anchorX: 0.5, anchorY: 0.5 }); self.progress = 0; self.collectionTime = 3000; // 3 seconds for collection cycle // Business info display self.infoText = new Text2('', { size: 40, fill: 0xFFFFFF }); self.infoText.anchor.set(0.5, 0); self.infoText.y = 100; self.addChild(self.infoText); // Progress bar background self.progressBg = self.attachAsset('upgrade_btn', { anchorX: 0.5, anchorY: 0.5, width: 200, height: 20, y: -100, tint: 0x555555 }); // Progress bar fill self.progressFill = self.attachAsset('upgrade_btn', { anchorX: 0, anchorY: 0.5, width: 0, height: 16, x: -98, y: -100, tint: 0x00FF00 }); // Buy button self.buyBtn = self.attachAsset('upgrade_btn', { anchorX: 0.5, anchorY: 0.5, y: 150 }); self.buyText = new Text2('Buy', { size: 36, fill: 0xFFFFFF }); self.buyText.anchor.set(0.5, 0.5); self.buyBtn.addChild(self.buyText); // Interaction handlers self.buyBtn.interactive = true; self.buyBtn.down = function () { self.buyBusiness(); }; businessGraphics.interactive = true; businessGraphics.down = function () { self.collectIncome(); }; self.updateUI = function () { if (self.data.owned > 0) { var income = self.calculateIncome(); self.infoText.setText(self.data.name + "\nLvl " + self.data.level + "\nIncome: $" + formatMoney(income)); } else { self.infoText.setText(self.data.name + "\nCosts: $" + formatMoney(self.calculatePrice())); } self.buyText.setText(self.data.owned > 0 ? "Upgrade ($" + formatMoney(self.data.upgradePrice) + ")" : "Buy ($" + formatMoney(self.calculatePrice()) + ")"); }; self.calculatePrice = function () { return Math.floor(self.data.basePrice * Math.pow(1.15, self.data.level - 1)); }; self.calculateIncome = function () { return self.data.baseIncome * self.data.level * self.data.upgradeLevel * self.data.owned; }; self.buyBusiness = function () { var price = self.calculatePrice(); if (money >= price) { money -= price; self.data.upgradePrice = Math.floor(self.data.upgradePrice * 1.15); // Increase upgrade price LK.getSound('purchase').play(); if (self.data.owned === 0) { self.data.owned = 1; // Tween to show the business is now active tween(businessGraphics, { alpha: 1 }, { duration: 500 }); } else { self.data.level++; // Scale effect on level up tween(businessGraphics, { scaleX: 1.2, scaleY: 1.2 }, { duration: 300, onFinish: function onFinish() { tween(businessGraphics, { scaleX: 1, scaleY: 1 }, { duration: 300 }); } }); LK.getSound('level_up').play(); } updateMoneyDisplay(); self.updateUI(); saveGame(); } }; self.collectIncome = function () { if (self.data.owned > 0 && self.progress >= 1) { var income = self.calculateIncome(); money += income; // Reset progress self.progress = 0; self.progressFill.width = 0; self.data.lastCollectTime = Date.now(); // Show coin animation spawnCoinEffect(self.x, self.y, income); updateMoneyDisplay(); saveGame(); } }; self.update = function () { if (self.data.owned > 0) { // Only update if not managed or if managed and progress not complete if (!self.data.manager || self.data.manager && self.progress < 1) { // Calculate progress based on time var currentTime = Date.now(); var elapsedTime = currentTime - self.data.lastCollectTime; if (self.data.lastCollectTime > 0) { self.progress = Math.min(1, elapsedTime / self.collectionTime); self.progressFill.width = self.progress * 196; // 196 is the max width } // Auto-collect if manager is hired and progress is complete if (self.data.manager && self.progress >= 1) { self.collectIncome(); } } } // Hide progress bar if business not owned self.progressBg.visible = self.data.owned > 0; self.progressFill.visible = self.data.owned > 0; // Update buy button based on affordability if (money >= self.calculatePrice()) { self.buyBtn.tint = 0x4CAF50; // Green } else { self.buyBtn.tint = 0x888888; // Gray } }; // Initial setup if (self.data.owned === 0) { businessGraphics.alpha = 0.5; // Dim if not owned } self.updateUI(); return self; }); var ClickableButton = Container.expand(function () { var self = Container.call(this); var buttonGraphics = self.attachAsset('upgrade_btn', { anchorX: 0.5, anchorY: 0.5 }); var buttonText = new Text2('Collect', { size: 36, fill: 0xFFFFFF }); buttonText.anchor.set(0.5, 0.5); self.addChild(buttonText); buttonGraphics.interactive = true; buttonGraphics.down = function () { money += 10; // Add 10 to money on click updateMoneyDisplay(); LK.getSound('coin_collect').play(); }; return self; }); var Coin = Container.expand(function (value) { var self = Container.call(this); var coinGraphics = self.attachAsset('coin', { anchorX: 0.5, anchorY: 0.5 }); var valueText = new Text2("$" + formatMoney(value), { size: 30, fill: 0xFFFFFF }); valueText.anchor.set(0.5, 0.5); valueText.y = -30; self.addChild(valueText); self.update = function () { self.y -= 3; self.alpha -= 0.02; if (self.alpha <= 0) { self.destroy(); } }; return self; }); var ManagerButton = Container.expand(function (business) { var self = Container.call(this); self.business = business; var btnGraphics = self.attachAsset('manager_btn', { anchorX: 0.5, anchorY: 0.5 }); var nameText = new Text2(business.data.name + " Manager", { size: 36, fill: 0xFFFFFF }); nameText.anchor.set(0.5, 0.5); nameText.y = -20; self.addChild(nameText); var priceText = new Text2("$" + formatMoney(business.data.managerPrice), { size: 32, fill: 0xFFFFFF }); priceText.anchor.set(0.5, 0.5); priceText.y = 20; self.addChild(priceText); self.update = function () { self.visible = !business.data.manager && business.data.owned > 0; if (self.visible) { if (money >= business.data.managerPrice) { btnGraphics.tint = 0x2196F3; // Blue } else { btnGraphics.tint = 0x888888; // Gray } } }; btnGraphics.interactive = true; btnGraphics.down = function () { if (money >= business.data.managerPrice && !business.data.manager) { money -= business.data.managerPrice; business.data.manager = true; LK.getSound('purchase').play(); updateMoneyDisplay(); saveGame(); } }; return self; }); var UpgradeButton = Container.expand(function (business) { var self = Container.call(this); self.business = business; var btnGraphics = self.attachAsset('upgrade_btn', { anchorX: 0.5, anchorY: 0.5 }); var nameText = new Text2("Upgrade", { size: 36, fill: 0xFFFFFF }); nameText.anchor.set(0.5, 0.5); nameText.y = -20; self.addChild(nameText); var priceText = new Text2("$" + formatMoney(business.data.upgradePrice), { size: 32, fill: 0xFFFFFF }); priceText.anchor.set(0.5, 0.5); priceText.y = 20; self.addChild(priceText); self.update = function () { self.visible = business.data.owned > 0; if (self.visible) { if (money >= business.data.upgradePrice) { btnGraphics.tint = 0x4CAF50; // Green } else { btnGraphics.tint = 0x888888; // Gray } } }; btnGraphics.interactive = true; btnGraphics.down = function () { if (money >= business.data.upgradePrice) { money -= business.data.upgradePrice; business.data.upgradeLevel++; business.data.upgradePrice = Math.floor(business.data.upgradePrice * 1.15); // Increase upgrade price LK.getSound('purchase').play(); updateMoneyDisplay(); saveGame(); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x2C3E50 }); /**** * Game Code ****/ var clickableButton = new ClickableButton(); clickableButton.x = 2048 / 2; clickableButton.y = 2732 / 2; // Center the button vertically clickableButton.scaleX = 1.5; // Enlarge the button clickableButton.scaleY = 1.5; game.addChild(clickableButton); var money = 0; var businesses = []; var managerButtons = []; var coins = []; var lastSaveTime = storage.lastSaveTime || Date.now(); // Money display var moneyText = new Text2("$" + formatMoney(money), { size: 80, fill: 0xFFFFFF }); moneyText.anchor.set(0.5, 0); LK.gui.top.addChild(moneyText); // Create businesses for (var i = 0; i < storage.businesses.length; i++) { var businessData = storage.businesses[i]; var business = new Business(businessData); // Position each business in a column business.x = 2048 / 2; business.y = 450 + i * 450; game.addChild(business); businesses.push(business); // Create manager button var managerBtn = new ManagerButton(business); managerBtn.x = 1650; managerBtn.y = 450 + i * 450; game.addChild(managerBtn); managerButtons.push(managerBtn); // Create upgrade button var upgradeBtn = new UpgradeButton(business); upgradeBtn.x = 2048 - 150; // Position near the right edge upgradeBtn.y = 50 + i * 100; // Position in the top right, spaced vertically game.addChild(upgradeBtn); // Initialize last collect time if needed if (businessData.owned > 0 && businessData.lastCollectTime === 0) { businessData.lastCollectTime = Date.now(); } } // Calculate offline earnings function calculateOfflineEarnings() { var offlineTime = Date.now() - lastSaveTime; var totalEarnings = 0; for (var i = 0; i < storage.businesses.length; i++) { var business = storage.businesses[i]; if (business.owned > 0 && business.manager) { // Calculate cycles completed during offline time var cycleTime = 3000; // Same as in Business class var cycles = Math.floor(offlineTime / cycleTime); var income = business.baseIncome * business.level * business.upgradeLevel * business.owned; totalEarnings += cycles * income; } } return totalEarnings; } // Apply offline earnings function applyOfflineEarnings() { var earnings = calculateOfflineEarnings(); if (earnings > 0) { money += earnings; updateMoneyDisplay(); // Show popup for offline earnings var earningsText = new Text2("Welcome Back!\nYou earned $" + formatMoney(earnings) + " while away", { size: 60, fill: 0xFFFFFF }); earningsText.anchor.set(0.5, 0.5); earningsText.x = 2048 / 2; earningsText.y = 2732 / 2; game.addChild(earningsText); // Fade out after a few seconds LK.setTimeout(function () { tween(earningsText, { alpha: 0 }, { duration: 1000, onFinish: function onFinish() { earningsText.destroy(); } }); }, 3000); } } // Format money with abbreviations for large numbers function formatMoney(amount) { if (amount >= 1e12) { return (amount / 1e12).toFixed(1) + "T"; } if (amount >= 1e9) { return (amount / 1e9).toFixed(1) + "B"; } if (amount >= 1e6) { return (amount / 1e6).toFixed(1) + "M"; } if (amount >= 1e3) { return (amount / 1e3).toFixed(1) + "K"; } return Math.floor(amount); } // Update money display function updateMoneyDisplay() { moneyText.setText("$" + formatMoney(money)); } // Spawn coin collection effect function spawnCoinEffect(x, y, value) { var coin = new Coin(value); coin.x = x; coin.y = y; game.addChild(coin); coins.push(coin); LK.getSound('coin_collect').play(); } // Save game state function saveGame() { storage.money = money; storage.lastSaveTime = Date.now(); storage.businesses = []; for (var i = 0; i < businesses.length; i++) { storage.businesses.push(businesses[i].data); } } // Auto-save timer var saveTimer = LK.setInterval(function () { saveGame(); }, 30000); // Save every 30 seconds // Apply offline earnings on game start applyOfflineEarnings(); // Start background music LK.playMusic('bgmusic', { loop: true, fade: { start: 0, end: 0.3, duration: 1000 } }); // Main update loop game.update = function () { // Update all businesses for (var i = 0; i < businesses.length; i++) { businesses[i].update(); } // Update manager buttons for (var i = 0; i < managerButtons.length; i++) { managerButtons[i].update(); } // Update coins for (var i = coins.length - 1; i >= 0; i--) { coins[i].update(); if (coins[i].alpha <= 0) { coins.splice(i, 1); } } };
===================================================================
--- original.js
+++ change.js
@@ -301,8 +301,52 @@
}
};
return self;
});
+var UpgradeButton = Container.expand(function (business) {
+ var self = Container.call(this);
+ self.business = business;
+ var btnGraphics = self.attachAsset('upgrade_btn', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var nameText = new Text2("Upgrade", {
+ size: 36,
+ fill: 0xFFFFFF
+ });
+ nameText.anchor.set(0.5, 0.5);
+ nameText.y = -20;
+ self.addChild(nameText);
+ var priceText = new Text2("$" + formatMoney(business.data.upgradePrice), {
+ size: 32,
+ fill: 0xFFFFFF
+ });
+ priceText.anchor.set(0.5, 0.5);
+ priceText.y = 20;
+ self.addChild(priceText);
+ self.update = function () {
+ self.visible = business.data.owned > 0;
+ if (self.visible) {
+ if (money >= business.data.upgradePrice) {
+ btnGraphics.tint = 0x4CAF50; // Green
+ } else {
+ btnGraphics.tint = 0x888888; // Gray
+ }
+ }
+ };
+ btnGraphics.interactive = true;
+ btnGraphics.down = function () {
+ if (money >= business.data.upgradePrice) {
+ money -= business.data.upgradePrice;
+ business.data.upgradeLevel++;
+ business.data.upgradePrice = Math.floor(business.data.upgradePrice * 1.15); // Increase upgrade price
+ LK.getSound('purchase').play();
+ updateMoneyDisplay();
+ saveGame();
+ }
+ };
+ return self;
+});
/****
* Initialize Game
****/