def update(self, sight_blockers): # split out pathfinding and sighting functions # if player can be seen, and is in range, stop and fire # else move towards player along path for blocker in sight_blockers: while not check_sight(self[0].position, self[1].position, blocker): # set old dist as current dist olddist = get_distance(self[0].position, self[1].position) tx = int(self[1].position.x) ty = int(self[1].position.y) # setup points to check for x in [tx - 5, tx, tx + 5]: for y in [ty - 5, ty, ty + 5]: if not point_rect_intersect(sf.Vector2(x, y), blocker.global_bounds): newdist = get_distance(self[0].position, sf.Vector2(x, y)) if newdist < olddist: olddist = newdist newpos = x, y # add newpos to vertex array v = sf.Vertex() v.position = sf.Vector2(newpos[0], newpos[1]) v.color = sf.Color.RED self.append(self[1]) self[1] = v for i in range(len(self)): print "Point #" + str(i) + ": " + str( self[i].position.x), str(self[i].position.y)
def update(self, sight_blockers): # split out pathfinding and sighting functions # if player can be seen, and is in range, stop and fire # else move towards player along path for blocker in sight_blockers: while not check_sight(self[0].position, self[1].position, blocker): # set old dist as current dist olddist = get_distance(self[0].position, self[1].position) tx = int(self[1].position.x) ty = int(self[1].position.y) # setup points to check for x in [tx - 5, tx, tx + 5]: for y in [ty - 5, ty, ty + 5]: if not point_rect_intersect(sf.Vector2(x, y), blocker.global_bounds): newdist = get_distance(self[0].position, sf.Vector2(x, y)) if newdist < olddist: olddist = newdist newpos = x, y # add newpos to vertex array v = sf.Vertex() v.position = sf.Vector2(newpos[0], newpos[1]) v.color = sf.Color.RED self.append(self[1]) self[1] = v for i in range(len(self)): print "Point #" + str(i) + ": " + str(self[i].position.x), str(self[i].position.y)
def check_angle_and_range(self): ret = False own_point = sf.Vertex() own_point.position = self.position far_point = sf.Vertex() far_point.position = (cos(self.rotation) * 100, sin(self.rotation) * 100) if check_sight(own_point.position, far_point.position, self.target): ret = True return ret
def check_sight_to_target(self, objects): ret = True blockers = [] for ob in objects: if ob.blocks_sight: blockers.append(ob) for blocker in blockers: if check_sight(self.position, self.target.position, blocker): ret = False return ret
def update(self, sight_blockers): # split out pathfinding and sighting functions # if player can be seen, and is in range, stop and fire # else move towards player along path for blocker in sight_blockers: while not check_sight(self[0].position, self[1].position, blocker): # set old dist as current dist # olddist = get_distance(self[0].position, self[1].position) # bad idea, what if next point is further away? Still gotta pick it! # Maybe measure line length rather than straight line distance? If it makes the movement path shorter # move along it olddist = None tx = int(self[1].position.x) ty = int(self[1].position.y) pointpos = [] for v in self: pointpos.append([v.position.x, v.position.y]) # setup points to check for x in [tx - self.step, tx, tx + self.step]: for y in [ty - self.step, ty, ty + self.step]: if x == tx and y == ty or [x, y] in pointpos: continue else: if not point_rect_intersect( sf.Vector2(x, y), blocker.global_bounds): newdist = get_distance(self[0].position, sf.Vector2(x, y)) if newdist < olddist or not olddist: olddist = newdist newpos = x, y # add newpos to vertex array v = sf.Vertex() v.position = sf.Vector2(newpos[0], newpos[1]) v.color = sf.Color.RED self.append(self[1]) self[1] = v
def update(self, sight_blockers): # split out pathfinding and sighting functions # if player can be seen, and is in range, stop and fire # else move towards player along path for blocker in sight_blockers: while not check_sight(self[0].position, self[1].position, blocker): # set old dist as current dist # olddist = get_distance(self[0].position, self[1].position) # bad idea, what if next point is further away? Still gotta pick it! # Maybe measure line length rather than straight line distance? If it makes the movement path shorter # move along it olddist = None tx = int(self[1].position.x) ty = int(self[1].position.y) pointpos = [] for v in self: pointpos.append([v.position.x, v.position.y]) # setup points to check for x in [tx - self.step, tx, tx + self.step]: for y in [ty - self.step, ty, ty + self.step]: if x == tx and y == ty or [x, y] in pointpos: continue else: if not point_rect_intersect(sf.Vector2(x, y), blocker.global_bounds): newdist = get_distance(self[0].position, sf.Vector2(x, y)) if newdist < olddist or not olddist: olddist = newdist newpos = x, y # add newpos to vertex array v = sf.Vertex() v.position = sf.Vector2(newpos[0], newpos[1]) v.color = sf.Color.RED self.append(self[1]) self[1] = v