Skip to content

Instantly share code, notes, and snippets.

@laserbat
Created July 20, 2011 11:47
Show Gist options
  • Save laserbat/1094816 to your computer and use it in GitHub Desktop.
Save laserbat/1094816 to your computer and use it in GitHub Desktop.
def inLos(self, x1, y1, px, py):
"""Checks if point is in LOS"""
x2 = px
y2 = py
if FAST_LOS:
self.gamemap[x1][y1].changed = True
issteep = abs(y2 - y1) > abs(x2 - x1)
if issteep:
x1, y1 = y1, x1
x2, y2 = y2, x2
if x1 > x2:
x1, x2 = x2, x1
y1, y2 = y2, y1
deltax = x2 - x1
deltay = abs(y2 - y1)
error = int(deltax / 2)
y = y1
ystep = None
if y1 < y2:
ystep = 1
else:
ystep = -1
b = False
for x in range(x1, x2 + 1):
if b:
return False
if issteep:
if not self.gamemap[y][x].type[1]:
b = True
else:
if not self.gamemap[x][y].type[1]:
b = True
error -= deltay
if error < 0:
y += ystep
error += deltax
return True
else:
b = False
ret = True
line = self.getLine(py, px, y1, x1)
for j in line:
if b:
ret = False
jx = j[1]
jy = j[0]
if not self.gamemap[jx][jy].type[1]:
b = True
self.gamemap[x1][y1].changed = True
return ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment