Esempio n. 1
0
 def choose_bounce_old_way(self):
     ball_goal_vector = la.vec2(self.enemy_goal_loc[0], self.enemy_goal_loc[1]) - \
                        la.vec2(self.ball_loc[0], self.ball_loc[1])
     radius_multiplier = 1 / 1  # 0.8
     num_bounce = len(self.ground_bounce[1])
     # num_bounce = 3
     path = [None] * num_bounce
     for bounce_n in range(num_bounce):
         bounce = self.ground_bounce[1][bounce_n]
         if ((self.ground_bounce[0][bounce_n]) - self.time) != 0:
             speed_needed = la.norm(bounce - self.loc) / (
                 (self.ground_bounce[0][bounce_n]) - self.time)
         else:
             speed_needed = self.max_speed[1]
         if 0 > speed_needed or speed_needed > self.max_speed[1]:
             continue
         else:
             return [
                 bounce +
                 (self.g_vec3(la.normalize(ball_goal_vector)) * -40),
                 speed_needed
             ]
     return [self.ball_loc, self.time + 0.01]
Esempio n. 2
0
 def choose_bounce_new_way(self):
     ball_goal_vector = la.vec2(self.enemy_goal_loc[0], self.enemy_goal_loc[1]) - \
                        la.vec2(self.ball_loc[0], self.ball_loc[1])
     radius_multiplier = 1 / 1  # 0.8
     num_bounce = len(self.ground_bounce[1])
     # num_bounce = 3
     path = [None] * num_bounce
     end_radius = self.max_current_radius
     self.renderer.begin_rendering('bounce time')
     for bounce_n in range(num_bounce):
         bounce = self.ground_bounce[1][bounce_n]
         if bounce_n < 5:
             self.renderer.draw_string_3d(
                 bounce, 1, 1,
                 str(self.ground_bounce[0][bounce_n] - self.time),
                 self.renderer.black())
         bounce = self.grounded(bounce)
         radius_1_sgn = la.sgn(self.ball_loc_loc[1])
         radius_2_sgn = -la.sgn(
             self.ball_loc_loc[1] * self.enemy_goal_loc_loc[0])
         path[bounce_n] = sim.ArcLineArc(
             self.g_vec2(self.loc),  # first point
             self.g_vec2(la.normalize(self.vel)),  # first tangent
             self.max_current_radius * radius_1_sgn *
             radius_multiplier,  #first radius
             self.g_vec2(bounce) + la.normalize(ball_goal_vector) * -500,
             la.normalize(ball_goal_vector),
             end_radius * radius_2_sgn * radius_multiplier)
         # path.is_valid
         # path.length
         # path.p1  # point 1
         # path.p2  # point 2
         # path.q1  # circle to line 1
         # path.q2  # line to circle 2
         # path.o1  # circle 1 center
         # path.o2  # circle 2 center
         # print(path.q1)
     self.renderer.end_rendering()
     self.renderer.begin_rendering('path')
     for line in range(len(path)):
         if not path[line].is_valid:
             continue
         speed_needed = abs((path[line].length + 1000) /
                            ((self.ground_bounce[0][line]) - self.time))
         if 0 > speed_needed or speed_needed > self.max_speed[1]:
             continue
         else:
             print(line)
             print(path[line].is_valid)
             bounce = self.ground_bounce[1][line]
             self.renderer.draw_line_3d(self.g_vec3(path[line].q1),
                                        self.g_vec3(path[line].q2),
                                        self.renderer.pink())
             points = 25
             curve1 = [None] * (points + 1)
             curve2 = [None] * (points + 1)
             for divn in range(points + 1):
                 x = math.cos(
                     ((2 * math.pi) / points) *
                     divn) * -self.max_current_radius * radius_multiplier
                 y = math.sin(
                     ((2 * math.pi) / points) *
                     divn) * -self.max_current_radius * radius_multiplier
                 x2 = math.cos(((2 * math.pi) / points) *
                               divn) * -end_radius * radius_multiplier
                 y2 = math.sin(((2 * math.pi) / points) *
                               divn) * -end_radius * radius_multiplier
                 curve1[divn] = self.to_world(la.vec3(
                     x, y, 0)) + self.g_vec3(path[line].o1)
                 curve2[divn] = self.to_world(la.vec3(
                     x2, y2, 0)) + self.g_vec3(path[line].o2)
             self.renderer.draw_polyline_3d(curve1, self.renderer.pink())
             self.renderer.draw_polyline_3d(curve2, self.renderer.pink())
             self.renderer.draw_line_3d(self.g_vec3(path[line].p2),
                                        self.g_vec3(self.enemy_goal_loc),
                                        self.renderer.pink())
             self.renderer.draw_line_3d((self.g_vec3(
                 self.g_vec2(bounce) +
                 la.normalize(ball_goal_vector) * -500)), ((self.c_vec3(
                     self.g_vec2(bounce) +
                     la.normalize(ball_goal_vector) * -500))),
                                        self.renderer.black())
             self.renderer.draw_line_3d((self.g_vec3(self.g_vec2(bounce))),
                                        (self.c_vec3(self.g_vec2(bounce))),
                                        self.renderer.red())
             self.renderer.end_rendering()
             print(self.g_vec3(path[line].q2))
             return [self.g_vec3(path[line].q2), speed_needed]
     self.renderer.end_rendering()
     print('old way')  # Todo: if none found use current or last position
     return self.choose_bounce_old_way()