diff --git a/config.lua b/config.lua index c582db6..67698c8 100644 --- a/config.lua +++ b/config.lua @@ -2,21 +2,21 @@ require 'tablefuncs' -- Global config table ---@class Config ----@field pointRadius number Radius of each grid point ----@field linePointRadius number Radius of line start/end point +---@field pointRadius number Radius of each grid point, relative to cellSize +---@field linePointRadius number Radius of line start/end points, relative to cellSize ---@field cellSize number Size of each grid cell ---@field lineStyle string love2d line style setting ---@field lineWidth number love2d line width setting ---@field dragSensivity number drag sensivity, px Config = { - pointRadius = 7, + pointRadius = 0.3, - linePointRadius = 10, + linePointRadius = 0.4, cellSize = 30, lineStyle = "smooth", - lineWidth = 5, + lineWidth = 0.1, dragSensivity = 5 } diff --git a/grid.lua b/grid.lua index 5faeab4..d6ca755 100644 --- a/grid.lua +++ b/grid.lua @@ -40,7 +40,7 @@ function Grid:draw() for y = 1, self.size.y do 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.cellSize * Config.pointRadius) end end -- Draw lines diff --git a/levelhandler.lua b/levelhandler.lua index e5941e7..ed7b874 100644 --- a/levelhandler.lua +++ b/levelhandler.lua @@ -6,7 +6,7 @@ require 'makegrid' ---@field current integer LevelHandler = { levels = { - 'test2', 'test' + 'test3', 'test2', 'test' }, current = 1, } diff --git a/levels/test3.lua b/levels/test3.lua new file mode 100644 index 0000000..e256e3e --- /dev/null +++ b/levels/test3.lua @@ -0,0 +1,9 @@ +return { + width = 6, + height = 6, + lines = { + { 5, 4, 2, 2, "green" }, + { 2, 5, 4, 1, "red" }, + { 2, 4, 5, 1, "blue" } + } +} diff --git a/line.lua b/line.lua index 4208a66..08d8703 100644 --- a/line.lua +++ b/line.lua @@ -51,9 +51,9 @@ function Line:draw() love.graphics.setColor( self.color ) -- Draw start and end points (should look like rings) local sx, sy = self.startpoint:globalCoords() - love.graphics.circle( "fill", sx, sy, Config.linePointRadius ) + love.graphics.circle( "fill", sx, sy, Config.cellSize * Config.linePointRadius ) local ex, ey = self.endpoint:globalCoords() - love.graphics.circle( "fill", ex, ey, Config.linePointRadius ) + love.graphics.circle( "fill", ex, ey, Config.cellSize * Config.linePointRadius ) if #self.points <= 1 then love.graphics.setColor( Color.white ) return diff --git a/main.lua b/main.lua index 404a262..7d4d338 100644 --- a/main.lua +++ b/main.lua @@ -5,11 +5,19 @@ require 'mouse' require 'levelhandler' Input = require 'input' -function love.load() - love.graphics.setLineStyle( Config.lineStyle ) - love.graphics.setLineWidth( Config.lineWidth ) +local function updateCellSize() + local width, height = love.graphics.getDimensions() + local gridX, gridY = GameGrid.size:coords(); + local isWidthBased = (width / height) / (gridX / gridY) + Config.cellSize = math.floor(isWidthBased and height / gridY or width / gridX) + love.graphics.setLineWidth( Config.cellSize * Config.lineWidth ) +end +function love.load() GameGrid = LevelHandler:first() + updateCellSize() + + love.graphics.setLineStyle( Config.lineStyle ) end function love.update( dt ) @@ -23,6 +31,7 @@ function love.update( dt ) if Input:actionReleased( 'nextlevel' ) then if GameGrid:isCompleted() then GameGrid = LevelHandler:next() + updateCellSize() end end end