/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var BuySlotButton = Container.expand(function () { var self = Container.call(this); self.buttonGraphics = self.attachAsset('buySlotButton', { anchorX: 0.5, anchorY: 0.5 }); self.buttonText = new Text2('Buy Slot\n$500', { size: 24, fill: 0xFFFFFF }); self.buttonText.anchor.set(0.5, 0.5); self.addChild(self.buttonText); self.updatePrice = function () { var price = 500 * Math.pow(2, slotsOwned - 20); self.buttonText.setText('Buy Slot\n$' + Math.floor(price)); if (money >= price) { self.alpha = 1.0; } else { self.alpha = 0.6; } }; self.down = function (x, y, obj) { var price = 500 * Math.pow(2, slotsOwned - 20); if (money >= price) { money -= price; slotsOwned++; // Add new slot to the grid var row = Math.floor((slotsOwned - 1) / 5); var col = (slotsOwned - 1) % 5; var slotX = 300 + col * 160; var slotY = 400 + row * 120; var newSlot = new GunSlot(slotX, slotY); gunSlots.push(newSlot); game.addChild(newSlot); LK.getSound('buySlot').play(); self.updatePrice(); // Animation for new slot tween(newSlot, { scaleX: 1.3, scaleY: 1.3 }, { duration: 300, onFinish: function onFinish() { tween(newSlot, { scaleX: 1.0, scaleY: 1.0 }, { duration: 200 }); } }); } }; return self; }); var Gun = Container.expand(function (tier) { var self = Container.call(this); self.tier = tier || 1; self.income = self.tier * 10; self.value = self.tier * 100; self.lastIncomeTime = Date.now(); var gunAssetId = 'gun' + Math.min(self.tier, 34); self.gunGraphics = self.attachAsset(gunAssetId, { anchorX: 0.5, anchorY: 0.5 }); self.tierText = new Text2(self.tier.toString(), { size: 24, fill: 0xFFFFFF }); self.tierText.anchor.set(0.5, 0.5); self.tierText.x = 0; self.tierText.y = -50; self.addChild(self.tierText); self.isDragging = false; self.startDragPos = { x: 0, y: 0 }; self.originalSlot = null; self.generateIncome = function () { var now = Date.now(); if (now - self.lastIncomeTime >= 2000) { money += self.income; self.lastIncomeTime = now; LK.getSound('earnMoney').play(); var incomeText = new Text2('+$' + self.income, { size: 20, fill: 0x00FF00 }); incomeText.anchor.set(0.5, 0.5); incomeText.x = self.x; incomeText.y = self.y - 60; game.addChild(incomeText); tween(incomeText, { y: incomeText.y - 50, alpha: 0 }, { duration: 1500, onFinish: function onFinish() { incomeText.destroy(); } }); } }; self.update = function () { self.generateIncome(); }; self.down = function (x, y, obj) { self.isDragging = true; self.startDragPos = { x: x, y: y }; self.alpha = 0.7; draggedGun = self; if (self.originalSlot) { self.originalSlot.occupiedBy = null; self.originalSlot = null; } }; return self; }); var GunSlot = Container.expand(function (slotX, slotY) { var self = Container.call(this); self.x = slotX; self.y = slotY; self.occupiedBy = null; self.slotGraphics = self.attachAsset('gunSlot', { anchorX: 0.5, anchorY: 0.5, alpha: 0.3 }); self.canAcceptGun = function (gun) { return self.occupiedBy === null; }; self.placeGun = function (gun) { if (self.canAcceptGun(gun)) { self.occupiedBy = gun; gun.originalSlot = self; gun.x = self.x; gun.y = self.y; gun.alpha = 1.0; return true; } return false; }; self.checkForMerge = function (newGun) { if (self.occupiedBy && self.occupiedBy.tier === newGun.tier) { var oldGun = self.occupiedBy; self.occupiedBy = null; var mergedTier = oldGun.tier + 1; var mergedGun = new Gun(mergedTier); oldGun.destroy(); newGun.destroy(); self.placeGun(mergedGun); game.addChild(mergedGun); var mergeEffect = LK.getAsset('mergeEffect', { anchorX: 0.5, anchorY: 0.5, alpha: 0.8 }); mergeEffect.x = self.x; mergeEffect.y = self.y; game.addChild(mergeEffect); tween(mergeEffect, { scaleX: 1.5, scaleY: 1.5, alpha: 0 }, { duration: 800, onFinish: function onFinish() { mergeEffect.destroy(); } }); LK.getSound('mergeGun').play(); return true; } return false; }; return self; }); var ShopButton = Container.expand(function () { var self = Container.call(this); self.buttonGraphics = self.attachAsset('shopButton', { anchorX: 0.5, anchorY: 0.5 }); self.buttonText = new Text2('Buy Gun\n$100', { size: 28, fill: 0xFFFFFF }); self.buttonText.anchor.set(0.5, 0.5); self.addChild(self.buttonText); self.updatePrice = function () { var price = 100 * Math.pow(1.5, gunsOwned); self.buttonText.setText('Buy Gun\n$' + Math.floor(price)); if (money >= price) { self.alpha = 1.0; } else { self.alpha = 0.6; } }; self.down = function (x, y, obj) { var price = 100 * Math.pow(1.5, gunsOwned); if (money >= price) { money -= price; gunsOwned++; var newGun = new Gun(1); var placed = false; for (var i = 0; i < gunSlots.length; i++) { if (gunSlots[i].placeGun(newGun)) { game.addChild(newGun); placed = true; break; } } if (placed) { LK.getSound('buyGun').play(); self.updatePrice(); tween(newGun, { scaleX: 1.2, scaleY: 1.2 }, { duration: 300, onFinish: function onFinish() { tween(newGun, { scaleX: 1.0, scaleY: 1.0 }, { duration: 200 }); } }); } else { money += price; gunsOwned--; newGun.destroy(); } } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x1a1a2e }); /**** * Game Code ****/ var money = storage.money || 500; var gunsOwned = storage.gunsOwned || 0; var slotsOwned = storage.slotsOwned || 20; var gunSlots = []; var draggedGun = null; var moneyText = new Text2('$' + money, { size: 60, fill: 0xFFD700 }); moneyText.anchor.set(0.5, 0); LK.gui.top.addChild(moneyText); var titleText = new Text2('Gun Merger Tycoon', { size: 48, fill: 0xFFFFFF }); titleText.anchor.set(0.5, 0); titleText.x = 2048 / 2; titleText.y = 100; game.addChild(titleText); for (var row = 0; row < 4; row++) { for (var col = 0; col < 5; col++) { var slotX = 300 + col * 160; var slotY = 400 + row * 120; var slot = new GunSlot(slotX, slotY); gunSlots.push(slot); game.addChild(slot); } } var shopButton = new ShopButton(); shopButton.x = 2048 / 2 - 120; shopButton.y = 900; game.addChild(shopButton); var buySlotButton = new BuySlotButton(); buySlotButton.x = 2048 / 2 + 120; buySlotButton.y = 900; game.addChild(buySlotButton); if (gunsOwned === 0) { for (var i = 0; i < 3; i++) { var starterGun = new Gun(1); if (gunSlots[i].placeGun(starterGun)) { game.addChild(starterGun); gunsOwned++; } } } game.move = function (x, y, obj) { if (draggedGun) { draggedGun.x = x; draggedGun.y = y; } }; game.up = function (x, y, obj) { if (draggedGun) { var gun = draggedGun; var placed = false; for (var i = 0; i < gunSlots.length; i++) { var slot = gunSlots[i]; var distance = Math.sqrt(Math.pow(gun.x - slot.x, 2) + Math.pow(gun.y - slot.y, 2)); if (distance < 80) { if (slot.checkForMerge(gun)) { placed = true; break; } else if (slot.placeGun(gun)) { placed = true; break; } } } if (!placed && gun.originalSlot && gun.originalSlot.canAcceptGun(gun)) { gun.originalSlot.placeGun(gun); placed = true; } if (!placed) { var nearestSlot = null; var nearestDistance = Infinity; for (var i = 0; i < gunSlots.length; i++) { if (gunSlots[i].canAcceptGun(gun)) { var distance = Math.sqrt(Math.pow(gun.x - gunSlots[i].x, 2) + Math.pow(gun.y - gunSlots[i].y, 2)); if (distance < nearestDistance) { nearestDistance = distance; nearestSlot = gunSlots[i]; } } } if (nearestSlot) { nearestSlot.placeGun(gun); } } gun.alpha = 1.0; gun.isDragging = false; draggedGun = null; } }; game.update = function () { moneyText.setText('$' + Math.floor(money)); shopButton.updatePrice(); buySlotButton.updatePrice(); storage.money = money; storage.gunsOwned = gunsOwned; storage.slotsOwned = slotsOwned; if (LK.ticks % 120 === 0) { money += 5; } };
===================================================================
--- original.js
+++ change.js
@@ -67,9 +67,9 @@
self.tier = tier || 1;
self.income = self.tier * 10;
self.value = self.tier * 100;
self.lastIncomeTime = Date.now();
- var gunAssetId = 'gun' + Math.min(self.tier, 5);
+ var gunAssetId = 'gun' + Math.min(self.tier, 34);
self.gunGraphics = self.attachAsset(gunAssetId, {
anchorX: 0.5,
anchorY: 0.5
});