What I'm doing is pretty new to me, or at least I think it is, so I'm not really sure of what I'm looking for. Hopefully someone here knows =-)

Using a grid of hexes I generate, I can hover over any tile and it will highlight just fine. Now what I'm trying to figure out is how to allow for a radial selection of tiles around that hovered tile (brush size, basically), eventually allowing for a somewhat radial soft-selection gradient to allow falloff.

Each hex already knows about their neighbors, so currently I am hard-coding logic to handle a radius of 1, 2 or 3. I could duplicate that logic over and over to handle bigger radii but this is definitely not going to work for much longer, so I am trying to figure out a more efficient and cleaner way using loops/recursion/whatever.

Can anyone offer any pseudo-code or possibly a link that explains how to do this? Below is a (probably bad) attempt at what I think it would look like.

    // This would select a radius of x hex tiles including center tile

    for(int i = 0; i <= selectionRadius; ++i){
        if(i < selectionRadius){
            foreach(HexTile tile in thisTile.neighbors){
                tile.SelectTile(selectionRadius - i);

Edit: I'm using this fantastic resource to help with hexes - http://www.redblobgames.com/grids/hexagons/ - so might there be a section on this page that may explain what I need and I'm just missing?



Browse other questions tagged .