Tag Info

59

Octogons: Hexagons: The gaps in the octogons make for an unappealing game world. Typically, if you wanted to allow for eight directions of movement, you would just use squares.

51

To summarize and elaborate upon what has been said in other answers and in comments, triangles, squares and hexagons are the only mathematically possible regular tilings aka regular tessellations of the Euclidean plane. So yeah, this sucks. Triangles are completely useless here, squares suck because you can't move diagonally without having a somewhat ...

36

*Edit: Fixed error in javascript that caused error on firefox * Edit: just added ability to scale hexes to the PHP source code. Tiny 1/2 sized ones or 2x jumbo, it's all up to you :) I wasn't quite sure how to put this all into writing, but found it was easier to just write the code for a full live example. The page (link and source below) dynamically ...

28

I have been able to come up with a few reasons myself, but I'd really like to hear more. Horizontal layout matches the layout of the keyboard. You could use WEADZX for movement, similar to WASD on square grids. On the other hand, I have also found suggestions that QWEASD is a natural fit for vertical hexes. Horizontal hexes seem to be better suited for 3D/...

27

This guide didn't exist when the question was asked, but here's my guide to hex grid math: Hexagonal Grids

21

The author of HyperRogue here. HyperRogue actually uses a tesselation made of hexagons and heptagons, here is the reason why this particular tesselation has been chosen, instead of only octagons or heptagons, for example: Hyperbolic geometry in Hyperbolic Rogue Basically, the octagons are too big. Also some consequences of using hyperbolic geometry in a ...

18

I would go with vertical layout if you are using any sort of bird's eye perspective, as in the image above. Why? Because all walls will be visible. If you use horizontal layout, and you have walls that run along the vertical lines, you will not be able to make out details on them very well (such as doors or gates). Furthermore, if you are using the ...

17

A few answers! The coordinate system I've seen most often for hex-based traversal is one where the player can move in every normal NSEW direction, as well as NW and SE. Then you just render each row half-a-square offset. As an example, the location (2,7) is considered adjacent to (1,7), (3,7), (2,6), (2,8), and the weird ones: (1,6) and (3,8). Meanwhile, if ...

17

A hexagonal ring with the radius of N consists of 6 straight lines, each with length N - see my extremely crude example below :) For N=2: The arrows cover 2 hexes each. I assume you have some functions which give you the neighbouring tile in a specific direction, like north(), southeast() etc. So your algorithm, in pseudocode, should be something like ...

16

I have been working on a hex tile game and found these tutorials useful: Coordinates in Hexagon-Based Tile Maps Isometric 'n Hexogonal Maps Part I Isometric 'n Hexogonal Maps Part II Drawing a Hex Grid in Illustrator (for designing maps) Good luck with your project!

16

Sounds like you're leaning toward horizontal as having more advantage. For what it's worth, bees agree with you when they build their honeycombs: The axes of honeycomb cells are always quasi-horizontal, and the nonangled rows of honeycomb cells are always horizontally (not vertically) aligned. Thus, each cell has two vertical walls, with "floors" ...

16

No. √3 is an irrational number, and by definition an irrational number can not be used as a ratio between two natural numbers (integers) such as pixel counts. However, there is no rule that says you have to use ideal hexagons in your game tiles. If you approximate it closely and avoid any miscalculations that may result, which you should be able to do ...

14

Regular hexagons have six axes of symmetry, but I will assume your hexagons only have two axes of symmetry (ie. all angles are not exactly 60-degrees). Not necessarily because yours don't have the full symmetry, but because it may be useful to someone else. Here are the parameters of one hexagon. Its centre is in O, the largest width is 2a, the height is 2b,...

13

Take a look to this picture As you can see there is a relatively intuitive way to map x,y rectangular coordinate system to the hexagonal one. We may talk about "rect" irregular hexagons ie hexagons inscribed in ellipses or hexagons obtained from regular hexagons scaled in both directions disproportionately (no rotations-shearings). A rect hexagon can be ...

12

I guess I'll take the counterpoint here and argue against using static values. In this case, all of the hex regions you're talking about are (a) easy to compute - you don't need to use BFS or anything so complicated; you should be able to iterate over all of the hexes in any of them with straightforward doubly-nested loops; and (b) not something you'll need ...

11

You should write a small javascript tile layout engine that maps the database tile coordinates into a view on the web page, because this lets you outsource the cpu processing time to the players computer. It's not hard to do and you can do it in few pages of code. So essentially you'll be writing a thin layer of PHP of which only purpose is to deliver ...

11

From a technical and programming perspective, there should be no fundamental difference in data structure between the two orientations - any reasonable scheme should be easily modifiable to work well with either setup. Design-wise, in the end it will come down to preference — as you've noted, there are multiple games using either scheme, which is ...

11

Your hex orientation will influence both your general aesthetics and your asset production. If you choose vertical tiles, you can make your hexes twice as wide as they are tall and have pixel-perfect accuracy. Here are some 64x32 hexes. Note that the diagonal edges are at 45 degree angles, making them easier to render in pixels. The narrow height of ...

10

If the values will never change, they may as well be static. Why waste CPU time recalculating something that will be the same as last time? However, they don't necessarily need to be 'hard-coded': You can put the values in a data file, and load that in at the start. You can perform the search during play and cache the values once you find them. The ...

10

If you are building a strategy game, the game requirements and design itself should dictate which orientation you choose. Note that defensive lines are more easily held with the grain than against it, so your choice of grid orientation relative to map orientation will affect game play. To emphasize defence, such as in WWI, align the hex grid with the natural ...

10

Have you tried Lloyd's Algorithm? The procedure is pretty simple, and will generate fairly regular looking regions (depending on how many iterations you run). Tile the map with blank hexes to start. Choose N hexes at random. These will represent the "center of mass" for each country. Tag each hex with the center hex it is closest to (Voronoi Diagram). ...

9

Basically what you want is a monohedral tesselation (or tiling), that is a coverage of the entire plane (assuming 2d) with a single shape where the tiles do neither overlap nor leave gaps. There are lots of shapes with which this can be done but when we introduce other constraints, usually orientation should stay the same or they should conform to a ...

9

There are two ways to handle this problem, in my opinion. Use a better coordinate system. You can make the math much easier on yourself if you're clever about how you number the hexes. Amit Patel has the definitive reference on hexagonal grids. You'll want to look for axial coordinates on that page. Borrow code from someone who has already solved it. I ...

8

Use a Canonical (Or oblique) coordinate system (with axes at 120 degrees) to identify the hexes that are in the triangle. Then convert the coordinates of those hexes (with a homogenous transformation) to Rectangular coordinates for display. The utility toolkit I linked to above could be of help in writing this code.

8

Before I answer the question you already asked, some notes: You can use A* with the original grid system you are using. The key things you need are neighbors and distance (for the heuristic). For neighbors with your grid system, you need to do something different for even and odd columns (as you mention); here's how: neighbors = [ [ [+1, +1], [+1, 0]...

8

There are many hex coordinate systems. The “offset” approaches are nice for storing a rectangular map but the hex algorithms tend to be trickier. In my hex grid guide (which I believe you've already found), your coordinate system is called “even-r”, except you're labeling them r,q instead of q,r. You can convert pixel locations to hex coordinates with these ...

7

As Martin Sojka notes, rotations are simpler if you convert to a different coordinate system, perform the rotation, then convert back. I use a different coordinate system than Martin does, labeled x,y,z. There's no wobble in this system, and it's useful for lots of hex algorithms. In this system you can rotate the hex around 0,0,0 by “rotating” the ...

7

From the image you posted it looks like the only thing you did wrong was the order in which you applied the scale and rotation to your transformation. I don't have any experience with Cocos2D but I just mocked it up in XNA and here are the results: And here's the transformation matrix I used in XNA. See if you can find any correlation to your code: ...

7

It seems to me that the easiest way to do this would be in two steps: Determine the smallest possible convex polygon surrounding all red nodes. Expand the convex polygon until it reaches the largest possible area without intersecting with white nodes. Suppose we start with this situation: Look at that glorious programmer art. I've chose red and green ...

7

While I don't know of any truly official convention for classifying these, in the mathematical sense, I'll take Anko's advice and write up what I do know... Amit Patel (Red Blob Games) wrote what I'd consider the definitive guide to using hexagonal grids in games. This guide uses the nomenclature: flat topped pointy topped So while it's not super ...

Only top voted, non community-wiki answers of a minimum length are eligible