コード例 #1
0
    def step(self, packet: GameTickPacket, drone: Drone, index: int):
        if drone.start_pos is None:
            drone.start_pos = drone.position

        # spin = (index % 16 - 8) * 0.01 # Unwind helix.
        # rotation = axis_to_rotation(vec3(0, 0, spin))
        # position_on_circle = normalize(xy(drone.position)) * self.start_radius
        # drone.hover.target = dot(rotation, position_on_circle)
        # drone.hover.target[2] = drone.start_pos[2]
        # drone.hover.step(self.dt)
        # drone.controls = drone.hover.controls

        current_radius = norm(vec2(drone.position))

        desired_angle = (2 * math.pi / 64) * index
        current_angle = math.atan2(drone.position[1], drone.position[0])
        if current_angle < 0.0:
            current_angle += 2 * math.pi  # only positive angles

        # Expand radius.
        if current_radius < self.radius - 150:
            direction_angle = (math.pi / 4) + ((math.pi / 2) * (index // 16))
            direction = vec3(dot(rotation(direction_angle), vec2(1, 0)))
            target = drone.position + direction * 200
            target[2] = drone.start_pos[2]
        # Get to correct angle.
        elif abs(desired_angle - current_angle) > 0.05:
            target = vec3(dot(rotation(desired_angle), vec2(self.radius, 0)))
            target[2] = drone.start_pos[2]
        # Get to correct height.
        else:
            target = vec3(dot(rotation(desired_angle), vec2(self.radius, 0)))
            target[2] = self.height

        drone.hover.up = normalize(drone.position)
        drone.hover.target = target
        drone.hover.step(self.dt)
        drone.controls = drone.hover.controls
コード例 #2
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
コード例 #3
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