User prompt
If the cursor is in coin position rotate the coin asset
User prompt
add collision to coin and cursor if touched play rotation animation
User prompt
rotate the coin image 360° x 2 times if mouse button was clicked then cursor touched the coin object asset.
User prompt
Make the rotation x 2 to the left side for the coin
User prompt
If cursor touched coin make it rotated by 360° x 2 times.
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (7 edits merged)
Please save this source code
User prompt
Lower the size of background1 little bit from the top to be below the pause button.
User prompt
Make the coin big a bit
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
Make coin 1-7 position code for each
User prompt
Add position of each coin in the code
User prompt
center the coins
User prompt
If i hold on the coin and move the cursor move the coin with it
User prompt
Don't random the coins positions
User prompt
Add drag by click on the coin
User prompt
Add the 7 coins to the game
User prompt
Set the background behind all objects
User prompt
increase size of the coins and make it inside the screen not outside the boundaries.
User prompt
add 7 coins with random position in the screen.
User prompt
Add coin assets to get collected by cursor on the screen
/**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Create a point asset for the cursor var point = LK.getAsset('point', { anchorX: 0.5, anchorY: 0.5 }); game.addChild(point); // Handle mouse movement // Add background to the game var background = LK.getAsset('Background1', { anchorX: 0.5, anchorY: 0.5, scaleX: 2048 / 1000, scaleY: 2732 / 1075 }); game.addChildAt(background, 0); background.x = 2048 / 2; background.y = 2732 / 2 + 115; // Lower the background a bit from the top game.down = function (x, y, obj) { // Check if the mouse is down game.isMouseDown = true; // Check for intersection with coin assets game.children.forEach(function (child) { if (child.id === 'coin' && point.intersects(child)) { // Set the coin asset to be dragged game.draggedCoin = child; // Rotate the coin by 360° x 2 times to the left when the cursor touches it child.rotation -= Math.PI * 4; // Rotate the coin by 360° x 2 times to the left when the cursor touches it child.rotation -= Math.PI * 4; } }); }; // Create 7 new coin assets at fixed positions for (var i = 0; i < 7; i++) { var newCoin = LK.getAsset('coin', { anchorX: 0.5, anchorY: 0.5, scaleX: 3, scaleY: 3 }); game.addChild(newCoin); // Set the coins at fixed positions if (i === 0) { newCoin.x = 1035; newCoin.y = 550; } else if (i === 1) { newCoin.x = 775; newCoin.y = 790; } else if (i === 2) { newCoin.x = 640; newCoin.y = 1485; } else if (i === 3) { newCoin.x = 1685; newCoin.y = 670; } else if (i === 4) { newCoin.x = 640; newCoin.y = 1840; } else if (i === 5) { newCoin.x = 365; newCoin.y = 1425; } else if (i === 6) { newCoin.x = 1815; newCoin.y = 1425; } else { newCoin.x = 200 + i * 200; newCoin.y = 200 + i * 200; } console.log("Coin " + (i + 1) + " position: x=" + newCoin.x + ", y=" + newCoin.y); } game.up = function (x, y, obj) { // Set a flag to track if the mouse is up game.isMouseDown = false; }; game.move = function (x, y, obj) { // Check if the mouse is down if (game.isMouseDown) { // Create a new point asset at the current mouse position var newPoint = LK.getAsset('point', { anchorX: 0.5, anchorY: 0.5 }); game.addChild(newPoint); newPoint.x = x; newPoint.y = y; // Add speed to the point newPoint.speed = 5; // Check for intersection with coin assets game.children.forEach(function (child) { if (child.id === 'coin' && newPoint.intersects(child)) { // Remove the coin asset from the game game.removeChild(child); } }); } };
===================================================================
--- original.js
+++ change.js
@@ -34,8 +34,10 @@
// Set the coin asset to be dragged
game.draggedCoin = child;
// Rotate the coin by 360° x 2 times to the left when the cursor touches it
child.rotation -= Math.PI * 4;
+ // Rotate the coin by 360° x 2 times to the left when the cursor touches it
+ child.rotation -= Math.PI * 4;
}
});
};
// Create 7 new coin assets at fixed positions