summaryrefslogtreecommitdiff
path: root/client/drawing.lua
diff options
context:
space:
mode:
Diffstat (limited to 'client/drawing.lua')
-rw-r--r--client/drawing.lua44
1 files changed, 27 insertions, 17 deletions
diff --git a/client/drawing.lua b/client/drawing.lua
index bbcf03a..5334a93 100644
--- a/client/drawing.lua
+++ b/client/drawing.lua
@@ -1,6 +1,7 @@
local coords=require"common.coords"
local Pos = coords.Pos
local chunk = require"common.chunk"
+local CHUNK_SIZE = require"common.constants".CHUNK_SIZE
local tau=math.pi*2
@@ -38,20 +39,24 @@ local colors = {
c(192,0,192), -- purple
c(128,128,128), -- grey
}
-
-
+-- precompute sins and cosines
+local _coss,_sins = {},{}
+for i=0,5 do
+ local angle = tau*(i+0.5)/6
+ _coss[i+1] = math.cos(angle)
+ _sins[i+1] = math.sin(angle)
+end
-local zthr0 = 2
-local zthr1 = 5
+local zthr0 = 2.7
+local zthr1 = 6
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
+ for i=1,6 do
+ local x = cx + _coss[i]
+ local y = cy + _sins[i]
+ _corners[2*i-1] = x
+ _corners[2*i ] = y
end
-- love.graphics.setColor(love.math.colorFromBytes(0xe7,0x9e,0))
love.graphics.setColor(color or {0.91,0.62,0})
@@ -63,22 +68,27 @@ local function draw_hex(cpos,color,zoom)
end
end
-local function draw_chunk(camera,the_chunk)
+local function draw_map(camera,map)
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()
+ local _h = coords.Hex:new()
+ local _p = coords.Pos:new()
+
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)
+ -- local h = coords.Hex:make(q,r)
+ _h:init(q,r)
+ _h:to_pos(_p)
+ local t = map:at(_h)
if type(t) == "number" then
- draw_hex(h:to_pos(),colors[t],camera.zoom)
+ draw_hex(_p,colors[t],camera.zoom)
elseif t then
- draw_hex(h:to_pos(),nil,camera.zoom)
+ draw_hex(_p,nil,camera.zoom)
end
end
end
@@ -87,7 +97,7 @@ local function draw_chunk(camera,the_chunk)
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 h = CHUNK_SIZE-0.5
local c00 = p(-0.5,-0.5)
local c01 = p(-0.5,h)
local c10 = p(h,-0.5)
@@ -100,4 +110,4 @@ local function draw_chunk(camera,the_chunk)
end
-return {draw_hex=draw_hex,draw_chunk=draw_chunk}
+return {draw_hex=draw_hex,draw_map=draw_map}