Code edit (6 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'button')' in this line: 'if (obj.event.data.button === 0) {' Line Number: 79
User prompt
Fix Bug: 'ReferenceError: createBlueBlock is not defined' in this line: 'createBlueBlock(pos.x, pos.y);' Line Number: 171
User prompt
create floor using 1 on mause position
User prompt
add floor
User prompt
fix save into one key
User prompt
log for game saved and loaded
User prompt
fix save and load
User prompt
Fix Bug: 'ReferenceError: loadButton is not defined' in this line: 'if (!saveButton.getBounds().contains(pos.x, pos.y) && !loadButton.getBounds().contains(pos.x, pos.y)) {' Line Number: 139
User prompt
remove load button
Code edit (1 edits merged)
Please save this source code
User prompt
set reset button pos to right angle
User prompt
set reset button pos to 40 40
===================================================================
--- original.js
+++ change.js
@@ -42,44 +42,8 @@
}
};
});
// Function to save the current state of blueBlocks and blackBlocks
-// LoadButton class for creating load button
-var LoadButton = Container.expand(function () {
- var self = Container.call(this);
- var loadButtonGraphics = self.createAsset('loadButton', 'Load button', 0.5, 0.5);
- loadButtonGraphics.rotation = Math.PI / 4; // Set button at 45 degrees angle
- self.layer = 2;
- self.on('down', function () {
- // Load the saved state of blueBlocks and blackBlocks
- var savedBlueBlocks = typeof LK.localStorage !== 'undefined' && LK.localStorage.getItem('blueBlocks') ? JSON.parse(LK.localStorage.getItem('blueBlocks')) : [];
- var savedBlackBlocks = typeof LK.localStorage !== 'undefined' && LK.localStorage.getItem('blackBlocks') ? JSON.parse(LK.localStorage.getItem('blackBlocks')) : [];
- // Clear the current blocks from the game
- blueBlocks.forEach(function (block) {
- block.destroy();
- });
- blackBlocks.forEach(function (block) {
- block.destroy();
- });
- blueBlocks = [];
- blackBlocks = [];
- // Create new blocks from the saved state
- savedBlueBlocks.forEach(function (data) {
- var blueBlock = new BlueBlock();
- blueBlock.x = data.x;
- blueBlock.y = data.y;
- blueBlocks.push(blueBlock);
- game.addChild(blueBlock);
- });
- savedBlackBlocks.forEach(function (data) {
- var blackBlock = new BlackBlock();
- blackBlock.x = data.x;
- blackBlock.y = data.y;
- blackBlocks.push(blackBlock);
- game.addChild(blackBlock);
- });
- });
-});
// ResetButton class for creating reset button
var ResetButton = Container.expand(function () {
var self = Container.call(this);
var resetButtonGraphics = self.createAsset('resetButton', 'Reset button', 0.5, 0.5);
@@ -193,22 +157,17 @@
// Update all black blocks
for (var j = 0; j < blackBlocks.length; j++) {
blackBlocks[j].update();
}
-}); // Instantiate save and load buttons
+}); // Instantiate save button
var saveButton = new SaveButton();
saveButton.x = 20;
saveButton.y = 20;
game.addChild(saveButton);
-var loadButton = new LoadButton();
-loadButton.x = 20;
-loadButton.y = 20;
-loadButton.layer = 2;
-game.addChild(loadButton);
// Instantiate reset button
var resetButton = new ResetButton();
-resetButton.x = game.width - resetButton.width / 2 - 10;
-resetButton.y = 20;
+resetButton.x = game.width - resetButton.width / 2 - 50;
+resetButton.y = 50;
resetButton.layer = 2;
game.addChild(resetButton);
// Set up an automatic save function to trigger every 120 seconds (7200 frames at 60FPS)
var autoSaveTimer = LK.setInterval(game.saveGameState, 7200);
\ No newline at end of file