Author Topic: who has implemented a hex grid?  (Read 17607 times)

joeclark77

  • Rogueliker
  • ***
  • Posts: 90
  • Karma: +0/-0
    • View Profile
who has implemented a hex grid?
« on: March 01, 2013, 05:45:36 AM »
Does anybody have any good code examples from implementing hex-grid game maps?  Or know of any games that feature hex grids?  I've been reading up on the different types of hex coordinate systems but they make my head hurt, and it would be nice to see them in practice.

I'd particularly like to see an implementation of the Generalized Balanced
Ternary approach
.  I may have to set aside my dislike of Google for a while to sign in to that newsgroup and necro the thread at that link...

JohnK

  • Newcomer
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Re: who has implemented a hex grid?
« Reply #1 on: March 01, 2013, 09:26:20 AM »
I have found some success using libhex - http://blog.firetree.net/2008/01/26/libhex-v010/ it's a c++ library. It didn't compile for me right away but didn't take much time to fix up. The code's not too hard to understand if you want to customise it (I added a hex creation functor to mine so I can use custom hex classes).

Darren Grey

  • Rogueliker
  • ***
  • Posts: 2027
  • Karma: +0/-0
  • It is pitch black. You are likely to eat someone.
    • View Profile
    • Games of Grey
Re: who has implemented a hex grid?
« Reply #2 on: March 01, 2013, 01:44:22 PM »
I use hex in the T-Engine, but it's just an engine feature in that - I don't have to mess with any code, just set hex=true.  Might wanna check how it does it under the hood.

Z

  • Rogueliker
  • ***
  • Posts: 905
  • Karma: +0/-0
    • View Profile
    • Z's Roguelike Stuff
Re: who has implemented a hex grid?
« Reply #3 on: March 01, 2013, 04:29:14 PM »
You can look at my Hydra Slayer. It is not source-commented very well, but it abstracts geometry from the rest of the game, so you can choose whether to use 4-dir, hex, or 8-dir (or knight moves). The coordinate system is simple: inner coordinates equal screen coordinates (when in ASCII mode). This wastes each second coordinate pair, but this is not a problem at all.

Have you read the articles on RogueBasin? (Geometry and Hex Tiles linked from it)

joeclark77

  • Rogueliker
  • ***
  • Posts: 90
  • Karma: +0/-0
    • View Profile
Re: who has implemented a hex grid?
« Reply #4 on: March 01, 2013, 07:28:25 PM »
Have you read the articles on RogueBasin? (Geometry and Hex Tiles linked from it)

I read the Hex Tiles page and it had this mysterous note:
Quote
One more coordinate system: [1]

Which led me to the GBT method I mentioned above. However, the RGRD message doesn't describe it in much detail or give a reference implementation.

I hadn't read the Geometry page, thanks for recommending it.
The idea of abstracting out geometry is appealing but I want to just get it working first.
I'm leaning toward using a "zig-zagging y axis" representation.

Omnomnom

  • Rogueliker
  • ***
  • Posts: 79
  • Karma: +0/-0
    • View Profile
    • Email
Re: who has implemented a hex grid?
« Reply #5 on: March 01, 2013, 09:28:13 PM »
Careful you don't become hooked on ever more complex tile systems. I knew a guy who became facinated by strange coordinate systems and one day claimed he had discovered a tile system based on non-euclidian geometry. A week later he went totally mad, last time I saw him he was screaming something about a black goat in the woods.

joeclark77

  • Rogueliker
  • ***
  • Posts: 90
  • Karma: +0/-0
    • View Profile
Re: who has implemented a hex grid?
« Reply #6 on: March 01, 2013, 10:18:32 PM »
Careful you don't become hooked on ever more complex tile systems. I knew a guy who became facinated by strange coordinate systems and one day claimed he had discovered a tile system based on non-euclidian geometry. A week later he went totally mad, last time I saw him he was screaming something about a black goat in the woods.

Your comment reminds me of a documentary about indie game developers that I recently watched via Netflix.  One of the guys profiled in the movie was working on a game called "Fez" which is a typical 2D platform game, but when you hit a certain button the map rotates in a third, previously invisible dimension.  First time you see it, it blows your mind for just a moment.  Would be cool to try something like that in a roguelike, but today is not the day.

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: who has implemented a hex grid?
« Reply #7 on: March 02, 2013, 02:36:26 PM »
Hex grid could be ok if someone had actually succeeded to make it playable. It's just confusing and annoying mostly.

