Beispiel #1
0
    def render(self, screen):
        """Renders this scene on the given target

        Arguments:

            screen {pygame.Surface} -- Pygame surface where the scene should be drawn
        """
        # Create clip matrix to be passed to the root-level objects, so they can be drawn
        camera_matrix = self.camera.get_camera_matrix()
        projection_matrix = self.camera.get_projection_matrix()

        clip_matrix = camera_matrix * projection_matrix

        # Render all root-level objects
        for obj in self.objects:
            #makes objects only being rendered if their in front of the camre
            heading = obj.position - self.camera.position
            dot = Vector3.dot(heading, self.camera.forward())

            if dot > 4:
                obj.render(screen, clip_matrix)
Beispiel #2
0
def run(packet, fieldstate):
    global is_spline, state
    #Early start control
    if fieldstate.elapsed_time() < 8:
        return SimpleControllerState()

    #The following logic was written at 2 am by a programmer that just wants to be done with this project
    #It's horrible, and I'm sorry.

    if (not is_spline) or h_spline.finished(
            fieldstate.elapsed_time() - spline_start, spline_scale):
        is_spline = False
        controller = SimpleControllerState()
        aim_vector = fieldstate.goal_pos() - fieldstate.ball_location()
        #persue ball if close
        car_to_ball = fieldstate.ball_location() - fieldstate.car_location()
        print(car_to_ball.length())

        if Vector3.dot(fieldstate.car_velocity(), car_to_ball.normalize()) >= (
                0.4 * fieldstate.car_velocity().length()) and (Vector3.dot(
                    aim_vector, car_to_ball) >= -0.2):
            correction = -fieldstate.car_facing_vector().correction_to(
                car_to_ball)
            controller.steer = 5 * correction
            controller.throttle = clamp(
                0.3 + Vector3.dot(fieldstate.car_facing_vector(), car_to_ball),
                1.0, -1.0)
            if car_to_ball.length() < 500: controller.boost = True
            if car_to_ball.length() < 500: controller.jump = True
            #print("SUPER ATTACK")
            return controller

        if car_to_ball.length() < 2500 or (not fieldstate.car_in_field()):
            #if on wrong side, run away and try to reposition
            #if on right side, gfi
            if Vector3.dot(aim_vector, car_to_ball) <= 0:
                #run away to reposition
                target_pos = fieldstate.ball_location() - (5000 * sign(
                    Vector3.dot(aim_vector, Vector3.j())) * Vector3.j())
                set_target(fieldstate,
                           v_clamp(target_pos, Vector3(4096, 5140),
                                   Vector3(-4096, -5140)),
                           fieldstate.ball_location() - target_pos,
                           time_scale=(1.0 / 1.0))
                #print("RETREAT")
                return SimpleControllerState()
            else:
                correction = -fieldstate.car_facing_vector().correction_to(
                    car_to_ball)
                controller.steer = 5 * correction
                if (Vector3.dot(fieldstate.car_velocity().normalize(),
                                car_to_ball.normalize()) <=
                        0.7) and (fieldstate.car_velocity().length() > 250):
                    controller.handbrake = True
                controller.throttle = clamp(
                    0.2 +
                    Vector3.dot(fieldstate.car_facing_vector(), car_to_ball),
                    1.0, -1.0)
                if car_to_ball.length() < 500: controller.boost = True
                if car_to_ball.length() < 450: controller.jump = True
                #print("ATTACK")
                return controller

        #set setpoint if far away
        set_target(fieldstate,
                   v_clamp(
                       fieldstate.ball_location() -
                       (1000 * sign(Vector3.dot(aim_vector, Vector3.j())) *
                        Vector3.j()), Vector3(4096,
                                              5140), Vector3(-4096, -5140)),
                   aim_vector,
                   time_scale=(1.0 / 2.0))
        #print("PATH")

    else:
        return hermite_update(fieldstate)

    return SimpleControllerState()