Can Defold handle hex based maps? (SOLVED)

And, also to mention the https://defold.com/ref/stable/collectionfactory/ which is slightly more powerful than the factory (which spawns a single game object)

1 Like

Hey Albert,

My hex implementation is pretty hacked-together mess, and was really just a test of “hey, I wonder if I could make this work…” with no game in mind, really, and I haven’t looked at it since I posted this in December :rofl:

Just as a basic overview from what I remember in case it helps, each tile is a separate pre-made Game Object with a sprite and a custom .convexshape collision shape file, and no script.

I have a “map builder” script that uses a Factory to spawn however many hexes are needed for a given map, at the proper positions/in the proper order, and assigns them a number or other “tag” in a table so they can be individually referenced later.

Once the map space is populated with basic pre-made Game Objects, I have a sort of set of “map data” table set which determines which type of tile each one should be (it’s basically like… { 1, 1, 1, 0, 2, 0, 2, 2…} with each number representing a tile type (mountains, grass, water, etc)).

The sprite of each tile is changed to the visual representation of the tile type ( 0 = grass, 1 = water, etc).

These numbers are also used any time a tile is interacted with. Ex: a Tank takes a movement penalty when passing through a forest (if tile_type == 5 then movement_points -1, or whatever).

Navigation through the map is done with a hacky A* implementation (my first attempt at it, messy but functional!). Tile positions are referenced through cube coordinates, stored as a vec3 for each tile in a big ol’ table, if I remember correctly. Neighbour tiles are determined by a preset list of what defines a “neighbour,” something along the lines of “North Eastern neighbour = my X, my Y-1, my Z+1”

That’s about all I can remember. Let me know if you have any specific questions and I can dig out the old project to see what else I can see, but I can guarantee you that you don’t want to see the actual code :grimacing:

4 Likes

Tank you ryanscottlandry,
I am learning now, playing with Factory and Collection factory. I will come back to you with questions once I learned . Anyway thank you for your detailed answer :slight_smile:

1 Like