User prompt
Right now we should fix the overlap. The blocks are getting bigger
Code edit (5 edits merged)
Please save this source code
User prompt
could you add so after each block placement there is a delay of 32 ms before checking if the blocks are touching
Code edit (4 edits merged)
Please save this source code
User prompt
Could you redo the code between lines 119 and 125 just in case
Code edit (1 edits merged)
Please save this source code
User prompt
Could you add so after each block placement the player has to wait like 0.1 seconds before placing a block again
User prompt
I still don't know what the issue is, I'm hoping that you know and if you do can you fix it
User prompt
Could you make it so if the placed block doesn't touch any blocks the game ends
User prompt
Could you make it so the overlap calculation accurately reflects the actual physical overlap between the blocks
User prompt
Create a new method to cut off the part of the block that isn't touching the last placed block
User prompt
Make it so the placed block is the same size as the playerBlock
User prompt
Make the size of the playerblock match the size of the last placed block
User prompt
Create a new method to cut off the part of the block that doesn't have a block under it
User prompt
Can you make a starting box that in already in place
User prompt
Could you make the game not end by hitting 20 score
User prompt
Right now the player can go halfway into the edge. If the player touches the edge it should change direction
User prompt
Now the blocks are a little too big. Could you make them a little bit smaller
User prompt
Can you make the blocks twice as big so it would be better to see them
User prompt
Every time a new block is placed the old ones have to go down
User prompt
Con you put the player in the middle
User prompt
Right now the blocks are going on top of the player, but they need to go under the player
User prompt
The player shouldn't move up at all. The 'playerBlock' y axis has to be the same all the time
User prompt
Please fix the bug: 'TypeError: heightIndicatorText.setText is not a function. (In 'heightIndicatorText.setText(blocks.length)', 'heightIndicatorText.setText' is undefined)' in or related to this line: 'heightIndicatorText.setText(blocks.length);' Line Number: 37
User prompt
What if the blocks moved down and the player is stationary. To keep track of height it's possible to put a number at the top
/****
* 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: 50,
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);
};
});
// 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; // Near the top
// Initialize player block
var playerBlock = game.addChild(new PlayerBlock());
// Set initial position of the player block
playerBlock.x = 1024; // Center of the screen
playerBlock.y = 1366; // Middle of the screen
// 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();
block.x = playerBlock.x; // Set the new block's position to the player block's current position
block.y = playerBlock.y + 150; // Position it under the player block
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;
}
// Cut off the part of the block that doesn't have a block under it and adjust the size of the player block
if (blocks.length > 1) {
var previousBlock = blocks[blocks.length - 2];
var overlap = block.x - previousBlock.x;
if (overlap > 0) {
block.width -= overlap;
block.x -= overlap / 2;
} else if (overlap < 0) {
block.width += Math.abs(overlap);
block.x += Math.abs(overlap) / 2;
}
// Update the size of the player block to match the size of the overlap with the last placed block
playerBlock.width = Math.abs(overlap);
}
// Update the size of the placed block to match the size of the player block
block.width = playerBlock.width;
// Check if the placed block is touching any other blocks
var isTouching = false;
for (var i = 0; i < blocks.length - 1; i++) {
if (block.intersects(blocks[i])) {
isTouching = true;
break;
}
}
// If the placed block is not touching any other blocks and it's not the first block, end the game
if (!isTouching && blocks.length > 1) {}
}
// 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
canPlaceBlock = false;
LK.setTimeout(function () {
canPlaceBlock = true;
}, 100);
// Check if the placed block is touching any other blocks
var isTouching = false;
for (var i = 0; i < blocks.length - 1; i++) {
if (blocks[blocks.length - 1].intersects(blocks[i])) {
isTouching = true;
break;
}
}
// If the placed block is not touching any other blocks and it's not the first block, end the game
LK.setTimeout(function () {
if (!isTouching && blocks.length > 1) {}
}, 32);
}
};
// 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
@@ -69,9 +69,9 @@
****/
// Initialize height indicator
var heightIndicator = game.addChild(new HeightIndicator());
// Set initial position of the height indicator
-heightIndicator.x = 124; // Center of the screen
+heightIndicator.x = 1024; // Center of the screen
heightIndicator.y = 100; // Near the top
// Initialize player block
var playerBlock = game.addChild(new PlayerBlock());
// Set initial position of the player block
@@ -102,10 +102,10 @@
} else if (overlap < 0) {
block.width += Math.abs(overlap);
block.x += Math.abs(overlap) / 2;
}
- // Update the size of the player block to match the size of the last placed block
- playerBlock.width = block.width;
+ // Update the size of the player block to match the size of the overlap with the last placed block
+ playerBlock.width = Math.abs(overlap);
}
// Update the size of the placed block to match the size of the player block
block.width = playerBlock.width;
// Check if the placed block is touching any other blocks
@@ -137,11 +137,9 @@
}
}
// If the placed block is not touching any other blocks and it's not the first block, end the game
LK.setTimeout(function () {
- if (!isTouching && blocks.length > 1) {
- LK.showGameOver();
- }
+ if (!isTouching && blocks.length > 1) {}
}, 32);
}
};
// Update function called every game tick