From d0916d568a00f5171b96fbc3bfc19ff263affc27 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Fri, 27 Jan 2023 13:43:49 +0000 Subject: coords, hexagons, drawing, chunks --- client/drawing.lua | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 client/drawing.lua (limited to 'client/drawing.lua') 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} -- cgit v1.2.3