def move(self, delta_time):
        self.last_pos = euclid.Vector2(self.hitbox.left, self.hitbox.top)

        if math.fabs(self.velocity.y) > 50.0:  # if the player is moving in the y direction.
            self.can_jump = False

        #apply gravity
        if not self.is_jumping:  # ignore gravity while the user accelerates the jump
                self.velocity += self.gravity * delta_time

        self.start_position += self.velocity * delta_time + 0.5 * (self.gravity * (delta_time ** 2))

        #slow down player if they are moving too fast in the X
        if math.fabs(self.velocity.x) > math.fabs(self.max_speed.x) and not self.grapple_projectile.is_alive and\
           not self.is_dashing:
            self.velocity.x -= self.velocity.x * self.drag.x * delta_time
            #taking x velocity and multiplying it by drag and time and then adding it to add drag
        #stop the player in the x direction if they are on the ground and stopped giving input
        elif self.can_jump and self.not_walking(delta_time) and not self.is_dashing:
            self.velocity = euclid.Vector2(0.0, self.velocity.y)

        #slow down player if they are moving too fast in the Y
        if math.fabs(self.velocity.y) > math.fabs(self.max_speed.y) and not self.grapple_projectile.is_alive:
            self.velocity.y -= self.velocity.y * self.drag.y * delta_time
            if math.fabs(self.velocity.y) < math.fabs(self.max_speed.y):
                self.velocity.y = self.max_speed.y * -sign(self.velocity.y)  # take the inverse of the sign

        #reset rects
        self.reset_rects()
    def collision(self, direction, thing_hit):
        """sets objects position and velocity"""
        if thing_hit.is_solid:
            if direction == 'under':
                self.velocity = euclid.Vector2(self.velocity.x, 0.0)
                self.start_position.x = thing_hit.rect.bottom

            elif direction == 'above':
                self.velocity = euclid.Vector2(self.velocity.x, 0.0)
                self.start_position.x = thing_hit.rect.top + self.get_height()

            elif direction == 'on the left':
                self.velocity = euclid.Vector2(0.0, self.velocity.y)
                self.start_position.y = thing_hit.rect.left + self.get_width()

            elif direction == 'on the right':
                self.velocity = euclid.Vector2(0.0, self.velocity.y)
                self.start_position.y = thing_hit.rect.right

            elif direction == 'inside':
                pass

            else:
                raise Exception('Collision: no valid direction')

        thing_hit.on_collision(self, direction)
Ejemplo n.º 3
0
    def update_weapon_image(self, player):
        mouse_position = player.mouse_position
        gun_position_vector = get_vector_to_position(
            mouse_position, self.window_position_center)
        self.rotation_theta = self.roto_theta_conversion_tool_extreme(
            gun_position_vector) + 90
        if math.fabs(self.rotation_theta) > 90:
            self.rotation_theta += 180
            player.gun_is_pointed_right = False
        else:
            player.gun_is_pointed_right = True

        #set where the player is looking if they aren't dashing
        if not player.is_dashing:
            player.is_looking_right = player.gun_is_pointed_right

        if player.gun_is_pointed_right:
            self.set_center(
                euclid.Vector2(
                    player.start_position.x + player.get_width() / 2.0 +
                    self.gun_x_position, player.start_position.y +
                    player.get_height() / 2.0 + self.gun_y_position))
        else:
            self.set_center(
                euclid.Vector2(
                    player.start_position.x + player.get_width() / 2.0 +
                    self.gun_x_position + self.look_left_offset,
                    player.start_position.y + player.get_height() / 2.0 +
                    self.gun_y_position))

        #TODO notice that the server gun wil not always have the correct size rect. But it will have the correct center
        #self.server_rect.reform_rect(self.image.get_width(), self.image.get_height(), self.server_rect.center)
        self.reset_rects()
    def __init__(self,
                 start_position,
                 height,
                 length,
                 image_list,
                 weapons,
                 world_object_list_dictionary,
                 spawn_animation,
                 velocity=euclid.Vector2(0.0, 0.0),
                 gravity=euclid.Vector2(0.0, 0.0),
                 health=100.0):

        LunarPioneer.__init__(self, start_position, height, length, weapons,
                              world_object_list_dictionary, velocity, gravity,
                              health)

        #images
        self.spawn_animation = Spawnimation(self.start_position, 90, 651,
                                            spawn_animation, self)
        self.dashing_animation = Animation(image_list[9:14], self, .1,
                                           self.end_dash_animation)
        self.dust_image_list = image_list[15:21]
        self.running_animation = Animation(image_list[0:9], self, .08)
        self.image = self.running_animation.current_image()

        self.rect = self.server_rect.get_pygame_rect()

        #override
        self.grapple_projectile = Grapple(start_position, self.weapons[0],
                                          self)
        self.grapple_projectile.is_alive = False  # kill default grapple

        self.add_to_world(self.spawn_animation, "foreground")
    def get_info(self, level, y_index, x_index, code):
        """
        Gets the basic info of the world_object.
        """
        start_position = euclid.Vector2(int(x_index * self.pixel_multiplier),
                                        int(y_index * self.pixel_multiplier))
        end_position = euclid.Vector2(0.0, 0.0)
        last_x_position = 0.0
        last_y_position = 0.0

        for last_x_position in range(x_index + 1, len(level[y_index])):
            col = level[y_index + 1][last_x_position]
            if col == code:
                end_position.x = last_x_position * self.pixel_multiplier
                break

        for last_y_position in range(y_index + 1, len(level)):
            row = level[last_y_position][x_index + 1]
            if row == code:
                end_position.y = last_y_position * self.pixel_multiplier
                break

        width = end_position.x - start_position.x + self.pixel_multiplier
        height = end_position.y - start_position.y + self.pixel_multiplier

        if level[last_y_position][last_x_position] != code:
            data = level[last_y_position][last_x_position].split("-")
        else:
            data = level[last_y_position][x_index].split("-")

        self.clearArea(level, start_position, end_position)

        return Info(start_position, width, height, data)
    def __init__(self, start_position, width, height, frame_parent):
        UIFrame.__init__(self, start_position, width, height, frame_parent)
        self.rect.center = self.frame_parent.rect.center

        self.close_button = Button(euclid.Vector2(width - 35, 5), 30, 30,
                                   list(globals.close_button_img_list), self,
                                   self.frame_parent.close_pause_menu)

        self.quit_game_button = TextButton(euclid.Vector2(5, 100),
                                           145,
                                           25,
                                           list(globals.button_img_list),
                                           "Quit Game",
                                           self,
                                           self.main_frame_parent().quit_game,
                                           text_pos=(25, 6))

        self.quit_to_lobby_button = TextButton(
            euclid.Vector2(5, 130),
            160,
            25,
            list(globals.button_img_list),
            "Quit to Lobby",
            self,
            self.main_frame_parent().quit_to_lobby,
            text_pos=(25, 6))

        self.all_elements = [
            self.close_button, self.quit_game_button, self.quit_to_lobby_button
        ]
    def draw_sprites(self, background, foreground, players):
        #screen.blit(gameBG, (-self.rect.left, -self.rect.top))
        #screen.blit(gameBG, (0, 0), self.rect)
        self.screen.fill(BLACK)
        for s in background:
            if self.rect.colliderect(s.rect):
                self.screen.blit(s.image, self.RelRect(s.rect))

        for player in players:
            if self.rect.colliderect(player.rect):
                player_rel_rect = self.RelRect(player.rect)
                self.screen.blit(player.image, self.RelRect(player.rect))
                gun_rel_rect = self.RelRect(
                    self.player.weapons[IS_EQUIPPED].rect)
                self.player.weapons[
                    IS_EQUIPPED].window_position_center = euclid.Vector2(
                        gun_rel_rect.center[0], gun_rel_rect.center[1])
                self.player.window_position_center = euclid.Vector2(
                    player_rel_rect.center[0], player_rel_rect.center[1])
                self.screen.blit(self.player.weapons[IS_EQUIPPED].image,
                                 gun_rel_rect)

        for s in foreground:
            if self.rect.colliderect(s.rect):
                self.screen.blit(s.image, self.RelRect(s.rect))
 def collision_under(self, thing_hit):
     if self.is_grappled():
         self.velocity = euclid.Vector2(0.0, 0.0)
     else:
         self.is_jumping = False
         self.is_grapple_jumping = False
         self.velocity = euclid.Vector2(self.velocity.x, 0.0)
     self.start_position.y = thing_hit.start_position.y + thing_hit.get_height() - self.top_padding()
Ejemplo n.º 9
0
 def __init__(self,
              start_position,
              width,
              height,
              velocity=euclid.Vector2(0.0, 10.0),
              max_displacement=euclid.Vector2(0, 5)):
     ServerPlatform.__init__(self, start_position, width, height, velocity)
     self.max_displacement = max_displacement  # in pixels
     self.initial_position = start_position.copy()
    def __init__(self, start_position=euclid.Vector2(0, 0), width=0, height=0, velocity=euclid.Vector2(0.0, 0.0),
                 image_code=None):
        self.start_position = start_position
        self.server_rect = ServerRect(int(self.start_position.x), int(self.start_position.y), width, height)
        self.velocity = velocity
        self.image_code = image_code

        self.is_alive = True  # removes object from map
        self.last_pos = euclid.Vector2(self.start_position.x, self.start_position.y)
        self.is_solid = True
Ejemplo n.º 11
0
 def __init__(self,
              start_position,
              width,
              height,
              image,
              velocity=euclid.Vector2(0.0, 50.0),
              max_displacement=euclid.Vector2(0, 250)):
     Platform.__init__(self, start_position, width, height, image, velocity)
     ServerMovingPlatform.__init__(self, start_position, width, height,
                                   velocity, max_displacement)
 def collision_on_the_right(self, thing_hit):
     if self.is_grappled():
         self.velocity = euclid.Vector2(0.0, 0.0)
     else:
         if isinstance(thing_hit, ServerStep):
             self.start_position.y = thing_hit.start_position.y - self.hitbox.height - self.top_padding()
             return
         else:
             self.velocity = euclid.Vector2(0.0, self.velocity.y)
     self.start_position.x = thing_hit.start_position.x + thing_hit.get_width() - self.side_padding()
Ejemplo n.º 13
0
 def __init__(self,
              center,
              shot_from,
              player,
              velocity=euclid.Vector2(0.0, 0.0),
              gravity=euclid.Vector2(0.0, 0.0)):
     """can you handle the inheritance"""
     ServerGrapple.__init__(self, center, shot_from, player, velocity,
                            gravity)
     Projectile.__init__(self, center, shot_from, player, velocity, gravity)
    def __init__(self,
                 center,
                 shot_from,
                 player,
                 velocity=euclid.Vector2(0.0, 0.0),
                 gravity=euclid.Vector2(0.0, 0.0)):

        ServerProjectile.__init__(self, center, shot_from, player, velocity,
                                  gravity)
        self.start_direction = self.get_direction()
 def __init__(self,
              start_position,
              width,
              height,
              velocity=euclid.Vector2(0.0, 10.0),
              max_displacement=euclid.Vector2(0, 5)):
     ServerMovingPlatform.__init__(self, start_position, width, height,
                                   velocity, max_displacement)
     #overrides
     self.is_solid = False
Ejemplo n.º 16
0
    def __init__(self,
                 center,
                 shot_from,
                 player,
                 velocity=euclid.Vector2(0.0, 0.0),
                 gravity=euclid.Vector2(0.0, 0.0)):

        ServerPredatorMissile.__init__(self, center, shot_from, player,
                                       velocity, gravity)
        Projectile.__init__(self, center, shot_from, player, velocity, gravity)
        self.explosion_animation = Animation(
            self.shot_from.bullet_image_list[1:6], self, .15)
    def __init__(self, start_position, width, height, parent_frame=None):
        #images
        UIFrame.__init__(self, start_position, width, height, parent_frame)
        self.display_name_label = Label(euclid.Vector2(0, 0), "Displayed Name:", self)
        self.display_name_textfield = TextField(euclid.Vector2(width - 150,
                                                               self.display_name_label.rect.top),
                                                150, 15, user_name, list(globals.text_field_img_list), 10, self)

        self.save_button = TextButton(euclid.Vector2(width / 2 - 25, height - 20), 50, 20,
                                      list(globals.ready_button_img_list), "Save", self, self.save_pressed)

        self.all_elements = [self.display_name_label, self.display_name_textfield, self.save_button]
    def __init__(self, start_position, height, length, weapons, world_object_list_dictionary,
                 velocity=euclid.Vector2(0.0, 0.0), gravity=euclid.Vector2(0.0, 0.0), health=100.0):

        ServerSpritePlayer.__init__(self, start_position, height, length, weapons, world_object_list_dictionary,
                                    velocity, gravity, health)

        #grapple attributes
        self.last_grapple_time = 0.0
        self.grapple_projectile = ServerGrapple(start_position, self.weapons[0], self)
        self.grapple_projectile.is_alive = False  # kill default grapple
        self.is_grapple_jumping = False
        self.max_grapple_speed = euclid.Vector2(self.max_speed.x / 1.5, self.max_speed.y / 1.5)
Ejemplo n.º 19
0
 def use(self, start_position, bullet_position_vector, time_since_grapple,
         timeSinceReload, player):
     if time_since_grapple > self.delay:
         return [
             Grap(
                 euclid.Vector2(start_position.x + 1, start_position.y + 1),
                 self, player,
                 euclid.Vector2(
                     bullet_position_vector.x * self.bullet_velocity * 3,
                     bullet_position_vector.y * self.bullet_velocity * 3))
         ]
     return None
Ejemplo n.º 20
0
    def update_weapon_image(self, player):
        if player.is_shooting:
            self.animation.use_image_at = 1
        else:
            self.animation.use_image_at = 0

        mouse_position = player.mouse_position
        gun_position_vector = get_vector_to_position(
            mouse_position, self.window_position_center)
        theta = self.roto_theta_conversion_tool_extreme(
            gun_position_vector) + 90
        if math.fabs(theta) > 90:
            image = pygame.transform.flip(self.animation.current_image(), 1, 0)
            self.image = pygame.transform.rotate(image, theta + 180)
            player.gun_is_pointed_right = False
        else:
            self.image = pygame.transform.rotate(
                self.animation.current_image(), theta)
            player.gun_is_pointed_right = True

        #set where the player is looking if they aren't dashing
        if not player.is_dashing:
            player.is_looking_right = player.gun_is_pointed_right

        self.rect = self.image.get_rect()
        if player.gun_is_pointed_right:
            self.set_center(
                euclid.Vector2(
                    player.start_position.x + player.get_width() / 2.0 +
                    self.gun_x_position, player.start_position.y +
                    player.get_height() / 2.0 + self.gun_y_position))
        else:
            self.set_center(
                euclid.Vector2(
                    player.start_position.x + player.get_width() / 2.0 +
                    self.gun_x_position + self.look_left_offset,
                    player.start_position.y + player.get_height() / 2.0 +
                    self.gun_y_position))

        #stuff to display charge animation. Must be done at end of update weapon image
        if self.is_charging:
            if not self.charge_animation_object.is_alive:
                self.charge_animation_object.is_alive = True
                player.add_to_world(self.charge_animation_object, "foreground")
            self.calculate_end_of_barrel(player)
            self.charge_animation_object.manual_update()

        self.server_rect.reform_rect(self.image.get_width(),
                                     self.image.get_height(),
                                     self.server_rect.center)
        self.reset_rects()
        self.rect = self.server_rect.get_pygame_rect()
Ejemplo n.º 21
0
    def __init__(self,
                 start_position,
                 width,
                 height,
                 image_list,
                 velocity=euclid.Vector2(0.0, 10.0),
                 max_displacement=euclid.Vector2(0, 5)):
        ServerPickUp.__init__(self, start_position, width, height, velocity,
                              max_displacement)

        self.rect = self.server_rect.get_pygame_rect()
        self.animation = Animation(image_list, self)
        self.image = self.animation.current_image()
Ejemplo n.º 22
0
    def use(self, start_position, bullet_position_vector, time_since_grapple,
            timeSinceReload, player):

        if time_since_grapple > self.delay:
            return [
                Translocator(
                    euclid.Vector2(start_position.x, start_position.y), self,
                    player,
                    euclid.Vector2(
                        bullet_position_vector.x * self.bullet_velocity,
                        bullet_position_vector.y * self.bullet_velocity))
            ]
        return None
Ejemplo n.º 23
0
def init():
    global camera
    global current_screen
    global online_game
    global screen

    #menu images
    global button_img_list
    global join_game_img_list
    global forward_button_img_list
    global back_button_img_list
    global text_field_img_list
    global ready_button_img_list
    global small_forward_button_img_list
    global small_back_button_img_list
    global close_button_img_list

    #cycle button contents
    global map_names

    #sounds
    global button_1_sound

    current_screen = "main menu"
    screen_size = pygame.display.list_modes()[0]
    screen = pygame.display.set_mode(screen_size, DOUBLEBUF)

    #import button images
    button_sheet = SpriteSheet("resources/images/ButtonSpriteSheet.png")
    button_img_list = [button_sheet.imageAt(pygame.Rect(475, 306, 80, 19), None)]
    join_game_img_list = [button_sheet.imageAt(pygame.Rect(497, 281, 33, 10))]
    forward_button_img_list = [button_sheet.imageAt(pygame.Rect(0, 76, 50, 278), None)]
    back_button_img_list = [button_sheet.imageAt(pygame.Rect(54, 76, 50, 278), None)]
    small_forward_button_img_list = [button_sheet.imageAt(pygame.Rect(494, 226, 18, 15)),
                                     button_sheet.imageAt(pygame.Rect(494, 243, 18, 15))]
    small_back_button_img_list = [button_sheet.imageAt(pygame.Rect(516, 242, 18, 15)),
                                  button_sheet.imageAt(pygame.Rect(516, 225, 18, 15))]
    text_field_img_list = [button_sheet.imageAt(pygame.Rect(479, 278, 75, 12), None),
                           button_sheet.imageAt(pygame.Rect(479, 293, 75, 12), None)]
    ready_button_img_list = [button_sheet.imageAt(pygame.Rect(0, 0, 157, 38), None),
                             button_sheet.imageAt(pygame.Rect(0, 38, 157, 38), None)]
    close_button_img_list = [button_sheet.imageAt(pygame.Rect(108, 77, 44, 44), None)]

    #populate cycle_button elements
    map_names = [Label(euclid.Vector2(0, 0), "Matt World"),
                 Label(euclid.Vector2(0, 0), "Fun Zone"),
                 Label(euclid.Vector2(0, 0), "Snake Juice")]

    #sounds
    button_1_sound = pygame.mixer.Sound("resources/sounds/menu_button.wav")
 def collision_above(self, thing_hit):
     if self.is_grappled():
         self.velocity = euclid.Vector2(0.0, 0.0)
     else:
         if not self.can_jump and math.fabs(self.velocity.y) >= math.fabs(self.max_speed.y) - 100.0:
             #dust_cloud = DustCloud(euclid.Vector2(self.start_position.x + self.hitbox.width / 2.0 - 150 / 2.0,
             #                                      self.start_position.y + self.hitbox.height - 41),
             #                       150, 41, self.dust_image_list)
             #self.add_to_world(dust_cloud, "foreground")
             #TODO re implement dust cloud
             pass
         self.velocity = euclid.Vector2(self.velocity.x, 0.0)
         self.can_jump = True
     #calculates offset to y position
     self.start_position.y = thing_hit.start_position.y - self.hitbox.height - self.top_padding()
    def collision_on_left(self, thing_hit):
        """self is to the left of the object"""
        self.has_collided = True
        self.velocity = self.velocity.reflect(euclid.Vector2(1, 0))
        self.start_position.x = thing_hit.start_position.x - self.get_width()

        self.can_bounce()
    def collision_above(self, thing_hit):
        """self is above the object"""
        self.has_collided = True
        self.velocity = self.velocity.reflect(euclid.Vector2(0, 1))
        self.start_position.y = thing_hit.start_position.y - self.get_height()

        self.can_bounce()
    def __init__(self,
                 center,
                 shot_from,
                 player,
                 velocity=euclid.Vector2(0.0, 0.0),
                 gravity=euclid.Vector2(0.0, 0.0)):

        ServerProjectile.__init__(self, center, shot_from, player, velocity,
                                  gravity)

        self.delay_time = 2.0  # time that the seeker will not move before it goes to target
        self.distance = get_displacement(self.shot_from.window_position_center,
                                         player.mouse_position)
        self.starting_location = euclid.Vector2(self.start_position.x,
                                                self.start_position.y)
        self.acceleration = 1.1
    def __init__(self,
                 center,
                 shot_from,
                 player,
                 velocity=euclid.Vector2(0.0, 0.0),
                 gravity=euclid.Vector2(0.0, 0.0)):
        ServerProjectile.__init__(self, center, shot_from, player, velocity,
                                  gravity)

        self.pull_speed = 1000
        self.can_break_rocks = False
        self.go_to_coordinates = euclid.Vector2(0.0, 0.0)
        self.colliding_object = None
        #chain
        self.chain = []
        self.link_size = euclid.Vector2(8.0, 16.0)
    def __init__(self,
                 start_position,
                 frame_parent=None,
                 width=0,
                 height=0,
                 image_list=[]):
        pygame.sprite.Sprite.__init__(self)

        self.start_position = start_position
        self.use_image_at = 0
        self.image_list = image_list
        self.frame_parent = frame_parent
        self.is_pressed = False
        self.is_active = True
        self.sound = None

        if image_list:
            scale_image_list(width, height, self.image_list)
            self.image = self.image_list[self.use_image_at]
        else:
            self.image = pygame.Surface((width, height), pygame.SRCALPHA,
                                        32).convert_alpha()
            self.image_list = [self.image]

        self.rect = self.image.get_rect()
        self.rect.center = euclid.Vector2(start_position.x + width / 2.0,
                                          start_position.y + height / 2.0)
Ejemplo n.º 30
0
 def __init__(self,
              start_position,
              width,
              height,
              launch_velocity=euclid.Vector2(0.0, 1000.0)):
     ServerPlatform.__init__(self, start_position, width, height)
     self.launch_velocity = launch_velocity