User prompt
UI arka plan rengini beyaz yap
User prompt
1- UI arka planında bulunan yazıları sil 2- UI arka planını butonların arkasına gönder
User prompt
UI bölgesini bir şey ile doldur
User prompt
kenarda bulunan blok koyulmayan boşluğa da blok koyabilelim
User prompt
breaktan sonra DELETE ALL! diye buton gelsin
User prompt
envanterdeki blok sayısı sınırsız olsun
User prompt
çimenin katmanı 1 olsun
User prompt
Add a land with dirt and Grass
User prompt
çimen bloğu ekle
Code edit (1 edits merged)
Please save this source code
User prompt
Block Builder 2D
Initial prompt
Make me 2d minecraft
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Block = Container.expand(function (blockType) { var self = Container.call(this); this.blockType = blockType; this.gridX = 0; this.gridY = 0; var blockGraphics = self.attachAsset(blockType, { anchorX: 0.5, anchorY: 0.5 }); // Add slight border effect blockGraphics.alpha = 0.9; self.setGridPosition = function (gridX, gridY) { self.gridX = gridX; self.gridY = gridY; self.x = gridX * 80 + 40; self.y = gridY * 80 + 40; }; return self; }); var GridHighlight = Container.expand(function () { var self = Container.call(this); var highlightGraphics = self.attachAsset('highlight', { anchorX: 0.5, anchorY: 0.5 }); highlightGraphics.alpha = 0.3; self.visible = false; self.showAt = function (gridX, gridY) { self.x = gridX * 80 + 40; self.y = gridY * 80 + 40; self.visible = true; }; self.hide = function () { self.visible = false; }; return self; }); var InventorySlot = Container.expand(function (blockType, index) { var self = Container.call(this); this.blockType = blockType; this.count = -1; // Unlimited blocks var slotBackground = self.attachAsset('inventorySlot', { anchorX: 0.5, anchorY: 0.5 }); var blockPreview = self.attachAsset(blockType, { anchorX: 0.5, anchorY: 0.5, scaleX: 0.8, scaleY: 0.8 }); // No count display for unlimited blocks self.x = 150 + index * 120; self.y = 2600; self.updateCount = function (newCount) { // Unlimited blocks - no count updates needed }; self.down = function (x, y, obj) { selectedBlockType = self.blockType; updateSelectedIndicator(); }; return self; }); var ModeButton = Container.expand(function () { var self = Container.call(this); var buttonBackground = self.attachAsset('uiButton', { anchorX: 0.5, anchorY: 0.5 }); var buttonText = new Text2('BUILD', { size: 36, fill: 0xFFFFFF }); buttonText.anchor.set(0.5, 0.5); self.addChild(buttonText); self.x = 1024; self.y = 2500; self.updateMode = function (isBuildMode) { if (isBuildMode) { buttonText.setText('BUILD'); buttonBackground.tint = 0x00AA00; } else { buttonText.setText('BREAK'); buttonBackground.tint = 0xAA0000; } }; self.down = function (x, y, obj) { isBuildMode = !isBuildMode; self.updateMode(isBuildMode); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB }); /**** * Game Code ****/ // Game state variables // Grid-based building blocks // UI elements // Sound effects var gameGrid = {}; var gridWidth = 25; var gridHeight = 30; var isBuildMode = true; var selectedBlockType = 'stone'; // UI elements var gridHighlight; var inventorySlots = []; var modeButton; var selectedIndicator; // Initialize grid highlight gridHighlight = game.addChild(new GridHighlight()); // Initialize inventory var blockTypes = ['stone', 'wood', 'dirt', 'grass']; for (var i = 0; i < blockTypes.length; i++) { var slot = new InventorySlot(blockTypes[i], i); inventorySlots.push(slot); game.addChild(slot); } // Initialize mode button modeButton = game.addChild(new ModeButton()); modeButton.updateMode(isBuildMode); // Selected block indicator selectedIndicator = LK.getAsset('highlight', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.2, scaleY: 1.2 }); selectedIndicator.alpha = 0.5; game.addChild(selectedIndicator); function updateSelectedIndicator() { for (var i = 0; i < inventorySlots.length; i++) { if (inventorySlots[i].blockType === selectedBlockType) { selectedIndicator.x = inventorySlots[i].x; selectedIndicator.y = inventorySlots[i].y; break; } } } updateSelectedIndicator(); function worldToGrid(worldX, worldY) { return { x: Math.floor(worldX / 80), y: Math.floor(worldY / 80) }; } function isValidGridPosition(gridX, gridY) { return gridX >= 0 && gridX < gridWidth && gridY >= 0 && gridY < gridHeight; } function getGridKey(gridX, gridY) { return gridX + ',' + gridY; } function hasBlockAt(gridX, gridY) { return gameGrid[getGridKey(gridX, gridY)] !== undefined; } function getInventorySlot(blockType) { for (var i = 0; i < inventorySlots.length; i++) { if (inventorySlots[i].blockType === blockType) { return inventorySlots[i]; } } return null; } function placeBlock(gridX, gridY, blockType) { if (!isValidGridPosition(gridX, gridY) || hasBlockAt(gridX, gridY)) { return false; } var slot = getInventorySlot(blockType); if (!slot) { return false; } var block = new Block(blockType); block.setGridPosition(gridX, gridY); game.addChild(block); gameGrid[getGridKey(gridX, gridY)] = block; // Keep unlimited blocks - no count decrement LK.getSound('place').play(); // Place animation block.alpha = 0; tween(block, { alpha: 1 }, { duration: 200 }); return true; } function breakBlock(gridX, gridY) { var gridKey = getGridKey(gridX, gridY); var block = gameGrid[gridKey]; if (!block) { return false; } var slot = getInventorySlot(block.blockType); if (slot) { slot.updateCount(slot.count + 1); } LK.getSound('break').play(); // Break animation tween(block, { alpha: 0, scaleX: 0.5, scaleY: 0.5 }, { duration: 200, onFinish: function onFinish() { block.destroy(); } }); delete gameGrid[gridKey]; return true; } var lastHoverGridX = -1; var lastHoverGridY = -1; game.move = function (x, y, obj) { // Only show highlight in build area if (y < 2400) { var gridPos = worldToGrid(x, y); if (isValidGridPosition(gridPos.x, gridPos.y)) { if (gridPos.x !== lastHoverGridX || gridPos.y !== lastHoverGridY) { if (isBuildMode && !hasBlockAt(gridPos.x, gridPos.y)) { gridHighlight.showAt(gridPos.x, gridPos.y); } else if (!isBuildMode && hasBlockAt(gridPos.x, gridPos.y)) { gridHighlight.showAt(gridPos.x, gridPos.y); } else { gridHighlight.hide(); } lastHoverGridX = gridPos.x; lastHoverGridY = gridPos.y; } } else { gridHighlight.hide(); lastHoverGridX = -1; lastHoverGridY = -1; } } else { gridHighlight.hide(); lastHoverGridX = -1; lastHoverGridY = -1; } }; game.down = function (x, y, obj) { // Only allow building/breaking in the main game area if (y < 2400) { var gridPos = worldToGrid(x, y); if (isValidGridPosition(gridPos.x, gridPos.y)) { if (isBuildMode) { placeBlock(gridPos.x, gridPos.y, selectedBlockType); } else { breakBlock(gridPos.x, gridPos.y); } } } }; game.update = function () { // Update game state if needed };
===================================================================
--- original.js
+++ change.js
@@ -16,12 +16,8 @@
anchorY: 0.5
});
// Add slight border effect
blockGraphics.alpha = 0.9;
- // Set grass blocks to render on layer 1
- if (blockType === 'grass') {
- self.zIndex = 1;
- }
self.setGridPosition = function (gridX, gridY) {
self.gridX = gridX;
self.gridY = gridY;
self.x = gridX * 80 + 40;
@@ -49,9 +45,9 @@
});
var InventorySlot = Container.expand(function (blockType, index) {
var self = Container.call(this);
this.blockType = blockType;
- this.count = 10; // Start with 10 of each block type
+ this.count = -1; // Unlimited blocks
var slotBackground = self.attachAsset('inventorySlot', {
anchorX: 0.5,
anchorY: 0.5
});
@@ -60,27 +56,17 @@
anchorY: 0.5,
scaleX: 0.8,
scaleY: 0.8
});
- var countText = new Text2(self.count.toString(), {
- size: 24,
- fill: 0xFFFFFF
- });
- countText.anchor.set(0.5, 0.5);
- countText.x = 30;
- countText.y = 30;
- self.addChild(countText);
+ // No count display for unlimited blocks
self.x = 150 + index * 120;
self.y = 2600;
self.updateCount = function (newCount) {
- self.count = Math.max(0, newCount);
- countText.setText(self.count.toString());
+ // Unlimited blocks - no count updates needed
};
self.down = function (x, y, obj) {
- if (self.count > 0) {
- selectedBlockType = self.blockType;
- updateSelectedIndicator();
- }
+ selectedBlockType = self.blockType;
+ updateSelectedIndicator();
};
return self;
});
var ModeButton = Container.expand(function () {
@@ -122,12 +108,12 @@
/****
* Game Code
****/
-// Sound effects
-// UI elements
-// Grid-based building blocks
// Game state variables
+// Grid-based building blocks
+// UI elements
+// Sound effects
var gameGrid = {};
var gridWidth = 25;
var gridHeight = 30;
var isBuildMode = true;
@@ -195,16 +181,16 @@
if (!isValidGridPosition(gridX, gridY) || hasBlockAt(gridX, gridY)) {
return false;
}
var slot = getInventorySlot(blockType);
- if (!slot || slot.count <= 0) {
+ if (!slot) {
return false;
}
var block = new Block(blockType);
block.setGridPosition(gridX, gridY);
game.addChild(block);
gameGrid[getGridKey(gridX, gridY)] = block;
- slot.updateCount(slot.count - 1);
+ // Keep unlimited blocks - no count decrement
LK.getSound('place').play();
// Place animation
block.alpha = 0;
tween(block, {
@@ -280,45 +266,7 @@
}
}
}
};
-// Generate initial land with dirt and grass blocks
-function generateInitialLand() {
- // Create a basic landscape with dirt base and grass on top
- var landHeight = 5; // Height of dirt layer
- var grassHeight = 2; // Height of grass layer on top
- // Generate dirt base layer
- for (var x = 0; x < gridWidth; x++) {
- for (var y = gridHeight - landHeight; y < gridHeight; y++) {
- var block = new Block('dirt');
- block.setGridPosition(x, y);
- game.addChild(block);
- gameGrid[getGridKey(x, y)] = block;
- }
- }
- // Generate grass layer on top of dirt
- for (var x = 0; x < gridWidth; x++) {
- for (var y = gridHeight - landHeight - grassHeight; y < gridHeight - landHeight; y++) {
- var block = new Block('grass');
- block.setGridPosition(x, y);
- game.addChild(block);
- gameGrid[getGridKey(x, y)] = block;
- }
- }
- // Add some variation with scattered grass blocks
- for (var x = 0; x < gridWidth; x += 3) {
- if (Math.random() > 0.3) {
- var extraY = gridHeight - landHeight - grassHeight - 1;
- if (extraY >= 0 && !hasBlockAt(x, extraY)) {
- var block = new Block('grass');
- block.setGridPosition(x, extraY);
- game.addChild(block);
- gameGrid[getGridKey(x, extraY)] = block;
- }
- }
- }
-}
-// Generate the initial land when game starts
-generateInitialLand();
game.update = function () {
// Update game state if needed
};
\ No newline at end of file