• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

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 63
Joined
Aug 10, 2018
Messages
6,457
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 63
Joined
Jan 18, 2005
Messages
27,180
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