Apparently I like writing vector libraries. This one's specifically for working with hex-grids.
Code and full documentation on github: https://github.com/jasondelaat/hector/tree/release
The above cart demonstrates simple path-finding. The grid starts off randomly populated. Click on the hexes to add/remove obstacles and re-calculate the path. You can also switch between a "flat" or "pointy" grid. The draw code is not optimized so it will get laggy if you make the path really long, especially on the web player. But you get the idea.
Example Usage:
include 'hector.lua' -- Initialize the library -- hector.init() -- uses all default values hector.init{x_axis = P_AXIS, y_axis = -Q_AXIS, major = 64} -- Create and manipulate vectors u = vector(1, 2) v = vector(3, 4) w = u + v w = w:rotate(1, vector(1, 1)) |
Initialization Options
The code is written for standard Lua and works with Picotron but would need some changes to work with Pico-8. It's a bit heavy for a Pico-8 project anyway but most of the size and complexity comes from allowing the configuration options. You could probably make a reasonably sized library for Pico-8 by picking a single configuration and coding the transformations directly into the relevant functions. If anyone is interested in a smaller Pico-8 specific hex vector library let me know and I'll try to find some time to crunch this down.
[Please log in to post a comment]