Grid for Turn-Based Movement

5

Stats

164 visits, 233 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Let's start by adding objects:

  • Tile map with graphics for the playing field
  • TilePath "Tilepath" for the grid of moves
  • Sprite "Unit"

Since a single tile is used for all graphics on the map, it is necessary to add a second layer to the layout for the same tile. Thus, on the lower layer there will be tiles of land and water, and on the upper layer there will be tiles of hills, forests and mountains.

Now you need to add an array "Terra", which at the start of the layout will read both tilemaps and be filled with text values for each tile. This is necessary so that we have a database that will be used to calculate the cost of the unit path.

Add the "MP" variable to the "Unit" sprite, which contains the numerical value of movement points. For example, MP = 3 means that a unit can pass 3 tiles during its turn. At the same time, each tile should have a different cost of passage. For example, an ground tile requires 1 point to pass, a forest tile requires 2 points, and a mountain tile requires 3. Thus, a unit can pass 3 earth tiles or 1 earth tile and 1 forest tile or 1 mountain tile per turn.

Adding the "Path Cost" array, which reads the text values of the Terra array and sets the numeric values of the cost of passage for each tile on the entire map.

Adding the "Pathogen" array, which will be used in the function that calculates the movement area for the unit.

Add the function "TILEMAP > Generate Path", which is called when the player clicks on the unit.

How the function works:

  • creating a "TilePath" object that will graphically visualize the area of movement.
  • filling in the cost of passage array (in the future there will be not only land, but also sea and air units, which means that the cost of passage should be calculated not at the start of the level, but every time the player chooses a specific unit).
  • then, by the method of the wave algorithm, the array is filled with numbers.
  • finally, it remains to filter out the numbers we need and fill in the TilePath.

Now the player sees a grid with an area within which a unit can walk. By clicking on the tile inside the grid, the unit moves along the specified coordinates, and the grid is destroyed.

  • 1 Comments

  • Order by
Want to leave a comment? Login or Register an account!