chooseusername

  • Rogueliker
  • ***
  • Posts: 329
  • Karma: +0/-0
    • View Profile
    • Email
Re: who has implemented a hex grid?
« Reply #8 on: March 02, 2013, 08:22:35 PM »
You can look at my Hydra Slayer. It is not source-commented very well, but it abstracts geometry from the rest of the game, so you can choose whether to use 4-dir, hex, or 8-dir (or knight moves). The coordinate system is simple: inner coordinates equal screen coordinates (when in ASCII mode). This wastes each second coordinate pair, but this is not a problem at all.
I downloaded and installed Hydra Slayer, and couldn't work out how to get the hex view working.  It seemed tied to the noteye thing which had its own viewing modes.

Z

  • Rogueliker
  • ***
  • Posts: 905
  • Karma: +0/-0
    • View Profile
    • Z's Roguelike Stuff
Re: who has implemented a hex grid?
« Reply #9 on: March 02, 2013, 09:08:17 PM »
You get the option "geometry" while starting a game (on the same screen when you select the race). Note that the Tutorial is 4-directional Human only, you need to start the real game.

(BTW I am currently working on the hex fpp view in HS)

(improvements to the hex mode are completed in Hydra Slayer 14.7)

ekolis

  • 7DRL Reviewer
  • Rogueliker
  • *
  • Posts: 186
  • Karma: +0/-0
  • get ye dennis
    • View Profile
    • Ed's home page
    • Email
Re: who has implemented a hex grid?
« Reply #10 on: March 12, 2013, 06:06:39 PM »
Not in a roguelike, but in a few other games I've worked on, the hex grid is basically just a skewed square grid - the Y axis is up and down as normal, but the X axis goes off at a 60 degree angle to the right, instead of a 90 degree angle. (Sometimes we consider a third axis called "Z" which goes off at a 60 degree angle to the left, say, for purposes of computing bounding hexes, but strinctly speaking, any hex position can be described in terms of X and Y; Z is redundant.)
The Ed draws near! What dost thou deaux?

>EAT SANDVICH

joeclark77

  • Rogueliker
  • ***
  • Posts: 90
  • Karma: +0/-0
    • View Profile
Re: who has implemented a hex grid?
« Reply #11 on: March 12, 2013, 07:16:36 PM »
Not in a roguelike, but in a few other games I've worked on, the hex grid is basically just a skewed square grid - the Y axis is up and down as normal, but the X axis goes off at a 60 degree angle to the right, instead of a 90 degree angle. (Sometimes we consider a third axis called "Z" which goes off at a 60 degree angle to the left, say, for purposes of computing bounding hexes, but strinctly speaking, any hex position can be described in terms of X and Y; Z is redundant.)

That's one way to do it.  Another way is to treat it as a rectangular x/y grid but with one of the axes zig-zagging.  I use this method.  For a "vertical" hex grid (meaning hexes have vertical sides, so east/west movement is possible), the y-axis zig-zags.  (It's called the "vertically staggered" method at this very informative but apparently now defunct website: http://web.archive.org/web/20090205120106/http://sc.tri-bit.com/Hex_Grids

There's also a 3D method which I would call the Q*Bert method (visualize the hexes as outlines of cubes viewed from an angle), check the last visual at that link.

Here's my code implementing an abstracted geometry for a tiled roguelike:
https://github.com/joeclark77net/jc77rogue/blob/master/program/geometry.py

joeclark77

  • Rogueliker
  • ***
  • Posts: 90
  • Karma: +0/-0
    • View Profile
Re: who has implemented a hex grid?
« Reply #12 on: March 12, 2013, 08:50:25 PM »
By the way, I was wondering do any of you have any good ideas for cave or dungeon generation on a hex map?

Darren Grey

  • Rogueliker
  • ***
  • Posts: 2027
  • Karma: +0/-0
  • It is pitch black. You are likely to eat someone.
    • View Profile
    • Games of Grey
Re: who has implemented a hex grid?
« Reply #13 on: March 12, 2013, 11:40:54 PM »
Cellular automata works just the same on hex.  It's hard to get dungeony dungeons though.

guest509

  • Guest
Re: who has implemented a hex grid?
« Reply #14 on: March 13, 2013, 12:56:09 AM »
  Yeah. That's why old D&D had grid based dungeons but hex based overworlds.