コード例 #1
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)
コード例 #2
0
ファイル: search_item.py プロジェクト: darek-k/pygame-project
 def add_to_inventory_while_search(self, index, found_item_location):
     if len(inventory.inventory) >= 12:
         button_maker(290,
                      275,
                      220,
                      40,
                      'blue',
                      'blue',
                      '',
                      36,
                      "    Full Inventory",
                      'white',
                      transparent_on=False,
                      transparent_off=False)
         pygame.display.update()
         time.sleep(0.5)
     else:
         item = found_item_location[index]
         inventory.inventory.append(item)
         item_index = list(found_item_location)[index]
         found_item_location.remove(item_index)
コード例 #3
0
ファイル: inventory.py プロジェクト: darek-k/pygame-project
    def show_items_to_equip(self, type, attribute_text):
        x = 0
        y = 0

        for item in self.inventory:
            index = self.inventory.index(item)

            if item.type == type:

                if index <= 3:
                    y = 0
                elif index <= 7:
                    y = 150
                elif index <= 11:
                    y = 300

                if index == 0 or index == 4 or index == 8:
                    x = 0
                elif index == 1 or index == 5 or index == 9:
                    x = 200
                elif index == 2 or index == 6 or index == 10:
                    x = 400
                elif index == 3 or index == 7 or index == 11:
                    x = 600

                button_maker(x, y, item.size_x, item.size_y, 'red', 'blue', '',
                             40, item.name, 'red')
                writing_text('', 35, attribute_text + str(item.attribute),
                             'white', x, y + 50)
                button_maker(650,
                             550,
                             150,
                             40,
                             'grey',
                             'pure_red',
                             'Comic Sans MS',
                             23,
                             '  ESC = Exit',
                             'white',
                             transparent_on=False)  # Exit
コード例 #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)
コード例 #5
0
ファイル: search_item.py プロジェクト: darek-k/pygame-project
    def search(self, random_items, found_item_location):
        try:
            random_index = random.randint(0,
                                          len(random_items) -
                                          1)  # Searching for random items
            found_item = random_items[random_index]

            # Add items to Found Items and remove from the chest
            found_item_location.append(found_item)
            random_items.remove(found_item)

            player1.food -= 10
            player1.drink -= 10
            if player1.stamina > 0:
                player1.stamina -= 10
            elif player1.stamina <= 0:
                player1.stamina = 0
            player1.exp += 20
            if player1.exp >= player1.exp_to_next_level:
                player1.level_up()

            player1.food_and_drink()

        except ValueError:
            self.show_found_items(found_item_location)
            button_maker(300,
                         275,
                         200,
                         40,
                         'blue',
                         'blue',
                         '',
                         36,
                         "    Nothing left",
                         'white',
                         transparent_on=False,
                         transparent_off=False)
            pygame.display.update()
            time.sleep(0.5)
コード例 #6
0
ファイル: inventory.py プロジェクト: darek-k/pygame-project
    def show_inventory(self, count_weapon, count_torso, count_legs):
        x = 0
        y = 0
        font_size = 40
        font_size_text = 35

        self.sorted_inventory = sorted(self.inventory,
                                       key=operator.attrgetter('type', 'name'))

        for item in self.sorted_inventory:

            # icon = pygame.image.load(items.icon)     ###### Wyświetlanie grafiki #######
            # display.blit(icon, (300,120))

            if item.type == 'weapon':
                text = 'Damage: '
                button_maker(x, y, item.size_x, item.size_y, 'red', 'blue', '',
                             font_size, item.name, 'white')
                writing_text('', font_size_text, text + str(item.attribute),
                             'orange', x, y + 50)

            if item.type == 'torso' or item.type == 'legs':
                text = 'Defence: '
                button_maker(x, y, item.size_x, item.size_y, 'red', 'blue', '',
                             font_size, item.name, 'white')
                writing_text('', font_size_text, text + str(item.attribute),
                             'violet', x, y + 50)

            if item.type == 'food':
                text = 'Food: '
                button_maker(x, y, item.size_x, item.size_y, 'red', 'blue', '',
                             font_size, item.name, 'white')
                writing_text('', font_size_text, text + str(item.attribute),
                             'brown', x, y + 50)

            if item.type == 'drink':
                text = 'Drink: '
                button_maker(x, y, item.size_x, item.size_y, 'red', 'blue', '',
                             font_size, item.name, 'white')
                writing_text('', font_size_text, text + str(item.attribute),
                             'blue', x, y + 50)

            if item.type == 'health':
                text = 'Health: '
                button_maker(x, y, item.size_x, item.size_y, 'red', 'blue', '',
                             font_size, item.name, 'white')
                writing_text('', font_size_text, text + str(item.attribute),
                             'green', x, y + 50)

            if item.type == 'stamina':
                text = 'Stamina: '
                button_maker(x, y, item.size_x, item.size_y, 'red', 'blue', '',
                             font_size, item.name, 'white')
                writing_text('', font_size_text, text + str(item.attribute),
                             'yellow', x, y + 50)

            if item.type == 'other':
                text = ''
                button_maker(x, y, item.size_x, item.size_y, 'gold', 'blue',
                             '', font_size, item.name, 'gold')
                writing_text('', font_size_text, text + str(item.attribute),
                             'gold', x, y + 50)

            # Make equipped items GREEN
            if count_weapon == 0:
                if item.name == player1_equipment.equipped_weapon_name:
                    button_maker(x, y, item.size_x, item.size_y, 'red', 'blue',
                                 '', font_size, item.name, 'ultra_green')
                    writing_text('', font_size_text,
                                 text + str(item.attribute), 'orange', x,
                                 y + 50)
                    count_weapon += 1

            if count_torso == 0:
                if item.name == player1_equipment.equipped_torso_name:
                    button_maker(x, y, item.size_x, item.size_y, 'red', 'blue',
                                 '', font_size, item.name, 'ultra_green')
                    writing_text('', font_size_text,
                                 text + str(item.attribute), 'violet', x,
                                 y + 50)
                    count_torso += 1

            if count_legs == 0:
                if item.name == player1_equipment.equipped_legs_name:
                    button_maker(x, y, item.size_x, item.size_y, 'red', 'blue',
                                 '', font_size, item.name, 'ultra_green')
                    writing_text('', font_size_text,
                                 text + str(item.attribute), 'violet', x,
                                 y + 50)
                    count_legs += 1

            x += 200
            if x > 600:
                x = 0
                y += 150

        if len(self.inventory) < 12:
            length = 12 - len(self.inventory)
            for i in range(length):
                button_maker(x, y, 200, 150, 'red', 'blue', '', 40, '',
                             'ultra_green')

                x += 200
                if x > 600:
                    x = 0
                    y += 150
コード例 #7
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)
コード例 #8
0
ファイル: search_item.py プロジェクト: darek-k/pygame-project
    def show_found_items(self, found_item_location):
        x = 0
        y = 0
        for item in found_item_location:

            if item.type == 'weapon':
                text = 'Damage: '
                button_maker(x,
                             y,
                             item.size_x,
                             item.size_y,
                             'green',
                             'grey',
                             '',
                             40,
                             item.name,
                             'ultra_blue',
                             transparent_off=False,
                             transparent_on=True)
                writing_text('', 35, text + str(item.attribute), 'orange', x,
                             y + 50)

            if item.type == 'torso' or item.type == 'legs':
                text = 'Defence: '
                button_maker(x,
                             y,
                             item.size_x,
                             item.size_y,
                             'green',
                             'grey',
                             '',
                             40,
                             item.name,
                             'ultra_blue',
                             transparent_off=False,
                             transparent_on=True)
                writing_text('', 35, text + str(item.attribute), 'violet', x,
                             y + 50)

            if item.type == 'food':
                text = 'Food: '
                button_maker(x,
                             y,
                             item.size_x,
                             item.size_y,
                             'green',
                             'grey',
                             '',
                             40,
                             item.name,
                             'ultra_blue',
                             transparent_off=False,
                             transparent_on=True)
                writing_text('', 35, text + str(item.attribute), 'brown', x,
                             y + 50)

            if item.type == 'drink':
                text = 'Drink: '
                button_maker(x,
                             y,
                             item.size_x,
                             item.size_y,
                             'green',
                             'grey',
                             '',
                             40,
                             item.name,
                             'ultra_blue',
                             transparent_off=False,
                             transparent_on=True)
                writing_text('', 35, text + str(item.attribute), 'blue', x,
                             y + 50)

            if item.type == 'health':
                text = 'Health: '
                button_maker(x,
                             y,
                             item.size_x,
                             item.size_y,
                             'green',
                             'grey',
                             '',
                             40,
                             item.name,
                             'ultra_blue',
                             transparent_off=False,
                             transparent_on=True)
                writing_text('', 35, text + str(item.attribute), 'green', x,
                             y + 50)

            if item.type == 'stamina':
                text = 'Stamina: '
                button_maker(x,
                             y,
                             item.size_x,
                             item.size_y,
                             'green',
                             'grey',
                             '',
                             40,
                             item.name,
                             'ultra_blue',
                             transparent_off=False,
                             transparent_on=True)
                writing_text('', 35, text + str(item.attribute), 'yellow', x,
                             y + 50)

            if item.type == 'other':
                button_maker(x,
                             y,
                             item.size_x,
                             item.size_y,
                             'green',
                             'grey',
                             '',
                             40,
                             item.name.center(20),
                             'gold',
                             transparent_off=False,
                             transparent_on=True)

            x += 200
            if x > 600:
                x = 0
                y += 150