Scaling drawing

This commit is contained in:
Alexey 2025-07-03 15:11:46 +03:00
commit 293f529613
6 changed files with 30 additions and 12 deletions

View file

@ -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
}

View file

@ -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

View file

@ -6,7 +6,7 @@ require 'makegrid'
---@field current integer
LevelHandler = {
levels = {
'test2', 'test'
'test3', 'test2', 'test'
},
current = 1,
}

9
levels/test3.lua Normal file
View file

@ -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" }
}
}

View file

@ -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

View file

@ -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