예제 #1
0
 def help(self):
     # method, sets the display to the help screen format
     self.screen_state = "help"  # screen ID
     self.background = pygame.image.load(
         "source/resources/gui/backgrounds/help.jpg")  # background img
     self.number_page = 0  # stores the current book page
     # --- buttons ---
     # "MENU" button graphic method from tools
     self.menu_button = tools.Button(self.button_menu_st0,
                                     self.button_menu_st1, 375, 15)
     self.left_button = tools.Button(self.b_page_0, self.b_page_L, 17,
                                     175)  # button to go previous page
     self.right_button = tools.Button(self.b_page_0, self.b_page_R, 257,
                                      175)  # button to go next page
예제 #2
0
 def player(self):
     # method, sets the display to the format of the screen where the user enters the battle name
     self.screen_state = "player"  # screen ID
     self.background = pygame.image.load(
         "source/resources/gui/backgrounds/player.jpg")  # background img
     # --- buttons ---
     # "MENU" button graphic method from tools
     self.menu_button = tools.Button(self.button_menu_st0,
                                     self.button_menu_st1, 375, 15)
     # "JUGAR" button graphic method from tools
     self.game_button = tools.Button(self.button_start_game_st0,
                                     self.button_start_game_st1, 197, 464)
     # --- entry-text ---
     self.name_text = "INSERTE NOMBRE DE BATALLA"  # instruction text
     self.name = ""
예제 #3
0
 def __init__(self, screen, name, duration, main_screen):
     # --- load source/resources ---
     self.backgrounds = [
         "source/resources/gui/backgrounds/gameover.jpg",
         "source/resources/gui/backgrounds/winner.jpg"
     ]
     self.shields = [
         "source/resources/gui/props/go_1.png",
         "source/resources/gui/props/go_2.png",
         "source/resources/gui/props/go_3.png",
         "source/resources/gui/props/go_4.png",
         "source/resources/gui/props/go_5.png"
     ]
     self.trophies = [
         "source/resources/gui/props/win_1.png",
         "source/resources/gui/props/win_2.png",
         "source/resources/gui/props/win_3.png",
         "source/resources/gui/props/win_4.png"
     ]
     self.button_menu_st0 = pygame.image.load(
         "source/resources/gui/buttons/b0_menu.png")  # normal state image
     self.button_menu_st1 = pygame.image.load(
         "source/resources/gui/buttons/b1_menu.png")  # active state image
     # --- after-game methods ---
     self.cursor = tools.Cursor()  # cursor graphic method from tools.py
     # --- after-game variables ---
     self.screen = screen
     self.name = name
     self.time = duration
     self.main_screen = main_screen
     # --- button ---
     self.menu_button = tools.Button(self.button_menu_st0,
                                     self.button_menu_st1, 375, 15)
예제 #4
0
 def credits(self):
     # method, sets the display to show information about the developers of the program
     self.screen_state = "credits"  # screen ID
     self.background = pygame.image.load(
         "source/resources/gui/backgrounds/credits.jpg")  # background img
     # --- buttons ---
     # "MENU" button graphic method from tools
     self.menu_button = tools.Button(self.button_menu_st0,
                                     self.button_menu_st1, 375, 15)
예제 #5
0
 def load(self):
     # method, sets the display to battle loading format, receives and displays data from sessions.json
     self.screen_state = "load_game"  # screen ID
     self.background = pygame.image.load(
         "source/resources/gui/backgrounds/load.jpg")  # background img
     # --- buttons ---
     # "MENU" button graphic method from tools
     self.menu_button = tools.Button(self.button_menu_st0,
                                     self.button_menu_st1, 375, 15)
     self.game_button = tools.Button(self.button_start_game_st0,
                                     self.button_start_game_st1, 197, 464)
     # --- battle's information ---
     with open("source/resources/data/sessions.json") as file:
         data = json.load(file)
     self.battlename = data["name"]  # stored battle's name
     self.battlemode = data["difficulty"]  # stored battle's mode
     self.time_saved = data["hour"]  # time when the battle was stored
     self.date_saved = data["date"]  # date when the battle was stored
예제 #6
0
 def select_difficulty(self):
     # method, sets the display to the difficulty selection screen format (battle mode)
     self.screen_state = "select_difficulty"  # screen ID
     self.background = pygame.image.load(
         "source/resources/gui/backgrounds/power.jpg")  # background img
     # --- buttons ---
     # "MENU" button graphic method from tools
     self.menu_button = tools.Button(self.button_menu_st0,
                                     self.button_menu_st1, 375, 15)
     # "MONJE - MAESTRO - AVATAR" button graphic method from tools
     self.easy_button = tools.Button(self.button_easy_1, self.button_easy_0,
                                     127, 318)
     self.regular_button = tools.Button(self.button_regular_1,
                                        self.button_regular_0, 217, 318)
     self.hard_button = tools.Button(self.button_hard_1, self.button_hard_0,
                                     308, 318)
     # "SIGUIENTE" button graphic method from tools
     self.next_window_button = tools.Button(self.next_window_0,
                                            self.next_window_1, 200, 462)
예제 #7
0
 def scores(self):
     # method, sets the display to the best battle time display format
     self.screen_state = "scores"  # screen ID
     self.background = pygame.image.load(
         "source/resources/gui/backgrounds/scores.jpg")  # background img
     # --- buttons ---
     # "MENU" button graphic method from tools
     self.menu_button = tools.Button(self.button_menu_st0,
                                     self.button_menu_st1, 375, 15)
     # --- information's graph-format class ---
     self.table = Table(self.screen)
예제 #8
0
 def menu(self):
     # method, sets the display to the main menu format
     self.screen_state = "menu"  # screen ID
     self.background = pygame.image.load(
         "source/resources/gui/backgrounds/menu.jpg")  # background img
     # --- buttons ---
     # "INICIAR BATALLA" button graphic method from tools
     self.play_button = tools.Button(self.button_play_st0,
                                     self.button_play_st1, 132, 305)
     # "REANUDAR BATALLA" button graphic method from tools
     self.load_button = tools.Button(self.button_load_st0,
                                     self.button_load_st1, 132, 370)
     # "HISTORIAL DE BATALLAS" button graphic method from tools
     self.scores_button = tools.Button(self.button_scores_st0,
                                       self.button_scores_st1, 132, 435)
     # "AYUDA" button graphic method from tools
     self.help_button = tools.Button(self.button_help_st0,
                                     self.button_help_st1, 132, 500)
     # "CREDITOS" button graphic method from tools
     self.credits_button = tools.Button(self.button_credits_st0,
                                        self.button_credits_st1, 132, 565)
