Changed drawing order and updated line connecting
This commit is contained in:
parent
abce928481
commit
178043bac3
2 changed files with 23 additions and 4 deletions
19
grid.lua
19
grid.lua
|
@ -22,20 +22,26 @@ end
|
||||||
|
|
||||||
-- Draw lines and the whole grid
|
-- Draw lines and the whole grid
|
||||||
function Grid:draw()
|
function Grid:draw()
|
||||||
-- Draw lines
|
-- Draw grid
|
||||||
|
for x = 1, self.size.x do-- Draw lines
|
||||||
for _, line in ipairs( self.lines ) do
|
for _, line in ipairs( self.lines ) do
|
||||||
line:draw()
|
line:draw()
|
||||||
end
|
end
|
||||||
-- Draw grid
|
|
||||||
for x = 1, self.size.x do
|
|
||||||
for y = 1, self.size.y do
|
for y = 1, self.size.y do
|
||||||
local px, py = x * Config.cellSize, y * Config.cellSize
|
local px, py = x * Config.cellSize, y * Config.cellSize
|
||||||
love.graphics.circle( "fill", px - Config.cellSize / 2, py - Config.cellSize / 2, Config.pointRadius)
|
love.graphics.circle( "fill", px - Config.cellSize / 2, py - Config.cellSize / 2, Config.pointRadius)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
-- Draw lines
|
||||||
|
for _, line in ipairs( self.lines ) do
|
||||||
|
line:draw()
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check all lines and return one, which contains point (if any)
|
-- Check all lines and return one, which contains point (if any)
|
||||||
|
-- TODO: rewrite this function to extract clear/reverse behavior
|
||||||
function Grid:matchesLine( point, ignoreEnd )
|
function Grid:matchesLine( point, ignoreEnd )
|
||||||
local line = self.lines[tableFind( self.lines, point,
|
local line = self.lines[tableFind( self.lines, point,
|
||||||
function( value, innervalue )
|
function( value, innervalue )
|
||||||
|
@ -71,6 +77,13 @@ function Grid:matchesLine( point, ignoreEnd )
|
||||||
return line
|
return line
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Grid:isOtherEndpoint( line, point )
|
||||||
|
return tableHas( self.lines, { line=line, point=point }, function( value, innervalue )
|
||||||
|
return innervalue ~= value.line and innervalue.endpoint:equals( value.point )
|
||||||
|
end
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
function Grid:inBounds( point )
|
function Grid:inBounds( point )
|
||||||
return point.x <= self.size.x and point.y <= self.size.y
|
return point.x <= self.size.x and point.y <= self.size.y
|
||||||
end
|
end
|
||||||
|
|
8
main.lua
8
main.lua
|
@ -56,8 +56,14 @@ function love.update( dt )
|
||||||
if vectorLength( mouse.point, lastLinePoint ) == 1
|
if vectorLength( mouse.point, lastLinePoint ) == 1
|
||||||
and gameGrid:inBounds( mouse.point )
|
and gameGrid:inBounds( mouse.point )
|
||||||
and gameGrid:matchesLine( mouse.point, true ) == nil
|
and gameGrid:matchesLine( mouse.point, true ) == nil
|
||||||
and not lastLinePoint:equals( mouse.lastLine.endpoint ) then
|
and not lastLinePoint:equals( mouse.lastLine.endpoint )
|
||||||
|
and not gameGrid:isOtherEndpoint( mouse.lastLine, mouse.point ) then
|
||||||
mouse.lastLine:push( mouse.point )
|
mouse.lastLine:push( mouse.point )
|
||||||
|
elseif mouse.lastLine:has( mouse.point )
|
||||||
|
and not mouse.point:equals( lastLinePoint ) then
|
||||||
|
while not mouse.lastLine.points[#mouse.lastLine.points]:equals( mouse.point ) do
|
||||||
|
mouse.lastLine:pop()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue