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
@@ -1,22 +1,23 @@
/****
* Classes
****/
-// Assets will be automatically created and loaded by the LK engine based on their usage in the code.
-// Define a Tile class to represent each tile in the grid
var Tile = Container.expand(function () {
var self = Container.call(this);
- self.type = 'empty'; // Default type
+ // Properties
+ self.type = 'empty';
self.baseTint = 0x8FBE00;
self.baseTintLight = 0x5ED000;
- self.maxWaterSize = 250; // V
+ self.maxWaterSize = 250;
+ self.flowSpeed = 4;
self.flow = true;
- self.connections = []; // Connection points for pipes
+ self.connections = [];
self.position = {
x: 0,
y: 0
- }; // Grid position
- // Method to set the tile type
+ };
+ self.rotation = 0;
+ // Methods
self.setType = function (type) {
self.type = type;
var baseTileAsset = type == 'start' || type == 'end' || type == 'fixed' ? 'baseTile' : 'baseMobileTile';
if (type == 'empty') {
@@ -27,14 +28,12 @@
anchorX: 0.5,
anchorY: 0.5,
width: tileSize,
height: tileSize,
- tint: 0xFFFFFF // 0x9EBE7E // vert
+ tint: 0xFFFFFF
});
- // Set default dimensions based on tileSize
self.width = tileSize;
self.height = tileSize;
- // Attach appropriate asset based on type
switch (type) {
case 'start':
self.attachAsset('startTile', {
anchorX: 0.5,
@@ -60,12 +59,8 @@
tint: self.baseTint
});
break;
case 'fixed':
- // self.attachAsset('fixedPipe', {
- // anchorX: 0.5,
- // anchorY: 0.5
- // });
self.attachAsset('straightPipe', {
anchorX: 0.5,
anchorY: 0.5,
y: -40,
@@ -105,8 +100,17 @@
scaleY: -1,
y: 30,
tint: self.baseTint
});
+ self.water = self.attachAsset('waterH', {
+ anchorX: 0,
+ anchorY: 0.5,
+ x: -130,
+ y: -5,
+ width: 0,
+ visible: false,
+ dir: 'lr'
+ });
break;
case 'straightPipeV':
self.attachAsset('straightPipeV', {
anchorX: 0.5,
@@ -120,16 +124,16 @@
scaleX: -1,
x: 30,
tint: self.baseTint
});
- // Water
self.water = self.attachAsset('waterV', {
anchorX: 0.5,
anchorY: 0,
x: -0,
y: -120,
height: 0,
- visible: false
+ visible: false,
+ dir: 'tb'
});
break;
case 'cornerPipe':
self.attachAsset('cornerPipe', {
@@ -139,18 +143,10 @@
y: -60,
tint: self.baseTintLight
});
break;
- //case 'empty':
- default:
- // self.attachAsset('emptyTile', {
- // anchorX: 0.5,
- // anchorY: 0.5
- // });
- break;
}
};
- // Method to update the tile's position
self.updatePosition = function (x, y) {
self.position.x = x;
self.position.y = y;
if (self.baseTile) {
@@ -161,116 +157,252 @@
self.y = y * tileSize + gridBoard.y - gridBoard.height / 2 + tileSize / 2 + boardOffsetY;
log('Tile index:', x, y, 'Tile position:', self.x, self.y, 'Tile dimensions:', self.width, self.height, ' self:', self);
};
self.setRotation = function (direction) {
- self.rotation = Math.PI * 0.5;
+ switch (direction) {
+ case 'left':
+ self.rotation = Math.PI * 0.5;
+ break;
+ case 'right':
+ self.rotation = -Math.PI * 0.5;
+ break;
+ case 'up':
+ self.rotation = 0;
+ break;
+ case 'down':
+ self.rotation = Math.PI;
+ break;
+ }
log('Tile position:', self.x, self.y, 'Tile rotation:', self.rotation);
};
- self.setType(self.type);
- // Add update function to animate the alpha of self.water1 and self.water2
self.update = function () {
if (self.water && self.flow) {
- if (!self.water.height) {
+ if (!self.water.height || !self.water.width) {
self.water.visible = true;
}
- // self.water2.tint = tintValue;
- // Add height animation
- var heightValue = LK.ticks % 250; // Calculate height value in a linear way
+ var heightValue = LK.ticks * self.flowSpeed;
if (heightValue < self.maxWaterSize) {
- self.water.height = heightValue;
+ if (self.water.dir == 'tb') {
+ self.water.height = heightValue;
+ }
+ if (self.water.dir == 'lr') {
+ self.water.width = heightValue;
+ }
} else {
self.flow = false;
}
- // self.water2.height = heightValue;
}
};
+ self.setType(self.type);
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
- backgroundColor: 0x000000 // Init game with black background
+ backgroundColor: 0x000000
});
/****
* Game Code
****/
-// Add a global log() function that makes console.debug if global debug is true
-1;
+// Debug and logging
+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;
+ self.maxLevels = 30;
+ self.grid = [];
+ self.gridSize = 4;
+ self.selectedTile = null;
+ 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']],
+ rotations: {
+ '2,2': 'right',
+ '0,3': 'left'
+ }
+ },
+ 2: {
+ tiles: [['start', 'straightPipeH', null, null], [null, 'cornerPipe', null, null], [null, 'straightPipeV', 'cornerPipe', null], [null, null, null, 'end']],
+ rotations: {
+ '0,1': 'right',
+ '1,1': 'down',
+ '2,2': 'left'
+ }
+ }
+ // Add more levels here
+ };
+ // Initialize the puzzle for current level
+ self.initPuzzle = function () {
+ log("Initializing puzzle for level", self.currentLevel);
+ // Clear existing grid
+ self.grid = [];
+ // Get level config
+ var config = self.levelConfigs[self.currentLevel];
+ if (!config) {
+ log("No configuration for level", self.currentLevel);
+ return;
+ }
+ // Initialize grid
+ for (var i = 0; i < self.gridSize; i++) {
+ self.grid[i] = [];
+ for (var j = 0; j < self.gridSize; j++) {
+ var tile = new Tile();
+ if (config.tiles[i] && config.tiles[i][j]) {
+ tile.setType(config.tiles[i][j]);
+ }
+ tile.updatePosition(i, j);
+ self.grid[i][j] = tile;
+ game.addChild(tile);
+ }
+ }
+ // Apply rotations
+ if (config.rotations) {
+ for (var pos in config.rotations) {
+ var _pos$split$map = pos.split(',').map(Number),
+ _pos$split$map2 = _slicedToArray(_pos$split$map, 2),
+ x = _pos$split$map2[0],
+ y = _pos$split$map2[1];
+ self.grid[x][y].setRotation(config.rotations[pos]);
+ }
+ }
+ };
+ // Check if the current puzzle is solved
+ self.checkWinCondition = function () {
+ // Implement win condition check
+ // Should check if water can flow from start to end
+ 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
+ }
+ };
+ self.moveTile = function (direction) {
+ if (!self.selectedTile) {
+ return;
+ }
+ // Implement tile movement logic
+ // Should handle sliding tiles in the specified direction
+ };
+ self.rotateTile = function () {
+ if (!self.selectedTile) {
+ return;
+ }
+ // Implement tile rotation logic
+ // Should rotate the selected tile 90 degrees
+ };
+ return self;
+};
+var debug = true;
function log() {
if (debug) {
- var _console;
- (_console = console).log.apply(_console, arguments);
+ console.log.apply(console, arguments);
}
}
-var debug = true;
+// Game constants
var tileSize = 400;
var boardOffsetX = 90;
var boardOffsetY = 90;
-// Add the gridBoard to the game and place it at the center
-var gridBoard = LK.getAsset('gridBoard', {
+// Game state
+var gridBoard;
+var puzzleManager;
+// Initialize game board
+gridBoard = LK.getAsset('gridBoard', {
anchorX: 0.5,
anchorY: 0.5
});
-game.addChild(gridBoard);
gridBoard.x = 2048 / 2;
gridBoard.y = 2732 / 2;
-// Log gridBoard dimensions and location
-console.log("gridBoard width: " + gridBoard.width);
-console.log("gridBoard height: " + gridBoard.height);
-console.log("gridBoard x position: " + gridBoard.x);
-console.log("gridBoard y position: " + gridBoard.y);
-// Initialize the grid
-var grid = [];
-var gridSize = 4; // 4x4 grid
-// Create the grid and populate it with tiles
-for (var i = 0; i < gridSize; i++) {
- grid[i] = [];
- for (var j = 0; j < gridSize; j++) {
- var tile = new Tile();
- tile.updatePosition(i, j); // Update the position to be in terms of grid indexes
- grid[i][j] = tile;
- game.addChild(tile);
- }
-}
-// Set up initial puzzle configuration
-grid[0][0].setType('start');
-grid[3][3].setType('end');
-grid[1][0].setType('fixed');
-grid[2][2].setType('straightPipeH');
-grid[1][1].setType('straightPipeV');
-grid[1][2].setType('cornerPipe');
-grid[3][2].setType('cornerPipe');
-// Set up initial rotations
-grid[3][3].setRotation('left');
-// Function to handle sliding of tiles
-function slideTiles(direction) {
- // Implement sliding logic based on direction
- // Validate moves and update tile positions
-}
-// Function to trace the water path
-function traceWaterPath() {
- // Implement path tracing logic
- // Check if the path is complete from start to end
-}
-// Event listeners for user interactions
+game.addChild(gridBoard);
+// Event handlers
game.down = function (x, y, obj) {
- // Determine which tile was clicked and initiate sliding
+ // Handle touch/click events
+ // Should call appropriate puzzle manager methods
};
game.up = function (x, y, obj) {
- // Finalize sliding and check for puzzle completion
+ // Handle touch/click release
};
-// Game update loop
game.update = function () {
- // Continuously check for path completion
- traceWaterPath();
+ // Update game state
+ if (puzzleManager) {
+ // Update puzzle state
+ }
};
-// Initialize the game with a simple puzzle
-function initializePuzzle() {
- log("initializePuzzle...");
- // Set up a solvable puzzle configuration
- // Ensure start and end tiles are connected through movable pipes
+// Initialize game
+function initializeGame() {
+ puzzleManager = new PuzzleManager();
+ puzzleManager.initPuzzle();
}
-// Add a global 'debug' variable
-initializePuzzle();
\ No newline at end of file
+// Start the game
+initializeGame();
\ No newline at end of file
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