This example shows the basic principles of implementing certain mechanics:
- How to implement a board a pieces. In this case, we use grids for both boards and pieces.
- How to use the coordinates in the piece grid and board grid together. In this case, the coordinates of the cells in the piece are used to black out the cells in the board grid.
- How to drag grids around. (It’s not a polished drag!)
The example also shows some basic grids idioms:
- How to initialize and handle logic in a grid through a
GridBehaviour
. - How to make your own cells.
- How to use cells to keep minimal state.
- How to handle cell presentation based on state.
This example uses the same cells for the board and pieces. In retrospect, it may have been better to use separate cells. In this simple example it does not make a big difference, but if you have more complicated game logic, it is worth considering whether separate cells would be better.
Another thing to notice is the “architecture” of the cell. Because triangular grids require cells in two orientations, it’s sometimes difficult to make the images exactly right so that they will align properly in the grid. For this reason we added a pivot node, which is used for rotating the cell, and a offset, which is used to move the visual part of the cell vertically. The offset is parented to the pivot, and all visual elements are parented to the offset.
This is the first time we played with using Grids as prefabs. Although it works well, you have to take care:
- Always edit your grid prefab in the editor. (Do not try to build the grid from the project view – it wont be able to parent cells correctly).
- Set the update type to EditorManual.
Important: When we implemented this example, we discovered a missing feature for alignment which is necessary to implement dragging properly. This package contains updated version of the MapAlignment
and TileGridBuilder
files. (These updates will also be included with the next update of grids).
To run the example:
- Import Grids 1.8 into a new project.
- Import the package below into the project.
- Open the TrianglePuzzleGame scene, and run it.
Pingback: Support for Bitmask Shapes and Polyominoes in Grids 2.3 | Gamelogic