hexyz is tower defense game, and a lua library for dealing with hexagonal grids
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
3.5 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. ## INTRODUCTION
  2. this is a library for using hexagonal grids in amulet/lua.
  3. it is extremely incomplete. the following list of features is
  4. either implemented shoddily, or not at all.
  5. if you want an actual good resource, go to [amit's guide to hexagonal grids](#resources-used-to-develop-this-library,-and-for-which-i-am-grateful).
  6. ## GETTING STARTED
  7. 1) initialize a map.
  8. 2) iterate over the map and draw some hexagons.
  9. ## COORDINATE SYSTEMS
  10. As much coordinate manipulation as possible is done internally.
  11. Depending on the task, uses either Axial, Cube, or Offset coordinates.
  12. ## MAPS & MAP STORAGE
  13. Some map shapes: parallelogram, rectangular, hexagonal, triangular. (and more)
  14. The storage system used is based on the map shape - see chart:
  15. | SHAPE | MAP STORAGE |
  16. | ----------------- | --------------------------------------------- |
  17. | parallelogram | unordered, hash-like |
  18. | rectangular | unordered, hash-like |
  19. | hexagonal | unordered, hash-like |
  20. | triangular | unordered, hash-like |
  21. | ring | ordered, array-like |
  22. | spiral | ordered, array-like |
  23. | arbitrary | unordered, hash-like |
  24. * note that a spiral map is just a hexagonal one with a particular order.
  25. By default, the unordered, hash-like maps have pseudo-random noise stored
  26. as their values. This can be useful for a whole bunch of things, but if you
  27. wish, you can simply iterate over your map and set every value to 'true'.
  28. ## CONVENTIONS AND TERMINOLOGY
  29. If you have read amit's guide to hexagon grids, (see TODO LINK), a lot of the
  30. terminology will be familiar to you - I utilize many conventions he does in
  31. his guide. That being said...
  32. Because so many similar kinds of data structures with different goals are used
  33. in this library it can be hard to remember precisely what they all refer to.
  34. The following table shows what each table/vector/array refers to in the code:
  35. | NAME | REFERS TO |
  36. | ---- | ------------------------------------------------------------ |
  37. | cube | xyz, *vector* used for most maps, with constraint x+y+z=0. |
  38. | pix | xy, *vector* true screen pixel coordinates |
  39. | off | xy, 'offset', *vector* used for UI implementations |
  40. | map | xy, *table* of unit hexagon centerpoints arranged in a shape |
  41. * note that 'axial', vec2() coordinates are a subset of cube coordinates,
  42. where you simply omit the z value. for many algorithms this is done, but
  43. instead of using a seperate reference name 'axial' in these cases, I used
  44. the name 'cube' for both. I found this to be simpler. when an algorithm
  45. asks for a cube, give it a cube. if you want to know if it works with axial
  46. as well, look at the code and see if it uses a 'z' value.
  47. Other terminology:
  48. * TODO
  49. ## RESOURCES USED TO DEVELOP THIS LIBRARY, AND FOR WHICH I AM GRATEFUL
  50. * [Hex Map 1](https://catlikecoding.com/unity/tutorials/hex-map/) - unity tutorial for hexagon grids with some useful generalized math.
  51. * [3Blue1Brown - Essence of Linear Algebra](https://youtube.com/watch?v=fNk_zzaMoSs&list=PLZHQObOWTQDPD3MizzM2xVFitgF8hE_ab) - amazing series on linear algebra by 3Blue1Brown
  52. * [Hexagonal Grids](https://redblobgames.com/grid/hexagons) - THE resource on hexagonal grids on the internet.
  53. * [Amulet Docs](http://amulet.xyz/doc) - amulet documentation.