Grid distance formula? (SOLVED)

Worked like a charm! Thank you very much, I’ve been scratching my head over this for hours!

The code looks like this now:

local function draw_squares(self, pos, range)
	for i, v in ipairs(self.map_state) do
		local in_range = math.abs(v.pos.x-pos.x)+math.abs(v.pos.y-pos.y) <= range * 48
		if in_range and not v.occupied then
			square_factory(self, v.pos, self.light_blue)
		end
	end
end

And the end result!

2 Likes