hexgrid: created formula to determine offset
This commit is contained in:
parent
e1dc884af6
commit
31e148bf48
@ -1,9 +1,16 @@
|
|||||||
function createHex()
|
function createHex(centerX, centerY)
|
||||||
local hex = {}
|
local hex = {}
|
||||||
hex.centerX = 300
|
hex.centerX = centerX
|
||||||
hex.centerY = 300
|
hex.centerY = centerY
|
||||||
hex.size = 45
|
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 lastX = nil
|
||||||
local lastY = nil
|
local lastY = nil
|
||||||
|
|
||||||
@ -23,6 +30,8 @@ function createHex()
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return hex
|
return hex
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -36,10 +45,31 @@ end
|
|||||||
|
|
||||||
function love.draw()
|
function love.draw()
|
||||||
love.graphics.setColor({255,255,255,255})
|
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
|
for i=1, #hex1.sides do
|
||||||
love.graphics.line(unpack(hex1.sides[i]))
|
love.graphics.line(unpack(hex1.sides[i]))
|
||||||
end
|
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
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user