• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Hexagon-style gameboard - what should I do?

Status
Not open for further replies.
Level 19
Joined
Oct 12, 2007
Messages
1,821
It's been a while since I've been here and lately I've been thinking of giving map making a go again now that corona has kinda given me a lot of (unwanted) free time, haha.

Over the past years I've been thinking a lot about a specific type of game I had in mind and it requires me to create some kind of a gameboard with hexagons - sort of like settlers of catan.

I was wondering what would be the best way to set up in a functional way so I can name each tile and use it for future purposes of the game. To me, making hexagon zones seems like a very annoying thing to do in wc3 where most things are determed by squares or circles.

Or is there a new function from reforged I'm unaware of?
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
Create Rects for the Hexagon shape, store them in Arrays, and then you can do things like:
vJASS:
call CreateUnit(Player(0), 'hpal', GetRectCenterX(rectArray[0]), GetRectCenterY(rectArray[0]), 270);

You can use Mouse Events to detect which Hexagon you're currently moused over by comparing the X/Y of the Mouse with the X/Y of the Rects. To make it more efficient, since you may have 100's if not 1000's of Hexagons, you can create multiple Arrays that store the Rects in Rows and/or Columns. So you know if a player's Mouse Y-Pos is >= 0 and <= 128 then it it's in "Row 1" for example. And then instead of enumerating over ALL 1000 Hexagons, you can check just the ones that you're keeping in "Row 1".

I'd recommend doing this in Lua (or some of the other languages we have available that get converted to Lua).

Note that I've never actually messed around with Hexagons before so I may be way off with my approach. I've only done simple grid based stuff with square tiles on a square board. I'm sure you can google around for some tutorials on the matter, and not just wc3 tutorials.
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,286
I think hexagon grids are procedurally generated in most modern games. I would not advise creating a rect each as this would require a lot of work to manually position each one, especially if there are thousands.

Fundamentally you can consider it as rows of hex mid points, with different offsets to create the tessellated pattern. Using this logic you can assign each hex its own unique row and column number for access. Each hex could contain some number of member variables to help build the state of the game world, such as units placed on it or terrain mechanics.

You can also define a relationship with neighbouring hexes since each hex only has edge sharing neighbours in the columns and rows next to it. This relationship is how movement or interaction between hexes could be calculated or enforced for game mechanics.
 
Status
Not open for further replies.
Top