Added more borders. Fixed border render issue on edge cases with values equal to threshhold.
This commit is contained in:
parent
c6890d5ef5
commit
ea91cc6bc9
18
map.lua
18
map.lua
|
@ -42,10 +42,17 @@ function map.draw()
|
|||
lg.clear( 0, 0, 0, 1 )
|
||||
|
||||
do --territory
|
||||
lg.setColor( 1,1,1,1)
|
||||
lg.setLineJoin( "none" )
|
||||
lg.setLineWidth( 1 / Camera.zoom )
|
||||
lg.replaceTransform( Camera.tfTerritory )
|
||||
lg.setBlendMode( "add" )
|
||||
for k, v in pairs(map.territory) do
|
||||
if v.visible then v:draw() end
|
||||
if v.visible then
|
||||
v:draw()
|
||||
v:drawBorder( "land" )
|
||||
v:drawBorder( "sea" )
|
||||
end
|
||||
end
|
||||
if map.sailable.visible then map.sailable:draw() end
|
||||
lg.setBlendMode( "alpha" )
|
||||
|
@ -54,10 +61,15 @@ function map.draw()
|
|||
end
|
||||
|
||||
do --borders
|
||||
lg.setColor( 1,1,1,1)
|
||||
lg.setLineJoin( "none" )
|
||||
lg.setLineWidth( 1 / Camera.zoom )
|
||||
map.sailable:drawBorder()
|
||||
|
||||
lg.setColor( 1, 1, 1, 0.5)
|
||||
map.sailable:drawBorder( "sailable" )
|
||||
|
||||
|
||||
lg.setColor( 1, 0, 0, 0.5)
|
||||
map.sailable:drawBorder( "placeable" )
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -25,7 +25,11 @@ function t.load( filename, name )
|
|||
|
||||
if name == "sailable" then
|
||||
t.sailable = territory
|
||||
t.computeBorder( territory, 20 / 255 )
|
||||
t.computeBorder( territory, 20 / 255, "sailable" )
|
||||
t.computeBorder( territory, 60 / 255, "placeable" )
|
||||
else
|
||||
t.computeBorder( territory, 60 / 255, "sea" )
|
||||
t.computeBorder( territory, 130 / 255, "land" )
|
||||
end
|
||||
return setmetatable( territory, {__index = t } )
|
||||
end
|
||||
|
@ -90,17 +94,18 @@ function t.draw( territory )
|
|||
lg.draw( territory.img )
|
||||
end
|
||||
|
||||
function t.drawBorder( territory )
|
||||
--lg.setColor( territory.colour )
|
||||
for _, poly in ipairs( territory.border ) do
|
||||
function t.drawBorder( territory, key )
|
||||
key = key or "border"
|
||||
for _, poly in ipairs( territory[key] ) do
|
||||
lg.line( poly )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function t.computeBorder( territory, threshold )
|
||||
territory.border = {}
|
||||
local border = territory.border
|
||||
function t.computeBorder( territory, threshold, key )
|
||||
key = key or "border"
|
||||
territory[key] = {}
|
||||
local border = territory[key]
|
||||
local n = 1
|
||||
|
||||
for x = 0, 511 do
|
||||
|
@ -112,25 +117,25 @@ function t.computeBorder( territory, threshold )
|
|||
|
||||
--Sample image and detect edge:
|
||||
local curValue = territory.imgd:getPixel( x, y )
|
||||
local leftValue = territory.imgd:getPixel( math.min( x + 1, 511 ), y )
|
||||
local rightValue = territory.imgd:getPixel( math.min( x + 1, 511 ), y )
|
||||
local downValue = territory.imgd:getPixel( x, math.min( 284, y + 1 ) )
|
||||
|
||||
local isLeftEdge =
|
||||
((curValue >= threshold) and (leftValue < threshold)) or
|
||||
((curValue <= threshold) and (leftValue > threshold))
|
||||
local isRightEdge =
|
||||
((curValue >= threshold) and (rightValue < threshold)) or
|
||||
((curValue < threshold) and (rightValue >= threshold))
|
||||
local isDownEdge =
|
||||
((curValue >= threshold) and (downValue < threshold)) or
|
||||
((curValue <= threshold) and (downValue > threshold))
|
||||
((curValue < threshold) and (downValue >= threshold))
|
||||
|
||||
if isLeftEdge then
|
||||
if isRightEdge then
|
||||
--print( "Left edge:", brx, bry, trx, try )
|
||||
border[n] = { brx, bry, trx, try }
|
||||
border[n] = { x + 1, y, x + 1, y + 1 }
|
||||
n = n + 1
|
||||
end
|
||||
|
||||
if isDownEdge then
|
||||
--print( "Down edge:", blx, bly, brx, bry )
|
||||
border[n] = { blx, bly, brx, bry }
|
||||
border[n] = { x, y + 1, x + 1, y + 1 }
|
||||
n = n + 1
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue