Example #1
0
 def game_over(self):
     # game over screen setup
     tools.sounds("source/resources/gui/sounds/game_over.wav",
                  1)  # play game over song theme
     self.main_screen.screen_state = "game_over"  # screen ID
     self.background = pygame.image.load(
         self.backgrounds[0])  # background img
     self.shield = pygame.image.load(self.shields[random.randint(
         0, 4)])  # chooses a random image from shields-dic
Example #2
0
 def change_level(self, initial):
     #  method, according to the number of deaths of titans, the function changes the display identifier and calls up
     #  the lvl# method or shows the winner screen
     if self.murders == 10 and self.screen_state != "lvl2":
         self.grid.clean()  # clean matrix
         self.screen_state = "lvl2"  # screen ID
         tools.sounds("source/resources/gui/sounds/level_up.wav", 0.5)
         self.gems += 50
         self.lvl2()
     if self.murders == 20 and self.screen_state != "lvl3":
         self.grid.clean()  # clean matrix
         self.screen_state = "lvl3"  # screen ID
         tools.sounds("source/resources/gui/sounds/level_up.wav", 0.5)
         self.gems += 50
         self.lvl3()
     if self.murders == 50:
         self.screen_screen = "winner"  # screen ID
         print("⫸ VICTORY ⫷")  # notification
         pygame.mixer.music.stop()  # stops the main menu song
         after_game = AfterGame(self.screen, self.name,
                                int(time.time() - initial), self.menu)
         after_game.winner()  # winner screen
         after_game.setup()  # after_game class loop
