User prompt
Temas olmasa bile blok havada duruyor çarpışma algılama kötü
User prompt
Eger temas alanı alt blogun 4 te birinden az ise blok düşer ve kaybolur
User prompt
Çarpışma algılama temas bölgesi 4/1 ise blok düşmeye devam eder
User prompt
Oyında bulunan 2 farklı çarpışma algılamadan birini kaldır
User prompt
Blok düşme hızını 25 yap
User prompt
Düşme hızını biraz arttır
User prompt
Blok düşme hızını sabitle böylece çarpışma sekronizasyonu düzelir
User prompt
Çeyrek kapsama kontrolünü düzelt ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Çarpışma ve fizik kuralları ekle ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Carpışma fizigi ekle
User prompt
Eger temas noktasında 4/1 den azsa düşme fizigi ekke ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Carpışmaya fizik kuralları ekle ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Gerekli ayarları yap ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Eger üstteki blok düşüşte alttaki blogun 4/1 alanına temas ediyorsa dönerek dogal olarak düşsün oyuncu can kaybeder ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Olmuyor oyun bozuldu
User prompt
Hedef kaynagı yarat ve düzenle
User prompt
Üstteki kırmızı blok dülerken bazen alttaki blogu görmezden geliyor
User prompt
Asagı yukarı sallanmayıda aktif et ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Düşen blok bazen düşmesi gereken bölgeyi aşıyor ve tekrar birden blogun üzerinde beliriyor
User prompt
Saga sola sallantıyı genişlet ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Düşme sırasında carpması gereken blogu aşarak asagı gidip birdan blogun üzerinde beliriyor
User prompt
Kırmızı blok düşmeye başladıgında dogal davransın ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Sallantı dogal ve ve hiç durmasın ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
İp başlangıcı ekran üste degmeli
User prompt
İpi ve blogu biraz asagı dogru uzat
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var StackedBlock = Container.expand(function () { var self = Container.call(this); var block = self.attachAsset('block', { anchorX: 0.5, anchorY: 0.5 }); // Physics properties self.mass = 1.0; self.friction = 0.3; self.bounciness = 0.2; self.velocityX = 0; self.velocityY = 0; self.angularVelocity = 0; self.isStatic = false; // Foundation will be static return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87ceeb }); /**** * Game Code ****/ // Game state var stackedBlocks = []; var gameHeight = 2732; var gameWidth = 2048; var groundLevel = gameHeight - 120; var stackHeight = 0; var gameActive = true; // Create foundation block var foundation = new StackedBlock(); foundation.x = gameWidth / 2; foundation.y = gameHeight - 120; // Move to bottom of screen foundation.isStatic = true; // Foundation doesn't move foundation.mass = 10.0; // Heavy foundation game.addChild(foundation); stackedBlocks.push(foundation); stackHeight = foundation.y; // Create rope hanging from top center var rope = LK.getAsset('rope', { anchorX: 0.5, anchorY: 0 }); rope.x = gameWidth / 2; rope.y = 0; // Rope starts at top of screen game.addChild(rope); // Create swinging block at the end of rope var swingingBlock = LK.getAsset('swingingBlock', { anchorX: 0.5, anchorY: 0.5 }); swingingBlock.x = 0; swingingBlock.y = rope.height + 100; // Extend the rope length by moving block further down rope.addChild(swingingBlock); // Natural pendulum swing variables var swingTime = 0; var swingSpeed = 0.03; // Controls swing speed var swingAmplitude = 0.6; // Controls swing range (max rotation) // Score display var scoreTxt = new Text2('Blocks: 0', { size: 80, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Touch handler to drop the block game.down = function (x, y, obj) { if (!gameActive || !swingingBlock.parent) return; // Get the current world position of the swinging block var worldPos = rope.toGlobal(swingingBlock.position); var gamePos = game.toLocal(worldPos); // Detach from rope and add to game rope.removeChild(swingingBlock); game.addChild(swingingBlock); // Set position in game coordinates swingingBlock.x = gamePos.x; swingingBlock.y = gamePos.y; // Add falling velocity and physics properties swingingBlock.velocityY = 0; swingingBlock.velocityX = 0; swingingBlock.gravity = 0.8; swingingBlock.mass = 1.0; swingingBlock.friction = 0.3; swingingBlock.bounciness = 0.2; swingingBlock.angularVelocity = 0; swingingBlock.falling = true; }; // Update function for falling blocks game.update = function () { // Update rope swing with natural pendulum motion if (rope && !swingingBlock.falling) { swingTime += swingSpeed; rope.rotation = Math.sin(swingTime) * swingAmplitude; // Add vertical swinging motion to the swinging block var verticalOffset = Math.cos(swingTime * 2) * 30; // Vertical swing with smaller amplitude swingingBlock.y = rope.height + 100 + verticalOffset; } if (swingingBlock.falling) { swingingBlock.velocityY += swingingBlock.gravity; swingingBlock.y += swingingBlock.velocityY; // Check collision with any stacked block using Y position bounds var hasCollision = false; var nextY = swingingBlock.y + swingingBlock.velocityY + swingingBlock.gravity; for (var i = 0; i < stackedBlocks.length; i++) { var block = stackedBlocks[i]; var blockTop = block.y - block.height / 2; var blockBottom = block.y + block.height / 2; var swingingTop = swingingBlock.y - swingingBlock.height / 2; var swingingBottom = nextY + swingingBlock.height / 2; // Check if falling block will intersect or has passed through this block if (swingingTop <= blockBottom && swingingBottom >= blockTop) { // Also check X overlap for more accurate collision var swingingLeft = swingingBlock.x - swingingBlock.width / 2; var swingingRight = swingingBlock.x + swingingBlock.width / 2; var blockLeft = block.x - block.width / 2; var blockRight = block.x + block.width / 2; if (swingingLeft < blockRight && swingingRight > blockLeft) { hasCollision = true; break; } } } if (hasCollision) { // Find the topmost block that the swinging block collided with var targetBlock = null; var highestY = gameHeight; for (var k = 0; k < stackedBlocks.length; k++) { if (swingingBlock.intersects(stackedBlocks[k]) && stackedBlocks[k].y < highestY) { targetBlock = stackedBlocks[k]; highestY = stackedBlocks[k].y; } } if (targetBlock) { // Check if the swinging block covers at least half of the target block var swingingLeft = swingingBlock.x - swingingBlock.width / 2; var swingingRight = swingingBlock.x + swingingBlock.width / 2; var targetLeft = targetBlock.x - targetBlock.width / 2; var targetRight = targetBlock.x + targetBlock.width / 2; // Calculate overlap var overlapLeft = Math.max(swingingLeft, targetLeft); var overlapRight = Math.min(swingingRight, targetRight); var overlapWidth = Math.max(0, overlapRight - overlapLeft); // Check if overlap is at least half of the target block width var requiredCoverage = targetBlock.width / 2; // Check for quarter coverage (1/4) to trigger natural fall with rotation var quarterCoverage = targetBlock.width / 4; if (overlapWidth <= quarterCoverage && overlapWidth > 0) { // Block is barely touching - apply realistic physics collision swingingBlock.falling = true; // Calculate collision response based on physics var relativeVelocityY = swingingBlock.velocityY - (targetBlock.velocityY || 0); var relativeVelocityX = swingingBlock.velocityX - (targetBlock.velocityX || 0); // Apply bounce with energy loss var combinedBounciness = (swingingBlock.bounciness + (targetBlock.bounciness || 0.2)) / 2; swingingBlock.velocityY = -relativeVelocityY * combinedBounciness; swingingBlock.velocityX = relativeVelocityX * 0.7; // Some horizontal bounce // Apply friction to reduce sliding swingingBlock.velocityX *= 1 - swingingBlock.friction; // Add natural rotation based on impact var rotationDirection = swingingBlock.x < targetBlock.x ? -1 : 1; swingingBlock.angularVelocity = rotationDirection * 0.2; // Start rotation animation tween(swingingBlock, { rotation: swingingBlock.rotation + rotationDirection * Math.PI * 2 }, { duration: 1500, easing: tween.easeOut }); // Game over - player loses gameActive = false; LK.setTimeout(function () { LK.showGameOver(); }, 800); // Delay to show the rotation effect } else if (overlapWidth >= requiredCoverage) { // Apply momentum transfer to target block if (!targetBlock.isStatic && swingingBlock.velocityY > 3) { var momentumTransfer = swingingBlock.mass * swingingBlock.velocityY / (targetBlock.mass + swingingBlock.mass); targetBlock.velocityY = momentumTransfer * 0.3; // Reduced transfer for stability targetBlock.velocityX = (swingingBlock.velocityX || 0) * 0.2; } // Award 1 point LK.setScore(LK.getScore() + 1); scoreTxt.setText('Blocks: ' + LK.getScore()); // Place block on stack with physics settling swingingBlock.falling = false; swingingBlock.velocityY = 0; swingingBlock.velocityX = 0; swingingBlock.angularVelocity = 0; stackHeight -= 240; // Move stack up by block height swingingBlock.y = stackHeight; stackedBlocks.push(swingingBlock); // If this is the second red block (score 2), start sliding foundation down if (LK.getScore() >= 2) { // Move foundation and all stacked blocks down by one block height for (var j = 0; j < stackedBlocks.length; j++) { tween(stackedBlocks[j], { y: stackedBlocks[j].y + 240 }, { duration: 500, easing: tween.easeInOut }); } // Update stack height stackHeight += 240; } // Create new swinging block swingingBlock = LK.getAsset('swingingBlock', { anchorX: 0.5, anchorY: 0.5 }); swingingBlock.x = 0; swingingBlock.y = rope.height + 100; rope.addChild(swingingBlock); } else { // Not enough coverage - continue falling swingingBlock.falling = true; } } } // Check if block has fallen below the screen else if (swingingBlock.y > gameHeight + 200) { // Game over - player missed the target gameActive = false; LK.showGameOver(); } } // Apply physics to all non-static blocks for (var p = 0; p < stackedBlocks.length; p++) { var physicsBlock = stackedBlocks[p]; if (!physicsBlock.isStatic && physicsBlock !== swingingBlock) { // Apply gravity if block has velocity if (Math.abs(physicsBlock.velocityY || 0) > 0.1 || Math.abs(physicsBlock.velocityX || 0) > 0.1) { physicsBlock.velocityY = (physicsBlock.velocityY || 0) + 0.3; // Gravity physicsBlock.x += physicsBlock.velocityX || 0; physicsBlock.y += physicsBlock.velocityY || 0; // Apply friction to slow down movement physicsBlock.velocityX = (physicsBlock.velocityX || 0) * 0.95; physicsBlock.velocityY = (physicsBlock.velocityY || 0) * 0.98; // Apply angular velocity for rotation if (physicsBlock.angularVelocity) { physicsBlock.rotation += physicsBlock.angularVelocity; physicsBlock.angularVelocity *= 0.95; // Damping } // Stop very small movements to prevent jitter if (Math.abs(physicsBlock.velocityX || 0) < 0.1) physicsBlock.velocityX = 0; if (Math.abs(physicsBlock.velocityY || 0) < 0.1) physicsBlock.velocityY = 0; if (Math.abs(physicsBlock.angularVelocity || 0) < 0.01) physicsBlock.angularVelocity = 0; } } } }; ;
===================================================================
--- original.js
+++ change.js
@@ -11,14 +11,16 @@
var block = self.attachAsset('block', {
anchorX: 0.5,
anchorY: 0.5
});
- // Physics properties for collision
+ // Physics properties
+ self.mass = 1.0;
+ self.friction = 0.3;
+ self.bounciness = 0.2;
self.velocityX = 0;
self.velocityY = 0;
- self.mass = 1;
- self.restitution = 0.3; // Bounce factor
- self.friction = 0.8; // Friction coefficient
+ self.angularVelocity = 0;
+ self.isStatic = false; // Foundation will be static
return self;
});
/****
@@ -41,8 +43,10 @@
// Create foundation block
var foundation = new StackedBlock();
foundation.x = gameWidth / 2;
foundation.y = gameHeight - 120; // Move to bottom of screen
+foundation.isStatic = true; // Foundation doesn't move
+foundation.mass = 10.0; // Heavy foundation
game.addChild(foundation);
stackedBlocks.push(foundation);
stackHeight = foundation.y;
// Create rope hanging from top center
@@ -83,11 +87,16 @@
game.addChild(swingingBlock);
// Set position in game coordinates
swingingBlock.x = gamePos.x;
swingingBlock.y = gamePos.y;
- // Add falling velocity
+ // Add falling velocity and physics properties
swingingBlock.velocityY = 0;
+ swingingBlock.velocityX = 0;
swingingBlock.gravity = 0.8;
+ swingingBlock.mass = 1.0;
+ swingingBlock.friction = 0.3;
+ swingingBlock.bounciness = 0.2;
+ swingingBlock.angularVelocity = 0;
swingingBlock.falling = true;
};
// Update function for falling blocks
game.update = function () {
@@ -98,22 +107,8 @@
// Add vertical swinging motion to the swinging block
var verticalOffset = Math.cos(swingTime * 2) * 30; // Vertical swing with smaller amplitude
swingingBlock.y = rope.height + 100 + verticalOffset;
}
- // Update physics for all stacked blocks
- for (var p = 0; p < stackedBlocks.length; p++) {
- var block = stackedBlocks[p];
- if (block.velocityX !== undefined && Math.abs(block.velocityX) > 0.1) {
- block.x += block.velocityX;
- // Apply friction to horizontal movement
- block.velocityX *= block.friction || 0.9;
- }
- if (block.velocityY !== undefined && Math.abs(block.velocityY) > 0.1) {
- block.y += block.velocityY;
- // Apply gravity and damping
- block.velocityY = block.velocityY * 0.98 + 0.1;
- }
- }
if (swingingBlock.falling) {
swingingBlock.velocityY += swingingBlock.gravity;
swingingBlock.y += swingingBlock.velocityY;
// Check collision with any stacked block using Y position bounds
@@ -147,42 +142,9 @@
targetBlock = stackedBlocks[k];
highestY = stackedBlocks[k].y;
}
}
- // Apply collision physics
if (targetBlock) {
- // Calculate collision normal and relative velocity
- var collisionNormalY = swingingBlock.y < targetBlock.y ? -1 : 1;
- var relativeVelocityY = swingingBlock.velocityY - (targetBlock.velocityY || 0);
- // Calculate impulse for realistic collision response
- var impulse = -(1 + (swingingBlock.restitution || 0.3)) * relativeVelocityY;
- impulse = impulse / ((swingingBlock.mass || 1) + (targetBlock.mass || 1));
- // Apply impulse to both blocks
- var swingingImpulse = impulse * (targetBlock.mass || 1);
- var targetImpulse = -impulse * (swingingBlock.mass || 1);
- // Update velocities with collision response
- swingingBlock.velocityY += swingingImpulse * collisionNormalY;
- if (targetBlock.velocityY !== undefined) {
- targetBlock.velocityY += targetImpulse * collisionNormalY;
- }
- // Add horizontal collision effects for more realistic physics
- var horizontalDistance = swingingBlock.x - targetBlock.x;
- if (Math.abs(horizontalDistance) > 0) {
- var horizontalForce = horizontalDistance > 0 ? 1 : -1;
- swingingBlock.velocityX = (swingingBlock.velocityX || 0) + horizontalForce * 3;
- // Apply friction to horizontal movement
- tween(swingingBlock, {
- velocityX: 0
- }, {
- duration: 1000,
- easing: tween.easeOut
- });
- }
- // Create visual impact effect
- LK.effects.flashObject(targetBlock, 0xffff00, 200);
- LK.effects.flashObject(swingingBlock, 0xff6600, 200);
- }
- if (targetBlock) {
// Check if the swinging block covers at least half of the target block
var swingingLeft = swingingBlock.x - swingingBlock.width / 2;
var swingingRight = swingingBlock.x + swingingBlock.width / 2;
var targetLeft = targetBlock.x - targetBlock.width / 2;
@@ -195,13 +157,23 @@
var requiredCoverage = targetBlock.width / 2;
// Check for quarter coverage (1/4) to trigger natural fall with rotation
var quarterCoverage = targetBlock.width / 4;
if (overlapWidth <= quarterCoverage && overlapWidth > 0) {
- // Block is barely touching - make it fall naturally with rotation
+ // Block is barely touching - apply realistic physics collision
swingingBlock.falling = true;
- swingingBlock.velocityY = Math.max(swingingBlock.velocityY, 2); // Ensure some downward velocity
- // Add natural rotation based on which side is touching
+ // Calculate collision response based on physics
+ var relativeVelocityY = swingingBlock.velocityY - (targetBlock.velocityY || 0);
+ var relativeVelocityX = swingingBlock.velocityX - (targetBlock.velocityX || 0);
+ // Apply bounce with energy loss
+ var combinedBounciness = (swingingBlock.bounciness + (targetBlock.bounciness || 0.2)) / 2;
+ swingingBlock.velocityY = -relativeVelocityY * combinedBounciness;
+ swingingBlock.velocityX = relativeVelocityX * 0.7; // Some horizontal bounce
+ // Apply friction to reduce sliding
+ swingingBlock.velocityX *= 1 - swingingBlock.friction;
+ // Add natural rotation based on impact
var rotationDirection = swingingBlock.x < targetBlock.x ? -1 : 1;
+ swingingBlock.angularVelocity = rotationDirection * 0.2;
+ // Start rotation animation
tween(swingingBlock, {
rotation: swingingBlock.rotation + rotationDirection * Math.PI * 2
}, {
duration: 1500,
@@ -212,14 +184,22 @@
LK.setTimeout(function () {
LK.showGameOver();
}, 800); // Delay to show the rotation effect
} else if (overlapWidth >= requiredCoverage) {
+ // Apply momentum transfer to target block
+ if (!targetBlock.isStatic && swingingBlock.velocityY > 3) {
+ var momentumTransfer = swingingBlock.mass * swingingBlock.velocityY / (targetBlock.mass + swingingBlock.mass);
+ targetBlock.velocityY = momentumTransfer * 0.3; // Reduced transfer for stability
+ targetBlock.velocityX = (swingingBlock.velocityX || 0) * 0.2;
+ }
// Award 1 point
LK.setScore(LK.getScore() + 1);
scoreTxt.setText('Blocks: ' + LK.getScore());
- // Place block on stack
+ // Place block on stack with physics settling
swingingBlock.falling = false;
swingingBlock.velocityY = 0;
+ swingingBlock.velocityX = 0;
+ swingingBlock.angularVelocity = 0;
stackHeight -= 240; // Move stack up by block height
swingingBlock.y = stackHeight;
stackedBlocks.push(swingingBlock);
// If this is the second red block (score 2), start sliding foundation down
@@ -242,14 +222,8 @@
anchorY: 0.5
});
swingingBlock.x = 0;
swingingBlock.y = rope.height + 100;
- // Initialize physics properties
- swingingBlock.velocityX = 0;
- swingingBlock.velocityY = 0;
- swingingBlock.mass = 1;
- swingingBlock.restitution = 0.4;
- swingingBlock.friction = 0.8;
rope.addChild(swingingBlock);
} else {
// Not enough coverage - continue falling
swingingBlock.falling = true;
@@ -262,6 +236,30 @@
gameActive = false;
LK.showGameOver();
}
}
+ // Apply physics to all non-static blocks
+ for (var p = 0; p < stackedBlocks.length; p++) {
+ var physicsBlock = stackedBlocks[p];
+ if (!physicsBlock.isStatic && physicsBlock !== swingingBlock) {
+ // Apply gravity if block has velocity
+ if (Math.abs(physicsBlock.velocityY || 0) > 0.1 || Math.abs(physicsBlock.velocityX || 0) > 0.1) {
+ physicsBlock.velocityY = (physicsBlock.velocityY || 0) + 0.3; // Gravity
+ physicsBlock.x += physicsBlock.velocityX || 0;
+ physicsBlock.y += physicsBlock.velocityY || 0;
+ // Apply friction to slow down movement
+ physicsBlock.velocityX = (physicsBlock.velocityX || 0) * 0.95;
+ physicsBlock.velocityY = (physicsBlock.velocityY || 0) * 0.98;
+ // Apply angular velocity for rotation
+ if (physicsBlock.angularVelocity) {
+ physicsBlock.rotation += physicsBlock.angularVelocity;
+ physicsBlock.angularVelocity *= 0.95; // Damping
+ }
+ // Stop very small movements to prevent jitter
+ if (Math.abs(physicsBlock.velocityX || 0) < 0.1) physicsBlock.velocityX = 0;
+ if (Math.abs(physicsBlock.velocityY || 0) < 0.1) physicsBlock.velocityY = 0;
+ if (Math.abs(physicsBlock.angularVelocity || 0) < 0.01) physicsBlock.angularVelocity = 0;
+ }
+ }
+ }
};
;
\ No newline at end of file