User prompt
Bloklar kısmındaki odun bloğunu kaldır
User prompt
Bloklar kısmındaki bir bloğu seçip envanterdeki bir bloğa dokunduğumuzda bloklar minecraft'taki gibi yer değiştirsin. Envantere geçen bloğu kullanalım
User prompt
Bloğu değiştirmek için minecrafttaki mekaniği kullan
User prompt
Bloklar kısmı 1 tuşa basınca aynı minecraft'taki gibi bir bölmede çıksın. Envanter 4 slot olsun. Değişen blok bloklar kısmına gitsin
User prompt
Oyuna bloklar kısmı ekle. Oraya dokunduğumuzda envanterimizde olmayan Demir, Bloğu, Odun Bloğu, Elmas Bloğunu envanterimize ekleyebilelim ve kullanabilelim
User prompt
Tüm blokları silme tuşu ekle
User prompt
çift tıklayarak bir alan belirleyebilelim. O yerdeki tüm blokları silebilelim veya bir bloktan seçilen her yere ekleyebilelim
User prompt
Oyuna bloklar katalogu ekle. Oraya farklı bloklar ekle . O blokları envantere ekleyebilelim
Code edit (1 edits merged)
Please save this source code
User prompt
BlockCraft Builder
Initial prompt
Minecraft 2
/****
* 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;
// 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';
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();
}
});
};
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.1
});
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 (currentSelectedBlock) {
if (!self.hasBlock) {
self.placeBlock(currentSelectedBlock);
} else {
self.removeBlock();
}
}
};
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';
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) {
selectInventorySlot(self.index);
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 = 20;
var blockSize = 80;
var gridOffsetX = 1024;
var gridOffsetY = 400;
var currentSelectedBlock = 'grass';
// 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', 'wood', 'diamond'];
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
});
// Block preview
var blockAsset = 'ironBlock';
if (blockType === 'wood') blockAsset = 'woodBlock';else if (blockType === 'diamond') blockAsset = 'diamondBlock';
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 add to inventory
blockSlot.down = function (x, y, obj) {
var blockType = this.blockType;
// 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 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 + 1) * 120;
clearAllButton.y = 0;
inventoryContainer.addChild(clearAllButton);
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]) {
gameGrid[x][y].placeBlock(savedGrid[key]);
}
}
}
// 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) {
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;
}
}; ===================================================================
--- original.js
+++ change.js
@@ -153,10 +153,10 @@
/****
* Game Code
****/
-// Block assets with different colors and appearances
// Sound effects
+// Block assets with different colors and appearances
var gridSize = 20;
var blockSize = 80;
var gridOffsetX = 1024;
var gridOffsetY = 400;
@@ -218,9 +218,9 @@
exists = true;
break;
}
}
- if (!exists) {
+ if (!exists && blockTypes.length < 4) {
// Add to blockTypes array
blockTypes.push(blockType);
// Create new inventory slot
var newInvSlot = new InventorySlot(blockType, blockTypes.length - 1);
@@ -244,16 +244,32 @@
var inventoryContainer = new Container();
inventoryContainer.x = 1024;
inventoryContainer.y = 2500;
game.addChild(inventoryContainer);
-// Create inventory slots
-for (var i = 0; i < blockTypes.length; i++) {
+// 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 - (blockTypes.length - 1) / 2) * 120;
+ 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 clear all button
var clearAllButton = new Container();
var clearButtonBg = clearAllButton.attachAsset('clearAllButton', {
anchorX: 0.5,
@@ -306,8 +322,32 @@
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++) {
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