diff options
Diffstat (limited to 'client')
-rw-r--r-- | client/conf.lua | 2 | ||||
-rw-r--r-- | client/drawing.lua | 40 | ||||
-rw-r--r-- | client/main.lua | 11 |
3 files changed, 52 insertions, 1 deletions
diff --git a/client/conf.lua b/client/conf.lua index 5c58cb3..e207e09 100644 --- a/client/conf.lua +++ b/client/conf.lua @@ -1,3 +1,3 @@ function love.conf(t) - t.window.title = "rectangle emulator" + t.window.title = "hexagon emulator" end 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} diff --git a/client/main.lua b/client/main.lua index 5884186..b5d322e 100644 --- a/client/main.lua +++ b/client/main.lua @@ -6,6 +6,9 @@ local PLAYER_SIZE = 30 local local_player = nil + +math.randomseed(os.time()) + -- { -- pos={100,100}, -- color={love.math.colorFromBytes(0xdf,0x73,0xff)}, @@ -13,6 +16,9 @@ local local_player = nil local host,peer + +local chunk = require"common.chunk".Chunk.make() + local function draw_player(pl,me) local hplsz = PLAYER_SIZE/2 love.graphics.setColor(pl.color) @@ -103,12 +109,17 @@ function love.update(dt) end function love.draw() + love.graphics.clear(1,1,1) if local_player then draw_player(local_player,true) end for _,pl in pairs(remote_players) do draw_player(pl) end + + -- require"drawing".drawhex({x=200,y=200},40) + require"drawing".draw_chunk(chunk) + end function love.load() |