local coords=require"common.coords" local Pos = coords.Pos local chunk = require"common.chunk" local tau=math.pi*2 local corners = {} for i=0,5 do local angle = tau*(i+0.5)/6 local x = math.cos(angle) local y = math.sin(angle) table.insert(corners,x) table.insert(corners,y) end -- local function draw_hex(cpos,color) -- love.graphics.push() -- love.graphics.setLineWidth(0.1) -- love.graphics.translate(cpos.x,cpos.y) -- if color then love.graphics.setColor(color) else -- love.graphics.setColor(love.math.colorFromBytes(0xe7,0x9e,0)) -- end -- love.graphics.polygon("fill",corners) -- love.graphics.setColor(0,0,0) -- love.graphics.polygon("line",corners) -- love.graphics.pop() -- end local _corners = {} local function draw_hex(cpos,color) local cx,cy = cpos.x,cpos.y for i=0,5 do local angle = tau*(i+0.5)/6 local x = cx + math.cos(angle) local y = cy + math.sin(angle) _corners[2*i+1] = x _corners[2*i+2] = y end love.graphics.setLineWidth(0.1) -- love.graphics.setColor(love.math.colorFromBytes(0xe7,0x9e,0)) love.graphics.setColor(color or {0.91,0.62,0}) love.graphics.polygon("fill",_corners) love.graphics.setColor(0,0,0) love.graphics.polygon("line",_corners) end local function draw_chunk(camera,the_chunk) local tl,br = camera:extents() local tlh,brh = tl:to_hex():round(), br:to_hex():round() local trh = coords.Pos.make(br.x,tl.y):to_hex():round() for r = tlh.r-1,brh.r+1 do local rowidx = r-tlh.r local minq = tlh.q - math.floor((rowidx+1)/2) local maxq = minq+(trh.q-tlh.q)+1 print(string.format("r=%d; q = %d to %d",r,minq,maxq)) for q = minq,maxq do local h = coords.Hex.make(q,r) local t = the_chunk:tile_at_offset(h) if t then draw_hex(h:to_pos()) end end end end return {draw_hex=draw_hex,draw_chunk=draw_chunk}