Hex Based - C++ and DirectX

Started by
8 comments, last by Alberth 4 years, 2 months ago

Hi all. I haven't visited Gamedev in some years. Was looking at my graphics engine project I spent 3 years on and feeling disappointed. I'd like to start again with something more simple and more specific, so that it is actually doable. I had some ideas for a simple hex based strategy game or two.

I've got 13 years of C++ experience and some basic linear algebra skills.

I've read up on https://www.redblobgames.com/grids/hexagons/, but that's about the only resource google is showing me. There used to be books back in the 9c days that would walk you though a game project from start to finish, it would be great if there was something out there like that to hold my hand with DX11 and hexes. Are there any other resources for me?

Advertisement

List off the things you want your engine to do, eg: is it a height based open world, is it tiled with the hexes as pregenerated meshes, is it only player and AI movement that uses the hexes (the terrain doesn't necessarily have to be based on a hexagon mesh for this). What exactly does a hex define?

The link you listed is kind of just focused on one thing that I would say is pretty straight forward. Not trying to insult the author, it just focuses on one area. How the hexes are represented is more than a numbering scheme, for example are they a linked list of objects or an array of structures, or just an offset grid of texture based information. If you think of it like a quad mesh, then you just have 6 neighbours instead of 4 and follow similar principles. If there is level of detail splitting it wont be as simple as a quad mesh but you may not want to go down that path anyway.

You will likely have to make decisions about things like texture mapping, because your textures will still probably be rectangular, so for example how would you blend two adjacent tiles using different texture sets (if you use texture sets).

Oh, nothing fancy. My whole focus is to keep it super simple this go around so as to be able to get it done. I just want a flat hex map that I can move static models on top of. Very board game like. A flat hex, with a texture applied to each.

I imagine there will be some class to represent the entire map/floor and it will have to be able to give me coords of the individual hexes by some manner of index, so that I can place things on top of a given hex. It will probably wrap the rendering of the whole thing with one call too. But I don't really know how these things are normally done. Hence why some kind of walk through tutorials would help.

 

There is a whole section about coordinate systems in the page that you linked. The Offset coordinates or the Double coordinates look simplest to understand. Movement code is a little strange though as you move sideways back and forth in one direction. Maybe the double coordinates works better, don't know.

I played with Axial coordinates a little bit, and that works too. Movement is simpler, but mapping a tile coordinate back and forth to the 2d position is quite more tricky I seem to remember. I didn't use your resource though, the solution might just be explained in it.

The hands-on approach is to take some paper and draw a grid, and define the coordinate system using one of the discussed coordinate systems. Then figure out how the coordinates change as you move in each direction. Maybe you want to try a few of these systems so you get an idea of how they compare, and which one you like best.

Once you know how it works you can start working on how to implement it.

Yes, I read the article I linked.

My problems aren't going to be with understanding the coordinate system. It's going to be how to organize the hexes and have them, and what they contain, rendered in DirectX. I was just answering TeaTrim's question.

The original question is simply a query to see if there are any resources out there beyond the link I gave, that people know of. I could swear there was a book that did a simple hex based strategy game from start to end circa 2003, but I cannot for the life of me remember the name. Any other resources at all would help.

Many turn-based strategy games use hexagons. If you look in that area, you'll likely find resources.

The coordinates can be very simple. Imagine a chess board (or a regular grid, for that matter). Horizontally x, vertically y, each square a (x,y) pair, nothing special.

Now move every other column a 1/2 height down. Make the left and right vertical edges more round so the square looks like a hex, and you have the Offset coordinates system, one of the two right-most pictures, depending on which columns you moved down.

The 2 left-most pictures do the same, but with rows instead of columns.

@Fleshbits Hi,

I realize I am 10 months behind on this thread but did you ever find a 2-D Hex Game Engine for C++? I am looking for the same thing.

I too am late to this thread, I am also looking for a tutorial specifically for C++ and OpenGL (or a library that uses OpenGL like SDL) that tackles this subject, I did come across the above mentioned link in my searches and itll be a good start but it seems to mostly cover theory and not actual graphical implementation (or maybe it does and i didn't get far enough into article yet.)

Theory is great and all but would also like to see different methods of drawing one to the screen.

Most likely, there is no such tutorial. Hexagon theory is completely independent from the programming language and the render backend, and opengl is independent of the programming language too.

Your best bet is to split the problem in two. Code a hexagon map in c++, and render that map. A hexagon board is basically a regular grid, with the odd (or even) rows (or columns) shifted half its height (or width). Map storage can thus simply be a 2d grid. Rendering in Opengl means you have to fiddle with the triangle or quad coordinates a bit to get Opengl to render things at the right spot, and that's about it.

This topic is closed to new replies.

Advertisement