Scaling drawing
This commit is contained in:
parent
d4c4c7bfd0
commit
293f529613
6 changed files with 30 additions and 12 deletions
10
config.lua
10
config.lua
|
@ -2,21 +2,21 @@ require 'tablefuncs'
|
||||||
|
|
||||||
-- Global config table
|
-- Global config table
|
||||||
---@class Config
|
---@class Config
|
||||||
---@field pointRadius number Radius of each grid point
|
---@field pointRadius number Radius of each grid point, relative to cellSize
|
||||||
---@field linePointRadius number Radius of line start/end point
|
---@field linePointRadius number Radius of line start/end points, relative to cellSize
|
||||||
---@field cellSize number Size of each grid cell
|
---@field cellSize number Size of each grid cell
|
||||||
---@field lineStyle string love2d line style setting
|
---@field lineStyle string love2d line style setting
|
||||||
---@field lineWidth number love2d line width setting
|
---@field lineWidth number love2d line width setting
|
||||||
---@field dragSensivity number drag sensivity, px
|
---@field dragSensivity number drag sensivity, px
|
||||||
Config = {
|
Config = {
|
||||||
pointRadius = 7,
|
pointRadius = 0.3,
|
||||||
|
|
||||||
linePointRadius = 10,
|
linePointRadius = 0.4,
|
||||||
|
|
||||||
cellSize = 30,
|
cellSize = 30,
|
||||||
|
|
||||||
lineStyle = "smooth",
|
lineStyle = "smooth",
|
||||||
lineWidth = 5,
|
lineWidth = 0.1,
|
||||||
|
|
||||||
dragSensivity = 5
|
dragSensivity = 5
|
||||||
}
|
}
|
||||||
|
|
2
grid.lua
2
grid.lua
|
@ -40,7 +40,7 @@ function Grid:draw()
|
||||||
|
|
||||||
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.cellSize * Config.pointRadius)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- Draw lines
|
-- Draw lines
|
||||||
|
|
|
@ -6,7 +6,7 @@ require 'makegrid'
|
||||||
---@field current integer
|
---@field current integer
|
||||||
LevelHandler = {
|
LevelHandler = {
|
||||||
levels = {
|
levels = {
|
||||||
'test2', 'test'
|
'test3', 'test2', 'test'
|
||||||
},
|
},
|
||||||
current = 1,
|
current = 1,
|
||||||
}
|
}
|
||||||
|
|
9
levels/test3.lua
Normal file
9
levels/test3.lua
Normal 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" }
|
||||||
|
}
|
||||||
|
}
|
4
line.lua
4
line.lua
|
@ -51,9 +51,9 @@ function Line:draw()
|
||||||
love.graphics.setColor( self.color )
|
love.graphics.setColor( self.color )
|
||||||
-- Draw start and end points (should look like rings)
|
-- Draw start and end points (should look like rings)
|
||||||
local sx, sy = self.startpoint:globalCoords()
|
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()
|
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
|
if #self.points <= 1 then
|
||||||
love.graphics.setColor( Color.white )
|
love.graphics.setColor( Color.white )
|
||||||
return
|
return
|
||||||
|
|
15
main.lua
15
main.lua
|
@ -5,11 +5,19 @@ require 'mouse'
|
||||||
require 'levelhandler'
|
require 'levelhandler'
|
||||||
Input = require 'input'
|
Input = require 'input'
|
||||||
|
|
||||||
function love.load()
|
local function updateCellSize()
|
||||||
love.graphics.setLineStyle( Config.lineStyle )
|
local width, height = love.graphics.getDimensions()
|
||||||
love.graphics.setLineWidth( Config.lineWidth )
|
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()
|
GameGrid = LevelHandler:first()
|
||||||
|
updateCellSize()
|
||||||
|
|
||||||
|
love.graphics.setLineStyle( Config.lineStyle )
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.update( dt )
|
function love.update( dt )
|
||||||
|
@ -23,6 +31,7 @@ function love.update( dt )
|
||||||
if Input:actionReleased( 'nextlevel' ) then
|
if Input:actionReleased( 'nextlevel' ) then
|
||||||
if GameGrid:isCompleted() then
|
if GameGrid:isCompleted() then
|
||||||
GameGrid = LevelHandler:next()
|
GameGrid = LevelHandler:next()
|
||||||
|
updateCellSize()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue