summaryrefslogtreecommitdiff
path: root/client/drawing.lua
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2023-01-27 13:43:49 +0000
committerubq323 <ubq323@ubq323.website>2023-01-27 13:46:41 +0000
commitd0916d568a00f5171b96fbc3bfc19ff263affc27 (patch)
treeef007be582d2b872ff2ac407def9d0ad64e3bc86 /client/drawing.lua
parent0eab09311f6634aefe0e79ecafd975ab68b2812c (diff)
coords, hexagons, drawing, chunks
Diffstat (limited to 'client/drawing.lua')
-rw-r--r--client/drawing.lua40
1 files changed, 40 insertions, 0 deletions
diff --git a/client/drawing.lua b/client/drawing.lua
new file mode 100644
index 0000000..e65e716
--- /dev/null
+++ b/client/drawing.lua
@@ -0,0 +1,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}