Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function computePath(origin, destination)
- sPath = { }
- local diff = (destination.pos - origin.pos)
- local direction = vector.new(diff.x / (math.abs(diff.x) + math.abs(diff.y)), diff.y / (math.abs(diff.x) + math.abs(diff.y)))
- local x,y = origin.pos.x, origin.pos.y
- local stepsLeft = math.abs(diff.x) + math.abs(diff.y)
- while stepsLeft > 0 do
- x = x + direction.x
- y = y + direction.y
- table.insert(sPath, { pos = vector.new(x, y), colour = colours.orange })
- stepsLeft = stepsLeft - (math.abs(direction.x) + math.abs(direction.y))
- end
- assert(sPath[#sPath].pos.x == destination.pos.x, sPath[#sPath].pos.x.." neq "..destination.pos.x)
- end
- computePath({ pos = vector.new(10,20) }, { pos = vector.new(15,11) })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement