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
@@ -1,5 +1,10 @@
/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
* Classes
****/
// Removed the import statement for the tween plugin as it is causing an error
// Removed the import statement for the tween plugin as it is causing an error
@@ -541,9 +546,10 @@
self.gridRow = row;
self.gridCol = col;
// Add base tile last so it appears under the pipes
var baseTileAsset = fixed ? 'baseTile' : 'baseMobileTile';
- self.attachAsset(baseTileAsset, {
+ log("setType : setting baseTile...");
+ self.baseTile = self.attachAsset(baseTileAsset, {
anchorX: 0.5,
anchorY: 0.5,
width: tileSize,
height: tileSize,
@@ -636,9 +642,9 @@
log("CORNER: turning from", incomingDirection, "to", outgoingDirection);
//log("if so, turn 90Β° or -90Β° depending on incoming and rotation...");
// For corner pipes, we turn 90Β° based on the incoming direction
// If incoming matches pipe entry point, turn 90Β° clockwise
- /*
+ /*
if (Math.abs(incomingDirection - normalizedRotation) < 0.1) {
outgoingDirection = (incomingDirection + Math.PI / 2) % (2 * Math.PI);
log("CORNER: turning clockwise from", incomingDirection, "to", outgoingDirection);
}
@@ -650,9 +656,9 @@
*/
if (outgoingDirection !== undefined) {
// Convert angle to grid movement
var dx = Math.round(Math.cos(outgoingDirection));
- var dy = Math.round(Math.sin(outgoingDirection));
+ var dy = -Math.round(Math.sin(outgoingDirection));
positions.push([col + dx, row + dy]);
log("CORNER: moving dx:", dx, "dy:", dy);
} else {
log("ERROR CORNER: incoming not matching!");
@@ -1193,17 +1199,19 @@
if (nextTile.type === TileFormat.TYPES.VERTICAL) {
if (Math.abs(incomingDirection - Math.PI / 2) < 0.1) {
nextTile.water.dir = 'tb'; // Top to Bottom
log("Set water direction to 'tb' (Top to Bottom)");
- } else if (Math.abs(incomingDirection - 3 * Math.PI / 2) < 0.1) {
+ } else {
+ //if (Math.abs(incomingDirection - 3 * Math.PI / 2) < 0.1)
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 - 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) < 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)");
}
}
@@ -1339,14 +1347,24 @@
break;
}
// Play tile slide sound
LK.getSound('tileSlide').play();
- // Move tile
+ // Move tile with tween animation
var movingTile = this.grid[oldRow][oldCol];
this.grid[oldRow][oldCol] = null;
this.grid[newRow][newCol] = movingTile;
- // Update tile position
- movingTile.updatePosition(newRow, newCol);
+ // Use tween to animate the tile movement
+ tween(movingTile, {
+ x: newCol * tileSize + gridBoard.x - gridBoard.width / 2 + tileSize / 2 + boardOffsetX,
+ y: newRow * tileSize + gridBoard.y - gridBoard.height / 2 + tileSize / 2 + boardOffsetY
+ }, {
+ duration: 300,
+ easing: tween.easeInOut,
+ onFinish: function onFinish() {
+ // Update tile position after animation completes
+ movingTile.updatePosition(newRow, newCol);
+ }
+ });
// Clear selection
this.selectedTile = null;
// Check if puzzle is solved
if (this.checkWinCondition()) {
@@ -1467,9 +1485,10 @@
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:
- flowDir = Math.PI / 2 * (Math.sin(tile.pipeContainer.rotation) - Math.cos(tile.pipeContainer.rotation));
+ log("Start detail: ", Math.PI * 2, " + ", tile.pipeContainer.rotation, " + ", Math.PI / 2, " * (", Math.abs(Math.sin(tile.pipeContainer.rotation)), " - ", Math.abs(Math.cos(tile.pipeContainer.rotation)), ")");
+ flowDir = Math.PI * 2 + tile.pipeContainer.rotation + Math.PI / 2 * (Math.abs(Math.sin(tile.pipeContainer.rotation)) - Math.abs(Math.cos(tile.pipeContainer.rotation)));
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;
@@ -1543,8 +1562,9 @@
var alphaIncrement = 0.05; // Adjust the increment for desired speed
// Animate all baseTile tiles' alpha from 1 to 0
puzzleManager.grid.forEach(function (row) {
row.forEach(function (tile) {
+ log("animate tile:", tile);
if (tile && tile.baseTile) {
tile.baseTile.alpha = 1;
LK.setInterval(function () {
if (tile.baseTile.alpha > 0) {
@@ -1598,10 +1618,10 @@
anchorY: 0.5,
visible: false,
alpha: 0
});
- gridBoardSoil.x = 2048 / 2 + 20;
- gridBoardSoil.y = 2732 / 2 - 20;
+ gridBoardSoil.x = 2048 / 2;
+ gridBoardSoil.y = 2732 / 2;
game.addChild(gridBoardSoil);
game.addChild(middleLayer);
// Create growGrass asset
growGrass = LK.getAsset('growGrass', {
@@ -1630,9 +1650,9 @@
changeGameState(GAME_STATE.MENU);
}
function initMenuState() {
// Show level selection UI
- console.log("Entering Menu State");
+ log("Entering Menu State");
isPlaying = false;
// Add backgroundPlaying1 to the menu state
var backgroundPlaying1 = LK.getAsset('backgroundPlaying1', {
anchorX: 0.5,
@@ -1709,9 +1729,9 @@
backgroundLayer.addChild(backgroundPlaying1);
//levelText.visible = true;
//levelText.text = "Level 1";
// Reset puzzle manager for new round
- console.log("Entering New Round State");
+ log("Entering New Round State");
if (puzzleManager) {
puzzleManager.initPuzzle();
}
// Show gridBoard
@@ -1728,9 +1748,9 @@
// Clean up any new round state
}
function initPlayingState() {
// Start the gameplay
- console.log("Entering Playing State");
+ log("Entering Playing State");
isPlaying = true;
}
function handlePlayingLoop() {
// Update game logic
@@ -1774,9 +1794,9 @@
}
}
function initScoreState() {
// Show score screen
- console.log("Entering Score State");
+ log("Entering Score State");
levelText.visible = true;
levelText.text = "Level Complete!\nTap to continue";
}
function handleScoreLoop() {
@@ -1795,9 +1815,9 @@
levelText.visible = false;
}
function changeGameState(newState) {
// Clean up current state
- console.log("Changing state from", currentState, "to", newState);
+ log("Changing state from", currentState, "to", newState);
switch (currentState) {
case GAME_STATE.MENU:
cleanMenuState();
break;
@@ -1919,9 +1939,9 @@
return null;
}
var parts = tileStr.split('-');
if (parts.length !== 3) {
- console.error("Invalid tile format:", tileStr);
+ log("ERROR !!! Invalid tile format:", tileStr);
return null;
}
return {
fixed: parts[0] === this.FIXED,
@@ -1991,16 +2011,8 @@
tile.type = tileData.type;
tile.fixed = tileData.fixed;
tile.gridRow = row;
tile.gridCol = col;
- // Create base tile graphics
- tile.baseTile = tile.attachAsset(tile.fixed ? 'baseTile' : 'baseMobileTile', {
- anchorX: 0.5,
- anchorY: 0.5,
- width: tileSize,
- height: tileSize,
- tint: 0xFFFFFF
- });
// Set type and create pipe graphics
tile.setType(tileData.type, row, col, tileData.fixed);
// Set initial rotation
tile.setRotation(tileData.rotation);
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