ID:153963
 
I was curious if anyone has tried adapting any games with hexagonal pieces/tiles to byond. If so, do you have a library available, or any general advice on design philosophy for such a game?

I have a structure worked out where each type of terrain hex would require 6 different icons in order to adapt into byond's square tiles. There would be 7 possible positions (icon states) for a road object, which would occupy one side of a hex. It's hard to describe too much more detail without using graphics. Based on what I've said so far, if it sounds like I'm making this much more complicated than it needs to be, please let me know.

Thanks!
6 icons? What are the dimensions of your hexagons in pixels? You could accomplish it with one icon that is 32x28 pixels (if I remember correctly...) but that really depends on how detailed you want the graphics to be and if you are planning on having the entire board on one screen or have it be scrollable.
In response to English (#1)
English wrote:
6 icons? What are the dimensions of your hexagons in pixels? You could accomplish it with one icon that is 32x28 pixels (if I remember correctly...) but that really depends on how detailed you want the graphics to be and if you are planning on having the entire board on one screen or have it be scrollable.


Sorry, my original post wasn't very clear on this point. The size of the hex is approximately equal to one standard square 32x32 byond tile. However, it would be constructed from a combination of 6 smaller icons for a particular terrain hex. Each square tile would actually have pieces of 3 separate game hexagons. Thus, the map would appear to be constructed of interlocking hexagons. I have a nice little sketch on paper that I don't feel like digitizing and figuring out how to include in a forum post, so I hope this makes more sense now ;).
I've done it once, just as sort of a proof of concept, with hexes of size 32x64. That's probably too big and irregular for what you want, but it made tiling REALLY easy. You can check out a screen shot of this at http://www.molotov.nu?page=projects under Hex-Based Strategy Game.
I can explain my method if you're interested, but it sounds like you might want to go a different way.

-AbyssDragon
In response to AbyssDragon (#3)
Hey, that little game looks like fun. I might have to build one like it! (As much as I try to avoid violence, I've been getting urges to create some kind of strategy game of that sort...)
In response to Foomer (#4)
I thought you were working on a space game after seeing someone elses space game :p
In response to English (#5)
I'll resume that when Dantom adds client.pixel controls.
In response to AbyssDragon (#3)
I'm still interested in hearing the method.
In response to Foomer (#7)
Whoops.. I forgot entirely about this.

Looking through my code, my method seems much simpler than I recall. I may be missing something.
It works like this: since tiles are 64x32, they take up two tiles horizontally. The point of each one on the side is right in the middle. So alternate columns of hexes just need to be placed 16 pixels up or down from each other. My code for generating this is:
obj/terrain
left
New(loc, shift)
. = ..()
link = new/obj/terrain/right(locate(x+1,y,z), shift, src)
if(shift)
pixel_x = 16
pixel_y = 16
return .
right
New(loc, shift, Link)
. = ..()
link = Link
if(!shift)
if(x != world.maxx) new/obj/terrain/left(locate(x,y,z), 1)
else
pixel_x = 16
pixel_y = 16
return .

Then my map file has /obj/terrain/left's placed in every third column (x=1, 4, 7, etc). The bottom row has one, but the very top does not (because it shifts up, this pushes tiles off of the map). The width of the map needs to be two more than a multiple of three.
I then have some half-written routines to assign actual icons and properties to all of these, after their created.

This method is probably pretty dumb, since you can't use the map editor to do anything with your hexes... but for the game I was creating, that wasn't necessary (it has a built in map-editor, so players can make and trade maps).

-AbyssDragon
In response to AbyssDragon (#8)
AbyssDragon wrote:
Whoops.. I forgot entirely about this.

Looking through my code, my method seems much simpler than I recall. I may be missing something.
It works like this: since tiles are 64x32, they take up two tiles horizontally. The point of each one on the side is right in the middle. So alternate columns of hexes just need to be placed 16 pixels up or down from each other. My code for generating this is:
> obj/terrain
> left
> New(loc, shift)
> . = ..()
> link = new/obj/terrain/right(locate(x+1,y,z), shift, src)
> if(shift)
> pixel_x = 16
> pixel_y = 16
> return .
> right
> New(loc, shift, Link)
> . = ..()
> link = Link
> if(!shift)
> if(x != world.maxx) new/obj/terrain/left(locate(x,y,z), 1)
> else
> pixel_x = 16
> pixel_y = 16
> return .
>

Then my map file has /obj/terrain/left's placed in every third column (x=1, 4, 7, etc). The bottom row has one, but the very top does not (because it shifts up, this pushes tiles off of the map). The width of the map needs to be two more than a multiple of three.
I then have some half-written routines to assign actual icons and properties to all of these, after their created.

This method is probably pretty dumb, since you can't use the map editor to do anything with your hexes... but for the game I was creating, that wasn't necessary (it has a built in map-editor, so players can make and trade maps).

-AbyssDragon

This sounds a lot simpler than what I ended up doing, and more easily adaptable to other games.

I ended up putting a lot more effort in than originally planned in order to create perfect hexagons (64 pixels wide, ~74 pixels tall). I was debating whether or not to generalize the code and release a library... I'm not sure if anyone would be interested in a method that requires 9 separate icon states for each type of terrain you would place on a hex. Then again, if you used solid colors (or a simple pattern), it would really only require 4 icon states, plus some icon flip() and turn() commands.
In response to Dramstud (#9)
I tried for near perfect hexagons as well but chose 32x~28 pixels for each hexagon.

This only requires one icon per hexagon but of course you would probably want to create variations on each terrain type because there are more hexagons so it could look more mundane if it just repeated over and over again. Then I just stored them in a two dimensional array.

I'm not sure if it is actually practical to try to create maps using the default map editor when using hexagons or even an isometric perspective. Having an ingame editor would basically work just as well.
In response to English (#10)
English wrote:
I'm not sure if it is actually practical to try to create maps using the default map editor when using hexagons or even an isometric perspective. Having an ingame editor would basically work just as well.


I agree, it would have been extremely inefficient to create the hex map in the map editor. Actually, in my case it would be impossible, since the terrain layout can be set randomly for each game (with a fixed distribution of each terrain type). I have a proc that does it at run-time, with lists of x and y coordinates for all the hex's, as well as a single global variable for x and y offsets so I can move the board around easily in case the interface changes (ie. to make room for buttons, etc.)