|Topic was automatically imported from the old Question2Answer platform.
I’m trying to recreate a game I saw recently which is like the old plumber kind of games in which you connect the pipes.
In my case the pipe parts are in square images, there are some empty movable tiles, some static and some with pipe parts(some can rotate, some not). There is a starting square which has a ball on it and an end square. By moving and rotating squares with pipe parts you try to create a path from start to end point. When the path is completed the ball starts moving and follow the path to the and point.
My 2 questions about this is:
1. How can detect when to tiles have a match(the 2 pipe parts are connected)? Every pipe tile has two exit points(at 2 of its sides), so to detect if on of the side has a match with the side of another pipe tile. Maybe with 2 collisionShape lines at the two sides of it?
2. How to create this correct path(maybe there are more than one) so the ball to move to the end point passing from all matched tiles? I show some tutorials about path2d and navigation which seems that can be used for this, but In all the path is pre-created. Is possible to use multiple paths on the different pipe tiles and then to be connected and create the final path? Can be done something like this with path2d or there is some other node more appropriate for this?
Ah, a game like Pipe Dream. I have a suggestion for designing this game. It involves mapping the pipe tiles to a 2D array.
The array holds the coordinates for the pipe tiles, which are organized into a grid. Start each round of the game by having a grid with all of the tiles connected to form a path. Scramble (i.e. rotate) as many random tiles as necessary. Once the player has rotated the correct tiles (and the array is the same as it looked before getting scrambled), the ball will then begin its movement towards the end point. To actually move the ball, have another array filled with the positions of the tiles which form the path. Finally, use
move_and_collide() to move the ball to its destination.
Thanks, I already started to do it like this, and I just finished the basic movement to the empty cells. But the game is a bit different from the Pipe Dream(which I just now google it and found a video about it). It’s a variation of roll the ball game and there are multiple paths to go from start point to end point, and the start and end points will be in different cells in each level. For this I need a way to detect when two tiles are positioning correct and the pipe parts(which are in the middle of a square tile) are connected.
dancaer69 | 2021-04-15 18:50
Then maybe have an array which keeps track of tile orientation? If the tiles can only be rotated four ways, have each element of the array account for the orientation of the tile, e.g.
tile_array[comment1-0] = 0, where “0” is the original orientation, “1” is the tile turned to the right 90°, “2” is for a tile turned 180°, and so on.
Ertain | 2021-04-15 19:27
I thought about something like that too, but because every tile have only two sides that can connected, maybe this will be too complicated. I mean if there is another way to check only the 2 sides, as an invisible node or a collision shape and check they share some space(connected) or not.
dancaer69 | 2021-04-16 08:45