Tag Info

New answers tagged

0

In my HexGridUtilities project (Open Source, MIT Licence) I found it both useful and performant to define the coordinates of a hex as a vector of four integers - the rectangular coordinates and the obtuse (120 degrees between basis vectors) coordinates. Although I initially used Lazy calculations, it turned out to be more performant to always track both. ...


0

You'll probably want distance eventually, so I'd use Marco13's solution. However if you only need adjacency, there's a simpler way. Because every other row is offset, the logic is going to be different for odd and even rows. Look around 2,3 (odd y) and you'll see the x==2 column bends to the right like ">". If you look at 2,2 (even y), the x==2 column bends ...


2

If I understood you correctly, you only want to know whether two tiles, specified by their 2D offset coordinates, are adjacent or not. For any question related to hexagon grids, I'd recommend to refer to the Hexagonal Grids page by Amit Patel. It contains the mathematical backgrounds as well as excellent animated interactive examples, and probably ...


2

Breadth First Search can calculate every location reachable from a start position, and it can also count how many steps to that location. (If some steps take more "moves" then use Dijkstra's Algorithm instead). See the fourth demo on this page. You would tell the algorithm to stop after some number of moves, so that it doesn't keep exploring the rest of the ...


0

There are several ways to achieve this, presumable you are not using Canvas but rather the DOM for your Isometric grid? If so, read on. Method Draw your Images at x10 the highest resolution you display them at, e.g. (1200x1200 for an image being displayed at 120x120). Vector (SVG) would be another choice, but fine detail is an issue for them, and, ...


0

Eric Lippert presented a tutorial (in C# of course) on calculating Line-of-Sight with Shadowcasting for a square grid. The first five sessions define various objects used in the algorithm, with the final code private static Func<int, int, T> TranslateOrigin<T>(Func<int, int, T> f, int x, int y) { return (a, b) => f(a + x, b + ...


1

Assuming your grid is represented as a 2d array of booleans (0 for path, 1 for wall) or integers (n for path, m for wall), and the player is smaller than the tiles, you need to check if any of the four corners of the player are inside a wall. If the center of the player's "square" is x, y and the width is w then you need to check in (x - width/2, y - ...



Top 50 recent answers are included