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 function c(...) return {love.math.colorFromBytes(...)} end -- taken from breadquest local colors = { c(255,64,64), -- red c(255,128,0), -- orange c(192,192,64), -- yellow c(0,192,0), -- green c(0,192,192), -- teal c(64,64,255), -- blue c(192,0,192), -- purple c(128,128,128), -- grey } local zthr0 = 2 local zthr1 = 5 local _corners = {} local function draw_hex(cpos,color,zoom) 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.setColor(love.math.colorFromBytes(0xe7,0x9e,0)) love.graphics.setColor(color or {0.91,0.62,0}) love.graphics.polygon("fill",_corners) if zoom > zthr0 then love.graphics.setLineWidth(0.1) love.graphics.setColor(0,0,0,zoom>zthr1 and 1 or (zoom-zthr0)/(zthr1-zthr0)) love.graphics.polygon("line",_corners) end 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 for q = minq,maxq do local h = coords.Hex:make(q,r) local t = the_chunk:at(h) if type(t) == "number" then draw_hex(h:to_pos(),colors[t],camera.zoom) elseif t then draw_hex(h:to_pos(),nil,camera.zoom) end end end if _G.debugmode then love.graphics.setColor(0,1,0) local function p(q,r) return coords.Hex:make(q,r):to_pos() end local h = chunk.SIZE-0.5 local c00 = p(-0.5,-0.5) local c01 = p(-0.5,h) local c10 = p(h,-0.5) local c11 = p(h,h) love.graphics.polygon("line", c00.x,c00.y, c01.x,c01.y, c11.x,c11.y, c10.x, c10.y) end end return {draw_hex=draw_hex,draw_chunk=draw_chunk}