lines-lua/main.lua
2025-05-20 09:31:19 +03:00

46 lines
1.1 KiB
Lua

require "grid"
require "point"
require "line"
function love.load()
love.graphics.setLineStyle( Config.lineStyle )
love.graphics.setLineWidth( Config.lineWidth )
gameGrid = Grid:new( Point:new( 5, 5 ) )
local line = Line:new(
GridPoint:new( 1, 1 ),
GridPoint:new( 3, 3 ),
Color.red
)
gameGrid:push( line )
mouse = {
x = 0,
y = 0,
pressed = false,
lastPressed = false
}
end
-- TODO: move input interactions into module
function love.update( dt )
mouse.x, mouse.y = love.mouse.getPosition()
mouse.lastPressed = pressed
mouse.pressed = love.mouse.isDown( 1 )
end
function love.draw()
gameGrid:draw()
if mouse.pressed then
local x, y = snapCoords( Point:new( mouse.x, mouse.y ) ):coords()
local text = string.format( "%d:%d global\n%d:%d local", mouse.x, mouse.y, x, y )
love.graphics.print( text, 64, 256 )
end
end
-- Returns local coords from global
function snapCoords( point )
local x = math.ceil( point.x / Config.cellSize )
local y = math.ceil( point.y / Config.cellSize )
return GridPoint:new( x, y )
end