Example #3
0
    def start_game(self):
        # method, main function of the game screen, managing events and displaying objects on screen
        fps = pygame.time.Clock()
        initial = time.time(
        )  # returns the time as a floating point number expressed in seconds since the epoch
        tools.music("source/resources/gui/sounds/game.mp3", 0.05,
                    -1)  # play game song theme
        while True:
            pygame.display.update()
            fps.tick(30)  # frames per second
            self.change_level(initial)
            if self.gameover:  # game over state
                print("⤲ GAME OVER ⤲")  # notification
                pygame.mixer.music.stop()  # stops the game screen theme song
                after_game = AfterGame(self.screen, self.name,
                                       int(time.time() - initial), self.menu)
                after_game.game_over()
                after_game.setup()
                break  # stops game screen loop
            else:
                self.cards_cs()
                self.generator(initial)
                self.entity_actions()
                for event in pygame.event.get():
                    # stops code execution by pressing the window button or the esc key
                    if (event.type == pygame.KEYDOWN and event.key
                            == pygame.K_ESCAPE) or event.type == pygame.QUIT:
                        pygame.quit()
                        exit()

                    # --- cursor-events ---
                    elif event.type == pygame.MOUSEBUTTONDOWN:
                        if self.cursor.colliderect(
                                self.save_button.rect):  # save game event
                            tools.sounds(
                                "source/resources/gui/sounds/button.wav",
                                0.5)  # button pressed sound
                            self.session_manager.save(
                                self)  # class, stores game play information
                            print("☸", self.name,
                                  "SUCCESSFULLY SAVED ☸")  # notification
                        elif self.cursor.colliderect(self.muted_button.rect):
                            tools.sounds(
                                "source/resources/gui/sounds/button.wav",
                                0.5)  # button pressed sound
                            pygame.mixer.music.stop(
                            )  # silence game screen theme song
                            print("♫ MUTED MUSIC ♫")  # notification
                        elif self.cursor.colliderect(
                                self.air_button.rect) and (self.gems >= 50):
                            # invoked air elemental
                            tools.sounds(
                                "source/resources/gui/sounds/invoke.wav", 0.5)
                            self.cursor.elemental = self.grid.create_object(
                                elementals.Air)  # elemental generation
                            self.gems -= 50  # elemental price
                        elif self.cursor.colliderect(
                                self.earth_button.rect) and (self.gems >= 100):
                            # invoked earth elemental
                            tools.sounds(
                                "source/resources/gui/sounds/invoke.wav", 0.5)
                            self.cursor.elemental = self.grid.create_object(
                                elementals.Earth)  # elemental generation
                            self.gems -= 100  # elemental price
                        elif self.cursor.colliderect(
                                self.water_button.rect) and (self.gems >= 150):
                            # invoked water elemental
                            tools.sounds(
                                "source/resources/gui/sounds/invoke.wav", 0.5)
                            self.cursor.elemental = self.grid.create_object(
                                elementals.Water)  # elemental generation
                            self.gems -= 150  # elemental price
                        elif self.cursor.colliderect(
                                self.fire_button.rect) and (self.gems >= 200):
                            # invoked fire elemental
                            tools.sounds(
                                "source/resources/gui/sounds/invoke.wav", 0.5)
                            self.cursor.elemental = self.grid.create_object(
                                elementals.Fire)  # elemental generation
                            self.gems -= 200  # elemental price

                        x, y = event.pos  # on-screen coordinates
                        for array in self.grid.sections:  # handles events within the matrix zone
                            for section in array:
                                location = section.pos  # get event position
                                if (location[0] < x < location[0] + 51) and (
                                        location[1] < y < location[1] +
                                        48):  # events within the box range
                                    section.on_click(self.cursor)

                # --- graphics ---
                # --- text ---
                self.level = tools.Trajan_font_15.render(
                    self.level_title, True, tools.white)  # level ID text
                self.battlename = tools.Insula_font_15.render(
                    self.name, True, tools.black)  # battle's name text
                self.gems_label = tools.Insula_font_15.render(
                    str(self.gems), True, tools.black)  # amount of gems text
                self.time = tools.Insula_font_15.render(
                    tools.clock(), True, tools.black)  # game time text

                # --- show ---
                self.screen.blit(self.background, (0, 0))  # background
                self.grid.update()  # matrix
                self.cursor.update()  # cursor update
                self.screen.blit(self.frame_image, (0, 0))  # gui frame
                self.screen.blit(self.level, (219, 39))  # level ID text
                self.screen.blit(self.battlename,
                                 (72, 76))  # battle's name text
                self.screen.blit(self.gems_label,
                                 (223, 76))  # amount of gems text
                self.screen.blit(self.time, (380, 76))  # game time text
                # --- update ---
                self.save_button.update(self.screen, self.cursor)
                self.muted_button.update(self.screen, self.cursor)
                self.air_button.update(self.screen, self.cursor)
                self.earth_button.update(self.screen, self.cursor)
                self.water_button.update(self.screen, self.cursor)
                self.fire_button.update(self.screen, self.cursor)
Example #4
0
 def hurt(self, damage):
     tools.sounds("source/resources/gui/sounds/hurt.wav", 0.1)
     self.health -= damage
Example #5
0
    def start_game(self):
        # method, main function of the game screen, managing events and displaying objects on screen
        icon = pygame.image.load(
            "source/resources/gui/props/icon.png")  # window's icon img
        pygame.display.set_icon(icon)  # window's icon
        pygame.display.set_caption("QALHALLA")  # window's title
        fps = pygame.time.Clock()  # handle events using the pygame-clock
        tools.music("source/resources/gui/sounds/bass.mp3", 0.3,
                    -1)  # play main menu song theme
        while True:
            pygame.display.update()
            self.screen.blit(self.background,
                             (0, 0))  # displays background img
            fps.tick(
                30
            )  # the events on this screen will be performed within 30 milliseconds

            for event in pygame.event.get():
                self.cursor.update()
                #  stops code execution by pressing the window button or the esc key
                if (event.type == pygame.KEYDOWN and event.key
                        == pygame.K_ESCAPE) or event.type == pygame.QUIT:
                    pygame.quit()
                    exit()

                # --- events ---
                # --- key-events ---
                elif self.screen_state == "player" and event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_BACKSPACE:  # erase character
                        self.name_text = self.name_text[:-1]
                        self.name = self.name[:-1]
                    elif len(self.name) < 10 and (
                            not event.key
                            == pygame.K_RETURN):  # checks the name length
                        self.name += event.unicode  # records a letter in the name constant
                        self.name_text = self.name  # deletes the instruction text "Inserte nombre de batalla"

                # --- cursor events ---
                elif event.type == pygame.MOUSEBUTTONDOWN:  # mouse-click selection
                    tools.sounds("source/resources/gui/sounds/button.wav", 0.5)
                    if self.screen_state == "menu":  # cursor events on the main menu screen
                        if self.cursor.colliderect(self.play_button):
                            MenuScreen.select_difficulty(self)
                        elif self.cursor.colliderect(self.load_button):
                            MenuScreen.load(self)
                        elif self.cursor.colliderect(self.scores_button):
                            MenuScreen.scores(self)
                        elif self.cursor.colliderect(self.help_button):
                            MenuScreen.help(self)
                        elif self.cursor.colliderect(self.credits_button):
                            MenuScreen.credits(self)

                    elif self.screen_state == "select_difficulty":  # cursor events on the battle mode selection screen
                        if self.cursor.colliderect(self.menu_button):
                            MenuScreen.menu(self)
                        elif self.cursor.colliderect(self.easy_button):
                            self.difficulty = "MONJE"
                            self.easy_button = tools.Button(
                                self.button_easy_1, self.button_easy_1, 127,
                                318)
                            self.regular_button = tools.Button(
                                self.button_regular_0, self.button_regular_0,
                                217, 318)
                            self.hard_button = tools.Button(
                                self.button_hard_0, self.button_hard_0, 308,
                                318)
                        elif self.cursor.colliderect(self.regular_button):
                            self.difficulty = "MAESTRO"
                            self.easy_button = tools.Button(
                                self.button_easy_0, self.button_easy_0, 127,
                                318)
                            self.regular_button = tools.Button(
                                self.button_regular_1, self.button_regular_1,
                                217, 318)
                            self.hard_button = tools.Button(
                                self.button_hard_0, self.button_hard_0, 308,
                                318)
                        elif self.cursor.colliderect(self.hard_button):
                            self.difficulty = "AVATAR"
                            self.easy_button = tools.Button(
                                self.button_easy_0, self.button_easy_0, 127,
                                318)
                            self.regular_button = tools.Button(
                                self.button_regular_0, self.button_regular_0,
                                217, 318)
                            self.hard_button = tools.Button(
                                self.button_hard_1, self.button_hard_1, 308,
                                318)
                        elif self.cursor.colliderect(
                                self.next_window_button) and isinstance(
                                    self.difficulty, str):
                            self.screen_state = "player"
                            MenuScreen.player(self)

                    elif self.screen_state == "player":  # cursor events in the battle name entry screen
                        if self.cursor.colliderect(self.menu_button):
                            MenuScreen.menu(self)
                        elif self.cursor.colliderect(
                                self.game_button) and self.check_box(
                                    self.name_text):
                            pygame.mixer.music.stop(
                            )  # stops the main menu song
                            tools.set_timer(0, 0)  # set the timer to 00:00
                            self.gems = 250  # initial amount of gems for new game
                            self.start_level = "lvl1"  # starting level for new game
                            self.screen_state = "game"  # return screen identifier

                    elif self.screen_state == "load_game":  # cursor events on the battle loading screen
                        if self.cursor.colliderect(self.menu_button):
                            MenuScreen.menu(self)
                        elif self.cursor.colliderect(self.game_button):
                            pygame.mixer.music.stop()
                            self.screen_state = "game"
                            self.game = tools.SessionManager().reload(
                                self.screen, self)

                    elif self.screen_state == "scores":  # cursor events on the best battle times screen
                        if self.cursor.colliderect(self.menu_button):
                            MenuScreen.menu(self)

                    elif self.screen_state == "help":  # cursor events in the help screen
                        if self.cursor.colliderect(self.menu_button):
                            MenuScreen.menu(self)
                        elif self.cursor.colliderect(
                                self.right_button) and (self.number_page < 7):
                            self.number_page += 1  # turn the page
                            tools.sounds(
                                "source/resources/gui/sounds/page.wav",
                                1)  # plays page sound
                        elif self.cursor.colliderect(
                                self.left_button) and (self.number_page > 0):
                            self.number_page -= 1  # back to page
                            tools.sounds(
                                "source/resources/gui/sounds/page.wav",
                                1)  # plays page sound

                    elif self.screen_state == "credits":  # cursor events in the credits screen
                        if self.cursor.colliderect(self.menu_button):
                            MenuScreen.menu(self)

            # --- graphics ---
            if self.screen_state == "menu":  # main menu screen graphics
                self.play_button.update(self.screen, self.cursor)
                self.load_button.update(self.screen, self.cursor)
                self.scores_button.update(self.screen, self.cursor)
                self.help_button.update(self.screen, self.cursor)
                self.credits_button.update(self.screen, self.cursor)

            elif self.screen_state == "select_difficulty":  # battle mode screen graphics
                self.easy_button.update(self.screen, self.cursor)
                self.regular_button.update(self.screen, self.cursor)
                self.hard_button.update(self.screen, self.cursor)
                self.menu_button.update(self.screen, self.cursor)
                self.next_window_button.update(self.screen, self.cursor)

            elif self.screen_state == "player":  # battle name screen graphics
                self.menu_button.update(self.screen, self.cursor)
                self.game_button.update(self.screen, self.cursor)
                text = tools.PfefferMediaeval_font.render(
                    self.name_text, True,
                    tools.ink_color)  # battle's name text
                self.screen.blit(text, (132, 338))

            elif self.screen_state == "game":  # decides to create or load game
                if not self.game:
                    self.game = game.Game(self.name_text, self.screen,
                                          self.difficulty, self.gems,
                                          self.start_level, self)
                self.game.load_game()
                self.game.start_game()

            elif self.screen_state == "load_game":  # battle loading screen graphics
                self.menu_button.update(self.screen, self.cursor)
                self.game_button.update(self.screen, self.cursor)
                # --- battle's information ---
                battlename = tools.Insula_font_28.render(
                    self.battlename, True, tools.blood_color)
                self.screen.blit(battlename, (130, 315))
                battlemode = tools.Insula_font_14.render(
                    self.battlemode, True, tools.blood_color)
                self.screen.blit(battlemode, (130, 360))
                time_saved = tools.Insula_font_13.render(
                    self.time_saved, True, tools.blood_color)
                self.screen.blit(time_saved, (345, 340))
                date_saved = tools.Insula_font_13.render(
                    self.date_saved, True, tools.blood_color)
                self.screen.blit(date_saved, (315, 360))

            elif self.screen_state == "scores":  # best battle times screen graphics
                self.menu_button.update(self.screen, self.cursor)
                self.table.update()  # updates position table

            elif self.screen_state == "help":  # help screen graphics
                self.book_image = pygame.image.load(
                    "source/resources/gui/props/book_" +
                    str(self.number_page) + ".png")
                self.menu_button.update(self.screen, self.cursor)
                self.screen.blit(self.book_image, (17, 175))
                self.left_button.update(self.screen, self.cursor)
                self.right_button.update(self.screen, self.cursor)

            elif self.screen_state == "credits":  # credits screen graphics
                self.menu_button.update(self.screen, self.cursor)
Example #6
0
 def hurt(self, damage):
     # method, subtracts from the elemental's health the amount of the titan's attack power
     tools.sounds("source/resources/gui/sounds/hurt.wav",
                  0.1)  # plays hit sound
     self.health -= damage