Little refactoring
This commit is contained in:
parent
d2308917b4
commit
8a8db93ac1
7 changed files with 67 additions and 53 deletions
|
@ -1,5 +1,5 @@
|
|||
require "point"
|
||||
require "config"
|
||||
require 'point'
|
||||
require 'config'
|
||||
|
||||
-- Point table with grid-based coordinates
|
||||
---@class GridPoint: Point
|
||||
|
@ -17,5 +17,15 @@ end
|
|||
-- Same as coords, but converted to global coords
|
||||
---@return number, number
|
||||
function GridPoint:globalCoords()
|
||||
return self.x * Config.cellSize - Config.cellSize / 2, self.y * Config.cellSize - Config.cellSize / 2
|
||||
return self.x * Config.cellSize - Config.cellSize / 2,
|
||||
self.y * Config.cellSize - Config.cellSize / 2
|
||||
end
|
||||
|
||||
-- Returns local coords from global
|
||||
---@param point Point
|
||||
---@return GridPoint
|
||||
function GridPoint.snapCoords( point )
|
||||
local x = math.ceil( point.x / Config.cellSize )
|
||||
local y = math.ceil( point.y / Config.cellSize )
|
||||
return GridPoint:new( x, y )
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue