[Sorry for the shitty title. Couldn't think of any title.]
I am trying to create a simple hex grid using Kenny's hex tiles.
For the grid, I need all the tiles to be rendered in proper order:
left to right
and then the next row.
Unfortunately, i am using a hex grid obj insetad of nested for loops (which were originaly used for creating the grid)
Code: Select all
for id, hex in pairs(hex_grid_obj) do
local hexX, hexY = cam:cameraCoords(hex.center.x, hex.center.y)
-- only render if hexes are within the screen
if 0 < hexX and hexX < scrWidth
and 0 < hexY and hexY < scrHeight then
love.graphics.draw( img_ocean,hex.center.x - (math.sqrt(3) * hex_size /2) , hex.center.y- hex_size)
end
end
Code: Select all
"38q50r-88s" = {
biome = "ocean",
center = {
x = 549.92613140312,
y = 380
},
coord = {
q = 38,
r = 50,
s = -88
},
elevation = 0,
isOnEdge = false,
lum = 237,
moisture = 0,
tempColor = { 20, 120, 200 },
vertices = { 554.25625842204, 382.5, 549.92613140312, 385, 545.5960043842, 382.5, 545.5960043842, 377.5, 549.92613140312, 375, 554.25625842204, 377.5 }
}
Code: Select all
hex_grid_obj[temp_hex_id] = temp_hex
Add a counter to the nested for loops used in creating grid. then assign the count as a attribute to each hex, putting a serial number against each. When the grid is done, sort the hexes in the obj using this serial number. except i dont know how to sort the elements of any object based on its attribute.
Add the hex to the set in a way that order is maintained. Again no idea how to do that.
I am sure many of you have conquered this issue. Can you give me some pointers on how to tackle it?