Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Vaiko committed Sep 9, 2024
1 parent 3702461 commit c81f67f
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ local reverseCourse = ToggleParameter('reverse', false, 'v', true)
table.insert(parameters, reverseCourse)
local smallOverlaps = ToggleParameter('small overlaps', false, 'm', true)
table.insert(parameters, smallOverlaps)
local nVehicles = AdjustableParameter(1, 'number of vehicles', 'Y', 'y', 1, 1, 5)
local nVehicles = AdjustableParameter(2, 'number of vehicles', 'Y', 'y', 1, 1, 5)
table.insert(parameters, nVehicles)
local position =AdjustableParameter(1, 'position', '.', ',', 1, -2, 2)
table.insert(parameters, position)
Expand Down Expand Up @@ -131,7 +131,12 @@ local swathColor = { 0, 0.7, 0, 0.25 }
local islandColor = { 0.7, 0, 0.7, 1 }
local islandPointColor = { 0.7, 0, 0.7, 0.4 }
local islandPerimeterPointColor = { 1, 0.4, 1 }

local multiVehicleColorForPosition = {}
multiVehicleColorForPosition[-2] = { 1, 0, 0 }
multiVehicleColorForPosition[-1] = { 1, 0.3, 0.3 }
multiVehicleColorForPosition[0] = courseColor
multiVehicleColorForPosition[1] = { 0.3, 1, 0.3 }
multiVehicleColorForPosition[2] = { 0, 1, 0 }

-- the selectedField to generate the course for
---@type CourseGenerator.Field
Expand Down Expand Up @@ -365,7 +370,7 @@ local function drawWaypoint(v)
drawVertexAsArrow(v)
end

local function drawPath(p)
local function drawPath(p, color)
if #p > 1 then
for i, v in p:vertices() do
if v:getExitEdge() then
Expand All @@ -377,7 +382,7 @@ local function drawPath(p)
love.graphics.setColor(turnColor)
else
love.graphics.setLineWidth(lineWidth)
love.graphics.setColor(courseColor)
love.graphics.setColor(color or courseColor)
end
love.graphics.line(v.x, v.y, v:getExitEdge():getEnd().x, v:getExitEdge():getEnd().y)
end
Expand Down Expand Up @@ -631,7 +636,16 @@ local function drawGraphics()
if course:getCenter() then
drawCenter(course:getCenter())
end
drawPath(course:getPath())
if nVehicles:get() > 1 then
for p = - math.floor(nVehicles:get() / 2), math.floor(nVehicles:get() / 2) do
if p ~= 0 or nVehicles:get() % 2 ~= 0 then
-- 0 position makes sense only with odd number of vehicles
drawPath(course:getPath(p), multiVehicleColorForPosition[p])
end
end
else
drawPath(course:getPath())
end
drawSwath(course:getPath())
end
drawStartLocation()
Expand Down Expand Up @@ -737,7 +751,8 @@ function love.textinput(key)
return true
end)
end
if key == ' ' then
if key == ' ' or key == 'y' or key == 'Y' then
-- regenerate when the number of vehicles changes
generate()
end
end
Expand Down

0 comments on commit c81f67f

Please sign in to comment.