Пример #1
0
    def __cohesion(self):
        steer = Vector2(0, 0)
        cumulative = Vector2(0, 0)
        distance = 0
        total = 0

        for e in self.query_result:
            if e is self:
                continue

            distance = Vector2.distance_between(e.location, self.location)
            if distance > 0 and distance < self.view_radius:
                cumulative.add(e.location)
                total += 1

        if total > 0:
            cumulative.divide(total)
            cumulative.subtract(self.location)
            cumulative.set_magnitude(self.default_move_speed)

            steer = Vector2(cumulative.x - self.velocity.x,
                            cumulative.y - self.velocity.y)
            steer.limit(self.max_force)

        return steer
Пример #2
0
    def __separation(self):
        steer = Vector2(0, 0)
        cumulative = Vector2(0, 0)
        force = Vector2(0, 0)
        distance = 0
        total = 0

        for e in self.query_result:
            if e is self:
                continue

            distance = Vector2.distance_between(e.location, self.location)
            if distance > 0 and distance < self.width:
                force = Vector2(self.location.x - e.location.x,
                                self.location.y - e.location.y)
                force.divide(distance**2)
                cumulative.add(force)
                total += 1

        if total > 0:
            cumulative.divide(total)
            cumulative.set_magnitude(self.default_move_speed)

            steer = Vector2(cumulative.x - self.velocity.x,
                            cumulative.y - self.velocity.y)
            steer.limit(self.max_force)

        return steer
Пример #3
0
    def _collision(self, scene_data):
        if self.y + self.height > scene_data.scene_bounds.height + 64:
            self.remove = True

        if Vector2.distance_between(
                Vector2(scene_data.actor.x + scene_data.actor.width,
                        scene_data.actor.y + scene_data.actor.height),
                self.center) < self.radius:
            scene_data.actor.get_yeeted()