예제 #1
0
    def push(self, bullet_blob, strength):
        direction = vector.normalize(
            vector.substract(self.position, bullet_blob.get_position()))
        bullet_force = bullet_blob.get_force()

        self_force_strength = vector.dot_product(direction,
                                                 bullet_force) * strength
        self.add_force(vector.multiply(direction, self_force_strength))
        bullet_blob.set_force(vector.substract(bullet_force, self.force))
예제 #2
0
    def update(self):
        if not self.manipulator.is_alive(): return

        blob = self.manipulator.get_largest_blob()

        others = self.manipulator.get_other_items()

        best_target = None

        for item in others:
            distance = vector.squared_distance(blob.get_position(),
                                               item.get_position())

            if isinstance(item, PelletProxy) or isinstance(
                    item, LargePelletProxy):
                value = item.get_bonus_weight()**2 / distance
                run_away = False
            elif isinstance(item, BlobProxy) or isinstance(
                    item, BulletBlobProxy):
                if item.get_weight() * (BLOB_WEIGHT_RATIO_TO_EAT *
                                        1.1) > blob.get_weight():
                    value = item.get_weight()**2 / distance
                    run_away = True
                elif blob.get_weight(
                ) * BLOB_WEIGHT_RATIO_TO_EAT > item.get_weight():
                    value = item.get_weight()**2 / distance
                    run_away = False
                else:
                    continue
            else:
                continue

            if best_target is None or value > best_target[1]:
                best_target = (item, value, run_away)

        if best_target is None:
            position = self.manipulator.get_blob_family_positions_and_weights(
            )[0][0]
            middle = vector.divide(self.manipulator.get_board_size(), 2)
            self.manipulator.set_velocity(vector.substract(middle, position))
        elif best_target[2]:
            self.manipulator.set_velocity(
                vector.normalize(
                    vector.substract(blob.get_position(),
                                     best_target[0].get_position())))
        else:
            self.manipulator.set_velocity(
                vector.normalize(
                    vector.substract(best_target[0].get_position(),
                                     blob.get_position())))
예제 #3
0
    def update(self):
        if not self.manipulator.is_alive(): return

        position = self.manipulator.get_largest_blob().get_position()
        middle = vector.divide(self.manipulator.get_board_size(), 2)

        self.manipulator.set_velocity(vector.substract(middle, position))
예제 #4
0
    def _draw_centered_text(self, text, pos, col):
        textsurface = self.font.render(text, ANTIALIASING, col)

        size = vector.divide(self.font.size(text), 2)
        mapped_pos = vector.substract(self._map_coord_to_screen(pos), size)

        x = int(mapped_pos[0] + 1 + 0.5)
        y = int(mapped_pos[1] + 1 + 0.5)

        self.screen.blit(textsurface, (x,y))
예제 #5
0
    def update(self):
        if not self.manipulator.is_alive(): return

        main_blob = self.manipulator.get_largest_blob()

        others = self.manipulator.get_other_items()
        closest = None

        for item in others:
            if isinstance(item, PelletProxy) or isinstance(item, LargePelletProxy):
                distance = vector.squared_distance(main_blob.get_position(), item.get_position())
                if closest is None or distance < closest[1]:
                    closest = (item.get_position(), distance)

        if closest is None:
            position = self.manipulator.get_largest_blob().get_position()
            middle = vector.divide(self.manipulator.get_board_size(), 2)
            self.manipulator.set_velocity(vector.substract(middle, position))
        else:
            self.manipulator.set_velocity(vector.normalize(vector.substract(closest[0], main_blob.get_position())))
예제 #6
0
    def _fits_on_screen(self, item):
        right, bottom = self._map_coord_to_screen(
            vector.substract(item.get_position(),
                             (item.get_radius(), item.get_radius())))
        left, top = self._map_coord_to_screen(
            vector.add(item.get_position(),
                       (item.get_radius(), item.get_radius())))
        screen_size = self.screen.get_size()

        return left >= 0 and top >= 0 and right <= screen_size[
            0] and bottom <= screen_size[1]
예제 #7
0
    def update(self):
        if not self.manipulator.is_alive(): return

        mouse_position = pygame.mouse.get_pos()
        direction = vector.substract(mouse_position, self.view_center)
        direction = vector.divide(direction, self.player_radius)
        self.manipulator.set_velocity(direction)

        for event in self.model.events:
            if event.type == pygame.MOUSEBUTTONDOWN:
                if event.button == 1: self.manipulator.divide()
                elif event.button == 3: self.manipulator.shoot()
예제 #8
0
파일: blob.py 프로젝트: davda54/agar.ai
    def repel_from_each_other(self, blob):
        difference = vector.substract(blob.get_position(), self.position)
        distance = vector.norm(difference)
        strength = distance - self.radius - blob.get_radius()

        self.add_force(
            vector.multiply(
                difference, BLOB_REPEL_STRENGTH * strength / distance -
                BLOB_REPEL_BASE_STRENGTH))
        blob.add_force(
            vector.multiply(
                difference, -BLOB_REPEL_STRENGTH * strength / distance +
                BLOB_REPEL_BASE_STRENGTH))
예제 #9
0
파일: blob.py 프로젝트: davda54/agar.ai
 def get_together(self, center):
     difference = vector.substract(center, self.position)
     self.add_force(vector.multiply(difference, BLOB_GRAVITATION))
예제 #10
0
 def __set_resize_offset(self):
     screen_center = vector.divide(self.screen.get_size(), 2)
     scale_position = vector.multiply(
         self.center_blob_family.get_largest_blob().get_position(),
         self._get_resize_ratio())
     self.resize_offset = vector.substract(screen_center, scale_position)
예제 #11
0
 def touches(self, other):
     distance = vector.squared_norm(vector.substract(self.position, other.position))
     return distance - (self.radius + other.radius)**2 < 0
예제 #12
0
 def collides(self, other):
     distance = vector.squared_norm(vector.substract(self.position, other.position))
     return distance - max(self.radius, other.radius)**2 < 0