Code edit (3 edits merged)
Please save this source code
User prompt
for the effect of continuity remove 1 block from bottom of the stack when stacked blocks exceed 5. when you remove the block remove it witha slide animation. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
stacked blocks are going up instead of going down.
Code edit (3 edits merged)
Please save this source code
User prompt
Please fix the bug: 'LK.Container is not a constructor' in or related to this line: 'var gameContainer = new LK.Container(); // Container to hold all game elements that move' Line Number: 71
User prompt
Please fix the bug: 'LK.Container is not a constructor' in or related to this line: 'var gameContainer = new LK.Container(); // Container to hold all game elements that move' Line Number: 71
User prompt
Please fix the bug: 'LK.Game.Container is not a constructor' in or related to this line: 'var gameContainer = new LK.Game.Container(); // Container to hold all game elements that move' Line Number: 71
User prompt
Please fix the bug: 'LK.Container is not a constructor' in or related to this line: 'var gameContainer = new LK.Container(); // Container to hold all game elements that move' Line Number: 71
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: rope is undefined' in or related to this line: 'rope.scaleY = Math.sqrt(Math.pow(currentBlock.x - crane.x, 2) + Math.pow(currentBlock.y - crane.y, 2)) / 100;' Line Number: 148
User prompt
Please fix the bug: 'TypeError: rope is undefined' in or related to this line: 'rope.scaleY = Math.sqrt(Math.pow(currentBlock.x - crane.x, 2) + Math.pow(currentBlock.y - crane.y, 2)) / 100;' Line Number: 147
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: rope is undefined' in or related to this line: 'rope.scaleY = Math.sqrt(Math.pow(currentBlock.x - crane.x, 2) + Math.pow(currentBlock.y - crane.y, 2)) / 100;' Line Number: 148
User prompt
Please fix the bug: 'TypeError: rope is undefined' in or related to this line: 'rope.scaleY = Math.sqrt(Math.pow(currentBlock.x - crane.x, 2) + Math.pow(currentBlock.y - crane.y, 2)) / 100;' Line Number: 147
User prompt
there should be only 1 rope but there are too many ropes and rope is not connected to the block. fix that please
User prompt
rope between the block and crane is not visible. can you add something visual for that? i added asset image named rope
User prompt
i created asset named rope. now implement it please
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: game.camera is undefined' in or related to this line: 'game.camera.y += (targetY - game.camera.y) * cameraFollowSpeed;' Line Number: 141
Code edit (2 edits merged)
Please save this source code
User prompt
then just make infinite
User prompt
okay so red block for crane shouldnt on the screen visible so put it way back on top and make rope longer
User prompt
make swinging slower and increase the range
Code edit (2 edits merged)
Please save this source code
===================================================================
--- original.js
+++ change.js
@@ -60,26 +60,27 @@
/****
* Game Code
****/
// Initialize variables
-var gameContainer = new LK.Game.Container(); // Container to hold all game elements that move
-game.addChild(gameContainer);
-var crane = gameContainer.addChild(new Crane());
-var baseBlock = gameContainer.addChild(new BaseBlock());
+var crane = game.addChild(new Crane());
+var baseBlock = game.addChild(new BaseBlock());
baseBlock.x = 2048 / 2;
baseBlock.y = 2732 - baseBlock.height / 2;
crane.x = 2048 / 2;
crane.y = 50; // Move the crane up
var blocks = [];
var currentBlock = null;
+var towerHeight = 0;
var scoreTxt = new Text2('0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var rope = null; // Define rope in the global scope
-var worldShiftSpeed = 10; // Adjust as needed
+// NEW: Target Y for smooth upward movement
+var towerTargetY = baseBlock.y;
+var towerMoveSpeed = 0.1; // Adjust for desired smoothness
// Function to drop a block
function dropBlock() {
if (currentBlock && !currentBlock.falling) {
currentBlock.falling = true;
@@ -88,9 +89,9 @@
currentBlock.momentum = horizontalSpeed;
blocks.push(currentBlock);
// Remove the rope when the block is dropped
if (rope) {
- gameContainer.removeChild(rope);
+ game.removeChild(rope);
rope = null;
}
currentBlock = null;
}
@@ -100,84 +101,90 @@
for (var i = blocks.length - 1; i >= 0; i--) {
if (!blocks[i].falling) {
continue;
}
- // Collision with the base block
if (blocks[i].intersects(baseBlock)) {
blocks[i].falling = false;
blocks[i].y = baseBlock.y - baseBlock.height / 2 - blocks[i].height / 2;
- LK.setScore(blocks.length);
+ // NEW: Trigger upward movement
+ towerHeight++;
+ LK.setScore(towerHeight);
scoreTxt.setText(LK.getScore());
- shiftWorldUp(); // Shift the world up after successful placement
+ towerTargetY -= 100; // Move the target up by the height of a block
} else {
- // Collision with other blocks
for (var j = 0; j < blocks.length; j++) {
- if (i !== j && blocks[i].falling && !blocks[j].falling && blocks[i].intersects(blocks[j])) {
+ if (i !== j && blocks[i].falling && blocks[j].y < 2732 && !blocks[j].falling && blocks[i].intersects(blocks[j])) {
blocks[i].falling = false;
blocks[i].y = blocks[j].y - blocks[j].height / 2 - blocks[i].height / 2;
- LK.setScore(blocks.length);
+ // NEW: Trigger upward movement
+ towerHeight++;
+ LK.setScore(towerHeight);
scoreTxt.setText(LK.getScore());
- shiftWorldUp(); // Shift the world up after successful placement
+ towerTargetY -= 100; // Move the target up by the height of a block
break;
}
}
- // Block lost if it goes below the screen (adjust threshold as needed)
- if (blocks[i].falling && blocks[i].y > 2732 + 500) {
- // Added some tolerance
- gameContainer.removeChild(blocks[i]);
+ if (blocks[i].falling && blocks[i].y > 2732) {
+ game.removeChild(blocks[i]);
blocks.splice(i, 1);
console.log("Block lost!");
}
}
}
}
-// Function to shift the game world upwards
-function shiftWorldUp() {
- gameContainer.y -= 100; // Shift up by the height of a block
- // Optionally reposition the crane to stay within view
- crane.y += 100;
-}
// Game update loop
game.update = function () {
crane.update();
if (!currentBlock) {
- currentBlock = gameContainer.addChild(new Block()); // Add new block to the container
- // Position the new block at the crane's position initially
- currentBlock.x = crane.x;
- currentBlock.y = crane.y + 100 + currentBlock.height / 2; // Start above the crane visually
+ currentBlock = new Block();
+ game.addChild(currentBlock);
// Add rope between the block and crane
rope = new Container();
var ropeGraphics = rope.attachAsset('rope', {
anchorX: 0.5,
anchorY: 0.0,
- height: 100 // Initial height
+ height: 200 // Initial height
});
rope.x = crane.x;
- rope.y = crane.y + crane.height / 2; // Attach to the bottom of the crane
+ rope.y = crane.y;
rope.rotation = crane.rotation;
- gameContainer.addChild(rope);
+ game.addChild(rope);
// Position the new block at the end of the rope
- var ropeLength = 100;
+ var ropeLength = 200;
currentBlock.x = crane.x + Math.sin(crane.rotation) * ropeLength;
- currentBlock.y = crane.y + crane.height / 2 + Math.cos(crane.rotation) * ropeLength;
+ currentBlock.y = crane.y + Math.cos(crane.rotation) * ropeLength;
} else if (!currentBlock.falling) {
// Update the block's position to stay synced with the crane
- var ropeLength = 100;
+ var ropeLength = 200;
currentBlock.x = crane.x + Math.sin(crane.rotation) * ropeLength;
- currentBlock.y = crane.y + crane.height / 2 + Math.cos(crane.rotation) * ropeLength;
+ currentBlock.y = crane.y + Math.cos(crane.rotation) * ropeLength;
// Update the rope's position and rotation
if (rope) {
rope.x = crane.x;
- rope.y = crane.y + crane.height / 2;
- rope.rotation = Math.atan2(currentBlock.y - rope.y, currentBlock.x - rope.x);
- rope.children[0].height = Math.sqrt(Math.pow(currentBlock.x - rope.x, 2) + Math.pow(currentBlock.y - rope.y, 2));
- rope.pivot.y = 0;
+ rope.y = crane.y;
+ rope.rotation = crane.rotation;
+ rope.children[0].height = ropeLength; // Update the height of the rope graphic
+ // Adjust rope's position to connect to the block
+ rope.pivot.y = 0; // Pivot at the top
+ rope.scaleY = ropeLength / 100; // Scale the rope height
+ rope.rotation = Math.atan2(currentBlock.y - crane.y, currentBlock.x - crane.x);
}
}
if (currentBlock) {
currentBlock.update();
}
checkCollisions();
+ // NEW: Smoothly move the tower upwards
+ if (baseBlock.y > towerTargetY) {
+ var dy = (towerTargetY - baseBlock.y) * towerMoveSpeed;
+ baseBlock.y += dy;
+ blocks.forEach(function (block) {
+ block.y += dy;
+ });
+ if (rope) {
+ rope.y += dy; // Move the rope up as well
+ }
+ }
};
// Event listener for dropping blocks
game.down = function (x, y, obj) {
dropBlock();