Esempio n. 1
0
def statistics_buttons(x, y, w, h, font, font_size, text_input, stat_group, stat_points):
    global color
    text_color = colors['black']

    if stat_group == 'needs':
        if stat_points >= 70:
            color = colors['green']
        elif stat_points < 70 and stat_points >= 30:
            color = colors['yellow']
        elif stat_points < 30:
            color = colors['red']

    elif stat_group == 'fight':
        color = colors['light_cream']

    elif stat_group == 'exp':
        color = colors['black']
        text_color = colors['white']

    elif stat_group == 'attribute':
        color = colors['dark_cream']

    pygame.draw.rect(display, (color), (x, y, w, h))
    my_font = pygame.font.SysFont(font, font_size)
    text = my_font.render(text_input, True, (text_color))
    display.blit(text, (x + 1, y + 2))
Esempio n. 2
0
def button_maker(x, y, w, h, color_on, color_off, font, font_size, text_input, text_color,
                 transparent_on=True, transparent_off=True, text_on=True):
    mouse_position = pygame.mouse.get_pos()

    # Active button
    if x + w > mouse_position[0] > x and y + h > mouse_position[1] > y:
        pygame.draw.rect(display, (colors[color_on]), (x, y, w, h), transparent_on)
        my_font = pygame.font.SysFont(font, font_size)
        text = my_font.render(text_input, True, (colors[text_color]))
        display.blit(text, (x + 1, y + 2))

    # Non active button
    else:
        pygame.draw.rect(display, (colors[color_off]), (x, y, w, h), transparent_off)
        if text_on:
            my_font = pygame.font.SysFont(font, font_size)
            text = my_font.render(text_input, True, (colors[text_color]))
            display.blit(text, (x + 1, y + 2))
Esempio n. 3
0
    def open_victory_window(self):
        pygame.mixer.music.load('audio/victory_music.mp3')
        pygame.mixer.music.play()

        while True:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.quit()
                    sys.exit()

                if event.type == pygame.KEYDOWN and event.key == pygame.MOUSEBUTTONDOWN:
                    pygame.quit()
                    sys.exit()

                if event.type == pygame.MOUSEBUTTONDOWN:
                    button = pygame.Rect(270, 400, 100, 50)
                    if event.button == 1:
                        if button.collidepoint(event.pos):
                            pass


                if event.type == pygame.MOUSEBUTTONDOWN:
                    button = pygame.Rect(430, 400, 100, 50)
                    if event.button == 1:
                        if button.collidepoint(event.pos):
                            pygame.quit()
                            sys.exit()

            # Window settings, graphic and sound
            pygame.display.set_caption('CONGRATULATIONS!')
            victory_image = pygame.image.load('images/victory_window.jpg')
            display.blit(victory_image, (0, 0))

            writing_text('', 70, 'Congratulations!', 'red', 200, 150)
            # writing_text('', 50, 'Your level: ' + str(player1.level), 'white', 300, 300)
            writing_text('', 40, 'Again?', 'white', 350, 300)
            button_maker(270, 400, 100, 50, 'green', 'white', '', 35, 'YES', 'white', transparent_on=False,
                         transparent_off=True)
            button_maker(430, 400, 100, 50, 'red', 'white', '', 35, 'NO', 'white', transparent_on=False,
                         transparent_off=True)

            pygame.display.update()
            clock.tick(FPS)
Esempio n. 4
0
    def open_game_over_window(self):
        pygame.mixer.music.load('audio/the_end.mp3')
        pygame.mixer.music.play()

        while True:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.quit()
                    sys.exit()

                if event.type == pygame.KEYDOWN and event.key == pygame.MOUSEBUTTONDOWN:
                    pygame.quit()
                    sys.exit()

                # if event.type == pygame.MOUSEBUTTONDOWN:
                #     button = pygame.Rect(270, 400, 100, 50)
                #     if event.button == 1:
                #         if button.collidepoint(event.pos):
                #             main_menu_window.open_main_menu_window()

                if event.type == pygame.MOUSEBUTTONDOWN:
                    button = pygame.Rect(430, 400, 100, 50)
                    if event.button == 1:
                        if button.collidepoint(event.pos):
                            pygame.quit()
                            sys.exit()

            # Window settings, graphic and sound
            pygame.display.set_caption('GAME OVER')
            game_over_image = pygame.image.load('images/game_over.jpg')
            display.blit(game_over_image, (0, 0))

            writing_text('', 70, 'GAME OVER', 'red', 250, 150)
            # writing_text('', 50, 'Your level: ' + str(player1.level), 'white', 300, 300)
            writing_text('', 40, 'Again?', 'white', 350, 300)
            button_maker(270, 400, 100, 50, 'green', 'white', '', 35, 'YES', 'white', transparent_on=False, transparent_off=True)
            button_maker(430, 400, 100, 50, 'red', 'white', '', 35, 'NO', 'white', transparent_on=False, transparent_off=True)

            pygame.display.update()
            clock.tick(FPS)
Esempio n. 5
0
    def open_sleep_window(self, image, previous_window):
        h = str(1)

        if player1.stamina < 100:
            stamina = int(player1.stamina) + 10
        else:
            stamina = 100

        hours_to_full_stamina = int((100 - player1.stamina) / 10)

        if player1.health < 100:
            health = int(player1.health) + 10
        else:
            health = 100
        hours_to_full_health = int((80 - player1.health) / 10)

        food = int(player1.food)
        drink = int(player1.drink)

        if player1.food > 0:
            food = int(player1.food) - 5
        if player1.drink > 0:
            drink = int(player1.drink) - 5

        while True:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.quit()
                    sys.exit()

                if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
                    return previous_window

                if event.type == pygame.MOUSEBUTTONDOWN:  # click MORE Button
                    button = pygame.Rect(410, 240, 60, 25)
                    if event.button == 1:
                        if button.collidepoint(event.pos):
                            # Change hour
                            if h == 12:
                                h = 12
                            elif int(h) < 12:
                                if food > 0 and drink > 0:
                                    h = int(h) + 1

                                    if stamina < 100:  # Change stamina value
                                        stamina += 10

                                    if health < 80:  # Change health value
                                        health += 10

                                    food -= 5
                                    drink -= 5

                                elif food == 0:
                                    writing_text(
                                        '', 45, "You are too hungry to sleep",
                                        'red', 235, 100)
                                    pygame.display.update()
                                    clock.tick(FPS)
                                    time.sleep(1.5)
                                elif drink == 0:
                                    writing_text(
                                        '', 45, "You are too thirsty to sleep",
                                        'red', 235, 100)
                                    pygame.display.update()
                                    clock.tick(FPS)
                                    time.sleep(1.5)

                if event.type == pygame.MOUSEBUTTONDOWN:  # click LESS Button
                    button = pygame.Rect(410, 265, 60, 25)
                    if event.button == 1:
                        if button.collidepoint(event.pos):
                            # Change hour
                            if int(h) < 2:
                                h = 1
                            elif int(h) >= 2:
                                h = int(h) - 1

                                if stamina == 100:  # Change stamina value
                                    if h >= hours_to_full_stamina:
                                        stamina = 100
                                    elif h < hours_to_full_stamina:
                                        stamina -= 10
                                elif stamina < 100:
                                    stamina -= 10

                                if health >= 80:  # Change stamina value
                                    if h >= hours_to_full_health:
                                        health = health
                                    elif h < hours_to_full_health:
                                        health -= 10
                                elif health < 80:
                                    health -= 10

                                food += 5
                                drink += 5

                if event.type == pygame.MOUSEBUTTONDOWN:  # click SLEEP Button
                    button = pygame.Rect(350, 500, 100, 35)
                    if event.button == 1:
                        if button.collidepoint(event.pos):
                            player1.stamina = stamina
                            player1.health = health
                            player1.food = food
                            player1.drink = drink

                            # Sleep "animation"
                            sleep_image = pygame.image.load(
                                'images/sleep1.jpg')
                            display.blit(sleep_image, (0, 0))
                            pygame.display.update()
                            time.sleep(0.8)

                            sleep_image = pygame.image.load(
                                'images/sleep2.jpg')
                            display.blit(sleep_image, (0, 0))
                            pygame.display.update()
                            time.sleep(0.8)

                            sleep_image = pygame.image.load(
                                'images/sleep3.jpg')
                            display.blit(sleep_image, (0, 0))
                            pygame.display.update()
                            time.sleep(0.8)

                            return previous_window

                if event.type == pygame.MOUSEBUTTONDOWN:  # click EXIT button
                    button = pygame.Rect(650, 550, 150, 40)
                    if event.button == 1:
                        if button.collidepoint(event.pos):
                            return previous_window

            # Window settings and graphic
            pygame.display.set_caption("Sleep")
            location_image = pygame.image.load(image)
            display.blit(location_image, (0, 0))

            button_maker(200,
                         200,
                         380,
                         35,
                         'grey',
                         'grey',
                         '',
                         35,
                         "How long do you want to sleep?",
                         'white',
                         transparent_on=False,
                         transparent_off=False)
            button_maker(
                330,
                240,
                80,
                50,
                'grey',
                'grey',
                '',
                60,
                str(h) + 'h',
                'white',  # How many hours
                transparent_on=False,
                transparent_off=False)
            button_maker(
                410,
                240,
                60,
                25,
                'green',
                'green',
                '',
                40,
                '   +',
                'white',  # More
                transparent_on=False,
                transparent_off=False)
            button_maker(
                410,
                265,
                60,
                25,
                'red',
                'red',
                '',
                40,
                '   -',
                'white',  # Less
                transparent_on=False,
                transparent_off=False)

            statistics_buttons(310, 300, 180, 35, '', 35,
                               f'STAMINA = {stamina}', 'needs', stamina)
            statistics_buttons(310, 340, 180, 35, '', 35, f'HEALTH = {health}',
                               'needs', health)
            statistics_buttons(310, 380, 180, 35, '', 35, f'FOOD = {food}',
                               'needs', food)
            statistics_buttons(310, 420, 180, 35, '', 35, f'DRINK = {drink}',
                               'needs', drink)

            button_maker(
                350,
                500,
                100,
                35,
                'green',
                'blue',
                '',
                45,
                'SLEEP',
                'white',  # SLEEP
                transparent_on=False,
                transparent_off=False)

            button_maker(650,
                         550,
                         150,
                         40,
                         'grey',
                         'pure_red',
                         'Comic Sans MS',
                         23,
                         '  ESC = Exit',
                         'white',
                         transparent_on=False)  # Exit

            pygame.display.update()
            clock.tick(FPS)
Esempio n. 6
0
def writing_text(font, font_size, text_input, color, x, y):
    my_font = pygame.font.SysFont(font, font_size)
    text = my_font.render(text_input, True, (colors[color]))
    display.blit(text, (x, y))