/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Block = Container.expand(function (blockType) {
var self = Container.call(this);
self.blockType = blockType;
self.isOnFire = false;
self.fireObject = null;
self.fireTimer = 0;
// Create the block visual based on type
var blockAsset = 'grassBlock';
if (blockType === 'stone') blockAsset = 'stoneBlock';else if (blockType === 'wood') blockAsset = 'woodBlock';else if (blockType === 'special') blockAsset = 'specialBlock';else if (blockType === 'iron') blockAsset = 'ironBlock';else if (blockType === 'diamond') blockAsset = 'diamondBlock';else if (blockType === 'lighter') blockAsset = 'lighter';
var blockGraphics = self.attachAsset(blockAsset, {
anchorX: 0.5,
anchorY: 0.5
});
// Add isometric depth effect
var shadowGraphics = self.attachAsset(blockAsset, {
anchorX: 0.5,
anchorY: 0.5,
x: 4,
y: 4,
alpha: 0.3
});
// Animate block placement
self.animatePlace = function () {
blockGraphics.scaleX = 0.1;
blockGraphics.scaleY = 0.1;
tween(blockGraphics, {
scaleX: 1,
scaleY: 1
}, {
duration: 200,
easing: tween.bounceOut
});
};
// Animate block removal
self.animateRemove = function () {
tween(blockGraphics, {
scaleX: 0.1,
scaleY: 0.1,
alpha: 0
}, {
duration: 150,
easing: tween.easeIn,
onFinish: function onFinish() {
self.destroy();
}
});
};
// Set block on fire
self.setOnFire = function () {
if (self.isOnFire) return;
self.isOnFire = true;
self.fireTimer = 0;
self.fireObject = self.attachAsset('fire', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.8,
scaleY: 0.8,
alpha: 0.8
});
// Animate fire flickering
tween(self.fireObject, {
scaleX: 1.2,
scaleY: 1.2,
alpha: 1
}, {
duration: 500,
easing: tween.easeInOut,
onFinish: function onFinish() {
if (self.fireObject) {
tween(self.fireObject, {
scaleX: 0.8,
scaleY: 0.8,
alpha: 0.8
}, {
duration: 500,
easing: tween.easeInOut
});
}
}
});
};
// Extinguish fire
self.extinguishFire = function () {
if (!self.isOnFire) return;
self.isOnFire = false;
self.fireTimer = 0;
if (self.fireObject) {
tween(self.fireObject, {
scaleX: 0.1,
scaleY: 0.1,
alpha: 0
}, {
duration: 200,
easing: tween.easeIn,
onFinish: function onFinish() {
if (self.fireObject) {
self.fireObject.destroy();
self.fireObject = null;
}
}
});
}
};
// Update fire spreading
self.update = function () {
if (self.isOnFire) {
self.fireTimer++;
// Spread fire every 120 ticks (2 seconds)
if (self.fireTimer >= 120) {
self.fireTimer = 0;
spreadFireFromBlock(self);
}
// Animate fire flickering continuously
if (self.fireObject && self.fireTimer % 30 === 0) {
tween(self.fireObject, {
scaleX: 0.8 + Math.random() * 0.4,
scaleY: 0.8 + Math.random() * 0.4,
alpha: 0.7 + Math.random() * 0.3
}, {
duration: 300,
easing: tween.easeInOut
});
}
}
};
return self;
});
var GridSlot = Container.expand(function (gridX, gridY) {
var self = Container.call(this);
self.gridX = gridX;
self.gridY = gridY;
self.hasBlock = false;
self.blockObj = null;
// Background grid visual
var slotGraphics = self.attachAsset('gridSlot', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0
});
self.placeBlock = function (blockType) {
if (self.hasBlock) return false;
self.blockObj = new Block(blockType);
self.addChild(self.blockObj);
self.hasBlock = true;
self.blockObj.animatePlace();
LK.getSound('placeBlock').play();
return true;
};
self.removeBlock = function () {
if (!self.hasBlock) return false;
self.blockObj.animateRemove();
self.hasBlock = false;
self.blockObj = null;
LK.getSound('removeBlock').play();
return true;
};
self.down = function (x, y, obj) {
if (deleteMode) {
// In delete mode, only remove blocks
if (self.hasBlock) {
self.removeBlock();
}
} else if (self.hasBlock && self.blockObj.isOnFire) {
// Extinguish fire when touching burning blocks
self.blockObj.extinguishFire();
} else if (currentSelectedBlock === 'lighter' && self.hasBlock) {
// Lighter ignites existing blocks
self.blockObj.setOnFire();
} else if (currentSelectedBlock) {
if (!self.hasBlock) {
var placed = self.placeBlock(currentSelectedBlock);
// If lighter is placed, immediately set it on fire
if (placed && currentSelectedBlock === 'lighter') {
self.blockObj.setOnFire();
}
}
}
};
return self;
});
var InventorySlot = Container.expand(function (blockType, index) {
var self = Container.call(this);
self.blockType = blockType;
self.index = index;
self.isSelected = false;
// Slot background
var slotBg = self.attachAsset('inventorySlot', {
anchorX: 0.5,
anchorY: 0.5
});
// Selected indicator
var selectedBg = self.attachAsset('inventorySelected', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0
});
// Block preview
var blockAsset = 'grassBlock';
if (blockType === 'stone') blockAsset = 'stoneBlock';else if (blockType === 'wood') blockAsset = 'woodBlock';else if (blockType === 'special') blockAsset = 'specialBlock';else if (blockType === 'iron') blockAsset = 'ironBlock';else if (blockType === 'diamond') blockAsset = 'diamondBlock';else if (blockType === 'lighter') blockAsset = 'lighter';
var blockPreview = self.attachAsset(blockAsset, {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.7,
scaleY: 0.7
});
self.setSelected = function (selected) {
self.isSelected = selected;
selectedBg.alpha = selected ? 1 : 0;
if (selected) {
tween(blockPreview, {
scaleX: 0.8,
scaleY: 0.8
}, {
duration: 150
});
} else {
tween(blockPreview, {
scaleX: 0.7,
scaleY: 0.7
}, {
duration: 150
});
}
};
self.down = function (x, y, obj) {
// If a collection block is selected, swap it with this inventory slot
if (selectedCollectionBlock !== null) {
var oldBlockType = self.blockType;
// Update this inventory slot to the selected collection block
self.blockType = selectedCollectionBlock;
blockTypes[self.index] = selectedCollectionBlock;
// Update the visual
self.destroy();
var newSlot = new InventorySlot(selectedCollectionBlock, self.index);
newSlot.x = self.x;
newSlot.y = self.y;
inventorySlots[self.index] = newSlot;
inventoryContainer.addChild(newSlot);
// Update the collection slot to show the old block type
if (selectedCollectionSlot) {
selectedCollectionSlot.blockType = oldBlockType;
selectedCollectionSlot.setSelected(false);
// Update collection slot visual
var oldBlockAsset = 'grassBlock';
if (oldBlockType === 'stone') oldBlockAsset = 'stoneBlock';else if (oldBlockType === 'wood') oldBlockAsset = 'woodBlock';else if (oldBlockType === 'special') oldBlockAsset = 'specialBlock';else if (oldBlockType === 'iron') oldBlockAsset = 'ironBlock';else if (oldBlockType === 'diamond') oldBlockAsset = 'diamondBlock';
// Remove old block preview and add new one
var children = selectedCollectionSlot.children;
for (var i = children.length - 1; i >= 0; i--) {
if (children[i] !== selectedCollectionSlot.children[0] && children[i] !== selectedCollectionSlot.children[1]) {
children[i].destroy();
}
}
var newBlockPreview = selectedCollectionSlot.attachAsset(oldBlockAsset, {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.7,
scaleY: 0.7
});
}
// Clear selection
selectedCollectionBlock = null;
selectedCollectionSlot = null;
// Select the new inventory slot
selectInventorySlot(self.index);
LK.getSound('selectBlock').play();
} else {
// Normal inventory slot selection
selectInventorySlot(self.index);
// Disable delete mode when selecting inventory slot
if (deleteMode) {
deleteMode = false;
deleteModeButtonBg.tint = 0xffffff;
deleteModeButtonText.setText('DELETE\nMODE');
}
LK.getSound('selectBlock').play();
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Sound effects
// Block assets with different colors and appearances
var gridSize = 80;
var blockSize = 80;
var gridOffsetX = 1024;
var gridOffsetY = 200;
var currentSelectedBlock = 'grass';
var selectedCollectionBlock = null;
var selectedCollectionSlot = null;
// Game state
var gameGrid = [];
var inventorySlots = [];
var blockTypes = ['grass', 'stone', 'wood', 'special'];
// Initialize grid
for (var x = 0; x < gridSize; x++) {
gameGrid[x] = [];
for (var y = 0; y < gridSize; y++) {
var slot = new GridSlot(x, y);
// Calculate isometric position
var isoX = (x - y) * (blockSize / 2);
var isoY = (x + y) * (blockSize / 4);
slot.x = gridOffsetX + isoX;
slot.y = gridOffsetY + isoY;
gameGrid[x][y] = slot;
game.addChild(slot);
}
}
// Create blocks collection area
var blocksContainer = new Container();
blocksContainer.x = 1024;
blocksContainer.y = 2300;
game.addChild(blocksContainer);
// Create blocks collection slots for new blocks
var blocksToCollect = ['iron', 'diamond', 'lighter'];
var blockCollectionSlots = [];
for (var i = 0; i < blocksToCollect.length; i++) {
var blockSlot = new Container();
var blockType = blocksToCollect[i];
// Background
var slotBg = blockSlot.attachAsset('inventorySlot', {
anchorX: 0.5,
anchorY: 0.5
});
// Selected indicator for collection slots
var selectedBg = blockSlot.attachAsset('inventorySelected', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0
});
blockSlot.setSelected = function (selected) {
selectedBg.alpha = selected ? 1 : 0;
if (selected) {
tween(blockPreview, {
scaleX: 0.8,
scaleY: 0.8
}, {
duration: 150
});
} else {
tween(blockPreview, {
scaleX: 0.7,
scaleY: 0.7
}, {
duration: 150
});
}
};
// Block preview
var blockAsset = 'ironBlock';
if (blockType === 'wood') blockAsset = 'woodBlock';else if (blockType === 'diamond') blockAsset = 'diamondBlock';else if (blockType === 'lighter') blockAsset = 'lighter';
var blockPreview = blockSlot.attachAsset(blockAsset, {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.7,
scaleY: 0.7
});
// Position
blockSlot.x = (i - (blocksToCollect.length - 1) / 2) * 120;
blockSlot.y = 0;
blockSlot.blockType = blockType;
// Touch handler to select block for swapping or add to inventory
blockSlot.down = function (x, y, obj) {
var blockType = this.blockType;
// If no block is selected, select this one
if (selectedCollectionBlock === null) {
// Deselect all collection slots
for (var m = 0; m < blockCollectionSlots.length; m++) {
blockCollectionSlots[m].setSelected(false);
}
// Select this slot
selectedCollectionBlock = blockType;
selectedCollectionSlot = this;
this.setSelected(true);
LK.getSound('selectBlock').play();
} else {
// Deselect current selection
selectedCollectionBlock = null;
if (selectedCollectionSlot) {
selectedCollectionSlot.setSelected(false);
}
selectedCollectionSlot = null;
// Check if block type already exists in inventory
var exists = false;
for (var j = 0; j < blockTypes.length; j++) {
if (blockTypes[j] === blockType) {
exists = true;
break;
}
}
if (!exists && blockTypes.length < 4) {
// Add to blockTypes array
blockTypes.push(blockType);
// Create new inventory slot
var newInvSlot = new InventorySlot(blockType, blockTypes.length - 1);
newInvSlot.x = (blockTypes.length - 1 - (blockTypes.length - 1) / 2) * 120;
newInvSlot.y = 0;
inventorySlots.push(newInvSlot);
inventoryContainer.addChild(newInvSlot);
// Update clear button position
clearAllButton.x = (blockTypes.length / 2 + 1) * 120;
// Reposition all inventory slots to center them
for (var k = 0; k < inventorySlots.length; k++) {
inventorySlots[k].x = (k - (blockTypes.length - 1) / 2) * 120;
}
LK.getSound('selectBlock').play();
}
}
};
blockCollectionSlots.push(blockSlot);
blocksContainer.addChild(blockSlot);
}
// Create inventory UI
var inventoryContainer = new Container();
inventoryContainer.x = 1024;
inventoryContainer.y = 2500;
game.addChild(inventoryContainer);
// Create inventory slots (max 4)
var maxInventorySlots = 4;
for (var i = 0; i < Math.min(blockTypes.length, maxInventorySlots); i++) {
var invSlot = new InventorySlot(blockTypes[i], i);
invSlot.x = (i - (Math.min(blockTypes.length, maxInventorySlots) - 1) / 2) * 120;
invSlot.y = 0;
inventorySlots.push(invSlot);
inventoryContainer.addChild(invSlot);
}
// Create blocks toggle button
var blocksToggleButton = new Container();
var blocksButtonBg = blocksToggleButton.attachAsset('inventorySlot', {
anchorX: 0.5,
anchorY: 0.5
});
var blocksButtonText = new Text2('BLOCKS', {
size: 24,
fill: '#ffffff'
});
blocksButtonText.anchor.set(0.5, 0.5);
blocksToggleButton.addChild(blocksButtonText);
blocksToggleButton.x = -(blockTypes.length / 2 + 1) * 120;
blocksToggleButton.y = 0;
inventoryContainer.addChild(blocksToggleButton);
// Create delete mode toggle button
var deleteMode = false;
var deleteModeButton = new Container();
var deleteModeButtonBg = deleteModeButton.attachAsset('clearAllButton', {
anchorX: 0.5,
anchorY: 0.5
});
var deleteModeButtonText = new Text2('DELETE\nMODE', {
size: 20,
fill: '#ffffff'
});
deleteModeButtonText.anchor.set(0.5, 0.5);
deleteModeButton.addChild(deleteModeButtonText);
deleteModeButton.x = (blockTypes.length / 2 + 1) * 120;
deleteModeButton.y = 0;
inventoryContainer.addChild(deleteModeButton);
// Create clear all button
var clearAllButton = new Container();
var clearButtonBg = clearAllButton.attachAsset('clearAllButton', {
anchorX: 0.5,
anchorY: 0.5
});
var clearButtonText = new Text2('CLEAR\nALL', {
size: 24,
fill: '#ffffff'
});
clearButtonText.anchor.set(0.5, 0.5);
clearAllButton.addChild(clearButtonText);
clearAllButton.x = (blockTypes.length / 2 + 2) * 120;
clearAllButton.y = 0;
inventoryContainer.addChild(clearAllButton);
// Delete mode button functionality
deleteModeButton.down = function (x, y, obj) {
deleteMode = !deleteMode;
if (deleteMode) {
deleteModeButtonBg.tint = 0x44ff44;
deleteModeButtonText.setText('DELETE\nON');
// Deselect all inventory slots when in delete mode
for (var i = 0; i < inventorySlots.length; i++) {
inventorySlots[i].setSelected(false);
}
currentSelectedBlock = null;
} else {
deleteModeButtonBg.tint = 0xffffff;
deleteModeButtonText.setText('DELETE\nMODE');
// Select first inventory slot when exiting delete mode
if (inventorySlots.length > 0) {
inventorySlots[0].setSelected(true);
currentSelectedBlock = blockTypes[0];
}
}
LK.getSound('selectBlock').play();
};
clearAllButton.down = function (x, y, obj) {
// Clear all blocks from grid
for (var x = 0; x < gridSize; x++) {
for (var y = 0; y < gridSize; y++) {
if (gameGrid[x][y].hasBlock) {
gameGrid[x][y].removeBlock();
}
}
}
// Save the cleared state
saveGame();
};
// Select first inventory slot by default
inventorySlots[0].setSelected(true);
// Title text
var titleText = new Text2('BlockCraft Builder', {
size: 80,
fill: '#ffffff'
});
titleText.anchor.set(0.5, 0);
LK.gui.top.addChild(titleText);
titleText.y = 50;
// Instructions text
var instructionsText = new Text2('Tap blocks to select, then tap grid to place/remove', {
size: 40,
fill: '#ffffff'
});
instructionsText.anchor.set(0.5, 0);
LK.gui.top.addChild(instructionsText);
instructionsText.y = 150;
// Blocks collection area title
var blocksTitle = new Text2('Tap to add blocks to inventory:', {
size: 36,
fill: '#ffffff'
});
blocksTitle.anchor.set(0.5, 1);
blocksTitle.x = 1024;
blocksTitle.y = 2250;
game.addChild(blocksTitle);
// Blocks UI visibility state
var blocksUIVisible = false;
blocksContainer.alpha = 0;
blocksTitle.alpha = 0;
// Toggle blocks UI function
function toggleBlocksUI() {
blocksUIVisible = !blocksUIVisible;
var targetAlpha = blocksUIVisible ? 1 : 0;
tween(blocksContainer, {
alpha: targetAlpha
}, {
duration: 300
});
tween(blocksTitle, {
alpha: targetAlpha
}, {
duration: 300
});
}
// Add toggle functionality to blocks button
blocksToggleButton.down = function (x, y, obj) {
toggleBlocksUI();
LK.getSound('selectBlock').play();
};
// Functions
function selectInventorySlot(index) {
// Deselect all slots
for (var i = 0; i < inventorySlots.length; i++) {
inventorySlots[i].setSelected(false);
}
// Select the clicked slot
inventorySlots[index].setSelected(true);
currentSelectedBlock = blockTypes[index];
}
// Load saved game state
var savedGrid = storage.savedGrid || {};
for (var x = 0; x < gridSize; x++) {
for (var y = 0; y < gridSize; y++) {
var key = x + '_' + y;
if (savedGrid[key] && savedGrid[key] !== 'grass') {
gameGrid[x][y].placeBlock(savedGrid[key]);
}
}
}
// Remove all existing grass blocks from the grid
for (var x = 0; x < gridSize; x++) {
for (var y = 0; y < gridSize; y++) {
if (gameGrid[x][y].hasBlock && gameGrid[x][y].blockObj.blockType === 'grass') {
gameGrid[x][y].removeBlock();
}
}
}
// Fire spreading function
function spreadFireFromBlock(sourceBlock) {
// Find the grid position of the source block
var sourceX = -1,
sourceY = -1;
for (var x = 0; x < gridSize; x++) {
for (var y = 0; y < gridSize; y++) {
if (gameGrid[x][y].hasBlock && gameGrid[x][y].blockObj === sourceBlock) {
sourceX = x;
sourceY = y;
break;
}
}
if (sourceX !== -1) break;
}
if (sourceX === -1) return;
// Check adjacent blocks (4 directions)
var directions = [{
dx: -1,
dy: 0
},
// left
{
dx: 1,
dy: 0
},
// right
{
dx: 0,
dy: -1
},
// up
{
dx: 0,
dy: 1
} // down
];
for (var i = 0; i < directions.length; i++) {
var newX = sourceX + directions[i].dx;
var newY = sourceY + directions[i].dy;
// Check bounds
if (newX >= 0 && newX < gridSize && newY >= 0 && newY < gridSize) {
var targetSlot = gameGrid[newX][newY];
if (targetSlot.hasBlock && !targetSlot.blockObj.isOnFire) {
// Only spread to flammable blocks (not stone or diamond)
if (targetSlot.blockObj.blockType !== 'stone' && targetSlot.blockObj.blockType !== 'diamond') {
targetSlot.blockObj.setOnFire();
}
}
}
}
}
// Auto-save function
function saveGame() {
var saveData = {};
for (var x = 0; x < gridSize; x++) {
for (var y = 0; y < gridSize; y++) {
if (gameGrid[x][y].hasBlock && gameGrid[x][y].blockObj.blockType !== 'grass') {
var key = x + '_' + y;
saveData[key] = gameGrid[x][y].blockObj.blockType;
}
}
}
storage.savedGrid = saveData;
}
// Auto-save timer
var saveTimer = 0;
game.update = function () {
saveTimer++;
// Auto-save every 3 seconds (180 ticks at 60fps)
if (saveTimer >= 180) {
saveGame();
saveTimer = 0;
}
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Block = Container.expand(function (blockType) {
var self = Container.call(this);
self.blockType = blockType;
self.isOnFire = false;
self.fireObject = null;
self.fireTimer = 0;
// Create the block visual based on type
var blockAsset = 'grassBlock';
if (blockType === 'stone') blockAsset = 'stoneBlock';else if (blockType === 'wood') blockAsset = 'woodBlock';else if (blockType === 'special') blockAsset = 'specialBlock';else if (blockType === 'iron') blockAsset = 'ironBlock';else if (blockType === 'diamond') blockAsset = 'diamondBlock';else if (blockType === 'lighter') blockAsset = 'lighter';
var blockGraphics = self.attachAsset(blockAsset, {
anchorX: 0.5,
anchorY: 0.5
});
// Add isometric depth effect
var shadowGraphics = self.attachAsset(blockAsset, {
anchorX: 0.5,
anchorY: 0.5,
x: 4,
y: 4,
alpha: 0.3
});
// Animate block placement
self.animatePlace = function () {
blockGraphics.scaleX = 0.1;
blockGraphics.scaleY = 0.1;
tween(blockGraphics, {
scaleX: 1,
scaleY: 1
}, {
duration: 200,
easing: tween.bounceOut
});
};
// Animate block removal
self.animateRemove = function () {
tween(blockGraphics, {
scaleX: 0.1,
scaleY: 0.1,
alpha: 0
}, {
duration: 150,
easing: tween.easeIn,
onFinish: function onFinish() {
self.destroy();
}
});
};
// Set block on fire
self.setOnFire = function () {
if (self.isOnFire) return;
self.isOnFire = true;
self.fireTimer = 0;
self.fireObject = self.attachAsset('fire', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.8,
scaleY: 0.8,
alpha: 0.8
});
// Animate fire flickering
tween(self.fireObject, {
scaleX: 1.2,
scaleY: 1.2,
alpha: 1
}, {
duration: 500,
easing: tween.easeInOut,
onFinish: function onFinish() {
if (self.fireObject) {
tween(self.fireObject, {
scaleX: 0.8,
scaleY: 0.8,
alpha: 0.8
}, {
duration: 500,
easing: tween.easeInOut
});
}
}
});
};
// Extinguish fire
self.extinguishFire = function () {
if (!self.isOnFire) return;
self.isOnFire = false;
self.fireTimer = 0;
if (self.fireObject) {
tween(self.fireObject, {
scaleX: 0.1,
scaleY: 0.1,
alpha: 0
}, {
duration: 200,
easing: tween.easeIn,
onFinish: function onFinish() {
if (self.fireObject) {
self.fireObject.destroy();
self.fireObject = null;
}
}
});
}
};
// Update fire spreading
self.update = function () {
if (self.isOnFire) {
self.fireTimer++;
// Spread fire every 120 ticks (2 seconds)
if (self.fireTimer >= 120) {
self.fireTimer = 0;
spreadFireFromBlock(self);
}
// Animate fire flickering continuously
if (self.fireObject && self.fireTimer % 30 === 0) {
tween(self.fireObject, {
scaleX: 0.8 + Math.random() * 0.4,
scaleY: 0.8 + Math.random() * 0.4,
alpha: 0.7 + Math.random() * 0.3
}, {
duration: 300,
easing: tween.easeInOut
});
}
}
};
return self;
});
var GridSlot = Container.expand(function (gridX, gridY) {
var self = Container.call(this);
self.gridX = gridX;
self.gridY = gridY;
self.hasBlock = false;
self.blockObj = null;
// Background grid visual
var slotGraphics = self.attachAsset('gridSlot', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0
});
self.placeBlock = function (blockType) {
if (self.hasBlock) return false;
self.blockObj = new Block(blockType);
self.addChild(self.blockObj);
self.hasBlock = true;
self.blockObj.animatePlace();
LK.getSound('placeBlock').play();
return true;
};
self.removeBlock = function () {
if (!self.hasBlock) return false;
self.blockObj.animateRemove();
self.hasBlock = false;
self.blockObj = null;
LK.getSound('removeBlock').play();
return true;
};
self.down = function (x, y, obj) {
if (deleteMode) {
// In delete mode, only remove blocks
if (self.hasBlock) {
self.removeBlock();
}
} else if (self.hasBlock && self.blockObj.isOnFire) {
// Extinguish fire when touching burning blocks
self.blockObj.extinguishFire();
} else if (currentSelectedBlock === 'lighter' && self.hasBlock) {
// Lighter ignites existing blocks
self.blockObj.setOnFire();
} else if (currentSelectedBlock) {
if (!self.hasBlock) {
var placed = self.placeBlock(currentSelectedBlock);
// If lighter is placed, immediately set it on fire
if (placed && currentSelectedBlock === 'lighter') {
self.blockObj.setOnFire();
}
}
}
};
return self;
});
var InventorySlot = Container.expand(function (blockType, index) {
var self = Container.call(this);
self.blockType = blockType;
self.index = index;
self.isSelected = false;
// Slot background
var slotBg = self.attachAsset('inventorySlot', {
anchorX: 0.5,
anchorY: 0.5
});
// Selected indicator
var selectedBg = self.attachAsset('inventorySelected', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0
});
// Block preview
var blockAsset = 'grassBlock';
if (blockType === 'stone') blockAsset = 'stoneBlock';else if (blockType === 'wood') blockAsset = 'woodBlock';else if (blockType === 'special') blockAsset = 'specialBlock';else if (blockType === 'iron') blockAsset = 'ironBlock';else if (blockType === 'diamond') blockAsset = 'diamondBlock';else if (blockType === 'lighter') blockAsset = 'lighter';
var blockPreview = self.attachAsset(blockAsset, {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.7,
scaleY: 0.7
});
self.setSelected = function (selected) {
self.isSelected = selected;
selectedBg.alpha = selected ? 1 : 0;
if (selected) {
tween(blockPreview, {
scaleX: 0.8,
scaleY: 0.8
}, {
duration: 150
});
} else {
tween(blockPreview, {
scaleX: 0.7,
scaleY: 0.7
}, {
duration: 150
});
}
};
self.down = function (x, y, obj) {
// If a collection block is selected, swap it with this inventory slot
if (selectedCollectionBlock !== null) {
var oldBlockType = self.blockType;
// Update this inventory slot to the selected collection block
self.blockType = selectedCollectionBlock;
blockTypes[self.index] = selectedCollectionBlock;
// Update the visual
self.destroy();
var newSlot = new InventorySlot(selectedCollectionBlock, self.index);
newSlot.x = self.x;
newSlot.y = self.y;
inventorySlots[self.index] = newSlot;
inventoryContainer.addChild(newSlot);
// Update the collection slot to show the old block type
if (selectedCollectionSlot) {
selectedCollectionSlot.blockType = oldBlockType;
selectedCollectionSlot.setSelected(false);
// Update collection slot visual
var oldBlockAsset = 'grassBlock';
if (oldBlockType === 'stone') oldBlockAsset = 'stoneBlock';else if (oldBlockType === 'wood') oldBlockAsset = 'woodBlock';else if (oldBlockType === 'special') oldBlockAsset = 'specialBlock';else if (oldBlockType === 'iron') oldBlockAsset = 'ironBlock';else if (oldBlockType === 'diamond') oldBlockAsset = 'diamondBlock';
// Remove old block preview and add new one
var children = selectedCollectionSlot.children;
for (var i = children.length - 1; i >= 0; i--) {
if (children[i] !== selectedCollectionSlot.children[0] && children[i] !== selectedCollectionSlot.children[1]) {
children[i].destroy();
}
}
var newBlockPreview = selectedCollectionSlot.attachAsset(oldBlockAsset, {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.7,
scaleY: 0.7
});
}
// Clear selection
selectedCollectionBlock = null;
selectedCollectionSlot = null;
// Select the new inventory slot
selectInventorySlot(self.index);
LK.getSound('selectBlock').play();
} else {
// Normal inventory slot selection
selectInventorySlot(self.index);
// Disable delete mode when selecting inventory slot
if (deleteMode) {
deleteMode = false;
deleteModeButtonBg.tint = 0xffffff;
deleteModeButtonText.setText('DELETE\nMODE');
}
LK.getSound('selectBlock').play();
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Sound effects
// Block assets with different colors and appearances
var gridSize = 80;
var blockSize = 80;
var gridOffsetX = 1024;
var gridOffsetY = 200;
var currentSelectedBlock = 'grass';
var selectedCollectionBlock = null;
var selectedCollectionSlot = null;
// Game state
var gameGrid = [];
var inventorySlots = [];
var blockTypes = ['grass', 'stone', 'wood', 'special'];
// Initialize grid
for (var x = 0; x < gridSize; x++) {
gameGrid[x] = [];
for (var y = 0; y < gridSize; y++) {
var slot = new GridSlot(x, y);
// Calculate isometric position
var isoX = (x - y) * (blockSize / 2);
var isoY = (x + y) * (blockSize / 4);
slot.x = gridOffsetX + isoX;
slot.y = gridOffsetY + isoY;
gameGrid[x][y] = slot;
game.addChild(slot);
}
}
// Create blocks collection area
var blocksContainer = new Container();
blocksContainer.x = 1024;
blocksContainer.y = 2300;
game.addChild(blocksContainer);
// Create blocks collection slots for new blocks
var blocksToCollect = ['iron', 'diamond', 'lighter'];
var blockCollectionSlots = [];
for (var i = 0; i < blocksToCollect.length; i++) {
var blockSlot = new Container();
var blockType = blocksToCollect[i];
// Background
var slotBg = blockSlot.attachAsset('inventorySlot', {
anchorX: 0.5,
anchorY: 0.5
});
// Selected indicator for collection slots
var selectedBg = blockSlot.attachAsset('inventorySelected', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0
});
blockSlot.setSelected = function (selected) {
selectedBg.alpha = selected ? 1 : 0;
if (selected) {
tween(blockPreview, {
scaleX: 0.8,
scaleY: 0.8
}, {
duration: 150
});
} else {
tween(blockPreview, {
scaleX: 0.7,
scaleY: 0.7
}, {
duration: 150
});
}
};
// Block preview
var blockAsset = 'ironBlock';
if (blockType === 'wood') blockAsset = 'woodBlock';else if (blockType === 'diamond') blockAsset = 'diamondBlock';else if (blockType === 'lighter') blockAsset = 'lighter';
var blockPreview = blockSlot.attachAsset(blockAsset, {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.7,
scaleY: 0.7
});
// Position
blockSlot.x = (i - (blocksToCollect.length - 1) / 2) * 120;
blockSlot.y = 0;
blockSlot.blockType = blockType;
// Touch handler to select block for swapping or add to inventory
blockSlot.down = function (x, y, obj) {
var blockType = this.blockType;
// If no block is selected, select this one
if (selectedCollectionBlock === null) {
// Deselect all collection slots
for (var m = 0; m < blockCollectionSlots.length; m++) {
blockCollectionSlots[m].setSelected(false);
}
// Select this slot
selectedCollectionBlock = blockType;
selectedCollectionSlot = this;
this.setSelected(true);
LK.getSound('selectBlock').play();
} else {
// Deselect current selection
selectedCollectionBlock = null;
if (selectedCollectionSlot) {
selectedCollectionSlot.setSelected(false);
}
selectedCollectionSlot = null;
// Check if block type already exists in inventory
var exists = false;
for (var j = 0; j < blockTypes.length; j++) {
if (blockTypes[j] === blockType) {
exists = true;
break;
}
}
if (!exists && blockTypes.length < 4) {
// Add to blockTypes array
blockTypes.push(blockType);
// Create new inventory slot
var newInvSlot = new InventorySlot(blockType, blockTypes.length - 1);
newInvSlot.x = (blockTypes.length - 1 - (blockTypes.length - 1) / 2) * 120;
newInvSlot.y = 0;
inventorySlots.push(newInvSlot);
inventoryContainer.addChild(newInvSlot);
// Update clear button position
clearAllButton.x = (blockTypes.length / 2 + 1) * 120;
// Reposition all inventory slots to center them
for (var k = 0; k < inventorySlots.length; k++) {
inventorySlots[k].x = (k - (blockTypes.length - 1) / 2) * 120;
}
LK.getSound('selectBlock').play();
}
}
};
blockCollectionSlots.push(blockSlot);
blocksContainer.addChild(blockSlot);
}
// Create inventory UI
var inventoryContainer = new Container();
inventoryContainer.x = 1024;
inventoryContainer.y = 2500;
game.addChild(inventoryContainer);
// Create inventory slots (max 4)
var maxInventorySlots = 4;
for (var i = 0; i < Math.min(blockTypes.length, maxInventorySlots); i++) {
var invSlot = new InventorySlot(blockTypes[i], i);
invSlot.x = (i - (Math.min(blockTypes.length, maxInventorySlots) - 1) / 2) * 120;
invSlot.y = 0;
inventorySlots.push(invSlot);
inventoryContainer.addChild(invSlot);
}
// Create blocks toggle button
var blocksToggleButton = new Container();
var blocksButtonBg = blocksToggleButton.attachAsset('inventorySlot', {
anchorX: 0.5,
anchorY: 0.5
});
var blocksButtonText = new Text2('BLOCKS', {
size: 24,
fill: '#ffffff'
});
blocksButtonText.anchor.set(0.5, 0.5);
blocksToggleButton.addChild(blocksButtonText);
blocksToggleButton.x = -(blockTypes.length / 2 + 1) * 120;
blocksToggleButton.y = 0;
inventoryContainer.addChild(blocksToggleButton);
// Create delete mode toggle button
var deleteMode = false;
var deleteModeButton = new Container();
var deleteModeButtonBg = deleteModeButton.attachAsset('clearAllButton', {
anchorX: 0.5,
anchorY: 0.5
});
var deleteModeButtonText = new Text2('DELETE\nMODE', {
size: 20,
fill: '#ffffff'
});
deleteModeButtonText.anchor.set(0.5, 0.5);
deleteModeButton.addChild(deleteModeButtonText);
deleteModeButton.x = (blockTypes.length / 2 + 1) * 120;
deleteModeButton.y = 0;
inventoryContainer.addChild(deleteModeButton);
// Create clear all button
var clearAllButton = new Container();
var clearButtonBg = clearAllButton.attachAsset('clearAllButton', {
anchorX: 0.5,
anchorY: 0.5
});
var clearButtonText = new Text2('CLEAR\nALL', {
size: 24,
fill: '#ffffff'
});
clearButtonText.anchor.set(0.5, 0.5);
clearAllButton.addChild(clearButtonText);
clearAllButton.x = (blockTypes.length / 2 + 2) * 120;
clearAllButton.y = 0;
inventoryContainer.addChild(clearAllButton);
// Delete mode button functionality
deleteModeButton.down = function (x, y, obj) {
deleteMode = !deleteMode;
if (deleteMode) {
deleteModeButtonBg.tint = 0x44ff44;
deleteModeButtonText.setText('DELETE\nON');
// Deselect all inventory slots when in delete mode
for (var i = 0; i < inventorySlots.length; i++) {
inventorySlots[i].setSelected(false);
}
currentSelectedBlock = null;
} else {
deleteModeButtonBg.tint = 0xffffff;
deleteModeButtonText.setText('DELETE\nMODE');
// Select first inventory slot when exiting delete mode
if (inventorySlots.length > 0) {
inventorySlots[0].setSelected(true);
currentSelectedBlock = blockTypes[0];
}
}
LK.getSound('selectBlock').play();
};
clearAllButton.down = function (x, y, obj) {
// Clear all blocks from grid
for (var x = 0; x < gridSize; x++) {
for (var y = 0; y < gridSize; y++) {
if (gameGrid[x][y].hasBlock) {
gameGrid[x][y].removeBlock();
}
}
}
// Save the cleared state
saveGame();
};
// Select first inventory slot by default
inventorySlots[0].setSelected(true);
// Title text
var titleText = new Text2('BlockCraft Builder', {
size: 80,
fill: '#ffffff'
});
titleText.anchor.set(0.5, 0);
LK.gui.top.addChild(titleText);
titleText.y = 50;
// Instructions text
var instructionsText = new Text2('Tap blocks to select, then tap grid to place/remove', {
size: 40,
fill: '#ffffff'
});
instructionsText.anchor.set(0.5, 0);
LK.gui.top.addChild(instructionsText);
instructionsText.y = 150;
// Blocks collection area title
var blocksTitle = new Text2('Tap to add blocks to inventory:', {
size: 36,
fill: '#ffffff'
});
blocksTitle.anchor.set(0.5, 1);
blocksTitle.x = 1024;
blocksTitle.y = 2250;
game.addChild(blocksTitle);
// Blocks UI visibility state
var blocksUIVisible = false;
blocksContainer.alpha = 0;
blocksTitle.alpha = 0;
// Toggle blocks UI function
function toggleBlocksUI() {
blocksUIVisible = !blocksUIVisible;
var targetAlpha = blocksUIVisible ? 1 : 0;
tween(blocksContainer, {
alpha: targetAlpha
}, {
duration: 300
});
tween(blocksTitle, {
alpha: targetAlpha
}, {
duration: 300
});
}
// Add toggle functionality to blocks button
blocksToggleButton.down = function (x, y, obj) {
toggleBlocksUI();
LK.getSound('selectBlock').play();
};
// Functions
function selectInventorySlot(index) {
// Deselect all slots
for (var i = 0; i < inventorySlots.length; i++) {
inventorySlots[i].setSelected(false);
}
// Select the clicked slot
inventorySlots[index].setSelected(true);
currentSelectedBlock = blockTypes[index];
}
// Load saved game state
var savedGrid = storage.savedGrid || {};
for (var x = 0; x < gridSize; x++) {
for (var y = 0; y < gridSize; y++) {
var key = x + '_' + y;
if (savedGrid[key] && savedGrid[key] !== 'grass') {
gameGrid[x][y].placeBlock(savedGrid[key]);
}
}
}
// Remove all existing grass blocks from the grid
for (var x = 0; x < gridSize; x++) {
for (var y = 0; y < gridSize; y++) {
if (gameGrid[x][y].hasBlock && gameGrid[x][y].blockObj.blockType === 'grass') {
gameGrid[x][y].removeBlock();
}
}
}
// Fire spreading function
function spreadFireFromBlock(sourceBlock) {
// Find the grid position of the source block
var sourceX = -1,
sourceY = -1;
for (var x = 0; x < gridSize; x++) {
for (var y = 0; y < gridSize; y++) {
if (gameGrid[x][y].hasBlock && gameGrid[x][y].blockObj === sourceBlock) {
sourceX = x;
sourceY = y;
break;
}
}
if (sourceX !== -1) break;
}
if (sourceX === -1) return;
// Check adjacent blocks (4 directions)
var directions = [{
dx: -1,
dy: 0
},
// left
{
dx: 1,
dy: 0
},
// right
{
dx: 0,
dy: -1
},
// up
{
dx: 0,
dy: 1
} // down
];
for (var i = 0; i < directions.length; i++) {
var newX = sourceX + directions[i].dx;
var newY = sourceY + directions[i].dy;
// Check bounds
if (newX >= 0 && newX < gridSize && newY >= 0 && newY < gridSize) {
var targetSlot = gameGrid[newX][newY];
if (targetSlot.hasBlock && !targetSlot.blockObj.isOnFire) {
// Only spread to flammable blocks (not stone or diamond)
if (targetSlot.blockObj.blockType !== 'stone' && targetSlot.blockObj.blockType !== 'diamond') {
targetSlot.blockObj.setOnFire();
}
}
}
}
}
// Auto-save function
function saveGame() {
var saveData = {};
for (var x = 0; x < gridSize; x++) {
for (var y = 0; y < gridSize; y++) {
if (gameGrid[x][y].hasBlock && gameGrid[x][y].blockObj.blockType !== 'grass') {
var key = x + '_' + y;
saveData[key] = gameGrid[x][y].blockObj.blockType;
}
}
}
storage.savedGrid = saveData;
}
// Auto-save timer
var saveTimer = 0;
game.update = function () {
saveTimer++;
// Auto-save every 3 seconds (180 ticks at 60fps)
if (saveTimer >= 180) {
saveGame();
saveTimer = 0;
}
};
minecraft taş blok. In-Game asset. High contrast. No shadows
minecraft tahta blok. In-Game asset. High contrast. No shadows
Minecraft Demir Bloğu. 2D
Minecraft Elmas bloğu. In-Game asset. High contrast. No shadows
Minecraft çim bloğu. In-Game asset. High contrast. No shadows
Minecraft yanma efekti. In-Game asset. 2d. High contrast. No shadows
Minecraft su bloğu. In-Game asset. High contrast. No shadows
Minecraft obsidyen bloğu. mor renkli. In-Game asset. High contrast. No shadows