User prompt
fix save
User prompt
blue blocks can't created on save button
User prompt
set blue block can't created on save button
User prompt
change load button pos to 20 20
User prompt
change save button pos to 45 45
User prompt
change load button pos to 180 180
User prompt
change save button pos to 90 90
User prompt
save on x + right click on save button
User prompt
save on save button
User prompt
save button
User prompt
Fix Bug: 'TypeError: Cannot set properties of undefined (setting 'layer')' in this line: 'self.layer = 1;' Line Number: 103
User prompt
Fix Bug: 'TypeError: Cannot set properties of undefined (setting 'layer')' in this line: 'self.layer = 1;' Line Number: 102
User prompt
set layer for black block and blue block to 1
User prompt
set layer for save button and load button to 2
User prompt
can't create blue block at save button
User prompt
blue blocks can't created on save button
User prompt
set save button layer to 2
User prompt
set blue block can't created on save buttton
User prompt
set black blocks can't created at load button
User prompt
save using s
User prompt
black block can't created on save button
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'getItem')' in this line: 'var savedBlackBlocks = LK.localStorage.getItem('blackBlocks') ? JSON.parse(LK.localStorage.getItem('blackBlocks')) : [];' Line Number: 37
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'parse')' in this line: 'var savedBlackBlocks = JSON.parse(LK.localStorage.getItem('blackBlocks')) || [];' Line Number: 37
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'getItem')' in this line: 'var savedBlueBlocks = LK.localStorage.getItem('blueBlocks') ? JSON.parse(LK.localStorage.getItem('blueBlocks')) : [];' Line Number: 36
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'setItem')' in this line: 'LK.localStorage.setItem('blackBlocks', JSON.stringify(blackBlocks.map(function (block) {' Line Number: 82
/****
* Classes
****/
// BlueBlock class for creating blue blocks
var BlueBlock = Container.expand(function () {
var self = Container.call(this);
var blueBlockGraphics = self.createAsset('blueBlock', 'Blue block', 0.5, 0.5);
self.move = function () {};
self.update = function () {};
});
// BlackBlock class for creating black blocks
var BlackBlock = Container.expand(function () {
var self = Container.call(this);
var blackBlockGraphics = self.createAsset('blackBlock', 'Black block', 0.5, 0.5);
self.move = function () {};
self.update = function () {};
});
// SaveButton class for creating save button
var SaveButton = Container.expand(function () {
var self = Container.call(this);
var saveButtonGraphics = self.createAsset('saveButton', 'Save button', 0.5, 0.5);
saveButtonGraphics.rotation = Math.PI / 4; // Set button at 45 degrees angle
self.on('down', function () {
// Trigger save functionality
game.saveGameState();
});
});
// 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.on('down', function () {
// Load the saved state of blueBlocks and blackBlocks
var savedBlueBlocks = LK.localStorage.getItem('blueBlocks') ? JSON.parse(LK.localStorage.getItem('blueBlocks')) : [];
var savedBlackBlocks = 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) {
createBlueBlock(data.x, data.y);
});
savedBlackBlocks.forEach(function (data) {
createBlackBlock(data.x, data.y);
});
});
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Function to save the current state of blueBlocks and blackBlocks
// Initialize important asset arrays
game.saveGameState = function () {
if (typeof LK.localStorage !== 'undefined') {
LK.localStorage.setItem('blueBlocks', JSON.stringify(blueBlocks.map(function (block) {
return {
x: block.x,
y: block.y
};
})));
}
if (typeof LK.localStorage !== 'undefined') {
LK.localStorage.setItem('blackBlocks', JSON.stringify(blackBlocks.map(function (block) {
return {
x: block.x,
y: block.y
};
})));
}
};
var blueBlocks = [];
var blackBlocks = [];
// Function to handle the creation of blue blocks
function createBlueBlock(x, y) {
var blueBlock = new BlueBlock();
blueBlock.x = x;
blueBlock.y = y;
blueBlock.layer = 1;
blueBlocks.push(blueBlock);
game.addChild(blueBlock);
}
// Function to handle the creation of black blocks
function createBlackBlock(x, y) {
var blackBlock = new BlackBlock();
blackBlock.x = x;
blackBlock.y = y;
blackBlocks.push(blackBlock);
game.addChild(blackBlock);
}
// Event listener for left click to create blue blocks
game.on('down', function (obj) {
var pos = obj.event.getLocalPosition(game);
// Check if the position is not on the load button before creating a block
if (!loadButton.intersects(pos)) {
createBlueBlock(pos.x, pos.y);
}
});
// Event listener for right up to create black blocks
game.on('rightup', function (obj) {
var pos = obj.event.getLocalPosition(game);
// Check if the position is not on the load button before creating a block
if (!loadButton.intersects(pos)) {
createBlackBlock(pos.x, pos.y);
}
});
// Main game update loop
LK.on('tick', function () {
// Update all blue blocks
for (var i = 0; i < blueBlocks.length; i++) {
blueBlocks[i].update();
}
// Update all black blocks
for (var j = 0; j < blackBlocks.length; j++) {
blackBlocks[j].update();
}
}); // Instantiate save and load buttons
var saveButton = new SaveButton();
saveButton.x = LK.gui.bottomLeft.x + saveButton.width / 2;
saveButton.y = LK.gui.bottomLeft.y - saveButton.height / 2;
saveButton.layer = 2;
game.addChild(saveButton);
var loadButton = new LoadButton();
loadButton.x = LK.gui.bottomRight.x - loadButton.width / 2;
loadButton.y = LK.gui.bottomRight.y - loadButton.height / 2;
loadButton.layer = 2;
game.addChild(loadButton);