Code edit (3 edits merged)
Please save this source code
User prompt
Add arrow inside the circle.
User prompt
add the circle on the bottom right side, it indicates how close you are to getting a diamond, and also create a global diamond variable, and place it below the coins variable
User prompt
O botão de trocar está muito perto do de upgrade, d
User prompt
YES IT IS SUPPORTED! DO IT NOW
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'lastX')' in or related to this line: 'if (woodenBlock.lastX <= 1000 && woodenBlock.x > 1000) {' Line Number: 73
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'lastX')' in or related to this line: 'if (woodenBlock.lastX <= 1000 && woodenBlock.x > 1000) {' Line Number: 73
User prompt
then put in the latest version!
User prompt
when it is in the menu, there is no way to click to break. also add the play button
Code edit (1 edits merged)
Please save this source code
User prompt
create a menu using game_icon
User prompt
Se o desafio é um sucesso, desbloqueia um novo item.
User prompt
Adicione o desafio sucesso, se o player conseguir quebrar 10 madeiras antes do tempo.
User prompt
Ah, eu já sei. Para quebrar esse objeto, as 4 pernas dão um total de 1200 HP e a cadeira inteira dá 1600 de HP.
User prompt
Ok, então o metal vai ter 500 de HP.
User prompt
the object turns black when it has not been unlocked
User prompt
Ok! 225 of hp to raw wood
User prompt
the exchange object button opens a tab to choose an object, but to unlock the next one, you have to complete the challenge of the previous object
User prompt
Add object_change_button, and place it on the right side of the upgrade button
User prompt
The global variable wood broken is not working
User prompt
make the broken wood variable change when breaking a wood
User prompt
The challenge's global variables only appear when you toggle the challenge
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'x')' in or related to this line: 'globalTimeText.x = coinsText.x;' Line Number: 83
User prompt
Please fix the bug: 'globalTimeText is not defined' in or related to this line: 'woodPiecesBrokenText.y = globalTimeText.y + globalTimeText.height + 10;' Line Number: 78
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'x')' in or related to this line: 'woodPiecesBrokenText.x = coinsText.x;' Line Number: 72
/**** * Classes ****/ //<Assets used in the game will automatically appear here> // Create the Character class var Character = Container.expand(function () { var self = Container.call(this); // Attach the character asset var playerAssets = ['player_1', 'Player_2', 'Player_3', 'Player_4']; var currentAssetIndex = 0; var characterGraphics = self.attachAsset(playerAssets[currentAssetIndex], { anchorX: 0.85, anchorY: 0.5, scaleX: 5, scaleY: 5, frameRate: 10 // Set the frame rate for the sprite animation }); // Set the character's initial position self.x = 945; self.y = 2732 / 2 - characterGraphics.height / 2; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ if (challengeActive) { woodPiecesBroken++; woodPiecesBrokenText.setText('Wood Broken: ' + woodPiecesBroken); } // Add coins when the wood is broken var woodPiecesBrokenText, globalTimeText; // Start a countdown timer var instructionText = new Text2('Tap to break objects and earn rewards!', { size: 100, fill: 0xFFFFFF }); instructionText.anchor.set(0.5, 0); instructionText.x = 2048 / 2; // Center horizontally instructionText.y = 2732 / 2; // Center vertically LK.gui.top.addChild(instructionText); // Play background music LK.playMusic('Bgmusic', { loop: true }); // Initialize the upgrade button image var upgradeButton = LK.getAsset('Upgrade_button', { anchorX: 0.5, anchorY: 0.5, scaleX: 2, scaleY: 2 }); // Position the upgrade button at the bottom left of the screen upgradeButton.x = upgradeButton.width / 2; upgradeButton.y = 2732 - upgradeButton.height / 2; // Initialize the object change button image var objectChangeButton = LK.getAsset('Object_change_button', { anchorX: 0.5, anchorY: 0.5, scaleX: 2, scaleY: 2 }); // Position the object change button to the right of the upgrade button objectChangeButton.x = upgradeButton.x + upgradeButton.width + 20; objectChangeButton.y = upgradeButton.y; // Add the object change button to the game game.addChild(objectChangeButton); // Add an event listener for the object change button objectChangeButton.down = function (x, y, obj) { console.log("Object change button pressed!"); openObjectSelectionTab(); }; // Add the upgrade button to the game game.addChild(upgradeButton); // Bring the upgrade button to the front game.setChildIndex(upgradeButton, game.children.length - 1); game.setChildIndex(upgradeButton, game.children.length - 1); // Add an event listener for the upgrade button upgradeButton.down = function (x, y, obj) { console.log("Upgrade button pressed!"); // Handle wood breaking logic here if (challengeActive) { woodPiecesBroken++; woodPiecesBrokenText.setText('Wood Broken: ' + woodPiecesBroken); } openUpgradePanel(); }; // Add an event listener for the hand button icon to increase damage var handButtonIcon = LK.getAsset('Hand_icon_button', { anchorX: 0.5, anchorY: 0.5, scaleX: 2, scaleY: 2 }); // Add the hand button icon to the upgrade panel function addHandButtonIconToPanel(upgradePanel) { upgradePanel.addChild(handButtonIcon); } // Create a background for the panel var panelBackground = LK.getAsset('Bg', { anchorX: 0.5, anchorY: 0.5, scaleX: 2.0, // Increased scale for width scaleY: 2.0 // Increased scale for height }); var upgradePanel = new Container(); // Define upgradePanel upgradePanel.addChild(panelBackground); // Position the hand button icon at the top of the upgrade panel handButtonIcon.x = 0; // Align to the left handButtonIcon.y = -panelBackground.height / 2 + handButtonIcon.height / 2 + 20; // Align to the top with some padding // Add an event listener for the hand button icon handButtonIcon.down = function (x, y, obj) { if (coins >= 10) { console.log("Hand button icon pressed! Increasing damage."); playerDamage += 1; // Increase player damage by 1 coins -= 10; // Deduct 10 coins coinsText.setText(coins.toString()); // Update coins display } else { console.log("Not enough coins to upgrade damage."); } }; // Function to open the upgrade panel function openUpgradePanel() { // Create a new container for the upgrade panel var upgradePanel = new Container(); // Create a background for the panel var panelBackground = LK.getAsset('Bg', { anchorX: 0.5, anchorY: 0.5, scaleX: 2.0, // Increased scale for width scaleY: 2.0 // Increased scale for height }); var upgradePanel = new Container(); upgradePanel.addChild(panelBackground); // Position the panel in the center of the screen upgradePanel.x = 2048 / 2; upgradePanel.y = 2732 / 2; // Add the panel to the game game.addChild(upgradePanel); // Initialize the close button image var closeButton = LK.getAsset('close_tab_button', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.5, scaleY: 1.5 }); // Position the close button at the top right of the panel closeButton.x = panelBackground.width / 2 - closeButton.width / 2; closeButton.y = -panelBackground.height / 2 + closeButton.height / 2; // Add the close button to the upgrade panel upgradePanel.addChild(closeButton); // Add an event listener for the close button closeButton.down = function (x, y, obj) { console.log("Close button pressed!"); // Remove the upgrade panel from the game game.removeChild(upgradePanel); }; addHandButtonIconToPanel(upgradePanel); // Add an event listener for the energy button icon to increase energy recovery var energyButtonIcon = LK.getAsset('Energy_icon_button', { anchorX: 0.5, anchorY: 0.5, scaleX: 2, scaleY: 2 }); upgradePanel.addChild(energyButtonIcon); // Add an event listener for the energy max button icon to increase energy limit var energyMaxButtonIcon = LK.getAsset('Energy_max_button_icon', { anchorX: 0.5, anchorY: 0.5, scaleX: 2, scaleY: 2 }); upgradePanel.addChild(energyMaxButtonIcon); energyMaxButtonIcon.down = function (x, y, obj) { if (coins >= 10) { console.log("Energy max button icon pressed! Increasing energy limit."); playerEnergy += 10; // Increase energy limit by 10 coins -= 10; // Deduct 10 coins coinsText.setText(coins.toString()); // Update coins display } else { console.log("Not enough coins to upgrade energy limit."); } }; // Add an event listener for the upgrade button to increase energy recovery energyButtonIcon.down = function (x, y, obj) { if (coins >= 10) { console.log("Energy button icon pressed! Increasing energy recovery."); energyRecoveryRate += 1; // Increase energy recovery rate by 1 coins -= 10; // Deduct 10 coins coinsText.setText(coins.toString()); // Update coins display } else { console.log("Not enough coins to upgrade energy recovery."); } }; var energyUpgradeNameText = new Text2('Upgrade: Increase Energy Recovery', { size: 100, fill: 0xFFFFFF }); energyUpgradeNameText.anchor.set(0.5, 0); // Add cost and name display for the energy upgrade var energyUpgradeCostText = new Text2('Cost: 10 Coins', { size: 100, fill: 0xFFFFFF }); energyUpgradeCostText.anchor.set(0.5, 0); energyUpgradeCostText.y = energyButtonIcon.y + energyButtonIcon.height / 2 + 10; upgradePanel.addChild(energyUpgradeCostText); energyUpgradeNameText.y = energyUpgradeCostText.y + energyUpgradeCostText.height + 10; upgradePanel.addChild(energyUpgradeNameText); energyButtonIcon.x = panelBackground.width / 2 - energyButtonIcon.width / 2; energyButtonIcon.y = energyUpgradeNameText.y + energyUpgradeNameText.height + 20; energyUpgradeCostText.anchor.set(0.5, 0); energyUpgradeCostText.y = energyButtonIcon.y + energyButtonIcon.height / 2 + 10; upgradePanel.addChild(energyUpgradeCostText); var energyUpgradeNameText = new Text2('Upgrade: Increase Energy Recovery', { size: 100, fill: 0xFFFFFF }); energyUpgradeNameText.anchor.set(0.5, 0); energyUpgradeNameText.y = energyUpgradeCostText.y + energyUpgradeCostText.height + 10; upgradePanel.addChild(energyUpgradeNameText); // Add an event listener for the energy button icon energyButtonIcon.down = function (x, y, obj) { if (coins >= 10) { console.log("Energy button icon pressed! Increasing energy recovery."); energyRecoveryRate += 1; // Increase energy recovery rate by 1 coins -= 10; // Deduct 10 coins coinsText.setText(coins.toString()); // Update coins display } else { console.log("Not enough coins to upgrade energy recovery."); } }; // Add cost and name display for the upgrade var upgradeCostText = new Text2('Cost: 10 Coins', { size: 100, fill: 0xFFFFFF }); upgradeCostText.anchor.set(0.5, 0); upgradeCostText.y = handButtonIcon.y + handButtonIcon.height / 2 + 10; upgradePanel.addChild(upgradeCostText); var upgradeNameText = new Text2('Upgrade: Increase Damage', { size: 100, fill: 0xFFFFFF }); upgradeNameText.anchor.set(0.5, 0); upgradeNameText.y = upgradeCostText.y + upgradeCostText.height + 10; upgradePanel.addChild(upgradeNameText); } var coinGainText; // Define coinGainText in the global scope var scoreText = new Text2('0', { size: 150, fill: 0xFFFFFF }); // Define scoreText // Initialize the gold button image var goldButton = LK.getAsset('Gold_button_icon', { anchorX: 0.3, tint: 0x808080, // Set the initial tint to gray // Center the anchor point horizontally anchorY: -0.4, // Center the anchor point vertically scaleX: 2, // Scale the button size scaleY: 2 // Scale the button size }); // Create a text to display the brightness percentage above the gold button var goldButtonBrightnessText = new Text2(goldButtonBrightness + '%', { size: 50, fill: 0xFFFFFF }); goldButtonBrightnessText.anchor.set(0.5, 1); // Center horizontally, align bottom goldButtonBrightnessText.x = goldButton.x; goldButtonBrightnessText.y = goldButton.y - goldButton.height / 2 - 10; // Position above the button game.addChild(goldButtonBrightnessText); // Update the brightness text whenever the brightness changes function updateGoldButtonBrightnessText() { goldButtonBrightnessText.setText(goldButtonBrightness + '%'); } // Initialize the crown image var crown = LK.getAsset('crown', { anchorX: 1.0, // Right edge anchorY: 0.0, // Top edge scaleX: 2, // Scale the crown size scaleY: 2 // Scale the crown size }); // Position the crown at the top right of the screen crown.x = 2048 - crown.width / 2; crown.y = crown.height / 2; // Add the crown to the game game.addChild(crown); // Position the gold button further to the left goldButton.x = crown.x - crown.width - goldButton.width / 2; // Position to the left of the crown goldButton.y = crown.y + crown.height + goldButton.height / 2; // Position below the crown // Add the gold button to the game game.addChild(goldButton); // Function to open the object selection tab function openObjectSelectionTab() { // Create a new container for the object selection tab var objectSelectionTab = new Container(); // Create a background for the tab var tabBackground = LK.getAsset('Bg', { anchorX: 0.5, anchorY: 0.5, scaleX: 2.0, scaleY: 2.0 }); objectSelectionTab.addChild(tabBackground); // Position the tab in the center of the screen objectSelectionTab.x = 2048 / 2; objectSelectionTab.y = 2732 / 2; // Add the tab to the game game.addChild(objectSelectionTab); // Initialize the close button image var closeButton = LK.getAsset('close_tab_button', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.5, scaleY: 1.5 }); // Position the close button at the top right of the tab closeButton.x = tabBackground.width / 2 - closeButton.width / 2; closeButton.y = -tabBackground.height / 2 + closeButton.height / 2; // Add the close button to the object selection tab objectSelectionTab.addChild(closeButton); // Add an event listener for the close button closeButton.down = function (x, y, obj) { console.log("Close button pressed!"); // Remove the object selection tab from the game game.removeChild(objectSelectionTab); }; // Add logic to display objects and handle unlocking var objects = ['Object_1', 'Object_2', 'Object_3']; // Example object IDs var unlockedObjects = 1; // Number of unlocked objects objects.forEach(function (objectId, index) { var objectIcon = LK.getAsset(objectId, { anchorX: 0.5, anchorY: 0.5, scaleX: 2, scaleY: 2 }); // Position each object icon in the tab objectIcon.x = (index - 1) * 150; // Adjust spacing objectIcon.y = 0; // Add the object icon to the tab objectSelectionTab.addChild(objectIcon); // Add an event listener for each object icon objectIcon.down = function (x, y, obj) { if (index < unlockedObjects) { console.log("Object " + (index + 1) + " selected!"); // Logic to select the object } else { console.log("Object " + (index + 1) + " is locked!"); objectIcon.tint = 0x000000; // Set tint to black if locked } }; }); } // Add a click event to the game // Add an event listener for the crown var challengeActive = false; var woodPiecesBroken = 0; // Track the number of wood pieces broken during the challenge crown.down = function (x, y, obj) { if (challengeActive) { console.log("Challenge is already active or in cooldown."); return; } challengeActive = true; // Create and display the challenge text var challengeText = new Text2('Break 10 pieces of wood in 30 seconds!', { size: 100, fill: 0xFFFFFF }); challengeText.anchor.set(0.5, 0.5); challengeText.x = 2048 / 2; // Center horizontally challengeText.y = 2732 / 2; // Center vertically LK.gui.top.addChild(challengeText); // Add a text timer to the bottom middle of the screen var timerText = new Text2('30', { size: 100, fill: 0xFFFFFF }); timerText.anchor.set(0.5, 0.5); timerText.x = 2048 / 2; // Center horizontally timerText.y = 2732 - 100; // Position near the bottom LK.gui.bottom.addChild(timerText); // Add a global time variable below the coins if the challenge has started globalTimeText = new Text2('Time: 30s', { size: 100, fill: 0xFFFFFF }); globalTimeText.anchor.set(0.5, 0); globalTimeText.x = coinsText.x; globalTimeText.y = coinsText.y + coinsText.height + 10; LK.gui.top.addChild(globalTimeText); // Add a global variable to track wood pieces broken if the challenge has started woodPiecesBrokenText = new Text2('Wood Broken: 0', { size: 100, fill: 0xFFFFFF }); woodPiecesBrokenText.anchor.set(0.5, 0); woodPiecesBrokenText.x = coinsText.x; woodPiecesBrokenText.y = globalTimeText.y + globalTimeText.height + 10; LK.gui.top.addChild(woodPiecesBrokenText); // Start a countdown timer var countdown = 30; var countdownInterval = LK.setInterval(function () { countdown--; timerText.setText(countdown.toString()); globalTimeText.setText('Time: ' + countdown + 's'); // Update global time display if (countdown <= 0) { LK.clearInterval(countdownInterval); if (woodPiecesBroken >= 10) { // Unlock a new item unlockedObjects++; console.log("New item unlocked! Total unlocked items: " + unlockedObjects); // Display success message var successText = new Text2('Challenge Completed!', { size: 100, fill: 0x00FF00 }); successText.anchor.set(0.5, 0.5); successText.x = 2048 / 2; // Center horizontally successText.y = 2732 / 2; // Center vertically LK.gui.top.addChild(successText); // Remove the success text after a short delay LK.setTimeout(function () { if (successText.parent) { successText.parent.removeChild(successText); } }, 3000); // Display for 3 seconds } else { woodPiecesBroken = 0; // Reset wood pieces broken count if (woodPiecesBrokenText.parent) { woodPiecesBrokenText.parent.removeChild(woodPiecesBrokenText); } if (timerText.parent) { timerText.parent.removeChild(timerText); } if (globalTimeText.parent) { globalTimeText.parent.removeChild(globalTimeText); } // Display failure message var failureText = new Text2('You failed the challenge!', { size: 100, fill: 0xFF0000 }); failureText.anchor.set(0.5, 0.5); failureText.x = 2048 / 2; // Center horizontally failureText.y = 2732 / 2; // Center vertically LK.gui.top.addChild(failureText); // Remove the failure text after a short delay LK.setTimeout(function () { if (failureText.parent) { failureText.parent.removeChild(failureText); } }, 3000); // Display for 3 seconds challengeActive = false; // Start cooldown timer if challenge failed var cooldown = 60; var cooldownText = new Text2('Retry in: ' + cooldown + 's', { size: 100, fill: 0xFF0000 }); cooldownText.anchor.set(0.5, 0.5); cooldownText.x = 2048 / 2; cooldownText.y = 2732 - 200; LK.gui.bottom.addChild(cooldownText); var cooldownInterval = LK.setInterval(function () { cooldown--; cooldownText.setText('Retry in: ' + cooldown + 's'); if (cooldown <= 0) { LK.clearInterval(cooldownInterval); if (cooldownText.parent) { cooldownText.parent.removeChild(cooldownText); } } }, 1000); } } }, 1000); // Remove the challenge text after a short delay LK.setTimeout(function () { if (challengeText.parent) { challengeText.parent.removeChild(challengeText); } }, 3000); // Display for 3 seconds }; var hpWood = 100; // Initialize the HP of the wooden block var playerDamage = 10; // Initialize the player's damage to 10 var bg = LK.getAsset('Bg', { anchorX: 0.0, anchorY: 0.0, scaleX: 2048 / 100, // Scale to fit the screen width scaleY: 2732 / 98.44 // Scale to fit the screen height }); // Initialize the rope image var rope = LK.getAsset('Rope', { anchorX: 0.0, anchorY: 0.0, scaleX: 2048 / 400, // Scale to full screen width scaleY: 2732 / 500 // Increase the vertical size of the rope }); // Add the rope image to the game game.addChild(rope); // Initialize the wooden block image var woodenBlockPosition = { x: 0, y: 0 }; // Track the wooden block's position var woodHp = 225; // Initialize the HP of the wooden block var metalHp = 500; // Initialize the HP of the metal block var chairHp = 1600; // Initialize the HP of the chair var chairLegsHp = 1200; // Initialize the total HP of the chair legs var woodenBlock = LK.getAsset('Object_1', { anchorX: 0.1, anchorY: -2, scaleX: 5, scaleY: 5 }); // Position the wooden block further down the rope woodenBlock.x = rope.x + rope.width / 2; woodenBlock.y = rope.y + rope.height * 0.95; // Make the wooden block visible woodenBlock.alpha = 1; // Add the wooden block to the game game.addChild(woodenBlock); // Initialize the HP bar image var hpBar = LK.getAsset('Hp_bar', { anchorX: 0.1, anchorY: -4, scaleX: 5, scaleY: 5 }); // Position the HP bar on top of the wooden block hpBar.x = woodenBlock.x; hpBar.y = woodenBlock.y - woodenBlock.height / 2 - hpBar.height; // Add the HP bar to the game game.addChild(hpBar); // Add the character to the game var character = game.addChild(new Character()); // Define currentAssetIndex in the global scope var playerAssets = ['player_1', 'Player_2', 'Player_3', 'Player_4']; var currentAssetIndex = 0; // Add a new variable to track the state of the game var gameState = "playing"; // Add a variable to display the score at the top of the screen var playerEnergy = 100; // Initialize the player's energy variable // Function to recover player energy every second function recoverEnergy() { if (playerEnergy < 100) { playerEnergy += energyRecoveryRate; energyText.setText(playerEnergy.toString()); } } // Set an interval to call recoverEnergy every second LK.setInterval(recoverEnergy, 1000); var energyText = new Text2(playerEnergy.toString(), { size: 150, fill: 0xFFFFFF }); energyText.anchor.set(0.5, 0); LK.gui.top.addChild(energyText); var hpWoodText = new Text2(hpWood.toString(), { size: 150, fill: 0xFFFFFF }); hpWoodText.anchor.set(0.5, 0); hpWoodText.y = scoreText.height; LK.gui.top.addChild(hpWoodText); var goldButtonBrightness = 0; // Initialize the gold button brightness variable at 0% var coins = 0; // Initialize the coins variable var playerEnergy = 100; // Initialize the player's energy variable var energyRecoveryRate = 5; // Initialize the energy recovery rate to 5 var coinsText = new Text2(coins.toString(), { size: 150, fill: 0xFFFFFF }); coinsText.anchor.set(0.5, 0); coinsText.y = hpWoodText.height + hpWoodText.y; LK.gui.top.addChild(coinsText); // Initialize the game icon for the menu var gameIcon = LK.getAsset('Icon_game', { anchorX: 0.5, anchorY: 0.1, scaleX: 2, scaleY: 2 }); // Position the game icon at the top center of the screen gameIcon.x = 2048 / 2; gameIcon.y = gameIcon.height / 2 + 20; // Add the game icon to the game game.addChild(gameIcon); // Add an event listener for the game icon to open the menu gameIcon.down = function (x, y, obj) { console.log("Game icon pressed! Opening menu..."); openGameMenu(); }; // Function to open the game menu function openGameMenu() { // Create a new container for the game menu var gameMenu = new Container(); // Create a background for the menu var menuBackground = LK.getAsset('Bg', { anchorX: 0.5, anchorY: 0.5, scaleX: 2.0, scaleY: 2.0 }); gameMenu.addChild(menuBackground); // Position the menu in the center of the screen gameMenu.x = 2048 / 2; gameMenu.y = 2732 / 2; // Add the menu to the game game.addChild(gameMenu); // Initialize the close button image var closeButton = LK.getAsset('close_tab_button', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.5, scaleY: 1.5 }); // Position the close button at the top right of the menu closeButton.x = menuBackground.width / 2 - closeButton.width / 2; closeButton.y = -menuBackground.height / 2 + closeButton.height / 2; // Add the close button to the game menu gameMenu.addChild(closeButton); // Initialize the play button image var playButton = LK.getAsset('Play_button', { anchorX: 0.5, anchorY: 0.5, scaleX: 2, scaleY: 2 }); // Position the play button at the center of the menu playButton.x = 0; playButton.y = 0; // Add the play button to the game menu gameMenu.addChild(playButton); // Add an event listener for the play button playButton.down = function (x, y, obj) { console.log("Play button pressed!"); game.removeChild(gameMenu); gameState = "playing"; }; closeButton.down = function (x, y, obj) { console.log("Close button pressed!"); // Remove the game menu from the game game.removeChild(gameMenu); }; } game.down = function (x, y, obj) { // Prevent breaking objects when in the menu if (gameState !== "playing") { return; } if (instructionText.parent) { instructionText.parent.removeChild(instructionText); } if (playerEnergy === 0) { // Trigger hurt animation character.removeChildren(); var hurtAnimation = ['player_hurt_hand_1', 'player_hurt_hand_2', 'player_hurt_hand_3'].map(function (asset) { return character.attachAsset(asset, { anchorX: 0.85, anchorY: 0.5, scaleX: 5, scaleY: 5, frameRate: 10 // Set the frame rate for the sprite animation }); }); hurtAnimation.forEach(function (frame, index) { LK.setTimeout(function () { character.removeChildren(); character.addChild(frame); }, index * 100); // Adjust timing for each frame }); // After 3 seconds, transition to lifting animation LK.setTimeout(function () { character.removeChildren(); var liftingAnimation = ['Player_lifting_1', 'Player_lifting_2'].map(function (asset) { return character.attachAsset(asset, { anchorX: 0.85, anchorY: 0.5, scaleX: 5, scaleY: 5, frameRate: 10 // Set the frame rate for the sprite animation }); }); liftingAnimation.forEach(function (frame, index) { LK.setTimeout(function () { character.removeChildren(); character.addChild(frame); }, index * 100); // Adjust timing for each frame }); }, 3000); return; // Exit the function to prevent further actions } // Trigger a character animation sequence currentAssetIndex = (currentAssetIndex + 1) % playerAssets.length; character.removeChildren(); // Remove previous animation var animationSequence = playerAssets.map(function (asset) { return character.attachAsset(asset, { anchorX: 0.85, anchorY: 0.5, scaleX: 5, scaleY: 5, frameRate: 10 // Set the frame rate for the sprite animation }); }); animationSequence.forEach(function (frame, index) { LK.setTimeout(function () { character.removeChildren(); character.addChild(frame); if (index === animationSequence.length - 1) { // Deal damage to the wood when the animation ends var energyConsumption = Math.min(playerEnergy, 10); // Determine energy consumption, max 10 playerEnergy -= energyConsumption; // Reduce player energy energyText.setText(playerEnergy.toString()); // Update energy display hpWood -= playerDamage * (energyConsumption / 10); // Adjust damage based on energy consumption chairHp -= playerDamage * (energyConsumption / 10); // Adjust damage for chair chairLegsHp -= playerDamage * (energyConsumption / 10); // Adjust damage for chair legs // Increase gold button shine by 1% when wood is damaged goldButton.tint = Math.min(0xFFFFFF, goldButton.tint + 0x010101); goldButtonBrightness = Math.min(100, goldButtonBrightness + 1); // Increase brightness percentage updateGoldButtonBrightnessText(); // Update the text display // Enable gold button click when at maximum brightness if (goldButton.tint === 0xFFFFFF) { goldButton.down = function (x, y, obj) { console.log("Gold button clicked at maximum brightness!"); // Change any item to gold for a few seconds woodenBlock.tint = 0xFFD700; // Change the wooden block to gold color LK.setTimeout(function () { woodenBlock.tint = 0xFFFFFF; // Revert the wooden block color back to normal }, 3000); // Change lasts for 3 seconds goldButtonBrightness = 0; // Reset brightness percentage updateGoldButtonBrightnessText(); // Update the text display // Reset the gold button brightness to 0% after use goldButtonBrightness = 0; // Reset brightness percentage updateGoldButtonBrightnessText(); // Update the text display }; } hpWoodText.setText(hpWood.toString()); // Play the hit sound effect LK.getSound('Hit').play(); if (hpWood <= 0 || chairHp <= 0 || chairLegsHp <= 0) { // Handle wood breaking logic here if (challengeActive) { woodPiecesBroken++; woodPiecesBrokenText.setText('Wood Broken: ' + woodPiecesBroken); } console.log("Wood is broken!"); // Play the break sound effect LK.getSound('Break').play(); // Reset wood HP hpWood = 100; chairHp = 1600; // Reset chair HP chairLegsHp = 1200; // Reset chair legs HP hpWoodText.setText(hpWood.toString()); // Reposition the new wooden block woodenBlock.x = rope.x + rope.width / 2; woodenBlock.y = rope.y + rope.height * 0.95; // Add coins when the wood is broken coins += 10; // Add 10 coins coinsText.setText(coins.toString()); // Create a text effect for gaining coins if (!coinGainText) { coinGainText = new Text2('+10', { size: 100, fill: 0xFFFF00 // Yellow color for the coin gain text }); } coinGainText.anchor.set(0.5, 0.5); coinGainText.x = woodenBlock.x + 50; // Move the text effect further to the right coinGainText.y = woodenBlock.y - woodenBlock.height / 2; // Add the coin gain text to the game game.addChild(coinGainText); // Animate the coin gain text to move upwards and fade out LK.setTimeout(function () { // Custom animation to move the text upwards var startY = coinGainText.y; var endY = startY - 100; var duration = 1000; var startTime = Date.now(); function animateMove() { var currentTime = Date.now(); var elapsed = currentTime - startTime; var progress = Math.min(elapsed / duration, 1); coinGainText.y = startY + (endY - startY) * progress; if (progress < 1) { LK.setTimeout(animateMove, 16); // Approximately 60 FPS } } animateMove(); // Custom fade-out animation var fadeDuration = 1000; var fadeStartTime = Date.now(); function animateFadeOut() { var currentTime = Date.now(); var elapsed = currentTime - fadeStartTime; var fadeProgress = Math.min(elapsed / fadeDuration, 1); coinGainText.alpha = 1 - fadeProgress; if (fadeProgress < 1) { LK.setTimeout(animateFadeOut, 16); // Approximately 60 FPS } else { coinGainText.destroy(); // Remove the text after animation } } animateFadeOut(); }, 0); } } }, index * 100); // Adjust timing for each frame }); }; ;
===================================================================
--- original.js
+++ change.js
@@ -594,9 +594,9 @@
LK.gui.top.addChild(coinsText);
// Initialize the game icon for the menu
var gameIcon = LK.getAsset('Icon_game', {
anchorX: 0.5,
- anchorY: 0.4,
+ anchorY: 0.1,
scaleX: 2,
scaleY: 2
});
// Position the game icon at the top center of the screen
@@ -637,17 +637,37 @@
closeButton.x = menuBackground.width / 2 - closeButton.width / 2;
closeButton.y = -menuBackground.height / 2 + closeButton.height / 2;
// Add the close button to the game menu
gameMenu.addChild(closeButton);
- // Add an event listener for the close button
+ // Initialize the play button image
+ var playButton = LK.getAsset('Play_button', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 2,
+ scaleY: 2
+ });
+ // Position the play button at the center of the menu
+ playButton.x = 0;
+ playButton.y = 0;
+ // Add the play button to the game menu
+ gameMenu.addChild(playButton);
+ // Add an event listener for the play button
+ playButton.down = function (x, y, obj) {
+ console.log("Play button pressed!");
+ game.removeChild(gameMenu);
+ gameState = "playing";
+ };
closeButton.down = function (x, y, obj) {
console.log("Close button pressed!");
// Remove the game menu from the game
game.removeChild(gameMenu);
};
}
game.down = function (x, y, obj) {
- // Remove the instructional text when the screen is pressed
+ // Prevent breaking objects when in the menu
+ if (gameState !== "playing") {
+ return;
+ }
if (instructionText.parent) {
instructionText.parent.removeChild(instructionText);
}
if (playerEnergy === 0) {
A small piece of wood.
a hanging rope. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
piece_of_wood. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Upgrade button. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Gold_button_icon. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
crown. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
raw piece of wood. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Metal. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Chair. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
create a hand icon breaking a brick in half. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Play_button. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Diamond_icon. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
pixel person with black hair, black pants, black eyes, and blue clothes making a V with hands jumping in a rain of diamonds. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Shop_icon. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows