Tag Info

Hot answers tagged

49

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.


35

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 ...


34

*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 ...


27

The solution is actually simpler than expected. The trick is to use Minkowski subtraction before your hexagon technique. Here are your rectangles A and B, with their velocities vA and vB. Note that vA and vB aren't actually velocities, they are the distance traveled during one frame. Now replace rectangle B with a point P, and rectangle A with rectangle ...


20

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 ...


17

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


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

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 ...


14

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!


14

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 ...


13

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 ...


13

First of all, in the case of axis-aligned rectangles, Kevin Reid's answer is the best and the algorithm is the fastest. Second, for simple shapes, use relative velocities (as seen below) and the separating axis theorem for collision detection. It will tell you whether a collision happens in the case of linear motion (no rotation). And if there's rotation, ...


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 ...


12

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 ...


12

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 ...


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

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 ...


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

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 ...


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

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

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

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 ...


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, ...


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

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.


6

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 ...


6

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 ...


5

The parallelogram coordinates you're using are easier to work with, but they do have the drawback of being weird for rectangular maps. One approach is to store it with the offset coordinates but actually use parallelogram coordinates in your game logic. Observation: in each row of the map, the grid data is contiguous. All the wasted space is on the left ...



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