User prompt
Remove duplication and replace the first background2
User prompt
Add it to the game
User prompt
Add it to the game
User prompt
Add background2 with same size of background1
Code edit (17 edits merged)
Please save this source code
User prompt
Add wreckage 100x100 on all the background
User prompt
Name this page page1
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
Adjust background1 to align with the top of the screen
User prompt
Make the background1 up to the top of the screen
User prompt
Start hide the container slightly from the top or bottom of it when it reaches the top or bottom edges of the pagetab1.
User prompt
Start hide the container slightly in the top or bottom edges of the pagetab1 when i scroll it up or down.
User prompt
Make the container hides partially when i scroll it to the top or bottom edges of the pagetab1.
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'length')' in or related to this line: 'var duplicate = LK.getAsset(assetId, {' Line Number: 197
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'id')' in or related to this line: 'var assetId = slot.children[1].id; // Get the asset id of the item in the slot' Line Number: 194
User prompt
If i click any slot duplicate the asset woodhouse or tree in background1.
User prompt
Let the scrollbutton of container move vertically as the scrollbutton of container2
User prompt
Remove what's preventing the houses from duplicating to background1
User prompt
Hide the scroll bar and button of container when the game start
User prompt
Remove the dragge of background1
User prompt
If i click slot1 add woodhous1 to the middle of background1
User prompt
Fix the lines to be on the background1 image only and fix the size of the squares to be 100x100 some lines are not finished!
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'shape')' in or related to this line: 'var verticalLine = new LK.init.shape('line', {' Line Number: 118
User prompt
Add it than :)
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1", { lastScores: { silver: 0, stone: 0, gold: 0, bronze: 0, crystal: 0, wood: 0 } }); /**** * Classes ****/ var ContainerClass = Container.expand(function () { var self = Container.call(this); // Add assets to the container var containerAsset = self.attachAsset('Container', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 }); self.addChild(containerAsset); // Add functionality to the container self.update = function () { // Update logic for the container }; return self; }); var Page1 = Container.expand(function () { var self = Container.call(this); // Add map asset to Page1 below the pause button var background1 = self.attachAsset('background1', { anchorX: 0.5, anchorY: 0.0, x: 2048 / 2, y: 0, // Align with the top of the screen scaleX: 2000 / 2005, // Match width of background1 scaleY: 2420 / 2732 // Match height of background1 }); var wall1 = self.attachAsset('wall1', { anchorX: 0.5, anchorY: 1.0, x: 1024, // Center horizontally y: 2732 // Position at the bottom }); self.addChild(wall1); // Add Build asset to Page1 below the map var build = self.attachAsset('Build', { anchorX: 0.5, anchorY: 0.5, x: 110, // Position on the left side below the pause button y: 400 // Position directly below the pause button }); self.addChild(build); var buildText = new Text2('BUILD', { size: 80, fill: 0xFFA500 // Orange color }); buildText.anchor.set(0.5, 0); buildText.x = build.x; buildText.y = build.y + build.height / 2 + 2; // Position directly below and closer to the build asset self.addChild(buildText); // Add click event to build button to toggle visibility of pagetab2 and its components build.down = function (x, y, obj) { var anyPageVisible = pagetab1.visible || pagetab2.visible || container.visible || scrollbar.visible || scrollbutton.visible || scrollbar1.visible || scrollbutton1.visible; buttontab1.visible = !buttontab1.visible; buttontab2.visible = !buttontab2.visible; buttontab3.visible = !buttontab3.visible; buttontab1Text.visible = !buttontab1Text.visible; buttontab2Text.visible = !buttontab2Text.visible; buttontab3Text.visible = !buttontab3Text.visible; if (anyPageVisible) { pagetab1.visible = false; pagetab2.visible = false; container.visible = false; scrollbar.visible = false; scrollbutton.visible = false; container2.visible = false; scrollbar2.visible = false; scrollbutton2.visible = false; scrollbar1.visible = false; scrollbutton1.visible = false; } buildText.visible = true; }; // Add Buttontab1 asset beside the pause button from the right var buttontab1 = self.attachAsset('Buttontab1', { anchorX: 0.5, anchorY: 0.5, x: 450, // Position on the right side beside the pause button y: 100 }); self.addChild(buttontab1); var buttontab1Text = new Text2('House', { size: 70, fill: 0xFFFFFF // White color }); buttontab1Text.anchor.set(0.5, 0.5); buttontab1Text.x = buttontab1.x; buttontab1Text.y = buttontab1.y; self.addChild(buttontab1Text); // Add click event to buttontab1 to hide pagetab1 and its container with scrollbar-scrollbutton buttontab1.down = function (x, y, obj) { // Toggle visibility of pagetab1 and its components pagetab1.visible = !pagetab1.visible; container.visible = pagetab1.visible; scrollbar.visible = pagetab1.visible; scrollbutton.visible = pagetab1.visible; scrollbar1.visible = pagetab1.visible; scrollbutton1.visible = pagetab1.visible; // Add functionality to place houses from slots to background1 if (pagetab1.visible) { container.children.forEach(function (slot) { slot.down = function (x, y, obj) { if (slot.children[1]) { var assetId = slot.children[1].id; // Get the asset id of the item in the slot if (assetId) { var duplicate = LK.getAsset(assetId, { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 // Center in the middle of background1 }); background1.addChild(duplicate); // Add duplicate to background1 } } }; }); } }; // Add Buttontab2 asset beside Buttontab1 from the right var buttontab2 = self.attachAsset('Buttontab2', { anchorX: 0.5, anchorY: 0.5, x: buttontab1.x + buttontab1.width, y: 100 }); self.addChild(buttontab2); var buttontab2Text = new Text2('Tree', { size: 70, fill: 0xFFFFFF // White color }); buttontab2Text.anchor.set(0.5, 0.5); buttontab2Text.x = buttontab2.x; buttontab2Text.y = buttontab2.y; self.addChild(buttontab2Text); // Add click event to buttontab2 to toggle visibility of pagetab2 buttontab2.down = function (x, y, obj) { pagetab2.visible = !pagetab2.visible; container2.visible = pagetab2.visible; scrollbar2.visible = pagetab2.visible; scrollbutton2.visible = pagetab2.visible; // Add functionality to place trees from slots to background1 if (pagetab2.visible) { container2.children.forEach(function (slot) { slot.down = function (x, y, obj) { // Logic for placing trees removed }; }); } }; // Add Buttontab3 asset beside Buttontab2 from the right var buttontab3 = self.attachAsset('Buttontab3', { anchorX: 0.5, anchorY: 0.5, x: buttontab2.x + buttontab2.width, // Position Buttontab3 edge to edge with Buttontab2 y: 100 }); self.addChild(buttontab3); var buttontab3Text = new Text2('Resource', { size: 70, fill: 0xFFFFFF // White color }); buttontab3Text.anchor.set(0.5, 0.5); buttontab3Text.x = buttontab3.x; buttontab3Text.y = buttontab3.y; self.addChild(buttontab3Text); // Add resources and score similar to Page1 var wood = self.attachAsset('wood', { anchorX: 0.5, anchorY: 0.5, x: 1902, y: 2510 }); self.addChild(wood); var woodScoreText = new Text2('1000', { size: 70, fill: 0x471e00 }); woodScoreText.anchor.set(1, 0.5); woodScoreText.x = 1800; woodScoreText.y = 2510; self.addChild(woodScoreText); var silver = self.attachAsset('silver', { anchorX: 0.5, anchorY: 0.5, x: 1902, y: 2660 }); self.addChild(silver); var silverScoreText = new Text2('1000', { size: 70, fill: 0xc0c0c0 }); silverScoreText.anchor.set(1, 0.5); silverScoreText.x = silver.x - 90; silverScoreText.y = silver.y; self.addChild(silverScoreText); var stone = self.attachAsset('stone', { anchorX: 0.5, anchorY: 0.5, x: 1220, y: 2510 }); self.addChild(stone); var stoneScoreText = new Text2('1000', { size: 70, fill: 0x00ff00 }); stoneScoreText.anchor.set(1, 0.5); stoneScoreText.x = stone.x - 90; stoneScoreText.y = stone.y; self.addChild(stoneScoreText); var gold = self.attachAsset('gold', { anchorX: 0.5, anchorY: 0.5, x: 1220, y: 2660 }); self.addChild(gold); var goldScoreText = new Text2('1000', { size: 70, fill: 0xffd700 }); goldScoreText.anchor.set(1, 0.5); goldScoreText.x = gold.x - 90; goldScoreText.y = gold.y; self.addChild(goldScoreText); var bronze = self.attachAsset('bronze', { anchorX: 0.5, anchorY: 0.5, x: 595, y: 2510 }); self.addChild(bronze); var bronzeScoreText = new Text2('1000', { size: 70, fill: 0xcd7f32 }); bronzeScoreText.anchor.set(1, 0.5); bronzeScoreText.x = bronze.x - 90; bronzeScoreText.y = bronze.y; self.addChild(bronzeScoreText); var crystal = self.attachAsset('crystal', { anchorX: 0.5, anchorY: 0.5, x: 595, y: 2660 }); self.addChild(crystal); var crystalScoreText = new Text2('1000', { size: 70, fill: 0x00ffff }); crystalScoreText.anchor.set(1, 0.5); crystalScoreText.setText(1000); // Set crystalScoreText to '1000' initially crystalScoreText.x = crystal.x - 90; crystalScoreText.y = crystal.y; self.addChild(crystalScoreText); map.down = function (x, y, obj) { // Navigate to Page0 game.removeChild(page); page = game.addChild(new Page0()); }; }); var Pagetab1 = Container.expand(function () { var self = Container.call(this); var pagetab1Asset = self.attachAsset('Pagetab1', { anchorX: 0.5, anchorY: 0.5, x: 2250 / 2, y: 2550 / 2 }); self.addChild(pagetab1Asset); return self; }); var Tree = Container.expand(function (assetId, x, y) { var self = Container.call(this); var tree = self.attachAsset(assetId, { anchorX: -1.1, anchorY: 3, x: x, y: y }); tree.clickCount = 0; self.addChild(tree); self.getClickCount = function () { return tree.clickCount; }; self.incrementClickCount = function () { tree.clickCount += 1; }; self.hide = function () { tree.visible = false; }; return self; }); var WoodScoreText = Container.expand(function () { var self = Container.call(this); var woodScoreText = new Text2('0', { size: 70, fill: 0x471e00 }); woodScoreText.anchor.set(1, 0.5); self.addChild(woodScoreText); self.setText = function (text) { woodScoreText.setText(text); }; self.getText = function () { return woodScoreText.text; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ var scrollbar = LK.getAsset('Scrollbar', { anchorX: 0.5, anchorY: 0.5, x: 2000, y: 2550 / 2 }); scrollbar.visible = false; // Initially hidden game.addChild(scrollbar); var scrollbutton = LK.getAsset('Scrollbutton', { anchorX: 0.5, anchorY: 0.5, x: scrollbar.x, y: scrollbar.y }); scrollbutton.visible = false; // Initially hidden game.addChild(scrollbutton); scrollbutton.down = function (x, y, obj) { scrollbutton.dragging = true; scrollbutton.initialClick = { x: x, y: y }; scrollbutton.offset = { y: scrollbutton.y - y }; }; scrollbutton.up = function () { scrollbutton.dragging = false; }; scrollbutton.move = function (x, y, obj) { if (scrollbutton.dragging) { var dy = y - scrollbutton.initialClick.y; scrollbutton.y = y + scrollbutton.offset.y; if (scrollbutton.y < scrollbar.y - scrollbar.height / 2 + scrollbutton.height / 2) { scrollbutton.y = scrollbar.y - scrollbar.height / 2 + scrollbutton.height / 2; } else if (scrollbutton.y > scrollbar.y + scrollbar.height / 2 - scrollbutton.height / 2) { scrollbutton.y = scrollbar.y + scrollbar.height / 2 - scrollbutton.height / 2; } container.y -= dy; // Scroll the content inside Container scrollbutton2.y = scrollbutton.y; // Synchronize scrollbutton2 with scrollbutton // Ensure the container stays within the bounds of Pagetab1, but allow partial hiding if (container.y > pagetab1.y + pagetab1.height / 2 - container.height / 2 + 50) { container.y = pagetab1.y + pagetab1.height / 2 - container.height / 2 + 50; } else if (container.y < pagetab1.y - pagetab1.height / 2 + container.height / 2 - 50) { container.y = pagetab1.y - pagetab1.height / 2 + container.height / 2 - 50; } scrollbutton.initialClick = { x: x, y: y }; } }; var map = {}; // Initialize map variable as an empty object for global use var draggingItem = null; // Global variable to track the currently dragged item var lastScores = storage.lastScores || {}; var lastSilverScore = lastScores.silver || 0; var lastStoneScore = lastScores.stone || 0; var lastGoldScore = lastScores.gold || 0; var lastBronzeScore = lastScores.bronze || 0; var lastCrystalScore = lastScores.crystal || 0; var lastWoodScore = lastScores.wood || 0; var wood = { clickCount: 0 }; // Define wood object for global use wood.clickCount = lastWoodScore; var silver = { clickCount: 0 }; // Define silver object for global use silver.clickCount = lastSilverScore; var stone = { clickCount: 0 }; // Define stone object stone.clickCount = lastStoneScore; var gold = { clickCount: 0 }; // Define gold object gold.clickCount = lastGoldScore; var bronze = { clickCount: 0 }; // Define bronze object bronze.clickCount = lastBronzeScore; var crystal = { clickCount: 0 }; // Define crystal object crystal.clickCount = lastCrystalScore; function _slicedToArray2(r, e) { return _arrayWithHoles2(r) || _iterableToArrayLimit2(r, e) || _unsupportedIterableToArray2(r, e) || _nonIterableRest2(); } function _nonIterableRest2() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray2(r, a) { if (r) { if ("string" == typeof r) { return _arrayLikeToArray2(r, a); } var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray2(r, a) : void 0; } } function _arrayLikeToArray2(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) { n[e] = r[e]; } return n; } function _iterableToArrayLimit2(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) { return; } f = !1; } else { for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0) { ; } } } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) { return; } } finally { if (o) { throw n; } } } return a; } } function _arrayWithHoles2(r) { if (Array.isArray(r)) { return r; } } function saveStoneCooldowns() { var stoneCooldowns = []; for (var i = 1; i <= 10; i++) { var stone = window["stone" + i]; if (stone && stone.timetext && stone.timetext.visible) { stoneCooldowns.push({ id: i, cooldown: stone.timetext.getText() }); } } if (typeof localStorage !== 'undefined') { localStorage.setItem('stoneCooldowns', JSON.stringify(stoneCooldowns)); } } function restoreStoneCooldowns() { var storedStoneCooldowns = typeof localStorage !== 'undefined' ? localStorage.getItem('stoneCooldowns') : null; var stoneCooldowns = storedStoneCooldowns ? JSON.parse(storedStoneCooldowns) : []; stoneCooldowns.forEach(function (stoneData) { var stone = window["stone" + stoneData.id]; var _stoneData$cooldown$s = stoneData.cooldown.split(':').map(Number), _stoneData$cooldown$s2 = _slicedToArray2(_stoneData$cooldown$s, 2), minutes = _stoneData$cooldown$s2[0], seconds = _stoneData$cooldown$s2[1]; var totalSeconds = minutes * 60 + seconds; stone.clickCount = 3; stone.visible = false; stone.timetext.visible = true; stone.timetext.setText(stoneData.cooldown); var cooldown = totalSeconds; var interval = LK.setInterval(function () { cooldown--; var minutes = Math.floor(cooldown / 60); var seconds = cooldown % 60; stone.timetext.setText(minutes + ':' + (seconds < 10 ? '0' : '') + seconds); if (cooldown <= 0) { LK.clearInterval(interval); stone.clickCount = 0; stone.visible = true; stone.timetext.visible = false; } }, 1000); }); } function handleTreeClick(tree) { if (tree.clickCount < 3) { tree.clickCount++; if (tree.clickCount === 3) { tree.visible = false; // Use the visible property to hide the tree tree.timetext.visible = true; // Show timetext when tree is hidden var cooldown = 180; // 3 minutes in seconds var _interval = function interval() { if (cooldown > 0) { cooldown--; var minutes = Math.floor(cooldown / 60); var seconds = cooldown % 60; tree.timetext.setText(minutes + ':' + (seconds < 10 ? '0' : '') + seconds); LK.setTimeout(_interval, 1000); } else { tree.clickCount = 0; // Reset click count after 3 minutes tree.visible = true; // Make the tree visible again tree.timetext.visible = false; // Hide timetext when tree becomes visible } }; LK.setTimeout(_interval, 1000); } updateLastScores(); // Update last known scores for all resources var currentPage = page.constructor.name; if (!pageScores[currentPage]) { pageScores[currentPage] = { wood: { clickCount: 0 }, silver: { clickCount: 0 }, stone: { clickCount: 0 }, gold: { clickCount: 0 }, bronze: { clickCount: 0 }, crystal: { clickCount: 0 } }; } pageScores[currentPage].wood.clickCount = wood.clickCount; // Update score text for each resource woodScoreText.setText(wood.clickCount); silverScoreText.setText(silver.clickCount); stoneScoreText.setText(stone.clickCount); goldScoreText.setText(gold.clickCount); bronzeScoreText.setText(bronze.clickCount); crystalScoreText.setText(crystal.clickCount); // Log the click count for the tree console.log("Tree clicked ".concat(tree.clickCount, " times.")); } } var wood = { clickCount: 0 }; // Define wood object for global use var pageScores = { Page1: { wood: { clickCount: 0 }, silver: { clickCount: 0 }, stone: { clickCount: 0 }, gold: { clickCount: 0 }, bronze: { clickCount: 0 }, crystal: { clickCount: 0 } } }; // Initialize pageScores for each page var woodScoreText = new Text2('1000', { size: 70, fill: 0x471e00 }); woodScoreText.anchor.set(1, 0.5); woodScoreText.setText(1000); // Set woodScoreText to '1000' initially var silverScoreText = new Text2('1000', { size: 70, fill: 0xc0c0c0 }); silverScoreText.anchor.set(1, 0.5); silverScoreText.setText(1000); // Set silverScoreText to '1000' initially var stoneScoreText = new Text2('1000', { size: 70, fill: 0x00ff00 }); stoneScoreText.anchor.set(1, 0.5); stoneScoreText.setText(1000); // Set stoneScoreText to '1000' initially var goldScoreText = new Text2('1000', { size: 70, fill: 0xffd700 }); goldScoreText.anchor.set(1, 0.5); goldScoreText.setText(1000); // Set goldScoreText to '1000' initially var bronzeScoreText = new Text2('1000', { size: 70, fill: 0xcd7f32 }); bronzeScoreText.anchor.set(1, 0.5); bronzeScoreText.setText(1000); // Set bronzeScoreText to '1000' initially var crystalScoreText = new Text2('1000', { size: 70, fill: 0x00ffff }); crystalScoreText.anchor.set(1, 0.5); crystalScoreText.setText(1000); // Set crystalScoreText to '1000' initially // Initialize storage time if not already set if (!storage.time) { storage.time = new Date().getTime(); } // Calculate time elapsed since last visit var currentTime = new Date().getTime(); var timeElapsed = currentTime - storage.time; console.log('Time Elapsed:', timeElapsed); // Update storage time to current time storage.time = currentTime; // Function to update tree cooldowns based on time elapsed function updateTreeCooldowns(timeElapsed) { var secondsElapsed = Math.floor(timeElapsed / 1000); for (var i = 1; i <= 16; i++) { var tree = window["tree" + i]; if (tree && tree.timetext && tree.timetext.visible) { var _tree$timetext$getTe = tree.timetext.getText().split(':').map(Number), _tree$timetext$getTe2 = _slicedToArray(_tree$timetext$getTe, 2), minutes = _tree$timetext$getTe2[0], seconds = _tree$timetext$getTe2[1]; var totalSeconds = minutes * 60 + seconds; totalSeconds = Math.max(0, totalSeconds - secondsElapsed); minutes = Math.floor(totalSeconds / 60); seconds = totalSeconds % 60; tree.timetext.setText(minutes + ':' + (seconds < 10 ? '0' : '') + seconds); if (totalSeconds <= 0) { tree.clickCount = 0; tree.visible = true; tree.timetext.visible = false; } } } } // Update tree cooldowns based on time elapsed updateTreeCooldowns(timeElapsed); function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) { return _arrayLikeToArray(r, a); } var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) { n[e] = r[e]; } return n; } function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) { return; } f = !1; } else { for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0) { ; } } } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) { return; } } finally { if (o) { throw n; } } } return a; } } function _arrayWithHoles(r) { if (Array.isArray(r)) { return r; } } var pageScores = { Page1: { wood: { clickCount: 0 }, silver: { clickCount: 0 }, stone: { clickCount: 0 }, gold: { clickCount: 0 }, bronze: { clickCount: 0 }, crystal: { clickCount: 0 } } }; var stoneScoreText = new Text2('1000', { size: 70, fill: 0x00ff00 }); stoneScoreText.anchor.set(1, 0.5); var lastWoodScore = 0; // Initialize laststoneScore to store the last known stone score var silver = { clickCount: 0 }; // Define silver object var silverScoreText = new Text2('1000', { size: 70, fill: 0xc0c0c0 }); // Define silverScoreText in the global scope var lastSilverScore = 0; // Initialize lastSilverScore to store the last known silver score var stone = { clickCount: 0 }; // Define stone object var lastStoneScore = 0; // Initialize lastStoneScore to store the last known stone score var gold = { clickCount: 0 }; // Define gold object var goldScoreText = new Text2('1000', { size: 70, fill: 0xffd700 }); // Define goldScoreText in the global scope var lastGoldScore = 0; // Initialize lastGoldScore to store the last known gold score var bronze = { clickCount: 0 }; // Define bronze object var bronzeScoreText = new Text2('1000', { size: 70, fill: 0xcd7f32 }); // Define bronzeScoreText in the global scope var lastBronzeScore = 0; // Initialize lastBronzeScore to store the last known bronze score var crystal = { clickCount: 0 }; // Define crystal object var crystalScoreText = new Text2('1000', { size: 70, fill: 0x00ffff }); // Define crystalScoreText in the global scope var lastCrystalScore = 0; // Initialize lastCrystalScore to store the last known crystal score // Function to update last known scores function updateLastScores() { lastSilverScore = silver.clickCount; lastStoneScore = stone.clickCount; lastGoldScore = gold.clickCount; lastBronzeScore = bronze.clickCount; lastCrystalScore = crystal.clickCount; lastWoodScore = wood.clickCount; // Update woodScore } var page = game.addChild(new Page1()); //{0.b} var pagetab1 = LK.getAsset('Pagetab1', { anchorX: 0.5, anchorY: 0.5, x: 2250 / 2, y: 2550 / 2 }); pagetab1.visible = false; // Initially hidden game.addChild(pagetab1); var container = LK.getAsset('Container', { anchorX: 0.5, anchorY: 0.5, x: 2220 / 2, y: 2550 / 2 }); container.visible = false; // Initially hidden game.addChild(container); var scrollbar1 = LK.getAsset('Scrollbar', { anchorX: 0.5, anchorY: 0.5, x: 2000, y: 2550 / 2 }); scrollbar1.visible = false; // Initially hidden game.addChild(scrollbar1); var scrollbutton1 = LK.getAsset('Scrollbutton', { anchorX: 0.5, anchorY: 0.5, x: scrollbar1.x, y: scrollbar1.y }); scrollbutton1.visible = false; // Initially hidden game.addChild(scrollbutton1); var pagetab2 = LK.getAsset('Pagetab2', { anchorX: 0.5, anchorY: 0.5, x: 2250 / 2, y: 2550 / 2 }); pagetab2.visible = false; // Initially hidden game.addChild(pagetab2); var container2 = LK.getAsset('Container', { anchorX: 0.5, anchorY: 0.5, x: 2220 / 2, y: 2550 / 2 }); container2.visible = false; // Initially hidden game.addChild(container2); var scrollbar2 = LK.getAsset('Scrollbar', { anchorX: 0.5, anchorY: 0.5, x: 2000, y: 2550 / 2 }); scrollbar2.visible = false; // Initially hidden game.addChild(scrollbar2); var scrollbutton2 = LK.getAsset('Scrollbutton', { anchorX: 0.5, anchorY: 0.5, x: scrollbar2.x, y: scrollbar2.y }); scrollbutton2.visible = false; // Initially hidden game.addChild(scrollbutton2); scrollbutton2.down = function (x, y, obj) { scrollbutton2.dragging = true; scrollbutton2.initialClick = { x: x, y: y }; scrollbutton2.offset = { y: scrollbutton2.y - y }; }; scrollbutton2.up = function () { scrollbutton2.dragging = false; }; scrollbutton2.move = function (x, y, obj) { if (scrollbutton2.dragging) { var dy = y - scrollbutton2.initialClick.y; scrollbutton2.y = y + scrollbutton2.offset.y; if (scrollbutton2.y < scrollbar2.y - scrollbar2.height / 2 + scrollbutton2.height / 2) { scrollbutton2.y = scrollbar2.y - scrollbar2.height / 2 + scrollbutton2.height / 2; } else if (scrollbutton2.y > scrollbar2.y + scrollbar2.height / 2 - scrollbutton2.height / 2) { scrollbutton2.y = scrollbar2.y + scrollbar2.height / 2 - scrollbutton2.height / 2; } container2.y -= dy; // Scroll the content inside Container2 scrollbutton.y = scrollbutton2.y; // Synchronize scrollbutton with scrollbutton2 // Ensure the container2 stays within the bounds of Pagetab2, but allow partial hiding if (container2.y > pagetab2.y + pagetab2.height / 2 - container2.height / 2 + 25) { container2.y = pagetab2.y + pagetab2.height / 2 - container2.height / 2 + 25; } else if (container2.y < pagetab2.y - pagetab2.height / 2 + container2.height / 2 - 25) { container2.y = pagetab2.y - pagetab2.height / 2 + container2.height / 2 - 25; } scrollbutton2.initialClick = { x: x, y: y }; } }; // Ensure the scrollbutton stays within the scrollbar's top and bottom edges // Add 16 slots to the container for (var i = 0; i < 16; i++) { var slot = LK.getAsset('Slot', { anchorX: 0.5, anchorY: 0.5, x: i % 4 * 400 - 600, // Arrange in a grid, 4 slots per row y: Math.floor(i / 4) * 500 - 800 // Arrange in a grid, 4 slots per row }); container.addChild(slot); // Add woodhouse to each slot in container var woodhouse = LK.getAsset('woodhouse' + (i % 16 + 1), { anchorX: 0.5, anchorY: 0.5, x: slot.x, y: slot.y }); container.addChild(woodhouse); // Add drag functionality to woodhouse assets woodhouse.down = function (x, y, obj) { var duplicate = LK.getAsset('woodhouse' + (i % 16 + 1), { anchorX: 0.5, anchorY: 0.5, x: x, y: y }); background1.addChild(duplicate); // Add duplicate to background1 draggingItem = duplicate; duplicate.initialClick = { x: x, y: y }; duplicate.offset = { x: duplicate.x - x, y: duplicate.y - y }; tween(duplicate, { alpha: 0.5 }, { duration: 200, easing: tween.easeInOut }); duplicate.move = function (x, y, obj) { if (draggingItem === duplicate) { duplicate.x = x + duplicate.offset.x; duplicate.y = y + duplicate.offset.y; } }; }; woodhouse.up = function () { draggingItem = null; }; woodhouse.move = function (x, y, obj) { if (draggingItem === this) { tween(this, { x: x + this.offset.x, y: y + this.offset.y }, { duration: 300, easing: tween.easeOut }); if (this.intersects(background1)) { // Check if woodhouse is moved to background1 this.x = x + this.offset.x; this.y = y + this.offset.y; // Sync with background1 background1.addChild(this); this.offset.x = this.x - x; // Update offset to maintain position relative to background1 this.offset.y = this.y - y; } } }; } // Add 16 slots to container2 for (var i = 0; i < 16; i++) { var slot2 = LK.getAsset('Slot', { anchorX: 0.5, anchorY: 0.5, x: i % 4 * 400 - 600, y: Math.floor(i / 4) * 500 - 800 }); container2.addChild(slot2); // Add trees to each slot in container2 var tree = LK.getAsset('tree' + (i % 16 + 1), { anchorX: 0.5, anchorY: 0.5, x: slot2.x, y: slot2.y }); container2.addChild(tree); // Add drag functionality to tree assets tree.down = function (x, y, obj) { var duplicate = LK.getAsset('tree' + (i % 16 + 1), { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, // Center in the middle of background1 y: 2732 / 2 // Center in the middle of background1 }); background1.addChild(duplicate); // Add duplicate to background1 draggingItem = duplicate; duplicate.initialClick = { x: x, y: y }; duplicate.offset = { x: duplicate.x - x, y: duplicate.y - y }; tween(duplicate, { alpha: 0.5 }, { duration: 200, easing: tween.easeInOut }); duplicate.move = function (x, y, obj) { if (draggingItem === duplicate) { duplicate.x = x + duplicate.offset.x; duplicate.y = y + duplicate.offset.y; } }; }; tree.up = function () { draggingItem = null; }; tree.move = function (x, y, obj) { if (draggingItem === this) { tween(this, { x: x + this.offset.x, y: y + this.offset.y }, { duration: 300, easing: tween.easeOut }); if (this.intersects(background1)) { // Check if tree is moved to background1 this.x = x + this.offset.x; this.y = y + this.offset.y; } } }; } // Function to synchronize scores across all pages function synchronizeScores() { // Update score texts for all pages woodScoreText.setText(wood.clickCount + 1000); silverScoreText.setText(silver.clickCount + 1000); stoneScoreText.setText(stone.clickCount + 1000); goldScoreText.setText(gold.clickCount + 1000); bronzeScoreText.setText(bronze.clickCount + 1000); crystalScoreText.setText(crystal.clickCount + 1000); } // Set the score text2 of all 6 resources to 1000 when the game starts woodScoreText.setText(1000); silverScoreText.setText(1000); stoneScoreText.setText(1000); goldScoreText.setText(1000); bronzeScoreText.setText(1000); crystalScoreText.setText(1000); // Define tree variables to fix 'not defined' error for (var i = 1; i <= 16; i++) { window["tree" + i] = { timetext: new Text2('3:00', { size: 80, fill: 0x8B4513 }), clickCount: 0, visible: true }; window["tree" + i].timetext.anchor.set(0.5, 0.5); window["tree" + i].timetext.visible = false; // Initially hidden } LK.setTimeout(function () { // Function to save tree cooldowns to local storage function saveTreeCooldowns() { var treeCooldowns = []; for (var i = 1; i <= 16; i++) { var tree = window["tree" + i]; if (tree.timetext.visible) { treeCooldowns.push({ id: i, cooldown: tree.timetext.getText() }); } } localStorage.setItem('treeCooldowns', JSON.stringify(treeCooldowns)); } // Function to restore tree cooldowns from local storage function restoreTreeCooldowns() { var storedTreeCooldowns = typeof localStorage !== 'undefined' ? localStorage.getItem('treeCooldowns') : null; var treeCooldowns = storedTreeCooldowns ? JSON.parse(storedTreeCooldowns) : []; treeCooldowns.forEach(function (treeData) { var tree = window["tree" + treeData.id]; var _treeData$cooldown$sp = treeData.cooldown.split(':').map(Number), _treeData$cooldown$sp2 = _slicedToArray(_treeData$cooldown$sp, 2), minutes = _treeData$cooldown$sp2[0], seconds = _treeData$cooldown$sp2[1]; var totalSeconds = minutes * 60 + seconds; tree.clickCount = 3; tree.visible = false; tree.timetext.visible = true; tree.timetext.setText(treeData.cooldown); var cooldown = totalSeconds; var interval = LK.setInterval(function () { cooldown--; var minutes = Math.floor(cooldown / 60); var seconds = cooldown % 60; tree.timetext.setText(minutes + ':' + (seconds < 10 ? '0' : '') + seconds); if (cooldown <= 0) { LK.clearInterval(interval); tree.clickCount = 0; tree.visible = true; tree.timetext.visible = false; } }, 1000); }); } // Call restoreTreeCooldowns when the game starts function restoreTreeCooldowns() { var storedTreeCooldowns = typeof localStorage !== 'undefined' ? localStorage.getItem('treeCooldowns') : null; var treeCooldowns = storedTreeCooldowns ? JSON.parse(storedTreeCooldowns) : []; treeCooldowns.forEach(function (treeData) { var tree = window["tree" + treeData.id]; var _treeData$cooldown$sp = treeData.cooldown.split(':').map(Number), _treeData$cooldown$sp2 = _slicedToArray(_treeData$cooldown$sp, 2), minutes = _treeData$cooldown$sp2[0], seconds = _treeData$cooldown$sp2[1]; var totalSeconds = minutes * 60 + seconds; tree.clickCount = 3; tree.visible = false; tree.timetext.visible = true; tree.timetext.setText(treeData.cooldown); var cooldown = totalSeconds; var interval = LK.setInterval(function () { cooldown--; var minutes = Math.floor(cooldown / 60); var seconds = cooldown % 60; tree.timetext.setText(minutes + ':' + (seconds < 10 ? '0' : '') + seconds); if (cooldown <= 0) { LK.clearInterval(interval); tree.clickCount = 0; tree.visible = true; tree.timetext.visible = false; } }, 1000); }); } restoreTreeCooldowns(); // Restore tree cooldowns from persisted data woodScoreText.setText(1000); // Set woodScore back to 1000 var lastScores = storage.lastScores || {}; lastStatueScore = lastScores.statue || 0; lastSilverScore = lastScores.silver || 0; lastStoneScore = lastScores.stone || 0; lastGoldScore = lastScores.gold || 0; lastBronzeScore = lastScores.bronze || 0; lastCrystalScore = lastScores.crystal || 0; silverScoreText.setText(lastSilverScore); stoneScoreText.setText(lastStoneScore); goldScoreText.setText(lastGoldScore); bronzeScoreText.setText(lastBronzeScore); woodScoreText.setText(lastWoodScore); // Save tree cooldowns before navigating away from the page LK.on('beforeunload', function () { saveTreeCooldowns(); storage.woodClickCount = wood.clickCount; storage.lastScores = { silver: silver.clickCount, stone: stone.clickCount, gold: gold.clickCount, bronze: bronze.clickCount, crystal: crystal.clickCount, wood: wood.clickCount }; }); //{0.b}; }, 30000); // 30 seconds delay ; //{0.b}; ; //{0.b} if (typeof map !== 'undefined') { map.down = function (x, y, obj) { // Navigate to Page1 game.removeChild(page); page = game.addChild(new Page1()); }; } map.down = function (x, y, obj) { // Navigate to Page0 game.removeChild(page); page = game.addChild(new Page0()); };
===================================================================
--- original.js
+++ change.js
@@ -35,14 +35,14 @@
var Page1 = Container.expand(function () {
var self = Container.call(this);
// Add map asset to Page1 below the pause button
var background1 = self.attachAsset('background1', {
- anchorX: 1,
+ anchorX: 0.5,
anchorY: 0.0,
x: 2048 / 2,
y: 0,
// Align with the top of the screen
- scaleX: 2050 / 2048,
+ scaleX: 2000 / 2005,
// Match width of background1
scaleY: 2420 / 2732 // Match height of background1
});
var wall1 = self.attachAsset('wall1', {
2D wreckage of wood, square, HD colors. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
House from the front facing the screen with big sign above it have description "SHOP", Hd colors
coin with colors, have "DA", hd colors. have black circles and black line for the "DA", between the 2 circles do small black lines all around. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Modern App Store icon, square with rounded corners, HD colors for a 2d game titled "The Collector" and with the description "about building houses and trees and decorations on a map to make it look like city, which then generate "DA" coins after a countdown timer expires. Players can collect these coins to increase their score, which they can then use to purchase more houses and trees and decorations from the shop button on the middle left side of the screen". with text on the middle top of the banner "the collector"!