summaryrefslogtreecommitdiff
path: root/client/drawing.lua
blob: 21513cb64275ba151ac92b98988b73ea2a0be6dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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}