class bot5(Fly): curve = Curve(get_paths()[5].to_points(1000)) target_indexes = range(5, 6)
class bot3(Fly): curve = Curve(get_paths()[3].to_points(1000)) target_indexes = range(3, 4)
class bot4(Fly): curve = Curve(get_paths()[4].to_points(1000)) target_indexes = range(4, 5)
class bot1(Fly): curve = Curve(get_paths()[1].to_points(1000)) target_indexes = range(1, 2)
class bot2(Fly): curve = Curve(get_paths()[2].to_points(1000)) target_indexes = range(2, 3)
class bot8(Fly): curve = Curve(get_paths()[8].to_points(1000)) target_indexes = range(8, 9)
class bot0(Fly): curve = Curve(get_paths()[0].to_points(1000)) target_indexes = range(0, 1)
class bot6(Fly): curve = Curve(get_paths()[6].to_points(1000)) target_indexes = range(6, 7)
class bot7(Fly): curve = Curve(get_paths()[7].to_points(1000)) target_indexes = range(7, 8)
def main(self): main_path = BLUE_DRAGON_PATH other_path = PURPLE_DRAGON_PATH selected_point_index = 0 while True: packet = GameTickPacket() self.game_interface.update_live_data_packet(packet) renderer = self.game_interface.renderer renderer.begin_rendering() points = main_path.points selected_point_index = min(selected_point_index, len(points) - 1) # select previous if keyboard.is_pressed("-") and selected_point_index > 0: selected_point_index -= 1 time.sleep(0.1) # select next elif keyboard.is_pressed("+") and selected_point_index < len(points) - 1: selected_point_index += 1 time.sleep(0.1) # move selected elif keyboard.is_pressed("left arrow"): points[selected_point_index][0] -= 10 self.draw_line(renderer, points[selected_point_index], vec3(1, 0, 0)) elif keyboard.is_pressed("right arrow"): points[selected_point_index][0] += 10 self.draw_line(renderer, points[selected_point_index], vec3(1, 0, 0)) elif keyboard.is_pressed("up arrow"): points[selected_point_index][1] += 10 self.draw_line(renderer, points[selected_point_index], vec3(0, 1, 0)) elif keyboard.is_pressed("down arrow"): points[selected_point_index][1] -= 10 self.draw_line(renderer, points[selected_point_index], vec3(0, 1, 0)) elif keyboard.is_pressed("0"): points[selected_point_index][2] -= 10 self.draw_line(renderer, points[selected_point_index], vec3(0, 0, 1)) elif keyboard.is_pressed("1"): points[selected_point_index][2] += 10 self.draw_line(renderer, points[selected_point_index], vec3(0, 0, 1)) # insert new one after selected elif keyboard.is_pressed("*"): if selected_point_index == len(points) - 1: new_point = 2 * points[-1] - points[-2] else: new_point = (points[selected_point_index] + points[selected_point_index + 1]) * 0.5 selected_point_index += 1 points.insert(selected_point_index, new_point) time.sleep(0.2) # delete selected elif keyboard.is_pressed("delete"): del points[selected_point_index] selected_point_index -= 1 time.sleep(0.2) # dump points into file elif keyboard.is_pressed("enter"): with open("points.txt", "w") as file: file.write("\nBLUE DRAGON\n") for point in BLUE_DRAGON_PATH.points: file.write(f'vec3({int(point[0])}, {int(point[1])}, {int(point[2])}),\n') file.write("\nPURPLE DRAGON\n") for point in PURPLE_DRAGON_PATH.points: file.write(f'vec3({int(point[0])}, {int(point[1])}, {int(point[2])}),\n') print("dumped path to points.txt") renderer.clear_all_touched_render_groups() time.sleep(0.2) exit() # switch between paths elif keyboard.is_pressed("9"): main_path, other_path = other_path, main_path time.sleep(0.2) continue # render path path = BezierPath(points) curve = Curve(path.to_points(380)) # t = curve.find_nearest(points[min(selected_point_index, len(points) - 2)]) # rendered_points = [curve.point_at(t + i) for i in range(-5000, 5000, 200)] renderer.draw_polyline_3d(curve.points, renderer.white()) renderer.end_rendering() renderer.begin_rendering("stuff") for i in range(30): pos = curve.point_at((1 - i / 30) * curve.length) renderer.draw_string_3d(pos, 1, 1, str(i), renderer.white()) for i, point in enumerate(points): selected = i == selected_point_index color = renderer.yellow() if selected else renderer.red() size = 6 if selected else 4 renderer.draw_rect_3d(point, size, size, True, color, True) renderer.draw_string_2d(10, 10, 1, 1, str(int(curve.length)), renderer.yellow()) renderer.end_rendering() renderer.begin_rendering("reference") blue = renderer.create_color(255, 150, 180, 255) # render the other path for reference path = BezierPath(other_path.points) curve2 = Curve(path.to_points(380)) # rendered_points = [curve2.point_at(curve2.length - curve.length + t + i) for i in range(-5000, 5000, 200)] renderer.draw_polyline_3d(curve2.points, blue) for i in range(30): pos = curve2.point_at((1 - i / 30) * curve2.length) renderer.draw_string_3d(pos, 1, 1, str(i), renderer.blue()) renderer.draw_string_2d(10, 30, 1, 1, str(int(curve2.length)), renderer.yellow()) renderer.end_rendering() # render the rings of fire orbit for reference renderer.begin_rendering("orbit") points = [dot(axis_to_rotation(vec3(0, 0, i / 30 * pi * 2)), vec3(2200, 0, 1400)) for i in range(30)] renderer.draw_polyline_3d(points, renderer.orange()) renderer.end_rendering() time.sleep(0.02)
def to_Curve(self, team_sign): ''' Converts the path to an RLU Curve object that can be followed ''' control_points = [] #The first arc direction1 = self.start - self.center1 starting_angle = atan2(direction1.y, direction1.x) steps = ceil(30 * (self.phi1 / (2 * pi))) delta = -self.sgn1 * self.phi1 / steps center1 = Vec3_to_vec3(self.center1, team_sign) for i in range(1, steps - 2): angle = starting_angle + delta * i next_point = center1 + abs(self.radius1) * vec3( cos(angle), sin(angle), 0) normal = normalize(next_point - center1) next_control_point = ControlPoint() next_control_point.p = next_point next_control_point.t = cross(normal) next_control_point.n = normal control_points.append(next_control_point) #The line steps = max(10, ceil(self.length_line / 300)) delta = self.length_line / steps tangent = Vec3_to_vec3( (self.transition2 - self.transition1).normalize(), team_sign) normal = cross(tangent) for i in range(0, steps + 1): next_point = Vec3_to_vec3(self.transition1, team_sign) + delta * tangent * i next_control_point = ControlPoint() next_control_point.p = next_point next_control_point.t = tangent next_control_point.n = normal control_points.append(next_control_point) #The second arc direction2 = self.transition2 - self.center2 starting_angle = atan2(direction2.y, direction2.x) steps = ceil(30 * (self.phi2 / (2 * pi))) delta = -self.sgn2 * self.phi2 / steps center2 = Vec3_to_vec3(self.center2, team_sign) for i in range(1, steps + 1): angle = starting_angle + delta * i next_point = center2 + abs(self.radius2) * vec3( cos(angle), sin(angle), 0) normal = normalize(next_point - center2) next_control_point = ControlPoint() next_control_point.p = next_point next_control_point.t = cross(normal) next_control_point.n = normal control_points.append(next_control_point) curve = Curve(control_points) self.RLU_curve = curve self.discretized_path = [ vec3_to_Vec3(point.p, team_sign) for point in control_points ]
class bot3(Fly): duration = 10 curve = Curve(get_paths()[3].to_points(1000)) target_indexes = range(2, 3)
class bot2(Fly): duration = 10 curve = Curve(get_paths()[2].to_points(1000)) target_indexes = range(1, 2)
class bot1(Fly): duration = 10 curve = Curve(get_paths()[1].to_points(1000)) target_indexes = range(0, 1)
class PurpleDragon(Dragon): path = Curve(PURPLE_DRAGON_PATH.to_points(2000)) target_indexes = range(5, 10)
class BlueDragon(Dragon): path = Curve(BLUE_DRAGON_PATH.to_points(2000)) target_indexes = range(0, 5)