User prompt
Please fix the bug: 'Uncaught ReferenceError: levelText is not defined' in or related to this line: 'levelText.setText('Level: ' + self.currentLevel + ' Solved!');' Line Number: 592
User prompt
Please fix the bug: 'Uncaught TypeError: Set is not a constructor' in or related to this line: 'var visited = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new Set();' Line Number: 608
User prompt
Please fix the bug: 'Uncaught TypeError: Set is not a constructor' in or related to this line: 'var visited = new Set();' Line Number: 424
User prompt
implement checkWinCondition
User prompt
ok, now after each player move, check if puzzle is solved. if so add "Solved !" in levelText
User prompt
add a text under the board to show current level number
Code edit (14 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'undefined')' in or related to this line: 'var baseTileAsset = type == 'start' || type == 'end' || self.levelConfigs[self.currentLevel] && self.levelConfigs[self.currentLevel].fixedTiles && self.levelConfigs[self.currentLevel].fixedTiles.includes(self.position.x + ',' + self.position.y) ? 'baseTile' : 'baseMobileTile';' Line Number: 40
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'undefined')' in or related to this line: 'var baseTileAsset = type == 'start' || type == 'end' || self.levelConfigs[self.currentLevel] && self.levelConfigs[self.currentLevel].fixedTiles.includes(self.position.x + ',' + self.position.y) ? 'baseTile' : 'baseMobileTile';' Line Number: 40
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'undefined')' in or related to this line: 'var baseTileAsset = type == 'start' || type == 'end' || self.levelConfigs[self.currentLevel].fixedTiles.includes(self.position.x + ',' + self.position.y) ? 'baseTile' : 'baseMobileTile';' Line Number: 40
User prompt
update line `var baseTileAsset = type == 'start' || type == 'end' || type == 'fixed' ? 'baseTile' : 'baseMobileTile';` to use fixedTiles
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (9 edits merged)
Please save this source code
User prompt
make water height anim faster
Code edit (4 edits merged)
Please save this source code
User prompt
make height anim faster
User prompt
change height sin anim into a linear anim
Code edit (1 edits merged)
Please save this source code
User prompt
along with tint anim add a height anim
Code edit (1 edits merged)
Please save this source code
Code edit (5 edits merged)
Please save this source code
User prompt
change the sin anim by something more linear
Code edit (1 edits merged)
Please save this source code
User prompt
change alpha animation by a tint animation from black to white
===================================================================
--- original.js
+++ change.js
@@ -8,9 +8,9 @@
self.baseTint = 0x8FBE00;
self.baseTintLight = 0x5ED000;
self.maxWaterSize = 250;
self.flowSpeed = 4;
- self.flow = true;
+ self.flow = false;
self.connections = [];
self.position = {
x: 0,
y: 0
@@ -18,9 +18,9 @@
self.rotation = 0;
// Methods
self.setType = function (type) {
self.type = type;
- var baseTileAsset = type == 'start' || type == 'end' || type == 'fixed' ? 'baseTile' : 'baseMobileTile';
+ var baseTileAsset = type == 'start' || type == 'end' || self.levelConfigs[self.currentLevel].fixedTiles.includes(self.position.x + ',' + self.position.y) ? 'baseTile' : 'baseMobileTile';
if (type == 'empty') {
return;
}
// Attach baseTile asset
@@ -34,9 +34,9 @@
self.width = tileSize;
self.height = tileSize;
switch (type) {
case 'start':
- self.attachAsset('startTile', {
+ self.attachAsset('startPipeAsset', {
anchorX: 0.5,
anchorY: 0.5,
x: 20,
y: 55,
@@ -50,52 +50,52 @@
tint: self.baseTint
});
break;
case 'end':
- self.attachAsset('endTile', {
+ self.attachAsset('endPipeAsset', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 55,
tint: self.baseTint
});
break;
- case 'fixed':
- self.attachAsset('straightPipe', {
+ case 'crossPipe':
+ self.attachAsset('straightPipeHAsset', {
anchorX: 0.5,
anchorY: 0.5,
y: -40,
tint: self.baseTint
});
- self.attachAsset('straightPipe', {
+ self.attachAsset('straightPipeHAsset', {
anchorX: 0.5,
anchorY: 0.5,
scaleY: -1,
y: 30,
tint: self.baseTint
});
- self.attachAsset('straightPipeV', {
+ self.attachAsset('straightPipeVAsset', {
anchorX: 0.5,
anchorY: 0.5,
x: -30,
tint: self.baseTint
});
- self.attachAsset('straightPipeV', {
+ self.attachAsset('straightPipeVAsset', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: -1,
x: 30,
tint: self.baseTint
});
break;
case 'straightPipeH':
- self.attachAsset('straightPipe', {
+ self.attachAsset('straightPipeHAsset', {
anchorX: 0.5,
anchorY: 0.5,
y: -40,
tint: self.baseTint
});
- self.attachAsset('straightPipe', {
+ self.attachAsset('straightPipeHAsset', {
anchorX: 0.5,
anchorY: 0.5,
scaleY: -1,
y: 30,
@@ -111,15 +111,15 @@
dir: 'lr'
});
break;
case 'straightPipeV':
- self.attachAsset('straightPipeV', {
+ self.attachAsset('straightPipeVAsset', {
anchorX: 0.5,
anchorY: 0.5,
x: -30,
tint: self.baseTint
});
- self.attachAsset('straightPipeV', {
+ self.attachAsset('straightPipeVAsset', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: -1,
x: 30,
@@ -135,9 +135,9 @@
dir: 'tb'
});
break;
case 'cornerPipe':
- self.attachAsset('cornerPipe', {
+ self.attachAsset('cornerPipeAsset', {
anchorX: 0.5,
anchorY: 0.5,
x: -60,
y: -60,
@@ -206,8 +206,72 @@
/****
* 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() {
@@ -282,13 +346,14 @@
self.waterFlowing = false;
// Level configurations
self.levelConfigs = {
1: {
- tiles: [['start', 'straightPipeV', 'straightPipeV', 'cornerPipe'], [null, null, null, 'straightPipeH'], [null, 'straightPipeH', 'straightPipeH', null], [null, null, null, 'end']],
+ tiles: [['start', 'straightPipeV', 'straightPipeV', 'cornerPipe'], [null, null, null, 'straightPipeH'], [null, null, 'straightPipeH', null], [null, null, null, 'end']],
rotations: {
- '2,2': 'right',
- '0,3': 'left'
- }
+ '0,3': 'left',
+ '3,3': 'left'
+ },
+ fixedTiles: ['0,0', '0,1', '0,2', '0,3', '1,3', '3,3'] // All tiles fixed except 2,2
},
2: {
tiles: [['start', 'straightPipeH', null, null], [null, 'cornerPipe', null, null], [null, 'straightPipeV', 'cornerPipe', null], [null, null, null, 'end']],
rotations: {
@@ -341,28 +406,148 @@
return false;
};
// Handle tile selection and movement
self.selectTile = function (x, y) {
- var tile = self.grid[x][y];
- if (tile && tile.type !== 'empty' && tile.type !== 'start' && tile.type !== 'end' && tile.type !== 'fixed') {
- self.selectedTile = tile;
- // Add visual feedback for selection
+ // Convert screen coordinates to grid coordinates
+ var gridX = Math.floor((x - (gridBoard.x - gridBoard.width / 2 + tileSize / 2)) / tileSize);
+ var gridY = Math.floor((y - (gridBoard.y - gridBoard.height / 2 + tileSize / 2)) / tileSize);
+ // Check if coordinates are within grid
+ if (gridX >= 0 && gridX < self.gridSize && gridY >= 0 && gridY < self.gridSize) {
+ var tile = self.grid[gridX][gridY];
+ var key = gridX + ',' + gridY;
+ // Check if tile exists, is not empty, not start/end, and not fixed
+ if (tile && tile.type !== 'empty' && tile.type !== 'start' && tile.type !== 'end' && !self.levelConfigs[self.currentLevel].fixedTiles.includes(key)) {
+ self.selectedTile = {
+ x: gridX,
+ y: gridY,
+ tile: tile
+ };
+ // Check possible moves
+ self.checkPossibleMoves();
+ }
}
};
- self.moveTile = function (direction) {
+ self.checkPossibleMoves = function () {
if (!self.selectedTile) {
return;
}
- // Implement tile movement logic
- // Should handle sliding tiles in the specified direction
+ var x = self.selectedTile.x;
+ var y = self.selectedTile.y;
+ var possibleMoves = [];
+ // Check each direction
+ // Right
+ if (x < self.gridSize - 1 && self.grid[x + 1][y].type === 'empty') {
+ possibleMoves.push('right');
+ }
+ // Left
+ if (x > 0 && self.grid[x - 1][y].type === 'empty') {
+ possibleMoves.push('left');
+ }
+ // Down
+ if (y < self.gridSize - 1 && self.grid[x][y + 1].type === 'empty') {
+ possibleMoves.push('down');
+ }
+ // Up
+ if (y > 0 && self.grid[x][y - 1].type === 'empty') {
+ possibleMoves.push('up');
+ }
+ self.selectedTile.possibleMoves = possibleMoves;
};
- self.rotateTile = function () {
- if (!self.selectedTile) {
+ self.moveTile = function (direction) {
+ if (!self.selectedTile || !self.selectedTile.possibleMoves.includes(direction)) {
return;
}
- // Implement tile rotation logic
- // Should rotate the selected tile 90 degrees
+ var oldX = self.selectedTile.x;
+ var oldY = self.selectedTile.y;
+ var newX = oldX;
+ var newY = oldY;
+ // Calculate new position
+ switch (direction) {
+ case 'right':
+ newX++;
+ break;
+ case 'left':
+ newX--;
+ break;
+ case 'down':
+ newY++;
+ break;
+ case 'up':
+ newY--;
+ break;
+ }
+ // Swap tiles
+ var movingTile = self.grid[oldX][oldY];
+ var emptyTile = self.grid[newX][newY];
+ // Update grid
+ self.grid[newX][newY] = movingTile;
+ self.grid[oldX][oldY] = emptyTile;
+ // Update positions
+ movingTile.updatePosition(newX, newY);
+ emptyTile.updatePosition(oldX, oldY);
+ // Clear selection
+ self.selectedTile = null;
+ // Check if puzzle is solved
+ if (self.checkWinCondition()) {
+ self.startWaterFlow();
+ }
};
+ 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;
+ }
+ }
+ }
+ };
+ self.waterFlow = function (x, y) {
+ var visited = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new Set();
+ var key = "".concat(x, ",").concat(y);
+ if (visited.has(key)) {
+ return;
+ }
+ visited.add(key);
+ var tile = self.grid[x][y];
+ if (!tile || tile.type === 'empty') {
+ return;
+ }
+ // Enable water flow for this tile
+ tile.flow = true;
+ // 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':
+ // 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]);
+ }
+ // Add other rotation cases
+ break;
+ }
+ // Continue flow to next positions
+ for (var _i = 0, _nextPositions = nextPositions; _i < _nextPositions.length; _i++) {
+ var _nextPositions$_i = _slicedToArray2(_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 self;
};
var debug = true;
function log() {
@@ -376,8 +561,13 @@
var boardOffsetY = 90;
// Game state
var gridBoard;
var puzzleManager;
+var isMouseDown = false;
+var startX = 0;
+var startY = 0;
+var selectedTile = null;
+var dragThreshold = 20;
// Initialize game board
gridBoard = LK.getAsset('gridBoard', {
anchorX: 0.5,
anchorY: 0.5
@@ -386,18 +576,37 @@
gridBoard.y = 2732 / 2;
game.addChild(gridBoard);
// Event handlers
game.down = function (x, y, obj) {
- // Handle touch/click events
- // Should call appropriate puzzle manager methods
+ startX = x;
+ startY = y;
+ isMouseDown = true;
+ if (puzzleManager) {
+ puzzleManager.selectTile(x, y);
+ }
};
-game.up = function (x, y, obj) {
- // Handle touch/click release
+game.move = function (x, y, obj) {
+ if (!isMouseDown || !puzzleManager || !puzzleManager.selectedTile) {
+ return;
+ }
+ var deltaX = x - startX;
+ var deltaY = y - startY;
+ // Only move if drag distance exceeds threshold
+ if (Math.abs(deltaX) > dragThreshold || Math.abs(deltaY) > dragThreshold) {
+ var direction = null;
+ if (Math.abs(deltaX) > Math.abs(deltaY)) {
+ direction = deltaX > 0 ? 'right' : 'left';
+ } else {
+ direction = deltaY > 0 ? 'down' : 'up';
+ }
+ puzzleManager.moveTile(direction);
+ isMouseDown = false; // Reset after move
+ }
};
-game.update = function () {
- // Update game state
+game.up = function (x, y, obj) {
+ isMouseDown = false;
if (puzzleManager) {
- // Update puzzle state
+ puzzleManager.selectedTile = null;
}
};
// Initialize game
function initializeGame() {
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