What would be the best way to do a board game with hexes and multiple units per hex?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By rafeu
:warning: Old Version Published before Godot 3 was released.

TL;DR: how should a group of units should go from a tile to another while :
1)being spread out on the destination tile
2)Being blocked by forest borders on tiles (impassable)

I’m doing a virtual version of a board game with troops moving from hex to hex, multiple together. I don’t know how I could manage so they are always spread out on a tile they move to. I already have the map in a tilemap:

^^Started from the hexagonal tiles demo^^

also, the troops shall not go through forest borders (to or from) unless when controlling a special tile with 2.
As of now, since you can’t have a script on a tile, I started a script on the tilemap with the passable borders var passableCase=[ [false,true,true,false,true,false], [true,true,true,true,true,true], [true,false,true,false,true,false], [false,true,false,false,false,false], [false,true,false,true,false,false], #Tile5 [false,true,true,false,true,false], [false,true,true,false,true,false], [true,true,true,true,true,true], [false,true,true,false,true,false], [false,true,false,true,false,false], #Tile10 [false,true,false,false,false,false], [false,true,true,false,true,true], [true,false,true,false,true,false], [true,true,true,true,true,true], [true,false,true,false,true,false], #Tile15 ]
As can be seen, not that good…

Hope I’m not too hard to understand; haven’t done as much godot programming as I would like.

:bust_in_silhouette: Reply From: eons

I may not understand what you want to do but I’ll try…

To work with tiles (since could be complicated to use areas) you can use the tile ID, make a dictionary with characteristics for each ID.
You can get the cell ID from the TileMap.world_to_map position.

Now if what you want is to do is related to pathfinding, could be a lot more complicated (not for Godot but for the design itself), the class AStar could help there working on a parallel grid for the logic.

I just tested using Tilemap.world_to_map and it’s exactly what I need(just had to add my offset since they are hexes):
onready var sprite = get_node("../sprite") onready var tile= world_to_map(sprite.get_pos()+Vector2(384,335))
Big thanks to you :smiley:

Also your suggestion really helped figuring out my first point of spreading form the center with only getting the destination hex position with (for example moving up-right)
for i in movingWarriors: movingWarrior.get(i).set_pos(Tileset.get_cell(tile.x+2,tile.y).get_pos()+Vector2(i,i))

Now, since I can’t give scripts for my tiles, is my way the best way to store the “walls” on each sides of the tiles?

rafeu | 2017-01-04 22:44

Maybe you can use binary numbers to get all the combinations in a more simple way than true-false (which is almost the same).

Instead of [false,true,false,true,false,false] you can say 010100 or just 20.
With bitwise operations you can identify the open sides.

I don’t know if there is a more visual way to organize that.

eons | 2017-01-05 03:20