User prompt
Coins need to pocketed only 4 pockets
User prompt
Coins are not falling into the black pockets. Instead, they teleport or slide to the base area. Points are added even though they didn’t enter the pocket.
User prompt
This logic needs to apply for every coin including red and striker it is now working for single time I need many times
User prompt
Add logic to coins when they are goes into a pocket and coin should disappear and get points
User prompt
When the coins goes to pocket it should be pocketed and give score
User prompt
When the coins goes in the black hole even the 75 percent of the coin is in black hole make it pocketd and give score
User prompt
Add this logic to all the coins
User prompt
Add logic to pocket coins when they are near a pocket this is not working properly
User prompt
I want the coins to be pocketed after the coins went near the pocket
User prompt
Use all methods i need the striker to hit coins and the coins should move
User prompt
This method also not working
User prompt
Any alternate method to hit the coins
User prompt
Please fix the bug: 'TypeError: self.intersectsAny is not a function' in or related to this line: 'self.lastWasIntersecting = self.intersectsAny(coins);' Line Number: 241
User prompt
Still striker can't hit the coins
User prompt
Review and make this happen
User prompt
Not working
User prompt
But it's not working pocketing logic
User prompt
Implement these I need the coins and striker to be pocketed
User prompt
If the striker hit the coin the coin should move
User prompt
Velocity and Force**: Ensure that the velocity and force applied to the striker are sufficient to propel the coin towards the pocket. The power level should be adjusted to provide the right amount of force.
User prompt
Friction**: The friction settings should be calibrated to allow the coin to move smoothly towards the pocket. If the friction is too high, it might slow down the coin too quickly, preventing it from reaching the pocket.
User prompt
Restitution**: The restitution coefficient should be set to ensure that the collision is elastic enough for the coin to move towards the pocket. If the restitution is too low, the coin might not bounce effectively.
User prompt
Once a collision is detected, the momentum from the striker should be transferred to the coin. This involves calculating the relative velocity and applying the appropriate impulse to both the striker and the coin.
User prompt
Ensure that the collision detection logic is correctly implemented. The collision should be detected at the exact moment when the striker and the coin intersect. This requires checking their positions and radii to determine if they overlap.
User prompt
Add collision handling between striker and coins to ensure interaction.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1", { highScore: 0 }); /**** * Classes ****/ var AimLine = Container.expand(function () { var self = Container.call(this); var line = self.attachAsset('aimLine', { anchorX: 0.5, anchorY: 1.0 }); self.alpha = 0.5; self.visible = false; return self; }); var Board = Container.expand(function () { var self = Container.call(this); // Board base (outer) var boardBase = self.attachAsset('boardBase', { anchorX: 0.5, anchorY: 0.5 }); // Board inner area var boardInner = self.attachAsset('boardInner', { anchorX: 0.5, anchorY: 0.5 }); self.boardInner = boardInner; // Ensure boardInner is accessible self.width = boardBase.width; self.height = boardBase.height; self.innerWidth = boardInner.width; self.innerHeight = boardInner.height; // Create pockets in corners self.pockets = []; var pocketPositions = [{ x: -boardBase.width / 2 + 80, y: -boardBase.height / 2 + 80 }, // Top left { x: boardBase.width / 2 - 80, y: -boardBase.height / 2 + 80 }, // Top right { x: -boardBase.width / 2 + 80, y: boardBase.height / 2 - 80 }, // Bottom left { x: boardBase.width / 2 - 80, y: boardBase.height / 2 - 80 } // Bottom right ]; for (var i = 0; i < pocketPositions.length; i++) { var pocket = new Pocket(); pocket.x = pocketPositions[i].x; pocket.y = pocketPositions[i].y; self.addChild(pocket); self.pockets.push(pocket); } // Add red base assets to each side of the board var baseWidth = 20; var baseHeight = boardInner.height - 160; // Ensure it doesn't overlap with pockets // Top base var topBase = self.attachAsset('redBase', { anchorX: 0.5, anchorY: 0.5, width: boardInner.width - 160, height: baseWidth }); topBase.x = 0; topBase.y = -boardInner.height / 2 + baseWidth / 2 + 60; // Adjust space to be exactly in the middle of the striker's place self.addChild(topBase); // Bottom base var bottomBase = self.attachAsset('redBase', { anchorX: 0.5, anchorY: 0.5, width: boardInner.width - 160, height: baseWidth }); bottomBase.x = 0; bottomBase.y = boardInner.height / 2 - baseWidth / 2 - 60; // Adjust space to be exactly in the middle of the striker's place self.addChild(bottomBase); // Left base var leftBase = self.attachAsset('redBase', { anchorX: 0.5, anchorY: 0.5, width: baseWidth, height: baseHeight }); leftBase.x = -self.boardInner.width / 2 + baseWidth / 2 + 60; // Adjust space to be exactly in the middle of the striker's place leftBase.y = 0; self.addChild(leftBase); // Right base var rightBase = self.attachAsset('redBase', { anchorX: 0.5, anchorY: 0.5, width: baseWidth, height: baseHeight }); rightBase.x = self.boardInner.width / 2 - baseWidth / 2 - 60; // Adjust space to be exactly in the middle of the striker's place rightBase.y = 0; self.addChild(rightBase); return self; }); var Coin = Container.expand(function (type) { var self = Container.call(this); self.type = type || 'white'; self.value = self.type === 'red' ? 50 : 10; var assetId = self.type + 'Coin'; var coinGraphic = self.attachAsset(assetId, { anchorX: 0.5, anchorY: 0.5 }); self.velocityX = 0; self.velocityY = 0; self.friction = 0.95; self.radius = coinGraphic.width / 2; self.mass = self.type === 'red' ? 1.1 : 1; self.active = true; self.update = function () { if (!self.active) { return; } // Initialize last known positions if undefined if (self.lastX === undefined) { self.lastX = self.x; } if (self.lastY === undefined) { self.lastY = self.y; } // Apply velocity self.x += self.velocityX; self.y += self.velocityY; // Update last known positions self.lastX = self.x; self.lastY = self.y; // Apply friction self.velocityX *= self.friction; self.velocityY *= self.friction; // Stop small movements if (Math.abs(self.velocityX) < 0.1 && Math.abs(self.velocityY) < 0.1) { self.velocityX = 0; self.velocityY = 0; } }; self.applyForce = function (forceX, forceY) { self.velocityX += forceX / self.mass; self.velocityY += forceY / self.mass; }; return self; }); var Pocket = Container.expand(function () { var self = Container.call(this); var pocketGraphic = self.attachAsset('pocket', { anchorX: 0.5, anchorY: 0.5 }); self.radius = pocketGraphic.width / 2; return self; }); var PowerMeter = Container.expand(function () { var self = Container.call(this); // Background var bg = self.attachAsset('powerBG', { anchorX: 0.5, anchorY: 0.5 }); // Foreground (power indicator) var meter = self.attachAsset('powerMeter', { anchorX: 0.5, anchorY: 1.0, y: bg.height / 2 }); self.meter = meter; self.setLevel = function (level) { // level should be between 0 and 1 var clampedLevel = Math.max(0, Math.min(1, level)); self.meter.scaleY = clampedLevel; }; self.visible = false; return self; }); var Striker = Container.expand(function () { var self = Container.call(this); var strikerGraphic = self.attachAsset('striker', { anchorX: 0.5, anchorY: 0.5 }); // Override properties for striker self.mass = 1.5; self.friction = 0.975; self.value = 0; self.radius = strikerGraphic.width / 2; self.restitution = 1.1; // Increase restitution for a faster bounce back effect self.immovable = false; // Ensure striker is not immovable self.velocityX = 0; self.velocityY = 0; self.update = function () { // Initialize last known positions if undefined if (self.lastX === undefined) { self.lastX = self.x; } if (self.lastY === undefined) { self.lastY = self.y; } // Apply velocity self.x += self.velocityX; self.y += self.velocityY; // Update last known positions self.lastX = self.x; self.lastY = self.y; // Ensure striker stays within the board boundaries var boardLeft = board.x - board.width / 2 + self.radius; var boardRight = board.x + board.width / 2 - self.radius; var boardTop = board.y - board.height / 2 + self.radius; var boardBottom = board.y + board.height / 2 - self.radius; if (self.x < boardLeft) { self.x = boardLeft; self.velocityX *= -self.restitution; } else if (self.x > boardRight) { self.x = boardRight; self.velocityX *= -self.restitution; } if (self.y < boardTop) { self.y = boardTop; self.velocityY *= -self.restitution; } else if (self.y > boardBottom) { self.y = boardBottom; self.velocityY *= -self.restitution; } // Apply friction self.velocityX *= self.friction; self.velocityY *= self.friction; // Stop small movements if (Math.abs(self.velocityX) < 0.1 && Math.abs(self.velocityY) < 0.1) { self.velocityX = 0; self.velocityY = 0; } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x44AA44 }); /**** * Game Code ****/ // Game state variables var gameState = 'aiming'; // aiming, power, shooting, waiting var board; var striker; var coins = []; var aimLine; var powerMeter; var score = 0; var highScore = storage.highScore || 0; var isMoving = false; var powerLevel = 0; var powerDirection = 1; var powerSpeed = 0.02; // Text elements var scoreTxt = new Text2('Score: 0', { size: 70, fill: 0xFFFFFF }); scoreTxt.anchor.set(1, 0); LK.gui.topRight.addChild(scoreTxt); var highScoreTxt = new Text2('Best: ' + highScore, { size: 50, fill: 0xFFFFFF }); highScoreTxt.anchor.set(1, 1); LK.gui.bottomRight.addChild(highScoreTxt); var gameRulesTxt = new Text2('Pocket all coins to win!\nWhite/Black: 10pts\nRed: 50pts', { size: 40, fill: 0xFFFFFF, align: 'left' }); gameRulesTxt.anchor.set(0, 1); LK.gui.bottomLeft.addChild(gameRulesTxt); // Start music LK.playMusic('bgmusic', { fade: { start: 0, end: 0.3, duration: 1000 } }); // Initialize board function initializeGame() { // Create the board board = new Board(); board.x = 2048 / 2; board.y = 2732 / 2; game.addChild(board); // Create the striker striker = new Striker(); striker.x = board.x; striker.y = board.y + board.height / 2 - 200; game.addChild(striker); // Input handling for dragging the striker game.down = function (x, y) { if (gameState === 'aiming') { aimStriker(x, y); gameState = 'power'; powerLevel = 0; powerDirection = 1; powerMeter.setLevel(powerLevel); powerMeter.visible = true; } }; game.up = function () { if (gameState === 'power') { shootStriker(powerLevel); } }; // Input handling for dragging the striker game.down = function (x, y) { if (gameState === 'aiming') { aimStriker(x, y); gameState = 'power'; powerLevel = 0; powerDirection = 1; powerMeter.setLevel(powerLevel); powerMeter.visible = true; } }; game.up = function () { if (gameState === 'power') { shootStriker(powerLevel); } }; // Create aiming line aimLine = new AimLine(); game.addChild(aimLine); // Create power meter powerMeter = new PowerMeter(); powerMeter.x = 100; powerMeter.y = 2732 / 2; game.addChild(powerMeter); // Create coins createCoins(); // Reset game state gameState = 'aiming'; score = 0; updateScore(); } function createCoins() { // Clear existing coins for (var i = 0; i < coins.length; i++) { if (coins[i].parent) { coins[i].parent.removeChild(coins[i]); } } coins = []; // Create a formation of coins in the center var centerX = board.x; var centerY = board.y; var coinRadius = 40; var spacing = coinRadius * 2.1; // Create coins in a circular arrangement var coinPositions = [ // Center { x: 0, y: 0, type: 'red' }, // Inner circle (6 coins) { x: 0, y: -spacing, type: 'white' }, { x: -spacing * 0.866, y: -spacing * 0.5, type: 'black' }, { x: -spacing * 0.866, y: spacing * 0.5, type: 'white' }, { x: 0, y: spacing, type: 'black' }, { x: spacing * 0.866, y: spacing * 0.5, type: 'white' }, { x: spacing * 0.866, y: -spacing * 0.5, type: 'black' }, // Outer circle (12 coins) { x: 0, y: -spacing * 2, type: 'black' }, { x: -spacing, y: -spacing * 1.732, type: 'white' }, { x: -spacing * 1.732, y: -spacing, type: 'black' }, { x: -spacing * 2, y: 0, type: 'white' }, { x: -spacing * 1.732, y: spacing, type: 'black' }, { x: -spacing, y: spacing * 1.732, type: 'white' }, { x: 0, y: spacing * 2, type: 'black' }, { x: spacing, y: spacing * 1.732, type: 'white' }, { x: spacing * 1.732, y: spacing, type: 'black' }, { x: spacing * 2, y: 0, type: 'white' }, { x: spacing * 1.732, y: -spacing, type: 'black' }, { x: spacing, y: -spacing * 1.732, type: 'white' }]; for (var i = 0; i < coinPositions.length; i++) { var pos = coinPositions[i]; var coin = new Coin(pos.type); coin.x = centerX + pos.x; coin.y = centerY + pos.y; game.addChild(coin); coins.push(coin); } } function updateScore() { scoreTxt.setText('Score: ' + score); if (score > highScore) { highScore = score; storage.highScore = highScore; highScoreTxt.setText('Best: ' + highScore); } } function checkGameOver() { if (coins.length === 0) { // All coins are pocketed, player wins LK.showYouWin(); } } function aimStriker(x, y) { var dx = x - striker.x; var dy = y - striker.y; var maxDragDistance = 200; // Maximum drag distance var dragDistance = Math.sqrt(dx * dx + dy * dy); if (dragDistance > maxDragDistance) { var scale = maxDragDistance / dragDistance; dx *= scale; dy *= scale; } var angle = Math.atan2(dy, dx); // Rotate aim line to point in the direction aimLine.rotation = angle - Math.PI / 2; aimLine.x = striker.x; aimLine.y = striker.y; aimLine.visible = true; } function shootStriker(power) { // Convert power (0-1) to velocity var maxVelocity = 100; var velocity = power * maxVelocity; // Calculate direction from aim line angle var angle = aimLine.rotation + Math.PI / 2; striker.velocityX = -Math.cos(angle) * velocity; striker.velocityY = -Math.sin(angle) * velocity; // Hide aim line and power meter aimLine.visible = false; powerMeter.visible = false; // Play sound LK.getSound('hit').play(); // Change state gameState = 'shooting'; // Reset striker position after shot LK.setTimeout(function () { striker.x = board.x; striker.y = board.y + board.height / 2 - 200; striker.velocityX = 0; // Reset velocity to ensure it stops moving striker.velocityY = 0; // Reset velocity to ensure it stops moving }, 1000); } function handleCollisions() { // Collect all game pieces var allPieces = [striker].concat(coins); // Check collisions between all pieces for (var i = 0; i < allPieces.length; i++) { var pieceA = allPieces[i]; if (!pieceA.active) { continue; } // Board edge collisions checkBoardCollision(pieceA); // Pocket collisions checkPocketCollision(pieceA); // Piece to piece collisions for (var j = i + 1; j < allPieces.length; j++) { var pieceB = allPieces[j]; if (!pieceB.active) { continue; } checkPieceCollision(pieceA, pieceB); } // Striker to coin collision if (pieceA === striker) { for (var k = 0; k < coins.length; k++) { var coin = coins[k]; if (coin.active) { checkPieceCollision(pieceA, coin); } } } } } function checkBoardCollision(piece) { var boardLeft = board.x - board.width / 2; var boardRight = board.x + board.width / 2; var boardTop = board.y - board.height / 2; var boardBottom = board.y + board.height / 2; // Adjust for piece radius var leftEdge = boardLeft + piece.radius; var rightEdge = boardRight - piece.radius; var topEdge = boardTop + piece.radius; var bottomEdge = boardBottom - piece.radius; // Check horizontal collision if (piece.x < leftEdge) { piece.x = leftEdge; piece.velocityX *= -0.9; // Bounce with slight energy loss } else if (piece.x > rightEdge) { piece.x = rightEdge; piece.velocityX *= -0.9; } // Check vertical collision if (piece.y < topEdge) { piece.y = topEdge; piece.velocityY *= -0.9; } else if (piece.y > bottomEdge) { piece.y = bottomEdge; piece.velocityY *= -0.9; } } function checkPocketCollision(piece) { for (var i = 0; i < board.pockets.length; i++) { var pocket = board.pockets[i]; var dx = piece.x - pocket.x - board.x; var dy = piece.y - pocket.y - board.y; var distance = Math.sqrt(dx * dx + dy * dy); // If the piece is in the pocket if (distance < pocket.radius - piece.radius / 2) { // Striker went in if (piece === striker) { // Reset striker position piece.velocityX = 0; piece.velocityY = 0; piece.x = board.x; piece.y = board.y + board.height / 2 - 200; } else { // A coin went in piece.active = false; piece.visible = false; // Add score score += piece.value; updateScore(); // Remove from coins array var index = coins.indexOf(piece); if (index !== -1) { coins.splice(index, 1); } // Play sound LK.getSound('pocket').play(); } // Flash effect for pocket LK.effects.flashObject(pocket, 0xFFFFFF, 300); } } } function checkPieceCollision(pieceA, pieceB) { var dx = pieceB.x - pieceA.x; var dy = pieceB.y - pieceA.y; var distance = Math.sqrt(dx * dx + dy * dy); var minDistance = pieceA.radius + pieceB.radius; // If there's a collision if (distance < minDistance) { // Play hit sound if (Math.abs(pieceA.velocityX) > 1 || Math.abs(pieceA.velocityY) > 1 || Math.abs(pieceB.velocityX) > 1 || Math.abs(pieceB.velocityY) > 1) { LK.getSound('hit').play(); } // Normal vector of collision var nx = dx / distance; var ny = dy / distance; // Tangent vector of collision var tx = -ny; var ty = nx; // Correcting overlap var overlap = minDistance - distance; var correction = overlap * 0.5; pieceA.x -= nx * correction; pieceA.y -= ny * correction; pieceB.x += nx * correction; pieceB.y += ny * correction; // Relative velocity in normal direction var vRelativeX = pieceB.velocityX - pieceA.velocityX; var vRelativeY = pieceB.velocityY - pieceA.velocityY; // Normal velocity component var vn = vRelativeX * nx + vRelativeY * ny; // Don't do anything if pieces are moving away from each other if (vn > 0) { return; } // Elasticity coefficient var e = 0.9; // Set elasticity for a realistic bounce back effect // Simplified momentum and energy equations var j = -(1 + e) * vn / (1 / pieceA.mass + 1 / pieceB.mass); // Apply impulse var jnx = j * nx; var jny = j * ny; pieceA.velocityX -= jnx / pieceA.mass; pieceA.velocityY -= jny / pieceA.mass; pieceB.velocityX += jnx / pieceB.mass; pieceB.velocityY += jny / pieceB.mass; // Transfer momentum from striker to coin if (pieceA === striker || pieceB === striker) { var coin = pieceA === striker ? pieceB : pieceA; coin.applyForce(jnx, jny); } } } function isAnyPieceMoving() { if (Math.abs(striker.velocityX) > 0.1 || Math.abs(striker.velocityY) > 0.1) { return true; } for (var i = 0; i < coins.length; i++) { if (Math.abs(coins[i].velocityX) > 0.1 || Math.abs(coins[i].velocityY) > 0.1) { return true; } } return false; } // Input handlers game.down = function (x, y) { if (gameState === 'aiming') { aimStriker(x, y); gameState = 'power'; powerLevel = 0; powerDirection = 1; powerMeter.setLevel(powerLevel); powerMeter.visible = true; } }; game.move = function (x, y) { if (gameState === 'aiming' || gameState === 'power') { aimStriker(x, y); if (gameState === 'aiming') { gameState = 'power'; powerLevel = 0; powerDirection = 1; powerMeter.setLevel(powerLevel); powerMeter.visible = true; } } else if (gameState === 'power') { powerLevel += powerDirection * powerSpeed; if (powerLevel >= 1) { powerLevel = 1; powerDirection = -1; } else if (powerLevel <= 0) { powerLevel = 0; powerDirection = 1; } powerMeter.setLevel(powerLevel); } }; game.up = function () { if (gameState === 'power') { shootStriker(powerLevel); } }; // Game update loop game.update = function () { switch (gameState) { case 'aiming': // Update power meter while aiming powerLevel += powerDirection * powerSpeed; if (powerLevel >= 1) { powerLevel = 1; powerDirection = -1; } else if (powerLevel <= 0) { powerLevel = 0; powerDirection = 1; } powerMeter.setLevel(powerLevel); break; case 'power': // Update power meter powerLevel += powerDirection * powerSpeed; if (powerLevel >= 1) { powerLevel = 1; powerDirection = -1; } else if (powerLevel <= 0) { powerLevel = 0; powerDirection = 1; } powerMeter.setLevel(powerLevel); break; case 'shooting': // Update all piece physics striker.update(); for (var i = 0; i < coins.length; i++) { coins[i].update(); } // Check all collisions handleCollisions(); // Check if all pieces have stopped moving var wasMoving = isMoving; isMoving = isAnyPieceMoving(); // Transition from moving to stopped if (wasMoving && !isMoving) { gameState = 'waiting'; // Set timeout before allowing next shot LK.setTimeout(function () { gameState = 'aiming'; checkGameOver(); }, 1000); } break; case 'waiting': // Waiting for timeout before next turn break; } }; // Initialize the game initializeGame();
===================================================================
--- original.js
+++ change.js
@@ -496,9 +496,9 @@
aimLine.visible = true;
}
function shootStriker(power) {
// Convert power (0-1) to velocity
- var maxVelocity = 70;
+ var maxVelocity = 100;
var velocity = power * maxVelocity;
// Calculate direction from aim line angle
var angle = aimLine.rotation + Math.PI / 2;
striker.velocityX = -Math.cos(angle) * velocity;
Is a top-down circular image, ideally 60–70 pixels in diameter. Has a realistic or slightly stylized design (classic carrom striker look). Has a white outer ring, with either a red, blue, or black inner design.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
I’m creating a 2D Carrom game and need a high-quality top-down Carrom board asset. Please generate. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows