Exemplo n.º 1
0
 def step(self, packet: GameTickPacket, drone: Drone, index: int):
     self.finished = True
     drone.since_jumped = None
     drone.start_pos = None
     drone.sort_phase = 0
Exemplo n.º 2
0
    def step(self, packet: GameTickPacket, drone: Drone, index: int):
        if drone.start_pos is None:
            drone.start_pos = drone.position
            drone.sort_phase = 1

        # Finish if all have been sorted.
        if index == 0:
            # Initially set finished to True.
            self.finished = True
        if drone.sort_phase != 3:
            # Will be set to False if any is not in phase 3.
            self.finished = False

            # It's my time!
        if self.time_since_start > 0.5 + index * self.delay:

            desired_angle = (2 * math.pi / 64) * index

            # current_radius = norm(vec2(drone.position))
            current_angle = math.atan2(drone.position[1], drone.position[0])
            if current_angle < 0.0:
                current_angle += 2 * math.pi  # only positive angles

            # Rotate to correct angle.
            if drone.sort_phase == 1:
                # if index in range(64)[::8]: print(index, current_angle, desired_angle)
                if abs(current_angle - desired_angle) < 0.1:
                    drone.sort_phase = 2
                target = dot(rotation(current_angle + 0.4),
                             vec2(self.radius - 400, 0))
                target = vec3(target)
                target[2] = self.height + (180 * index // 16)

            # Height and final corrections.
            elif drone.sort_phase == 2:
                target = vec3(
                    dot(rotation(desired_angle), vec2(self.radius, 0)))
                target[2] = self.height
                if norm(drone.position - target) < 200:
                    drone.sort_phase = 3

                target[2] = (4 * drone.position[2] + self.height) / 5

            elif drone.sort_phase == 3:
                target = vec3(
                    dot(rotation(desired_angle), vec2(self.radius, 0)))
                target[2] = self.height

        else:
            # Stay in place.
            target = drone.start_pos

        # Hover controls
        drone.hover.target = target
        drone.hover.up = normalize(drone.position)
        drone.hover.step(self.dt)
        drone.controls = drone.hover.controls

        # If any bot got lost, now they have a chance to recover.
        if drone.on_ground:
            drone.controls.jump = True
        else:
            drone.controls.jump = False