Code edit (2 edits merged)
Please save this source code
User prompt
add a new global tapOffset = 50; Then In selectTile, only when no tile is found, search again nearby tiles by using the tapOffset around the actual x,y
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught ReferenceError: dx is not defined' in or related to this line: 'log("Move at ", x, y, " => dx,dy: ", dx, dy);' Line Number: 1911
Code edit (1 edits merged)
Please save this source code
User prompt
children found difficulty to move tiles: sometimes they want to go up or down and the tile goes left or right and vice versa, make movement detection easier,
User prompt
take into account boardOffsetX and boardOffsetY in selectTile
Code edit (13 edits merged)
Please save this source code
User prompt
now make tiles move more fluid, you cas use tween plugin ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (5 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading '0')' in or related to this line: 'if (self.grid[row] && self.grid[row][col]) {' Line Number: 612
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading '0')' in or related to this line: 'var normalizedIncoming = getFlowDirection(self.grid[row][col], incomingDirection);' Line Number: 612
Code edit (3 edits merged)
Please save this source code
User prompt
Please fix the bug: 'requestAnimationFrame is not a function' in or related to this line: 'requestAnimationFrame(animate);' Line Number: 1683
User prompt
Please fix the bug: 'Unable to load plugin: @upit/tween.v1' in or related to this line: 'var tween = LK.import("@upit/tween.v1");' Line Number: 34
User prompt
Please fix the bug: 'tween is not defined' in or related to this line: 'tween(logo, {' Line Number: 1662 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'Unable to load plugin: @upit/tween.v1' in or related to this line: 'var tween = LK.import("@upit/tween.v1");' Line Number: 34
Code edit (6 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught TypeError: self.getFlowDirection is not a function' in or related to this line: 'var normalizedIncoming = self.getFlowDirection(self, incomingDirection);' Line Number: 614
Code edit (1 edits merged)
Please save this source code
Code edit (3 edits merged)
Please save this source code
User prompt
in getFlowDirection, log type, rotation , normalized rotation and returned direction
Code edit (2 edits merged)
Please save this source code
===================================================================
--- original.js
+++ change.js
@@ -577,12 +577,12 @@
}
};
self.getNextPositions = function (col, row, rotation, type, incomingDirection) {
var positions = [];
- var normalizedIncoming = incomingDirection; //(incomingDirection + Math.PI) % (2 * Math.PI);
+ //var normalizedIncoming = (incomingDirection + Math.PI) % (2 * Math.PI);
//var normalizedIncoming = getFlowDirection(puzzleManager.grid[row][col], incomingDirection);
- log("Getting next position for tile at", row, col, "type:", type, "rotation:", rotation, "incoming direction:", incomingDirection, "normalizedIncoming::", normalizedIncoming);
- incomingDirection = normalizedIncoming;
+ log("Getting next position for tile at", row, col, "type:", type, "rotation:", rotation, "incoming direction:", incomingDirection); //, "normalizedIncoming::", normalizedIncoming);
+ //incomingDirection = normalizedIncoming;
switch (type) {
case TileFormat.TYPES.START:
// Start pipe flows in direction of rotation
var dx = -Math.sin(rotation);
@@ -609,12 +609,12 @@
case TileFormat.TYPES.HORIZONTAL:
// For horizontal pipes, we flow in the opposite direction of incoming
// If water comes from left (0), we flow right
// If water comes from right (Ï€), we flow left
- if (Math.abs(incomingDirection - Math.PI) < 0.1) {
+ if (Math.abs(incomingDirection) < 0.1) {
positions.push([col + 1, row]); // Flow right
log("HORIZONTAL: incoming from left, flowing right");
- } else if (Math.abs(incomingDirection) < 0.1 || incomingDirection === 0) {
+ } else if (Math.abs(incomingDirection - Math.PI) < 0.1 || incomingDirection === 0) {
positions.push([col - 1, row]); // Flow left
log("HORIZONTAL: incoming from right, flowing left");
} else {
log("ERROR HORIZONTAL: incoming not matching!");
@@ -1180,13 +1180,14 @@
if (!nextTile) {
log("No tile at next position");
continue;
}
- var incomingDirection = Math.atan2(nextRow - row, nextCol - col);
+ var incomingDirection = Math.atan2(nextRow - row, col - nextCol);
if (!canAcceptFlowFromDirection(nextTile, incomingDirection)) {
log("Tile at row:", nextRow, "col:", nextCol, "cannot accept flow from direction:", incomingDirection);
continue;
}
+ log("== OK. Prepare next tile with previous tile at ", incomingDirection, " (", nextRow, row, nextCol, col, ")");
// Update nextTile.water.dir depending on incomingDirection
if (nextTile.water) {
log("Updating water direction for tile at row:", nextRow, "col:", nextCol);
if (nextTile.type === TileFormat.TYPES.VERTICAL) {
@@ -1197,12 +1198,12 @@
nextTile.water.dir = 'bt'; // Bottom to Top
log("Set water direction to 'bt' (Bottom to Top)");
}
} else if (nextTile.type === TileFormat.TYPES.HORIZONTAL) {
- if (Math.abs(incomingDirection) < 0.1) {
+ if (Math.abs(incomingDirection - Math.PI) < 0.1) {
nextTile.water.dir = 'lr'; // Left to Right
log("Set water direction to 'lr' (Left to Right)");
- } else if (Math.abs(incomingDirection - Math.PI) < 0.1) {
+ } else if (Math.abs(incomingDirection) < 0.1) {
nextTile.water.dir = 'rl'; // Right to Left
log("Set water direction to 'rl' (Right to Left)");
}
}
@@ -1239,11 +1240,11 @@
log("Solution path reconstructed with", self.solutionPath.length, "tiles");
return true;
}
//var nextFlowDirection = getFlowDirection(nextTile, incomingDirection);
- log("Next incoming:", incomingDirection, "get next:", getFlowDirection(nextTile, incomingDirection));
- var nextFlowDirection = incomingDirection;
+ var nextFlowDirection = getFlowDirection(currentTile, flowDirection); // incomingDirection);
var nextKey = nextRow + "," + nextCol;
+ log("Set next tile ", nextKey, " flow dir:", nextFlowDirection);
toCheck.push([nextRow, nextCol, nextFlowDirection]);
pathMap[nextKey] = {
row: nextRow,
col: nextCol,
@@ -1462,49 +1463,54 @@
* Helper Functions
****/
function getFlowDirection(tile, incomingDirection) {
//var rotation = tile.normalizeRotation(tile.pipeContainer.rotation);
- var rotation = (incomingDirection + Math.PI) % (2 * Math.PI);
- log("Tile type:", tile.type, "Rotation:", tile.pipeContainer.rotation, "incomingDirection:", incomingDirection, "Normalized incoming:", rotation);
+ var flowDir; //(incomingDirection + Math.PI) % (2 * Math.PI);
+ log("Get Output flow dir:", tile.type, "Rotation:", tile.pipeContainer.rotation, "incomingDirection:", incomingDirection); //, "Normalized incoming:", rotation);
switch (tile.type) {
case TileFormat.TYPES.START:
- rotation = tile.pipeContainer.rotation + 3 * Math.PI / 2;
+ flowDir = Math.PI / 2 * (Math.sin(tile.pipeContainer.rotation) - Math.cos(tile.pipeContainer.rotation));
break;
- //case TileFormat.TYPES.CORNER:
- //rotation = (rotation + Math.PI / 2) % (2 * Math.PI);
- // break;
+ case TileFormat.TYPES.CORNER:
+ if (Math.abs(tile.pipeContainer.rotation - incomingDirection) < 0.1 || Math.abs(tile.pipeContainer.rotation + Math.PI - incomingDirection) < 0.1) {
+ flowDir = incomingDirection + Math.PI / 2;
+ } else {
+ flowDir = incomingDirection - Math.PI / 2;
+ }
+ break;
default:
- rotation = rotation;
+ flowDir = incomingDirection; // + Math.PI; // From side to oposite side
break;
}
- rotation = rotation % (2 * Math.PI);
- log("Returned flow direction:", rotation);
- return rotation;
+ flowDir = flowDir % (2 * Math.PI);
+ log("Returned output flow direction:", flowDir);
+ return flowDir;
}
function canAcceptFlowFromDirection(tile, incomingDirection) {
var normalizedIncoming = (incomingDirection + Math.PI) % (2 * Math.PI);
var tileRotation = tile.normalizeRotation(tile.pipeContainer.rotation);
- log("Checking if tile can accept flow. Tile type:", tile.type, "Incoming direction:", incomingDirection, "Normalized incoming:", normalizedIncoming, "Tile rotation:", tileRotation);
+ log("Checking if tile can accept flow. Tile type:", tile.type, "Tile rotation:", tileRotation, " previous tile at:", incomingDirection, " => Incoming flow dir:", normalizedIncoming);
+ var angleDiff = null;
switch (tile.type) {
case TileFormat.TYPES.START:
log("No => Tile type is START. Cannot accept flow.");
return false;
case TileFormat.TYPES.END:
- var angle = (normalizedIncoming - tileRotation - Math.PI / 2) % (2 * Math.PI);
- log("Yes => Tile type is END. Calculated angle:", angle);
- return angle < 0.1;
+ angleDiff = (normalizedIncoming - tileRotation - Math.PI / 2) % (2 * Math.PI);
+ log("Yes => Tile type is END.");
+ return angleDiff < 0.1;
case TileFormat.TYPES.VERTICAL:
- var angle = Math.abs(normalizedIncoming - Math.PI / 2) % (2 * Math.PI);
- log("Yes => Tile type is VERTICAL. Calculated angle:", angle);
- return angle < 0.1 || Math.abs(angle - Math.PI) < 0.1;
+ angleDiff = Math.abs(normalizedIncoming - Math.PI / 2) % (2 * Math.PI);
+ log("Yes => Tile type is VERTICAL");
+ return angleDiff < 0.1 || Math.abs(angleDiff - Math.PI) < 0.1;
case TileFormat.TYPES.HORIZONTAL:
- var angle = normalizedIncoming % (2 * Math.PI);
- log("Yes => Tile type is HORIZONTAL. Calculated angle:", angle);
- return angle < 0.1 || Math.abs(angle - Math.PI) < 0.1;
+ angleDiff = normalizedIncoming % (2 * Math.PI);
+ log("Yes => Tile type is HORIZONTAL");
+ return angleDiff < 0.1 || Math.abs(angleDiff - Math.PI) < 0.1;
case TileFormat.TYPES.CORNER:
- var angle = (normalizedIncoming - tileRotation - Math.PI) % (2 * Math.PI);
- log("Yes => Tile type is CORNER. Calculated angle:", angle);
- return angle < 0.1 || Math.abs(angle - Math.PI / 2) < 0.1;
+ angleDiff = (normalizedIncoming - tileRotation - Math.PI) % (2 * Math.PI);
+ log("Yes => Tile type is CORNER.");
+ return angleDiff < 0.1 || Math.abs(angleDiff - Math.PI / 2) < 0.1;
default:
log("No => Tile type is unknown. Cannot accept flow.");
return false;
}
straigth zenith view square light wooden pallet. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
straigth zenith view square wooden pallet with big screws in each corner Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
simple yellow rating star. Modern video game style
tileSlide
Sound effect
levelWon
Sound effect
tileBlocked
Sound effect
fountain
Sound effect
waterInPipe
Sound effect
bgMusic
Music
logoBounce
Sound effect
levelStart
Sound effect
bgMusic2
Music
flowerPop
Sound effect
roundResult
Sound effect
gameWon
Sound effect
resetSound
Sound effect
birds
Sound effect
birds2
Sound effect
birds3
Sound effect