08-13-2013, 10:55 PM
Does this help any?
Code:
#----------------------------------------------------------------------------
# * Get line of sight
#----------------------------------------------------------------------------
def line_of_sight?(xa, ya, xb, yb)
dx = (xa - xb).abs
dy = (ya - yb).abs
x = xa
y = ya
n = 1 + dx + dy
x_inc = (xb > xa) ? 1 : -1
y_inc = (yb > ya) ? 1 : -1
error = dx - dy;
dx = dx*2 #do this to
dy = dy*2 #get rid of fractions
n.downto(0){ |i|
if !$game_map.passable?(x, y, 0) #$game_map.terrain_tag(x, y) == 5
return false
end
if (error > 0)
x = x + x_inc
error = error - dy
else
y = y + y_inc
error = error + dx
end
}
return true
end