Example #1
0
def run():
    play_time = 0
    clock = pygame.time.Clock()

    while state == RUNNING:
        ms = clock.tick(60)
        play_time += ms / 1000.0

        # handle player inputs
        action = controls.process_events()
        controls.update_keys()

        # debug actions
        if action == "shoot":
            player1.shoot()
        elif action == "spawn_item":
            DroppedPerk(ab, player1.rect.move(30, 0).center)
        elif action == "spawn_gun":
            player1.add_weapon(Gun((0, 0)))
        elif action == "swap_gun":
            player1.swap_weapons()
        elif action == "host":
            if not is_host:
                init_host()
        elif action == "connect":
            if not is_host:
                init_net()
        elif action == "test_sock":
            client.send("hello")

        # update cursor
        cursor_pos_x, cursor_pos_y = pygame.mouse.get_pos()
        cursor.move((cursor_pos_x / options.scale(), cursor_pos_y / options.scale()),
                    controls.click)

        # update cursor text
        cursor.set_hover_text(examine.find_examine_text(cursor.point()))

        # update window title to show frame rate
        pygame.display.set_caption("FPS: {0:.2f}".format(clock.get_fps()))

        # update player with cursor information
        player1.update_cursor(cursor, camera)

        # flip player to face cursor
        # player1.flip(cursor.point()[0] < camera.apply(player1.rect).centerx)

        perk_collide(player1)

        # render screen
        render.draw()

        # update the camera to the player's position
        camera.follow(player1.rect)
Example #2
0
def run():
    play_time = 0
    clock = pygame.time.Clock()

    while state == RUNNING:
        ms = clock.tick(60)
        play_time += ms / 1000.0

        # handle player inputs
        action = controls.process_events()
        controls.update_keys()

        # debug actions
        if action == "shoot":
            player1.shoot()
        elif action == "spawn_item":
            DroppedPerk(ab, player1.rect.move(30, 0).center)
        elif action == "spawn_gun":
            player1.add_weapon(Gun((0, 0)))
        elif action == "swap_gun":
            player1.swap_weapons()
        elif action == "host":
            if not is_host:
                init_host()
        elif action == "connect":
            if not is_host:
                init_net()
        elif action == "test_sock":
            client.send("hello")

        # update cursor
        cursor_pos_x, cursor_pos_y = pygame.mouse.get_pos()
        cursor.move((cursor_pos_x / options.scale(), cursor_pos_y / options.scale()), controls.click)

        # update cursor text
        cursor.set_hover_text(examine.find_examine_text(cursor.point()))

        # update window title to show frame rate
        pygame.display.set_caption("FPS: {0:.2f}".format(clock.get_fps()))

        # update player with cursor information
        player1.update_cursor(cursor, camera)

        # flip player to face cursor
        # player1.flip(cursor.point()[0] < camera.apply(player1.rect).centerx)

        perk_collide(player1)

        # render screen
        render.draw()

        # update the camera to the player's position
        camera.follow(player1.rect)
Example #3
0
def follow(target):
    """Follow and centre on the target rect

    :param target: rect to follow
    """
    width = options.view_width() // options.scale()
    height = options.view_height() // options.scale()

    l, t, _, _ = target
    _, _, w, h = camera
    l, t = width // 2 - l, height // 2 - t

    l = min(0, l)
    l = max(width - camera.width, l)
    t = max(height - camera.height, t)
    t = min(0, t)

    global camera
    camera = Rect(l, t, w, h)