User prompt
Make the score text bigger
User prompt
Make the current background bigger
Code edit (2 edits merged)
Please save this source code
User prompt
Could you add an intresting background the matches the theme of the game
User prompt
Can you make the color of the playerblock change after each placment
User prompt
Make the player go faster every 10 stacks
Code edit (1 edits merged)
Please save this source code
User prompt
Add a *Grace period*
User prompt
Could you make it so less of the blocks have to touch for it to count as an overlap
User prompt
Can you make the color of the block change after each placment
User prompt
Make it so when the player's position is reseted to the start it will always go right
User prompt
Remove the game over cause text
User prompt
Make the starting block not count as a score point
User prompt
Make the score bigger
User prompt
Can you move the score a little more down
User prompt
Can you move the score down
User prompt
Reset the player position on each placement until it is game over
User prompt
Make it so if you lose the player will stay where it is
User prompt
Move the starting block under the playerblock
User prompt
Can you move the playerblock up by its height
User prompt
Can you move everything up by twice one block's height
User prompt
Can you move the starting block down until it's exactly under the playerBlock
User prompt
Can you move the starting block up by 1/8 of its height
User prompt
Can you move the starting block up by 1/16 of its height
/**** * Classes ****/ // Assets will be automatically created and loaded by the LK engine based on usage in the code. // Block class for stackable game blocks var Block = Container.expand(function () { var self = Container.call(this); // Attach a square asset to represent the block var blockGraphics = self.attachAsset('block', { width: 600, height: 150, color: 0xFFFFFF, shape: 'box', anchorX: 0.5, anchorY: 0.5 }); }); // HeightIndicator class for the height indicator var HeightIndicator = Container.expand(function () { var self = Container.call(this); // Attach a Text2 object to represent the height indicator var heightIndicatorText = new Text2('0', { size: 100, fill: "#ffffff" }); self.addChild(heightIndicatorText); // Update method called every game tick self.update = function () { // Update the text to display the current height heightIndicatorText.setText(blocks.length - 1); }; }); // Player class for the block that the player controls var PlayerBlock = Container.expand(function () { var self = Container.call(this); // Attach a square asset to represent the player block var playerBlockGraphics = self.attachAsset('playerBlock', { width: 600, height: 150, color: 0xFFD700, shape: 'box', anchorX: 0.5, anchorY: 0.5 }); // Set initial speed for horizontal movement self.speed = 5; // Direction of movement, 1 for right, -1 for left self.direction = 1; // Update method called every game tick self.update = function () { // Move the player block left or right self.x += self.speed * self.direction; // Reverse direction when hitting screen bounds if (self.x <= 300 || self.x >= 1748) { self.direction *= -1; } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ // Initialize height indicator var heightIndicator = game.addChild(new HeightIndicator()); // Set initial position of the height indicator heightIndicator.x = 1024; // Center of the screen heightIndicator.y = 100; // Position the score display a little more down on the screen // Initialize player block var playerBlock = game.addChild(new PlayerBlock()); // Set initial position of the player block playerBlock.x = 512; // More on the left of the screen playerBlock.y = 966; // Moved up by its height from its previous position // Initialize an array to keep track of stacked blocks var blocks = []; // Add a starting block to the game addBlock(); // Function to add a new block to the stack function addBlock() { var block = new Block(); // Change the color of the block after each placement var colors = [0x15b523, 0x4b2b81, 0xf65884, 0xFFD700, 0xFFFFFF]; var currentColorIndex = blocks.length % colors.length; block.attachAsset('block', { width: 600, height: 150, color: colors[currentColorIndex], shape: 'box', anchorX: 0.5, anchorY: 0.5 }); if (blocks.length == 0) { block.x = 1024; // Set the new block's position to the center of the screen } else { block.x = playerBlock.x; // Set the new block's position to the player block's current position } block.y = playerBlock.y + playerBlock.height; // Move the starting block under the playerBlock blocks.push(block); // Add the new block to the array game.addChild(block); // Add the new block to the game // Move all existing blocks down for (var i = 0; i < blocks.length - 1; i++) { blocks[i].y += 150; } // Adjust the size and position of the block based on the block directly under it if (blocks.length > 1) { var directlyUnderBlock = blocks[blocks.length - 2]; var deltaX = block.x - directlyUnderBlock.x; if (Math.abs(deltaX) < directlyUnderBlock.width) { // If there is a block directly under it, adjust the width and position based on the overlap var newWidth = Math.min(block.width, directlyUnderBlock.width - Math.abs(deltaX)); block.width = newWidth; block.x = directlyUnderBlock.x + deltaX / 2; playerBlock.width = newWidth; playerBlock.x = directlyUnderBlock.x + deltaX / 2; } else { // If there is no block directly under it, consider it a miss and trigger game over logic LK.showGameOver(); } } // Removed the overlap check with all other blocks except the last one } // Event listener for touch or mouse down to place the player block var canPlaceBlock = true; game.down = function (x, y, obj) { if (canPlaceBlock) { addBlock(); // Add the current player block to the stack playerBlock.x = 512; // Reset player block to its starting position on each placement playerBlock.direction = 1; // Ensure player block always starts moving right canPlaceBlock = false; LK.setTimeout(function () { canPlaceBlock = true; }, 100); // Check if the placed block is overlapping with any other blocks var isOverlapping = false; for (var i = 0; i < blocks.length - 1; i++) { // Calculate the overlap between the current block and the previous block var overlap = Math.abs(blocks[blocks.length - 1].x - blocks[i].x); // If the overlap is less than the width of the block, they are overlapping // Decrease the required overlap for a successful placement if (overlap < blocks[blocks.length - 1].width * 0.75) { isOverlapping = true; break; } } // If the placed block is not overlapping with any other blocks and it's not the first block, end the game // Add a grace period of 500ms before checking for overlap LK.setTimeout(function () { if (!isOverlapping && blocks.length > 1) { LK.showGameOver(); } }, 500); } }; // Update function called every game tick game.update = function () { // Removed the game over condition when the score reaches 20 // Update the height indicator heightIndicator.update(); }; // Note: The game does not handle dynamic resizing, orientation changes, or provide pause functionality as per the LK engine's automatic handling.
===================================================================
--- original.js
+++ change.js
@@ -148,13 +148,14 @@
break;
}
}
// If the placed block is not overlapping with any other blocks and it's not the first block, end the game
+ // Add a grace period of 500ms before checking for overlap
LK.setTimeout(function () {
if (!isOverlapping && blocks.length > 1) {
LK.showGameOver();
}
- }, 32);
+ }, 500);
}
};
// Update function called every game tick
game.update = function () {