### Author Topic: Hexagon Gameboard Engine  (Read 2906 times)

#### CW

• Mr. Polyvector
• Posts: 155
##### Hexagon Gameboard Engine
« on: 2013-Mar-27 »
I'm thinking of taking another run at a project I've attempted a few times in the past, but have never had success in programing. I would like to create a game-board engine which can handle the management of hexagons.

The engine would define a new type, called TYPE: HEX. Commands this engine would support would be to draw a hexagon game board of any size the user wants (provided it fits on the screen), dimension the memory-array to efficiently contain the game board hexes, place or remove an object (well an object number) into or from a given hex, check surrounding hexes of any desired radius for objects (obstacles, targets, firing range), return the distance from a given hex to any other hex, check line of sight to another hex, plot movement paths to another hex while avoiding obstacles, determine front/back/side facing of an object to another hex, and transparently handle all of the mapping of the hexagon game board and objects to the square grid of the memory array.

I'm a war-gamer from way back, and I have always loved paper-map games played on hexagons, so it is natural that I should love computer games played on hexagons too. My question (before taking another stab at this project) is, has anyone already created such an engine in GL-Basic? I don't want to reinvent the wheel when I can be playing with the game mechanics instead.

I have failed at this project a few times before, but I get closer each time I try. If anyone has any advice on programing such an engine, please share!

Attached is an image which shows what I have learned from previous studies of this challenge. The illustrations shows how a hexagon game-board can be created out of squares, and how the square-hexagons can be efficiently stored in a computer array. But notice the odd mapping of the hexes onto the memory array, and notice how that pattern flips when the center object (center hex) moves one hex north or south. (North, in this case.) This flipping of the pattern happens each time an object moves a row north or south on the game field, and it is that patten which makes it very difficult to plot movement based on the computer array. You can't even use simple trig functions to determine cells present at a given radius in either the computer array or the hexagon game board (because the hex shape on the game board very quickly fails to conform to that of a circle, so you gather increasingly greater numbers of false positives.)

It's an interesting problem that I'd like to share with everyone here in the hope that, even if I fail on this attempt too, maybe I can infect you with the bug to crack this problem and give our GLBasic community the ability to create games on hexagonal game boards.

-CW
« Last Edit: 2013-Mar-27 by CW »

#### Moru

• Prof. Inline
• Posts: 1793
##### Re: Hexagon Gameboard Engine
« Reply #1 on: 2013-Mar-27 »
If you download mappy and unpack it you will find some .htm files with instructions and formulas at least for displaying hexagonal maps and how to use them for accessing surrounding tiles.

http://www.tilemap.co.uk/mappy.php

#### fuzzy70

• Community Developer
• Prof. Inline
• Posts: 828
• Look left, Look right, LOOK OUT!!
##### Re: Hexagon Gameboard Engine
« Reply #2 on: 2013-Mar-27 »
Try http://www-cs-students.stanford.edu/~amitp/gameprog.html, besides hex/square/iso grids this site has a serious amount of info on a lot of game subjects

My current hex engine is not available for current consumption to the public due to not being 100% complete & some seriously messy code which is in the process of being tidied  .

Lee
« Last Edit: 2013-Mar-27 by fuzzy70 »
"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)

#### CW

• Mr. Polyvector
• Posts: 155
##### Re: Hexagon Gameboard Engine
« Reply #3 on: 2013-Apr-21 »
My latest attempt to create a game engine using Hexagons has also failed. I see the way forward, but after a month of effort, I think I'll mothball it for a while. I have created a blog on the project, if anyone is interested in seeing how far I got.

http://www.glbasic.com/forum/index.php?blog=17772

You might also like to download a zipped copy of my program.

The program lets you set the x,y size of the hex board you want to use, and it scales the hexes to fit your screen. If you call for too many hexes, the labels may not all fit, so you might want to change the CenterPrint command to commented lines.

Feel free to use it in any way you like. (Consider it open source share-ware.) I'm sure I'll pick it up again eventually, but for now I think I'll work on something else; maybe my long neglected animation spreadsheet program.

-CW

P.S.
Thanks for the reminder, Fuzz.
To all: 7zip may complain when you try to unzip my files. Just ignore that. Like the cranky uncle at Thanksgiving, those complaints don't mean much.
« Last Edit: 2013-Apr-23 by CW »

#### fuzzy70

• Community Developer
• Prof. Inline
• Posts: 828
• Look left, Look right, LOOK OUT!!
##### Re: Hexagon Gameboard Engine
« Reply #4 on: 2013-Apr-21 »
Thanks for sharing your code CW, I will have a look at that

I am currently toying around with my own isometric hex engine which is proving to be an interesting challenge. Why I choose that style I have no idea & while I have some game ideas until the engine is a bit more fleshed out those ideas may or may not work in a iso/hex style.

One thing for sure is that the graphics are probably going to be the hardest part  .

Lee
"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)

#### CW

• Mr. Polyvector
• Posts: 155
##### Re: Hexagon Gameboard Engine
« Reply #5 on: 2013-Apr-22 »
Hey Lee. Hey everyone.

I just realized that I did not capture everything in my zip. I use a program-specific version of floodfill which was not in the program folder. That mistake is now corrected. You can download the full Hex program using the link above. If you have any trouble running it, please let me know.

-CW

#### fuzzy70

• Community Developer
• Prof. Inline
• Posts: 828
• Look left, Look right, LOOK OUT!!
##### Re: Hexagon Gameboard Engine
« Reply #6 on: 2013-Apr-22 »
Hi CW, am getting the zip errors like we had in the past when I extract your archive.

Everything seems to be there though & the code loads/compiles without any problems.

Lee
"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)