diff --git a/love/hexgrid/main.lua b/love/hexgrid/main.lua index 32ffceb..637627d 100644 --- a/love/hexgrid/main.lua +++ b/love/hexgrid/main.lua @@ -1,9 +1,16 @@ -function createHex() +function createHex(centerX, centerY) local hex = {} - hex.centerX = 300 - hex.centerY = 300 + hex.centerX = centerX + hex.centerY = centerY hex.size = 45 +--The height is size *2 +--The width is sqrt(3)/2 * height +--Horizontal distance between two hexes is horiz = width + + hex.height = hex.size * 2 + hex.width = math.sqrt(3)/2 * hex.height + local lastX = nil local lastY = nil @@ -23,6 +30,8 @@ function createHex() end + + return hex end @@ -36,10 +45,31 @@ end function love.draw() love.graphics.setColor({255,255,255,255}) - hex1=createHex() + + --create our first hex #note: this will all end up + --in a single for loop to draw a complete grid + temp=createHex (300,300) + hex1=createHex(0+temp.width,0+temp.height) for i=1, #hex1.sides do love.graphics.line(unpack(hex1.sides[i])) end + + --Here we create another hex and place it to the side + newCenterX = hex1.centerX + hex1.width + hex2=createHex(newCenterX,hex1.centerY) + + for i=1, #hex2.sides do + love.graphics.line(unpack(hex2.sides[i])) + end + + -- Here we want to move down a row and base it from the first hex + newCenterY = hex1.centerY+(hex1.height * 3/4) + newCenterX = (hex1.centerX + hex2.centerX)/2 + hex3 = createHex(newCenterX, newCenterY) + + for i=1, #hex3.sides do + love.graphics.line(unpack(hex3.sides[i])) + end end