def can_see(self, other): if vector.mag2(vector.sub(other.rect.center, self.rect.center)) <= self.__vis_radius ** 2: angle = vector.dir(vector.sub(other.rect.center, self.rect.center)) - ( self.direction - self.__vis_angle / 2 ) % math.radians(360) if angle < self.__vis_angle: return True return False
def flock(self, l, delta): v1 = vector.muls(self.cohesion(l), self.__cohesion_factor) v2 = vector.muls(self.separation(l), self.__separation_factor) v3 = vector.muls(self.rate(l), self.__rate_factor) self.velocity = vector.add(self.velocity, v1, v2, v3) self.velocity = vector.maxs(vector.mins(self.velocity, self.__velocity_max), -self.__velocity_max) self.direction = vector.dir(vector.add(self.velocity, (0, 192 / 6))) self.set_rotation(-math.degrees((self.direction - math.radians(90)) % math.radians(360)))