Code edit (1 edits merged)
Please save this source code
User prompt
it only goes down once then even though i stack more blocks it doesnt go down anymore. i think it is because you only go down when it intersects with baseBlock. fix that
Code edit (4 edits merged)
Please save this source code
User prompt
the issue persists. it still doesnt slide down after first time. please fix that
User prompt
for the effect of going up. slide base block and the blocks stacked upon it to down everytime a block makes contact
User prompt
make the blocks drop faster
User prompt
remove the code where it removes block when exceedes 5.
User prompt
when you align it perfectly make a sound
User prompt
when base block slides down, the blockes stacked on it doesnt go down with it. it just hangs in air. fix that please
Code edit (4 edits merged)
Please save this source code
User prompt
instead of blocks going down maybe just base block should go down and the blocks stacked will follow
Code edit (1 edits merged)
Please save this source code
User prompt
add base block to the 5 condition so it pushes down too because it prevents other go down.
User prompt
they just weridly cramp together. last block is not pushed to out ot screen due to base block. so please make sure base block goes down too.
User prompt
okay they dont slide out of the scene due to base block. can you fix it
User prompt
instead of removing the last block when exceedes 5 maybe just slide them out of the scene
User prompt
removing block when exceedes 5 doesnt work right. the block diseapears but then it comes back.
User prompt
when i drop a block from a crane, new block is apearing immediately which is not good. you should add an animation where crane gets that new block delayed, maybe it can take it from somewhere ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
when i drop a block there should be an animation where crane brings another block from outside of the scene
User prompt
increase swinging range meaning wiggling block should be more at the bottom
User prompt
increase the range and increase length of the rope
User prompt
when faulty alignment is close to right it does rotate and fall to right but when it is vice versa it still rotates and falls to right.
User prompt
use base_block asset for base block also make it bigger.
User prompt
maybe it should spin or something change rotation and trajectory when the block falls due to wrong alignment before game over.
User prompt
maybe it should spin or something change rotation and trajectory.
===================================================================
--- original.js
+++ change.js
@@ -1,164 +1,71 @@
/****
-* Classes
-****/
-// Class for the base block
-var BaseBlock = Container.expand(function () {
- var self = Container.call(this);
- var baseBlockGraphics = self.attachAsset('base_block', {
- anchorX: 0.5,
- anchorY: 0.5,
- scaleX: 2,
- scaleY: 2
- });
-});
-// Class for the blocks
-var Block = Container.expand(function () {
- var self = Container.call(this);
- var blockGraphics = self.attachAsset('block', {
- anchorX: 0.5,
- anchorY: 0.5,
- scaleX: 2,
- scaleY: 2
- });
- self.falling = false;
- self.speed = 20;
- self.update = function () {
- if (self.falling) {
- self.y += self.speed;
- self.x += self.momentum;
- }
- };
-});
-//<Assets used in the game will automatically appear here>
-//<Write imports for supported plugins here>
-// Class for the swinging crane
-var Crane = Container.expand(function () {
- var self = Container.call(this);
- var craneGraphics = self.attachAsset('crane', {
- anchorX: 0.5,
- anchorY: 0.0
- });
- self.angle = 0;
- self.speed = 0.03;
- self.direction = 1;
- self.update = function () {
- self.angle += self.speed * self.direction;
- if (self.angle > 1.5 || self.angle < -1.5) {
- self.direction *= -1;
- }
- self.rotation = self.angle;
- };
-});
-
-/****
* Initialize Game
****/
var game = new LK.Game({
- backgroundColor: 0x87CEEB // Sky blue background
+ backgroundColor: 0x000000
});
/****
* 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;
-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);
-// 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
- currentBlock.momentum = horizontalSpeed;
- blocks.push(currentBlock);
- currentBlock = null;
- }
-}
// Function to check for collisions and update score
function checkCollisions() {
for (var i = blocks.length - 1; i >= 0; i--) {
if (!blocks[i].falling) {
continue;
}
+ var hasLanded = false;
+ // Check for collision with the base block first
if (blocks[i].intersects(baseBlock)) {
blocks[i].falling = false;
blocks[i].y = baseBlock.y - baseBlock.height / 2 - blocks[i].height / 2 - towerHeight * 100;
towerHeight++;
LK.setScore(towerHeight);
scoreTxt.setText(LK.getScore());
- // Slide base block and the blocks stacked upon it downwards
baseBlock.y += blocks[i].height;
for (var j = 0; j < blocks.length; j++) {
- blocks[j].y += blocks[i].height;
+ if (!blocks[j].falling && blocks[j] !== blocks[i]) {
+ // Make sure not to adjust the block that just landed
+ blocks[j].y += blocks[i].height;
+ }
}
+ hasLanded = true;
} else {
+ // Check for collision with other settled blocks
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[j].falling && blocks[i].intersects(blocks[j])) {
if (Math.abs(blocks[i].x - blocks[j].x) > blocks[i].width / 4) {
- // Check if the block is not aligned correctly
+ // Misaligned, game over
blocks[i].falling = true;
blocks[i].speed = 10;
- // Add rotation and change trajectory based on the alignment
if (blocks[i].x - blocks[j].x > 0) {
- blocks[i].rotation = 0.5; // Rotate to the right
- blocks[i].momentum += 5; // Fall to the right
+ blocks[i].rotation = 0.5;
+ blocks[i].momentum += 5;
} else {
- blocks[i].rotation = -0.5; // Rotate to the left
- blocks[i].momentum -= 5; // Fall to the left
+ blocks[i].rotation = -0.5;
+ blocks[i].momentum -= 5;
}
LK.getSound('gameover').play();
LK.setTimeout(function () {
LK.showGameOver();
}, 1000);
} else {
+ // Landed on another block
blocks[i].falling = false;
blocks[i].y = blocks[j].y - blocks[j].height / 2 - blocks[i].height / 2;
- LK.getSound('place').play(); // Play sound when block is aligned perfectly
- break;
+ LK.getSound('place').play();
+ hasLanded = true;
+ break; // Break the inner loop since the block has landed
}
}
}
- if (blocks[i].falling && blocks[i].y > 2732) {
- game.removeChild(blocks[i]);
- blocks.splice(i, 1);
- console.log("Block lost!");
- }
}
+ // If the block is still falling and goes off-screen
+ if (blocks[i].falling && blocks[i].y > 2732 && !hasLanded) {
+ // Only remove if it hasn't landed
+ game.removeChild(blocks[i]);
+ blocks.splice(i, 1);
+ console.log("Block lost!");
+ }
}
-}
-// Game update loop
-game.update = function () {
- crane.update();
- 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
- game.addChild(currentBlock);
- } 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
- }
- if (currentBlock) {
- currentBlock.update();
- }
- checkCollisions();
-};
-// Event listener for dropping blocks
-game.down = function (x, y, obj) {
- dropBlock();
-};
\ No newline at end of file
+}
\ No newline at end of file