User prompt
Make objects fall if they are not properly supported. If less than 50% of an element is supported by the one below it, it should tip over or fall off. Remove the invisible support between gaps
User prompt
Avoid jittering and stabilize physics when objects overlap slightly
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'x')' in or related to this line: 'towerBlocks[i].lastX = towerBlocks[i].x;' Line Number: 250
User prompt
Please implement a 1-second cooldown for the block dropping mechanism. Create a logic where after a block is released, the input is disabled for 1000 milliseconds to prevent spamming and physics glitches. To make it clear for the player, slightly reduce the opacity of the hook or the next block during this cooldown period, and return it to full visibility once it is ready to be dropped again ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the block spawning logic: ensure that when a block is dropped, its starting position is set exactly to the current X and Y coordinates of the swinging hook, rather than a fixed height at the top of the screen. The block should appear to be detached directly from the hook
User prompt
There is a bug when player clicked multiple, the blocks are shakings at drop. Fix it
User prompt
Why cannot throwable The last block? Fix it
User prompt
Limit number of block to 20. Do not load more after 20.
User prompt
The game only load 20 piece of block max.
User prompt
Remove counter from the game
User prompt
Not working
User prompt
When no more block left then change the counter text to it: Remaining Building Blocks: 0
User prompt
There is another bug in the game. You loaded block after counter reached 1. DO NOT LOAD MORE BLOCK AFTER IT. ALSO NOT LOAD TO CLICK.
User prompt
There is a counting bug in the game. You added one more block when the counter reached zero. The last one should be the 1. Do not load more block when counter reached 1
User prompt
Remove explosion asset from the game
User prompt
Remove hook asset from the game
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of null (reading 'swayDirection')' in or related to this line: 'var lastSwayDirection = currentBlock.swayDirection; // Save the sway direction of the current block' Line Number: 194
User prompt
Avoid this bug
User prompt
Not working well
User prompt
Syncronise crane horizontal movement to the last loaded block
User prompt
Crane is top in display order
User prompt
Cant see the crane
User prompt
Add it
User prompt
Stop click event if the counter reach zero
User prompt
Do it
/****
* Classes
****/
// Class for Bird
var Bird = Container.expand(function () {
var self = Container.call(this);
var birdGraphics = self.attachAsset('bird', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.x += self.speed;
self.y += Math.sin(self.x / 100) * 2; // Add vertical movement based on sine wave
if (self.x > 2048 + birdGraphics.width / 2) {
self.x = -birdGraphics.width / 2;
}
};
});
// Class for Crane
var Crane = Container.expand(function () {
var self = Container.call(this);
var craneGraphics = self.attachAsset('crane', {
anchorX: 0.5,
anchorY: 0.0
});
self.hook = self.attachAsset('hook', {
anchorX: 0.5,
anchorY: 0.0,
y: craneGraphics.height
});
self.loweringSpeed = 2;
self.lowerHook = function () {
self.hook.y += self.loweringSpeed;
};
});
// Class for Dove
var Dove = Container.expand(function () {
var self = Container.call(this);
var doveGraphics = self.attachAsset('bird', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.x += self.speed;
self.y += Math.sin(self.x / 100) * 2; // Add vertical movement based on sine wave
if (self.x > 2048 + doveGraphics.width / 2) {
self.x = -doveGraphics.width / 2;
}
};
});
var DoveBird = Container.expand(function () {
var self = Container.call(this);
var doveBirdGraphics = self.attachAsset('dovebird', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 4;
self.update = function () {
self.x -= self.speed;
self.y += Math.sin(self.x / 100) * 2; // Add vertical movement based on sine wave
if (self.x < -doveBirdGraphics.width / 2) {
self.x = 2048 + doveBirdGraphics.width / 2;
}
};
});
// Class for Explosion
var Explosion = Container.expand(function () {
var self = Container.call(this);
var explosionGraphics = self.attachAsset('explosion', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
explosionGraphics.alpha -= 0.01; // Fade out the explosion
if (explosionGraphics.alpha <= 0) {
self.destroy(); // Destroy the explosion when it's fully faded out
}
};
});
// Class for TowerBlock
var TowerBlock = Container.expand(function () {
var self = Container.call(this);
var blockGraphics = self.attachAsset('towerBlock', {
anchorX: 0.5,
anchorY: 0.5
});
self.swayDirection = 1;
self.swaySpeed = 1;
self.update = function () {
self.x += self.swaySpeed * self.swayDirection * 1.5;
if (self.x > 2048 - blockGraphics.width / 2 || self.x < blockGraphics.width / 2) {
self.swayDirection *= -1; // Reverse direction when reaching the edge
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Light blue background
});
/****
* Game Code
****/
var crane = new Crane();
crane.x = 2048 / 2;
crane.y = 0;
game.addChild(crane);
crane.lowerHook(); // Ensure the hook is visible by lowering it initially
var sky = game.addChild(LK.getAsset('sky', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
}));
var grass = game.addChild(LK.getAsset('grass', {
anchorX: 0,
anchorY: 1,
x: 0,
y: 2732
}));
// Initialize variables
var towerBlocks = [];
var baseY = 2500; // Base row position
var currentBlock = null;
var counter = 20; // Initialize counter
var counterTxt = new Text2('Remaining Building Blocks: ' + counter.toString(), {
size: 37.5,
fill: 0xFFFFFF
}); // Create counter text
counterTxt.anchor.set(0, 0); // Set anchor to top left
LK.gui.topLeft.addChild(counterTxt); // Add counter text to top left corner of the map
// Function to drop the current block
function dropBlock() {
if (currentBlock) {
currentBlock.swaySpeed = 0; // Stop swaying
towerBlocks.push(currentBlock);
currentBlock = null;
}
}
// Create a new block at the top of the screen
function createNewBlock() {
// Create a new block at the top of the screen
function createNewBlock() {
if (counter > 0) {
currentBlock = new TowerBlock();
currentBlock.x = 2048 / 2;
currentBlock.y = 100;
game.addChild(currentBlock);
counter--; // Decrease counter by one
counterTxt.setText('Remaining Building Blocks: ' + counter.toString()); // Update counter text
} else {
currentBlock = null; // Ensure no new block is created if counter is zero
}
}
currentBlock = new TowerBlock();
currentBlock.x = 2048 / 2;
currentBlock.y = 100;
game.addChild(currentBlock);
}
// Handle screen tap to drop the block
game.down = function (x, y, obj) {
crane.lowerHook();
if (!currentBlock && counter > 0) {
currentBlock = new TowerBlock();
currentBlock.x = 2048 / 2;
currentBlock.y = 100;
game.addChild(currentBlock);
counter--; // Decrease counter by one
counterTxt.setText('Remaining Building Blocks: ' + counter.toString()); // Update counter text
} else if (!currentBlock) {
currentBlock = null; // Ensure no new block is created if counter is zero
}
if (!currentBlock) {
currentBlock = new TowerBlock();
currentBlock.x = 2048 / 2;
currentBlock.y = 100;
game.addChild(currentBlock);
}
var lastSwayDirection = currentBlock.swayDirection; // Save the sway direction of the current block
dropBlock();
if (counter > 0) {
// Check if counter is greater than zero
createNewBlock();
currentBlock.x = towerBlocks[towerBlocks.length - 1].x; // Set the x position of the new block to the x position of the last block in the towerBlocks array
currentBlock.swayDirection = lastSwayDirection; // Set the sway direction of the new block to the saved sway direction
counter--; // Decrease counter by one
counterTxt.setText('Remaining Building Blocks: ' + counter.toString()); // Update counter text
}
};
// Initialize the first block
if (counter > 0) {
createNewBlock();
} else {
currentBlock = null; // Ensure no new block is created if counter is zero
}
// Add birds to the game
for (var i = 0; i < 2; i++) {
var bird = new Bird();
bird.x = Math.random() * 2048;
bird.y = Math.random() * (2732 / 2);
game.addChild(bird);
}
// Add doves to the game
for (var i = 0; i < 3; i++) {
var dove = new Dove();
dove.x = Math.random() * 2048;
dove.y = Math.random() * (2732 / 2);
game.addChild(dove);
}
// Add dovebirds to the game
for (var i = 0; i < 2; i++) {
var doveBird = new DoveBird();
doveBird.x = Math.random() * 2048;
doveBird.y = Math.random() * (2732 / 2);
game.addChild(doveBird);
}
// Update function for the game
game.update = function () {
if (currentBlock) {
currentBlock.update();
}
// Update positions of all blocks
for (var i = 0; i < towerBlocks.length; i++) {
towerBlocks[i].y += 10; // Increase the falling speed of blocks
// Check if the block has collided with the grass
if (towerBlocks[i].intersects(grass)) {
towerBlocks[i].y = grass.y - towerBlocks[i].height / 2; // Position the block on top of the grass
towerBlocks[i].swaySpeed = 0; // Stop the block from moving
}
// Check if the block has collided with another block
for (var j = 0; j < towerBlocks.length; j++) {
if (i != j && towerBlocks[i].intersects(towerBlocks[j])) {
towerBlocks[i].y = towerBlocks[j].y - towerBlocks[i].height; // Position the block on top of the other block
towerBlocks[i].swaySpeed = 0; // Stop the block from moving
towerBlocks[i].swayDirection = 0; // Ensure no further movement occurs
// Initialize lastX for tracking changes on X
if (towerBlocks[i].lastX === undefined) {
towerBlocks[i].lastX = towerBlocks[i].x;
towerBlocks[i].lastX = towerBlocks[i].x;
}
// Check if at least 90% of the tower block fits on the underlying one
if (towerBlocks[j] && Math.abs(towerBlocks[i].x - towerBlocks[j].x) > towerBlocks[i].width * 0.1) {
// If not, slide it off animatedly
towerBlocks[i].x += towerBlocks[i].x < towerBlocks[j].x ? -5 : 5;
// If not, slide it off animatedly
towerBlocks[i].x += towerBlocks[i].x < towerBlocks[j].x ? -5 : 5;
// Check if the block has fallen off completely
if (towerBlocks[i].lastX <= 0 && towerBlocks[i].x > 0) {
// Create an explosion effect
var explosion = new Explosion();
explosion.x = towerBlocks[i].x;
explosion.y = towerBlocks[i].y;
game.addChild(explosion);
// Create an explosion effect
var explosion = new Explosion();
explosion.x = towerBlocks[i].x;
explosion.y = towerBlocks[i].y;
game.addChild(explosion);
towerBlocks[i].destroy(); // Remove the block from the game
towerBlocks.splice(i, 1); // Remove the block from the array
i--; // Adjust the index after removal
} else if (towerBlocks[i].y > 2732) {
towerBlocks[i].destroy(); // Remove the block from the game
towerBlocks.splice(i, 1); // Remove the block from the array
i--; // Adjust the index after removal
// Check if the block has fallen off the map
towerBlocks[i].destroy(); // Remove the block from the game
towerBlocks.splice(i, 1); // Remove the block from the array
i--; // Adjust the index after removal
}
}
// Update last known states
towerBlocks[i].lastX = towerBlocks[i].x;
break; // Prevent block from bouncing by breaking the loop once a collision is detected
}
}
}
// Play dove sound in loop
if (LK.ticks % 420 == 0) {
LK.getSound('Dove').play();
LK.playMusic('Birds');
}
}; ===================================================================
--- original.js
+++ change.js
@@ -109,8 +109,9 @@
var crane = new Crane();
crane.x = 2048 / 2;
crane.y = 0;
game.addChild(crane);
+crane.lowerHook(); // Ensure the hook is visible by lowering it initially
var sky = game.addChild(LK.getAsset('sky', {
anchorX: 0,
anchorY: 0,
x: 0,