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
User prompt
okay good but when i release the block the momentum from swing is not effecting where block is going to land.fix it
User prompt
there is no way for me to loose even though crane and the block attached to crane moves it always stack perfectly. to fix that you should wiggle crane wider so there would be a chance that when i drop the block it wouldnt have landed on any previous block and i would loose. crane block should be connected to block attached with a rope or something so it wiggles and has big range.
Code edit (1 edits merged)
Please save this source code
User prompt
not enough range. the crane as you put it should not stay in its place. think of that crane like a you know rope of the crane.
User prompt
there is no way for me to loose even though crane and the block attached to crane moves it always stack perfectly. to fix that you should wiggle crane wider so there would be a chance that when i drop the block it wouldnt have landed on any previous block and i would loose
User prompt
Please fix the bug: 'TypeError: blocks[i].graphics is undefined' in or related to this line: 'blocks[i].graphics.scaleX = blocks[i].width / originalWidth; // Update the visual width' Line Number: 120
Code edit (2 edits merged)
Please save this source code
User prompt
i dont see any difference with blocks. they are not truncated. you should cut the parts wheere it doesnt align with previous block. please fix it
User prompt
okay so crane is wiggling way too fast. make it slower. and there is no way for me to loose even though crane and the block attached to crane moves it always stack perfectly. to fix that you should do something like this: truncate part of the block where it doesnt align with previous block.
User prompt
okay so block on the crane doesnt move synced with crane itself. fix that also make all blocks little bigger
Code edit (1 edits merged)
Please save this source code
User prompt
okay now it falls after but there is another problem. it goes through other blocks instead of stacking.
User prompt
okay so issue persists. when first block makes contact with the base block other blocks i drop are just stuck with the crane. also it looks like game is paused or something because other falling blocks stop when first block makes contact with base block.
User prompt
after first blocks makes contact with the base block on bottom other blocks are not falling.
User prompt
when a block reaches to bottom the game kind of stops. i mean when i drop other blocks they are not falling they are just stuck on crane. you can fix it by adding a base block where player stacks the blocks onto. oh and when you are adding that make sure they dont go through themselves and stack
User prompt
when a block reaches bottom the game stops and i cant release any more blocks. fix that.
User prompt
the block i dropped from crane goes through basis block. it should stack instead.
===================================================================
--- original.js
+++ change.js
@@ -19,8 +19,9 @@
scaleY: 2
});
self.falling = false;
self.speed = 5;
+ self.momentum = 0; // Initialize momentum
self.update = function () {
if (self.falling) {
self.y += self.speed;
self.x += self.momentum;
@@ -38,8 +39,9 @@
});
self.angle = 0;
self.speed = 0.03;
self.direction = 1;
+ self.ropeLength = 200; // Define rope length
self.update = function () {
self.angle += self.speed * self.direction;
if (self.angle > 1.5 || self.angle < -1.5) {
self.direction *= -1;
@@ -51,20 +53,23 @@
/****
* Initialize Game
****/
var game = new LK.Game({
- backgroundColor: 0x87CEEB // Sky blue background
+ backgroundColor: 0x87CEEB,
+ // Sky blue background
+ width: 2048,
+ height: 2732
});
/****
* Game Code
****/
// Initialize variables
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;
+baseBlock.x = game.width / 2;
+baseBlock.y = game.height - baseBlock.height / 2;
+crane.x = game.width / 2;
crane.y = 50; // Move the crane up
var blocks = [];
var currentBlock = null;
var towerHeight = 0;
@@ -73,14 +78,17 @@
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
+// Camera settings
+var cameraFollowSpeed = 0.05; // Adjust for smoother camera movement
+var cameraOffset = 500; // Offset to keep the player in view
// Function to drop a block
function dropBlock() {
if (currentBlock && !currentBlock.falling) {
currentBlock.falling = true;
// Calculate the horizontal speed based on the crane's angular velocity
- var horizontalSpeed = Math.sin(crane.rotation) * crane.speed * 10; // Reduced scaling factor
+ var horizontalSpeed = Math.sin(crane.rotation) * crane.speed * 500; // Adjust scaling factor as needed
currentBlock.momentum = horizontalSpeed;
blocks.push(currentBlock);
currentBlock = null;
}
@@ -92,46 +100,62 @@
continue;
}
if (blocks[i].intersects(baseBlock)) {
blocks[i].falling = false;
- blocks[i].y = baseBlock.y - baseBlock.height / 2 - blocks[i].height / 2 - towerHeight * 100;
+ blocks[i].y = baseBlock.y - baseBlock.height / 2 - blocks[i].height / 2;
towerHeight++;
LK.setScore(towerHeight);
scoreTxt.setText(LK.getScore());
} else {
for (var j = 0; j < blocks.length; j++) {
- if (i !== j && blocks[i].falling && blocks[j].y < 2732 && !blocks[j].falling && blocks[i].intersects(blocks[j])) {
+ if (i !== j && blocks[i].falling && blocks[j].y < game.height && !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;
break;
}
}
- if (blocks[i].falling && blocks[i].y > 2732) {
+ if (blocks[i].falling && blocks[i].y > game.height) {
game.removeChild(blocks[i]);
blocks.splice(i, 1);
console.log("Block lost!");
}
}
}
}
+// Function to update camera position
+function updateCamera() {
+ var targetY;
+ if (blocks.length > 0) {
+ // Follow the latest placed block, with an offset
+ targetY = blocks[blocks.length - 1].y - cameraOffset;
+ } else {
+ // If no blocks are placed yet, keep the camera centered or at the initial position
+ targetY = game.height / 2; // Or some other initial position if desired
+ }
+ // Smoothly move the camera
+ game.camera.y += (targetY - game.camera.y) * cameraFollowSpeed;
+ // Ensure the camera never goes above the top of the game world
+ game.camera.y = Math.max(game.camera.y, 0);
+}
// Game update loop
game.update = function () {
crane.update();
- if (!currentBlock || currentBlock.falling) {
+ if (!currentBlock) {
currentBlock = new Block();
// Position the new block directly attached to the crane's end
- currentBlock.x = crane.x + Math.sin(crane.rotation) * (crane.width / 2 + currentBlock.width / 2 + 200); // Increase the length of the rope
- currentBlock.y = crane.y + Math.cos(crane.rotation) * (crane.height / 2 + currentBlock.height / 2 + 200); // Increase the length of the rope
+ currentBlock.x = crane.x + Math.sin(crane.rotation) * crane.ropeLength;
+ currentBlock.y = crane.y + Math.cos(crane.rotation) * crane.ropeLength;
game.addChild(currentBlock);
- } else {
+ } else if (!currentBlock.falling) {
// Update the block's position to stay synced with the crane
- currentBlock.x = crane.x + Math.sin(crane.rotation) * (crane.width / 2 + currentBlock.width / 2 + 200); // Increase the length of the rope
- currentBlock.y = crane.y + Math.cos(crane.rotation) * (crane.height / 2 + currentBlock.height / 2 + 200); // Increase the length of the rope
+ currentBlock.x = crane.x + Math.sin(crane.rotation) * crane.ropeLength;
+ currentBlock.y = crane.y + Math.cos(crane.rotation) * crane.ropeLength;
}
if (currentBlock) {
currentBlock.update();
}
checkCollisions();
+ updateCamera(); // Update camera position every frame
};
// Event listener for dropping blocks
game.down = function (x, y, obj) {
dropBlock();