示例#1
0
def ask_clear_state(window, control) -> int:
    flag = True
    flag2 = False
    joy_ctrl = read_all_controls()
    dark = pygame.Surface((WIDTH, HEIGHT), pygame.SRCALPHA)
    dark.fill((0, 0, 0, 96))
    window.blit(dark, (0, 0))
    background = pygame.Surface((WIDTH // 2 - 150, HEIGHT // 2 - 150))
    button_font = pygame.font.SysFont("calibri", 41, True)
    colors = ((0, 0, 0), (255, 255, 255))
    button1 = Button(WIDTH // 2, HEIGHT // 2 - 40, (16, 16, 255), button_font, "COMMIT", colors, True).set_offset_pos().set_selected()
    button2 = Button(WIDTH // 2, HEIGHT // 2 + 10, (16, 16, 255), button_font, "CANCEL", colors, True).set_offset_pos()
    buttons = (button1, button2)
    ask_clear = Room(buttons, button_sound)
    q = 0

    while ask_clear.run:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                control["state"] = switch_state(ask_clear, states.QUIT)
                q = 1
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_UP:
                    ask_clear.update_button("up")
                elif event.key == pygame.K_DOWN:
                    ask_clear.update_button("down")
                if ask_clear.button_pressed() == 0:
                    clear_data()
                    ask_clear.exit()
                elif ask_clear.button_pressed() == 1:
                    ask_clear.exit()

        if not no_joystick:
            if str(joy.get_hat(0)) == joy_ctrl["up"] and flag:
                ask_clear.update_button("up")
                flag = False
            elif str(joy.get_hat(0)) == joy_ctrl["down"] and flag:
                ask_clear.update_button("down")
                flag = False
            if joy.get_hat(0) == (0, 0):
                flag = True
            if joy.get_button(joy_ctrl["accept"]) and flag2:
                flag2 = False
                if ask_clear.button_pressed(True) == 0:
                    clear_data()
                    ask_clear.exit()
                elif ask_clear.button_pressed(True) == 1:
                    ask_clear.exit()
            elif not joy.get_button(joy_ctrl["accept"]):
                flag2 = True

        window.blit(background, (WIDTH // 4 + 75, HEIGHT // 4 + 75))
        background.fill((16, 16, 216))
        ask_clear.show(window, 0, 0)
        pygame.display.flip()
        clock.tick(48)

    return q
示例#2
0
def game_over_state(window, control):
    flag = True
    joy_ctrl = read_all_controls()
    background = pygame.Surface((WIDTH // 2, HEIGHT // 2))
    button_font = pygame.font.SysFont("calibri", 45, True)
    title_text = pygame.font.SysFont("calibri", 60,
                                     True).render("Game Over", True,
                                                  (240, 240, 240))
    colors = ((0, 0, 0), (255, 255, 255))
    button1 = Button(WIDTH // 2, HEIGHT // 2 - 20, (16, 16, 255), button_font,
                     "RESTART", colors, True).set_offset_pos().set_selected()
    button2 = Button(WIDTH // 2, HEIGHT // 2 + 35, (16, 16, 255), button_font,
                     "EXIT", colors, True).set_offset_pos()
    button3 = Button(WIDTH // 2, HEIGHT // 2 + 90, (16, 16, 255), button_font,
                     "QUIT", colors, True).set_offset_pos()
    buttons = (button1, button2, button3)
    game_over = Room(buttons, button_sound)
    if control["game_mode"] == "easy":
        game_mode = states.GAME_2
    elif control["game_mode"] == "hard":
        game_mode = states.GAME_3
    else:
        game_mode = states.GAME_1

    while game_over.run:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                control["state"] = switch_state(game_over, states.QUIT)
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_UP:
                    game_over.update_button("up")
                elif event.key == pygame.K_DOWN:
                    game_over.update_button("down")
                if game_over.button_pressed() == 0:
                    control["state"] = switch_state(game_over, game_mode)
                elif game_over.button_pressed() == 1:
                    control["state"] = switch_state(game_over, states.MENU)
                elif game_over.button_pressed() == 2:
                    control["state"] = switch_state(game_over, states.QUIT)

        if not no_joystick:
            if str(joy.get_hat(0)) == joy_ctrl["up"] and flag:
                game_over.update_button("up")
                flag = False
            elif str(joy.get_hat(0)) == joy_ctrl["down"] and flag:
                game_over.update_button("down")
                flag = False
            elif joy.get_hat(0) == (0, 0):
                flag = True
            if joy.get_button(joy_ctrl["accept"]):
                if game_over.button_pressed(True) == 0:
                    control["state"] = switch_state(game_over, game_mode)
                elif game_over.button_pressed(True) == 1:
                    control["state"] = switch_state(game_over, states.MENU)
                elif game_over.button_pressed(True) == 2:
                    control["state"] = switch_state(game_over, states.QUIT)

        window.blit(background, (WIDTH // 4, HEIGHT // 4))
        background.fill((16, 16, 216))
        window.blit(title_text, (WIDTH // 2 - 140, HEIGHT // 2 - 110))
        game_over.show(window, 0, 0)
        pygame.display.flip()
        clock.tick(48)
示例#3
0
def pause_state(window, control) -> int:
    flag = True
    joy_ctrl = read_all_controls()
    background = pygame.Surface((WIDTH // 2, HEIGHT // 2))
    button_font = pygame.font.SysFont("calibri", 50, True)
    colors = ((0, 0, 0), (255, 255, 255))
    button1 = Button(WIDTH // 2, HEIGHT // 2 - 110, (16, 16, 255), button_font,
                     "RESUME", colors, True).set_offset_pos().set_selected()
    button2 = Button(WIDTH // 2, HEIGHT // 2 - 50, (16, 16, 255), button_font,
                     "RESTART", colors, True).set_offset_pos()
    button3 = Button(WIDTH // 2, HEIGHT // 2 + 10, (16, 16, 255), button_font,
                     "EXIT", colors, True).set_offset_pos()
    button4 = Button(WIDTH // 2, HEIGHT // 2 + 70, (16, 16, 255), button_font,
                     "QUIT", colors, True).set_offset_pos()
    buttons = (button1, button2, button3, button4)
    pause = Room(buttons, button_sound)
    q = 0
    if control["game_mode"] == "easy":
        game_mode = states.GAME_2
    elif control["game_mode"] == "hard":
        game_mode = states.GAME_3
    else:
        game_mode = states.GAME_1

    while pause.run:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                control["state"] = switch_state(pause, states.QUIT)
                q = 1
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_UP:
                    pause.update_button("up")
                elif event.key == pygame.K_DOWN:
                    pause.update_button("down")
                if pause.button_pressed() == 0:
                    pause.exit()
                elif pause.button_pressed() == 1:
                    control["state"] = switch_state(pause, game_mode)
                    q = 1
                elif pause.button_pressed() == 2:
                    control["state"] = switch_state(pause, states.MENU)
                    q = 1
                elif pause.button_pressed() == 3:
                    control["state"] = switch_state(pause, states.QUIT)
                    q = 1

        if not no_joystick:
            if str(joy.get_hat(0)) == joy_ctrl["up"] and flag:
                pause.update_button("up")
                flag = False
            elif str(joy.get_hat(0)) == joy_ctrl["down"] and flag:
                pause.update_button("down")
                flag = False
            if joy.get_hat(0) == (0, 0):
                flag = True
            if joy.get_button(joy_ctrl["accept"]):
                if pause.button_pressed(True) == 0:
                    pause.exit()
                elif pause.button_pressed(True) == 1:
                    control["state"] = switch_state(pause, game_mode)
                    q = 1
                elif pause.button_pressed(True) == 2:
                    control["state"] = switch_state(pause, states.MENU)
                    q = 1
                elif pause.button_pressed(True) == 3:
                    control["state"] = switch_state(pause, states.QUIT)
                    q = 1

        window.blit(background, (WIDTH // 4, HEIGHT // 4))
        background.fill((16, 16, 216))
        pause.show(window, 0, 0)
        pygame.display.flip()
        clock.tick(48)

    return q