Code edit (4 edits merged)
Please save this source code
User prompt
fix `self.waterCorner.alpha = Math.min(Math.max(0, (progress - thirdSize) / thirdSize - 0.5), 1); // Animate alpha from 0 to 1` so that alpha goes from 0 to 1 when `(progress-thirdSize)/thirdSize` goes from 0.5 to 1
Code edit (11 edits merged)
Please save this source code
User prompt
in cornerPipe water anim, animate warterCorner alpha from 0 to 1
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
let the fontain rotate indefinetly
Code edit (5 edits merged)
Please save this source code
User prompt
and make the fontain rotate
User prompt
For the end tile, for the water animation use the fountain asset and make grow w & h
Code edit (1 edits merged)
Please save this source code
Code edit (6 edits merged)
Please save this source code
User prompt
For start pipe, in update, instead of a water w/h anim, make the valve rotate
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 'type')' in or related to this line: 'log('Flowing through pipe at:', key, 'Tile type:', tile.type);' Line Number: 510
User prompt
add log in flowThroughPipe
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught ReferenceError: _slicedToArray is not defined' in or related to this line: 'var _pos$split$map = pos.split(',').map(Number),' Line Number: 283
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught TypeError: setInterval is not a function' in or related to this line: 'var checkFlowInterval = setInterval(function () {' Line Number: 628
User prompt
in animateWaterFlow, set flow to true in start tile and wait until flow returns to false; then do same for the next tile until the end pipe tile.
User prompt
When puzzle is solved we will run an animation to simulate water flowing from start pipe to end pipe. Add a new function for flow animation; call it when puzzle is solved;
User prompt
prevent moves when !isPlaying
===================================================================
--- original.js
+++ change.js
@@ -205,137 +205,8 @@
/****
* Game Code
****/
-// Debug and logging
-function _slicedToArray2(r, e) {
- return _arrayWithHoles2(r) || _iterableToArrayLimit2(r, e) || _unsupportedIterableToArray2(r, e) || _nonIterableRest2();
-}
-function _nonIterableRest2() {
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
-}
-function _unsupportedIterableToArray2(r, a) {
- if (r) {
- if ("string" == typeof r) {
- return _arrayLikeToArray2(r, a);
- }
- var t = {}.toString.call(r).slice(8, -1);
- return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray2(r, a) : void 0;
- }
-}
-function _arrayLikeToArray2(r, a) {
- (null == a || a > r.length) && (a = r.length);
- for (var e = 0, n = Array(a); e < a; e++) {
- n[e] = r[e];
- }
- return n;
-}
-function _iterableToArrayLimit2(r, l) {
- var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
- if (null != t) {
- var e,
- n,
- i,
- u,
- a = [],
- f = !0,
- o = !1;
- try {
- if (i = (t = t.call(r)).next, 0 === l) {
- if (Object(t) !== t) {
- return;
- }
- f = !1;
- } else {
- for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0) {
- ;
- }
- }
- } catch (r) {
- o = !0, n = r;
- } finally {
- try {
- if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) {
- return;
- }
- } finally {
- if (o) {
- throw n;
- }
- }
- }
- return a;
- }
-}
-function _arrayWithHoles2(r) {
- if (Array.isArray(r)) {
- return r;
- }
-}
-function _slicedToArray(r, e) {
- return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
-}
-function _nonIterableRest() {
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
-}
-function _unsupportedIterableToArray(r, a) {
- if (r) {
- if ("string" == typeof r) {
- return _arrayLikeToArray(r, a);
- }
- var t = {}.toString.call(r).slice(8, -1);
- return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
- }
-}
-function _arrayLikeToArray(r, a) {
- (null == a || a > r.length) && (a = r.length);
- for (var e = 0, n = Array(a); e < a; e++) {
- n[e] = r[e];
- }
- return n;
-}
-function _iterableToArrayLimit(r, l) {
- var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
- if (null != t) {
- var e,
- n,
- i,
- u,
- a = [],
- f = !0,
- o = !1;
- try {
- if (i = (t = t.call(r)).next, 0 === l) {
- if (Object(t) !== t) {
- return;
- }
- f = !1;
- } else {
- for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0) {
- ;
- }
- }
- } catch (r) {
- o = !0, n = r;
- } finally {
- try {
- if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) {
- return;
- }
- } finally {
- if (o) {
- throw n;
- }
- }
- }
- return a;
- }
-}
-function _arrayWithHoles(r) {
- if (Array.isArray(r)) {
- return r;
- }
-}
var PuzzleManager = function PuzzleManager() {
var self = this;
// Properties
self.currentLevel = 1;
@@ -562,27 +433,11 @@
isPlaying = false;
}
};
self.startWaterFlow = function () {
- // Find start tile and enable water flow
- for (var i = 0; i < self.gridSize; i++) {
- for (var j = 0; j < self.gridSize; j++) {
- if (self.grid[i][j].type === 'start') {
- // Start water flow from here
- self.waterFlow(i, j);
- break;
- }
- }
- }
- // Call the flow animation function
- self.animateWaterFlow();
- };
- self.animateWaterFlow = function () {
- // Logic to animate water flow from start to end
- log("Animating water flow from start to end");
+ // Find start position
var startX = -1,
startY = -1;
- // Find start position
for (var i = 0; i < self.gridSize; i++) {
for (var j = 0; j < self.gridSize; j++) {
if (self.grid[i][j].type === 'start') {
startX = i;
@@ -593,98 +448,74 @@
if (startX !== -1) {
break;
}
}
- function flowToNextTile(x, y, visited) {
- var key = x + ',' + y;
- if (visited.includes(key)) {
- return;
- }
- visited.push(key);
- var tile = self.grid[x][y];
- if (!tile || tile.type === 'empty') {
- return;
- }
- // Enable water flow for this tile
- tile.flow = true;
- // Wait until flow is false
- var checkFlowInterval = LK.setInterval(function () {
- if (!tile.flow) {
- clearInterval(checkFlowInterval);
- // Calculate next positions based on tile type and rotation
- var nextPositions = [];
- switch (tile.type) {
- case 'start':
- nextPositions.push([x, y + 1]); // Flow down
- break;
- case 'straightPipeV':
- nextPositions.push([x, y + 1], [x, y - 1]);
- break;
- case 'straightPipeH':
- nextPositions.push([x + 1, y], [x - 1, y]);
- break;
- case 'cornerPipe':
- if (tile.rotation === Math.PI * 0.5) {
- nextPositions.push([x, y - 1], [x + 1, y]);
- }
- break;
- }
- // Continue flow to next positions
- for (var i = 0; i < nextPositions.length; i++) {
- var nextX = nextPositions[i][0];
- var nextY = nextPositions[i][1];
- if (nextX >= 0 && nextX < self.gridSize && nextY >= 0 && nextY < self.gridSize) {
- flowToNextTile(nextX, nextY, visited);
- }
- }
- }
- }, 100);
- }
- flowToNextTile(startX, startY, []);
+ // Start the flow animation from the start tile
+ self.flowThroughPipe(startX, startY, []);
};
- self.waterFlow = function (x, y) {
- var visited = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
- var key = "".concat(x, ",").concat(y);
+ self.flowThroughPipe = function (x, y, visited) {
+ var key = x + ',' + y;
if (visited.includes(key)) {
return;
}
visited.push(key);
var tile = self.grid[x][y];
if (!tile || tile.type === 'empty') {
return;
}
- // Enable water flow for this tile
+ // Enable flow for current tile
tile.flow = true;
- // Calculate next positions based on tile type and rotation
- var nextPositions = [];
+ // Wait for flow animation to complete before moving to next tile
+ LK.setTimeout(function () {
+ // Get next tile position based on current tile type
+ var nextPos = self.getNextPosition(x, y, tile);
+ if (nextPos) {
+ self.flowThroughPipe(nextPos[0], nextPos[1], visited);
+ }
+ }, 500); // Wait 500ms before flowing to next tile
+ };
+ self.getNextPosition = function (x, y, tile) {
switch (tile.type) {
case 'start':
- nextPositions.push([x, y + 1]); // Flow down
- break;
+ return [x, y + 1];
+ // Flow down from start
case 'straightPipeV':
- nextPositions.push([x, y + 1], [x, y - 1]);
- break;
+ // Check if water came from top or bottom
+ var nextY = self.grid[x][y - 1] && self.grid[x][y - 1].flow ? y + 1 : y - 1;
+ return [x, nextY];
case 'straightPipeH':
- nextPositions.push([x + 1, y], [x - 1, y]);
- break;
+ // Check if water came from left or right
+ var nextX = self.grid[x - 1][y] && self.grid[x - 1][y].flow ? x + 1 : x - 1;
+ return [x, nextX];
case 'cornerPipe':
- // Add logic for corner pipe based on rotation
if (tile.rotation === Math.PI * 0.5) {
// Left rotation
- nextPositions.push([x, y - 1], [x + 1, y]);
+ // If water came from top, go right; if from right, go up
+ if (self.grid[x][y - 1] && self.grid[x][y - 1].flow) {
+ return [x + 1, y];
+ } else if (self.grid[x + 1][y] && self.grid[x + 1][y].flow) {
+ return [x, y - 1];
+ }
}
- // Add other rotation cases
+ // Add other rotations as needed
break;
+ case 'crossPipe':
+ // Determine direction based on where water came from
+ if (self.grid[x][y - 1] && self.grid[x][y - 1].flow) {
+ return [x, y + 1];
+ }
+ if (self.grid[x][y + 1] && self.grid[x][y + 1].flow) {
+ return [x, y - 1];
+ }
+ if (self.grid[x - 1][y] && self.grid[x - 1][y].flow) {
+ return [x + 1, y];
+ }
+ if (self.grid[x + 1][y] && self.grid[x + 1][y].flow) {
+ return [x - 1, y];
+ }
+ break;
}
- // Continue flow to next positions
- for (var _i = 0, _nextPositions = nextPositions; _i < _nextPositions.length; _i++) {
- var _nextPositions$_i = _slicedToArray(_nextPositions[_i], 2),
- nextX = _nextPositions$_i[0],
- nextY = _nextPositions$_i[1];
- if (nextX >= 0 && nextX < self.gridSize && nextY >= 0 && nextY < self.gridSize) {
- self.waterFlow(nextX, nextY, visited);
- }
- }
+ return null;
};
return self;
};
var debug = true;
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