예제 #9
0
    def __init__(self, name, screen, difficulty, gems, start_level, main_menu):
        # --- load sources---
        self.frame_image = pygame.image.load(
            "source/resources/gui/props/frame.png")  # gui frame img
        self.save_button_image_0 = pygame.image.load(
            "source/resources/gui/buttons/b0_save.png")  # normal state img
        self.save_button_image_1 = pygame.image.load(
            "source/resources/gui/buttons/b1_save.png")  # active state img
        self.muted_button_image_0 = pygame.image.load(
            "source/resources/gui/buttons/b0_muted.png")  # normal state img
        self.muted_button_image_1 = pygame.image.load(
            "source/resources/gui/buttons/b1_muted.png")  # active state img
        self.c0_air = pygame.image.load(
            "source/resources/gui/buttons/c0_air.png")  # normal state img
        self.c1_air = pygame.image.load(
            "source/resources/gui/buttons/c1_air.png")  # active state img
        self.c0_earth = pygame.image.load(
            "source/resources/gui/buttons/c0_earth.png")  # normal state img
        self.c1_earth = pygame.image.load(
            "source/resources/gui/buttons/c1_earth.png")  # active state img
        self.c0_water = pygame.image.load(
            "source/resources/gui/buttons/c0_water.png")  # normal state img
        self.c1_water = pygame.image.load(
            "source/resources/gui/buttons/c1_water.png")  # active state img
        self.c0_fire = pygame.image.load(
            "source/resources/gui/buttons/c0_fire.png")  # normal state img
        self.c1_fire = pygame.image.load(
            "source/resources/gui/buttons/c1_fire.png")  # active state img

        # --- buttons ---
        # --- save button---
        self.save_button = tools.Button(self.save_button_image_0,
                                        self.save_button_image_1, 11, 622)
        # --- muted button---
        self.muted_button = tools.Button(self.muted_button_image_0,
                                         self.muted_button_image_1, 432, 622)
        # --- air button---
        self.air_button = tools.Button(self.c0_air, self.c0_air, 99, 582)
        # ---earth button---
        self.earth_button = tools.Button(self.c0_earth, self.c0_earth, 188,
                                         583)
        # ---water button---
        self.water_button = tools.Button(self.c0_water, self.c0_water, 272,
                                         580)
        # ---fire button---
        self.fire_button = tools.Button(self.c0_fire, self.c0_fire, 354, 583)

        # --- game variables ---
        self.screen = screen
        self.menu = main_menu  # menu
        self.screen_state = start_level  # screen ID
        self.start_level = start_level  # lvl screen ID
        self.today = datetime.datetime.now()  # current date
        self.name = name  # battle name
        self.gems = gems  # gem counter, defines the value available to buy elementals
        self.murders = 0  # titan death counter, defines when the next level is set
        self.difficulty = difficulty  # battle mode
        self.frequency = 0  # frequency of attack of the elementals according to battle mode
        self.attack_freq = 0  # frequency of attack of the titans according to game level
        self.gameover = False
        self.started = False
        self.moving = False
        self.grid = None

        # --- game methods ---
        self.cursor = tools.Cursor()  # Cursor, class from tools.py
        self.grid = tools.Matrix(self)  # Matrix,  class from tools.py
        self.session_manager = tools.SessionManager(
        )  # SessionManager,  class from tools.py

        # --- setting the attack frequency of the elementals according to the battle mode ---
        if self.difficulty == "MONJE":  # high-frequency elemental attack configuration (easy level)
            self.attack_freq = 0.5
        if self.difficulty == "MAESTRO":  # regular frequency configuration of elemental attacks (regular level)
            self.attack_freq = 0.3
        if self.difficulty == "AVATAR":  # low frequency elemental attack configuration (hard level)
            self.attack_freq = 0

        # notification
        print("❆ BATTLE'S NAME:", self.name, " | BATTLE MODE:",
              self.difficulty, " | DATE & TIME:", self.today, "❆")
예제 #10
0
 def cards_cs(self):
     # method, cards control system is in charge of enabling and disabling the purchase options
     if self.gems >= 200:  # enables the four purchase options
         self.air_button = tools.Button(self.c1_air, self.c1_air, 99, 582)
         self.earth_button = tools.Button(self.c1_earth, self.c1_earth, 188,
                                          583)
         self.water_button = tools.Button(self.c1_water, self.c1_water, 272,
                                          580)
         self.fire_button = tools.Button(self.c1_fire, self.c1_fire, 354,
                                         583)
     elif self.gems >= 150:  # disables the fire purchase option
         self.air_button = tools.Button(self.c1_air, self.c1_air, 99, 582)
         self.earth_button = tools.Button(self.c1_earth, self.c1_earth, 188,
                                          583)
         self.water_button = tools.Button(self.c1_water, self.c1_water, 272,
                                          580)
         self.fire_button = tools.Button(self.c0_fire, self.c0_fire, 354,
                                         583)
     elif self.gems >= 100:  # disables fire and water purchase options
         self.air_button = tools.Button(self.c1_air, self.c1_air, 99, 582)
         self.earth_button = tools.Button(self.c1_earth, self.c1_earth, 188,
                                          583)
         self.water_button = tools.Button(self.c0_water, self.c0_water, 272,
                                          580)
         self.fire_button = tools.Button(self.c0_fire, self.c0_fire, 354,
                                         583)
     elif self.gems >= 50:  # disables fire,water and earth purchase options
         self.air_button = tools.Button(self.c1_air, self.c1_air, 99, 582)
         self.earth_button = tools.Button(self.c0_earth, self.c0_earth, 188,
                                          583)
         self.water_button = tools.Button(self.c0_water, self.c0_water, 272,
                                          580)
         self.fire_button = tools.Button(self.c0_fire, self.c0_fire, 354,
                                         583)
     elif self.gems < 50:  # disables all purchase options
         self.air_button = tools.Button(self.c0_air, self.c0_air, 99, 582)
         self.earth_button = tools.Button(self.c0_earth, self.c0_earth, 188,
                                          583)
         self.water_button = tools.Button(self.c0_water, self.c0_water, 272,
                                          580)
         self.fire_button = tools.Button(self.c0_fire, self.c0_fire, 354,
                                         583)
예제 #11
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)