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
|
||||
---@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
|
||||
}
|
||||
|
|
2
grid.lua
2
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
|
||||
|
|
|
@ -6,7 +6,7 @@ require 'makegrid'
|
|||
---@field current integer
|
||||
LevelHandler = {
|
||||
levels = {
|
||||
'test2', 'test'
|
||||
'test3', 'test2', 'test'
|
||||
},
|
||||
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 )
|
||||
-- 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
|
||||
|
|
15
main.lua
15
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue