Пример #1
0
def special_page():

    # - - - - - screen/loop properties - - - - - -
    seeing_size = (SCREEN_WIDTH, SCREEN_HEIGHT)
    screen = pygame.display.set_mode(seeing_size)
    pygame.display.set_caption("Template : Special")
    clock = pygame.time.Clock()
    running = True  # game loop

    # - - - - - background properties - - - - - -
    bg_imgs = []
    bg = Animation()
    bg.image = pygame.image.load("Characters\\Blank.png").convert()
    bg.rect = bg.image.get_rect()

    bg.img_load(bg_imgs, 'Backgrounds//broken temple ', 8, CENTER)
    bg.resize_sprite_list(bg_imgs, SCREEN_WIDTH, SCREEN_HEIGHT)

    # - - - - - variables/constants - - - - - -
    clicked = False
    font = pygame.font.SysFont(None, 20)

    button_highlighted = None
    select = False
    selected_button = None

    #stores executables
    links = pld()

    # button creation
    training_button = pygame.Rect(
        percentage(25, SCREEN_WIDTH) - 100,
        percentage(20, SCREEN_HEIGHT) - 50, 200, 50)
    challenge_button = pygame.Rect(
        percentage(75, SCREEN_WIDTH) - 100,
        percentage(40, SCREEN_HEIGHT) - 50, 200, 50)
    back_button = pygame.Rect(percentage(1, SCREEN_WIDTH),
                              percentage(99, SCREEN_HEIGHT) - 50, 200, 50)
    scenes_button = pygame.Rect(
        percentage(25, SCREEN_WIDTH) - 100,
        percentage(60, SCREEN_HEIGHT) - 50, 200, 50)
    special_button = pygame.Rect(
        percentage(75, SCREEN_WIDTH) - 100,
        percentage(80, SCREEN_HEIGHT) - 50, 200, 50)

    # before game loop
    links.add_link(training_button, sm.start_menu)
    links.add_link(challenge_button, sm.start_menu)
    links.add_link(back_button, mm.main_menu)
    links.add_link(scenes_button, sm.start_menu)
    links.add_link(special_button, sm.start_menu)
    # - - - - - game loop - - - - - -
    while running:
        clock.tick(60)
        screen.fill(BLACK)

        # background
        screen.blit(bg.image, (0, 0))
        bg.animating(bg_imgs, [.06], True)

        # mouse
        mx, my = pygame.mouse.get_pos()

        buttons = [
            training_button, challenge_button, scenes_button, special_button,
            back_button
        ]

        text = []

        if select:
            selected_button = button_highlighted
            running = False

        for i in buttons:
            #button_colour = WHITE

            if button_highlighted == None:  # default Button (group play)
                button_highlighted = buttons[0]

            if i.collidepoint((mx, my)):  # highlighted with mouse
                button_highlighted = i

            if i == button_highlighted and not clicked:  #remain higlighted after moving mouse off of button
                colour = YELLOW
            else:
                colour = button_colour_on_click((WHITE, YELLOW, BLACK), i,
                                                (mx, my), clicked)

            pygame.draw.rect(screen, colour, i)
            # end / switch program when button clicked

            if clicked:
                if i.collidepoint((mx, my)):
                    #print("button clicked")
                    select = True
                    selected_button = i
                    running = False

            # if this one is selected go into it

        #print(button_highlighted)

        # text
        draw_text("[  Training  ]", font, (GREY), screen,
                  training_button.center)
        draw_text("[  Challenge  ]", font, (GREY), screen,
                  challenge_button.center)
        draw_text("[  Back  ]", font, (GREY), screen, back_button.center)
        draw_text("[  Scenes  ]", font, (GREY), screen, scenes_button.center)
        draw_text("[  *Special*  ]", font, (GREY), screen,
                  special_button.center)

        clicked = False

        for ev in pygame.event.get():
            if ev.type == QUIT:
                running = False
            if ev.type == MOUSEBUTTONDOWN:
                if ev.button == 1:
                    clicked = True
            if ev.type == pygame.KEYDOWN:
                if ev.key == K_UP:
                    button_highlighted = buttons[
                        buttons.index(button_highlighted) - 1]

                if ev.key == K_DOWN:
                    button_highlighted = buttons[
                        (buttons.index(button_highlighted) + 1) % len(buttons)]

                if ev.key == K_RETURN:
                    select = True
        bg.update()
        pygame.display.flip()

    if selected_button != None:
        out = links.get_link(selected_button)
        selected_button = None
        return out()
Пример #2
0
def player_controls():

    # - - - - - screen/loop properties - - - - - -
    seeing_size = (SCREEN_WIDTH, SCREEN_HEIGHT)
    screen = pygame.display.set_mode(seeing_size)
    pygame.display.set_caption("Template: player controls")
    clock = pygame.time.Clock()
    running = True  # loop

    # - - - - - background properties - - - - - -
    bg_imgs = []
    bg = Animation()
    bg.image = pygame.image.load("Characters\\Blank.png").convert()
    bg.rect = bg.image.get_rect()

    bg.img_load(bg_imgs, 'Backgrounds//broken temple ', 8, CENTER)
    bg.resize_sprite_list(bg_imgs, SCREEN_WIDTH, SCREEN_HEIGHT)

    # - - - - - variables/constants - - - - - -
    clicked = False
    font = pygame.font.SysFont(None, 20)

    button_highlighted = None
    select = False
    selected_button = None
    selected_player = None

    tab_size_x = percentage(40, SCREEN_WIDTH)
    tab_size_y = percentage(60, SCREEN_HEIGHT) / 9
    tab_pos_x = percentage(10, SCREEN_WIDTH)

    player_tab_x = percentage(10, SCREEN_WIDTH)
    player_tab_y = percentage(5, SCREEN_HEIGHT)

    #stores executables
    links = pld()

    # button creation

    # place at 10% from top
    player_1 = pygame.Rect(
        percentage(20, SCREEN_WIDTH) - (player_tab_x / 2),
        percentage(10, SCREEN_HEIGHT), player_tab_x, player_tab_y)
    player_2 = pygame.Rect(
        percentage(40, SCREEN_WIDTH) - (player_tab_x / 2),
        percentage(10, SCREEN_HEIGHT), player_tab_x, player_tab_y)
    player_3 = pygame.Rect(
        percentage(60, SCREEN_WIDTH) - (player_tab_x / 2),
        percentage(10, SCREEN_HEIGHT), player_tab_x, player_tab_y)
    player_4 = pygame.Rect(
        percentage(80, SCREEN_WIDTH) - (player_tab_x / 2),
        percentage(10, SCREEN_HEIGHT), player_tab_x, player_tab_y)

    back_button = pygame.Rect(percentage(1, SCREEN_WIDTH),
                              percentage(99, SCREEN_HEIGHT) - 50, 2, 50)

    up_tab = pygame.Rect(tab_pos_x, percentage(20, SCREEN_HEIGHT), tab_size_x,
                         tab_size_y)
    down_tab = pygame.Rect(tab_pos_x, up_tab.bottom + 1, tab_size_x,
                           tab_size_y)
    left_tab = pygame.Rect(tab_pos_x, down_tab.bottom + 1, tab_size_x,
                           tab_size_y)
    right_tab = pygame.Rect(tab_pos_x, left_tab.bottom + 1, tab_size_x,
                            tab_size_y)
    jump_tab = pygame.Rect(tab_pos_x, right_tab.bottom + 1, tab_size_x,
                           tab_size_y)
    atk1_tab = pygame.Rect(tab_pos_x, jump_tab.bottom + 1, tab_size_x,
                           tab_size_y)
    atk2_tab = pygame.Rect(tab_pos_x, atk1_tab.bottom + 1, tab_size_x,
                           tab_size_y)
    guard_tab = pygame.Rect(tab_pos_x, atk2_tab.bottom + 1, tab_size_x,
                            tab_size_y)
    charge_tab = pygame.Rect(tab_pos_x, guard_tab.bottom + 1, tab_size_x,
                             tab_size_y)

    up_change_button = pygame.Rect(up_tab.right + 1, up_tab.top, tab_size_x,
                                   tab_size_y)
    down_change_button = pygame.Rect(down_tab.right + 1, down_tab.top,
                                     tab_size_x, tab_size_y)
    left_change_button = pygame.Rect(left_tab.right + 1, left_tab.top,
                                     tab_size_x, tab_size_y)
    right_change_button = pygame.Rect(right_tab.right + 1, right_tab.top,
                                      tab_size_x, tab_size_y)
    jump_change_button = pygame.Rect(jump_tab.right + 1, jump_tab.top,
                                     tab_size_x, tab_size_y)
    atk1_change_button = pygame.Rect(atk1_tab.right + 1, atk1_tab.top,
                                     tab_size_x, tab_size_y)
    atk2_change_button = pygame.Rect(atk2_tab.right + 1, atk2_tab.top,
                                     tab_size_x, tab_size_y)
    guard_change_button = pygame.Rect(guard_tab.right + 1, guard_tab.top,
                                      tab_size_x, tab_size_y)
    charge_change_button = pygame.Rect(charge_tab.right + 1, charge_tab.top,
                                       tab_size_x, tab_size_y)

    # before game loop
    links.add_link(back_button, op.options)

    # - - - - - game loop - - - - - -
    while running:
        clock.tick(60)
        screen.fill(BLACK)

        # background
        screen.blit(bg.image, (0, 0))
        bg.animating(bg_imgs, [.06], True)

        # mouse
        mx, my = pygame.mouse.get_pos()

        player_selection = [player_1, player_2, player_3, player_4]

        player_buttons = [player_1, player_2, player_3, player_4]

        tabs = [
            up_tab, down_tab, left_tab, right_tab, jump_tab, atk1_tab,
            atk2_tab, guard_tab, charge_tab
        ]

        buttons = [
            up_change_button, down_change_button, left_change_button,
            right_change_button, jump_change_button, atk1_change_button,
            atk2_change_button, guard_change_button, charge_change_button,
            back_button
        ]

        for i in buttons:
            pygame.draw.rect(screen, WHITE, i)

            if clicked:
                if i.collidepoint((mx, my)):
                    #print("button clicked")
                    select = True
                    selected_button = i
                    if i == back_button:
                        running = False
        for i in tabs:
            pygame.draw.rect(screen, TRANSPARENT, i)

        for i in player_buttons:
            # one selected at a time

            if button_highlighted == None:  # default Button (Player 1)
                button_highlighted = player_buttons[0]

            if i.collidepoint((mx, my)):  # highlighted with mouse
                button_highlighted = i

            if i == button_highlighted and not clicked:  #remain higlighted after moving mouse off of button
                colour = LIGHTGREY
            else:
                colour = button_colour_on_click((WHITE, YELLOW, BLACK), i,
                                                (mx, my), clicked)

            if selected_player == i:
                colour = YELLOW
            pygame.draw.rect(screen, colour, i)

            if selected_player == None:
                selected_player = i

            if clicked and i.collidepoint((mx, my)):
                selected_player = i
        # - - - - - text - - - - - -

        # players
        draw_text("[  Player 1  ]", font, (GREY), screen, player_1.center)
        draw_text("[  Player 2  ]", font, (GREY), screen, player_2.center)
        draw_text("[  Player 3  ]", font, (GREY), screen, player_3.center)
        draw_text("[  Player 4  ]", font, (GREY), screen, player_4.center)
        # label
        draw_text("Up", font, (GREY), screen, up_tab.center)
        draw_text("Down", font, (GREY), screen, down_tab.center)
        draw_text("Left", font, (GREY), screen, left_tab.center)
        draw_text("Right", font, (GREY), screen, right_tab.center)
        draw_text("Jump", font, (GREY), screen, jump_tab.center)
        draw_text("Attack 1", font, (GREY), screen, atk1_tab.center)
        draw_text("Attack 2", font, (GREY), screen, atk2_tab.center)
        draw_text("Guard", font, (GREY), screen, guard_tab.center)
        draw_text("Charge", font, (GREY), screen, charge_tab.center)
        # player control output
        draw_text("", font, (GREY), screen, up_change_button.center)
        draw_text("", font, (GREY), screen, down_change_button.center)
        draw_text("", font, (GREY), screen, left_change_button.center)
        draw_text("", font, (GREY), screen, right_change_button.center)
        draw_text("", font, (GREY), screen, jump_change_button.center)
        draw_text("", font, (GREY), screen, atk1_change_button.center)
        draw_text("", font, (GREY), screen, atk2_change_button.center)
        draw_text("", font, (GREY), screen, guard_change_button.center)
        draw_text("", font, (GREY), screen, charge_change_button.center)
        # back
        draw_text("[  Back  ]", font, (GREY), screen, back_button.center)

        # end / switch program when button clicked

        clicked = False

        for ev in pygame.event.get():
            if ev.type == QUIT:
                running = False
            if ev.type == MOUSEBUTTONDOWN:
                if ev.button == 1:
                    clicked = True
            if ev.type == pygame.KEYDOWN:
                if ev.key == K_LEFT:
                    button_highlighted = player_buttons[
                        player_buttons.index(button_highlighted) - 1]

                if ev.key == K_RIGHT:
                    button_highlighted = player_buttons[
                        (player_buttons.index(button_highlighted) + 1) %
                        len(player_buttons)]

                if ev.key == K_RETURN:
                    select = True
        bg.update()
        pygame.display.flip()

    if selected_button != None:
        out = links.get_link(selected_button)
        selected_button = None
        return out()