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
|
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,size)
love.graphics.push()
love.graphics.setLineWidth(0.1)
love.graphics.translate(cpos.x,cpos.y)
love.graphics.scale(size)
love.graphics.setColor(love.math.colorFromBytes(0xe7,0x9e,0))
love.graphics.polygon("fill",corners)
love.graphics.setColor(0,0,0)
love.graphics.polygon("line",corners)
love.graphics.pop()
end
local function draw_chunk(the_chunk)
for q = 0,chunk.SIZE-1 do
for r = 0,chunk.SIZE-1 do
local t = the_chunk.tiles[chunk.index(q,r)]
if t then
local p = coords.Hex.make(q,r):to_pos()
draw_hex(p*10,10)
end
end
end
end
return {draw_hex=draw_hex,draw_chunk=draw_chunk}
|