def __init__(self, hub):
        """ Initialize all the default values for MainMenuScreen """
        self.hub = hub
        self.screen = hub.main_screen

        # Set up background
        self.background_image = pygame.image.load('imgs/background/bg-1-1.png')
        self.background_rect = self.background_image.get_rect()
        self.prep_background()

        # Title image
        self.title_image = pygame.image.load('imgs/MainMenu/main_menu.png')
        self.title_rect = self.title_image.get_rect()
        self.prep_title()

        # Instruction text
        self.movement_text = Text(self.screen, "Movement: Arrow Keys/WASD")
        self.prep_movement_text()

        # Movement Text
        self.action_text = Text(self.screen, "Fire/Sprint: Shift/CTRL")
        self.prep_action_text()

        # Level Selection Mode
        self.level_button = Button(self.hub, "Level Select")
        self.prep_level_button()

        # Exit button
        self.exit_button = Button(self.hub, "Exit Game")
        self.prep_exit_button()
Esempio n. 2
0
    def __init__(self, screen, settings, gamemode, screenmanager):
        """ Initialize properties """
        self.screen = screen

        self.settings = settings

        self.gamemode = gamemode

        self.screenmanager = screenmanager

        # Initializing the title screen
        self.title = Text(self.screen, self.settings, 'GAME OVER', (0, 0, 0),
                          self.settings.BACKGROUND_COLOR,
                          self.settings.WINDOW_WIDTH / 2, 50)

        # Initializing the level selection button
        self.level_select_button = Button(self.screen, self.settings,
                                          'Level Select', 200, 50,
                                          self.settings.WINDOW_WIDTH / 2 - 100,
                                          self.settings.WINDOW_HEIGHT / 2,
                                          (0, 0, 0), (255, 255, 255))

        # Initializing the main menu button
        self.main_menu_button = Button(self.screen, self.settings, 'Main Menu',
                                       200, 50,
                                       self.settings.WINDOW_WIDTH / 2 - 100,
                                       self.settings.WINDOW_HEIGHT / 2 + 100,
                                       (0, 0, 0), (255, 255, 255))
Esempio n. 3
0
    def __init__(self, hub):
        """ Initialize default values """
        self.hub = hub
        self.screen = hub.main_screen

        # Set up background
        self.background_image = pygame.image.load('imgs/background/bg-1-1.png')
        self.background_rect = self.background_image.get_rect()
        self.prep_background()

        # get list of all levels
        self.level_list = []
        self.create_level_buttons()
        self.prep_level_buttons()

        # level text
        self.title_text = Text(self.screen, "Select Level")
        self.prep_title_text()

        # Back button
        self.back_button = Button(self.hub, "Back")
        self.prep_back_button()
Esempio n. 4
0
class GameOverScreen:
    """ Gameover screen displays if you have won or lost. """
    def __init__(self, screen, settings, gamemode, screenmanager):
        """ Initialize properties """
        self.screen = screen

        self.settings = settings

        self.gamemode = gamemode

        self.screenmanager = screenmanager

        # Initializing the title screen
        self.title = Text(self.screen, self.settings, 'GAME OVER', (0, 0, 0),
                          self.settings.BACKGROUND_COLOR,
                          self.settings.WINDOW_WIDTH / 2, 50)

        # Initializing the level selection button
        self.level_select_button = Button(self.screen, self.settings,
                                          'Level Select', 200, 50,
                                          self.settings.WINDOW_WIDTH / 2 - 100,
                                          self.settings.WINDOW_HEIGHT / 2,
                                          (0, 0, 0), (255, 255, 255))

        # Initializing the main menu button
        self.main_menu_button = Button(self.screen, self.settings, 'Main Menu',
                                       200, 50,
                                       self.settings.WINDOW_WIDTH / 2 - 100,
                                       self.settings.WINDOW_HEIGHT / 2 + 100,
                                       (0, 0, 0), (255, 255, 255))

    def run(self):
        """ The game-loop of the screen"""
        self.check_events()
        self.draw()

    def check_events(self):
        """ Checks players input and keybaord events """
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
            if event.type == KEYDOWN:
                if event.key == K_ESCAPE:
                    pygame.quit()
            if event.type == MOUSEBUTTONDOWN:
                mouse_x, mouse_y = pygame.mouse.get_pos()
                self.check_button_collision(mouse_x, mouse_y)

    def draw(self):
        """ Draw all the sprites inside of the game over screen"""
        self.title.draw()
        self.level_select_button.draw()
        self.main_menu_button.draw()

    def check_button_collision(self, mouse_x, mouse_y):
        """ Checks if any button has been clicked. """

        # Checks if the mouse clicked onto the level select button
        if self.level_select_button.rect.collidepoint(mouse_x, mouse_y):
            self.screenmanager.reset()
            self.screenmanager.bLevelSelect_Screen = True

        # Checks if the mouse clicked onto the main menu button
        elif self.main_menu_button.rect.collidepoint(mouse_x, mouse_y):
            self.screenmanager.reset()
 def create_level_buttons(self):
     """ Create all existing level and put them in list """
     for level in self.hub.game_levels.keys():
         self.level_list.append(Button(self.hub, level, 70, 50))
     # prit the list of buttons
     print(self.level_list)
class LevelSelectionScreen:
    """ Level Selection Screen, where you can select certain levels to play """
    def __init__(self, hub):
        """ Initialize default values """
        self.hub = hub
        self.gamemode = hub.gamemode
        self.screen = hub.main_screen

        # Set up background
        self.background_image = pygame.image.load('imgs/background/bg-1-1.png')
        self.background_rect = self.background_image.get_rect()
        self.prep_background()

        # get list of all levels
        self.level_list = []
        self.create_level_buttons()
        self.prep_level_buttons()

        # level text
        self.title_text = Text(self.screen, "Select Level")
        self.prep_title_text()

        # Back button
        self.back_button = Button(self.hub, "Back")
        self.prep_back_button()

    def run(self):
        self.run_event()
        self.run_update()
        self.run_draw()

    def run_event(self):
        for event in pygame.event.get():
            if event.type == QUIT:
                self.hub.exit_game()
            if event.type == KEYDOWN:
                if event.key == K_ESCAPE:
                    self.hub.exit_game()
            if event.type == MOUSEBUTTONDOWN:
                mouse_x, mouse_y = pygame.mouse.get_pos()
                self.check_button_clicked(mouse_x, mouse_y)

    def run_update(self):
        pass

    def run_draw(self):
        self.screen.blit(self.background_image, self.background_rect)
        self.title_text.draw()
        self.back_button.draw()
        self.draw_level_buttons()

    def prep_title_text(self):
        self.title_text.msg_image_rect.center = self.screen.get_rect().center
        self.title_text.msg_image_rect.top = 100

    def prep_back_button(self):
        self.back_button.rect.x = 10
        self.back_button.rect.y = 100
        self.back_button.update_message_position()

    def check_button_clicked(self, mouse_x, mouse_y):
        if self.back_button.rect.collidepoint(mouse_x, mouse_y):
            self.hub.screen_selector = 1
        for button in self.level_list:
            if button.rect.collidepoint(mouse_x, mouse_y):
                # noinspection PyBroadException
                try:
                    self.hub.open_level(button.message)
                    self.gamemode.reset_gamemode()
                    self.hub.screen_selector = 0
                except Exception:
                    print('error: failed to load level')
                    self.hub.screen_selector = 2

    def prep_background(self):
        """ Make background adjustments """
        self.background_image = pygame.transform.scale(
            self.background_image, (self.background_rect.width * 3 + 70,
                                    self.background_rect.height * 3 + 70))
        self.background_rect = self.background_image.get_rect()

    def create_level_buttons(self):
        """ Create all existing level and put them in list """
        for level in self.hub.game_levels.keys():
            self.level_list.append(Button(self.hub, level, 70, 50))
        # prit the list of buttons
        print(self.level_list)

    def prep_level_buttons(self):
        """ Adjustments to all the list of buttons created """
        counter = 0
        for button in self.level_list:
            button.rect.center = self.screen.get_rect().center
            button.rect.y -= 200
            button.rect.x -= 150
            button.rect.x += (counter % 4) * 100
            button.rect.y += int(counter / 4) * 70
            button.update_message_position()

            counter += 1

    def draw_level_buttons(self):
        """ Draw all the level buttons onto the screen """
        if self.level_list is []:
            print('level list is empty')
            return
        else:
            # noinspection PyBroadException
            try:
                for button in self.level_list:
                    button.draw()
            except Exception:
                print('error: could not open levels')
class MainMenuScreen:
    """ Main Menu Screen showing exit button and play button """

    def __init__(self, hub):
        """ Initialize all the default values for MainMenuScreen """
        self.hub = hub
        self.screen = hub.main_screen

        # Set up background
        self.background_image = pygame.image.load('imgs/background/bg-1-1.png')
        self.background_rect = self.background_image.get_rect()
        self.prep_background()

        # Title image
        self.title_image = pygame.image.load('imgs/MainMenu/main_menu.png')
        self.title_rect = self.title_image.get_rect()
        self.prep_title()

        # Instruction text
        self.movement_text = Text(self.screen, "Movement: Arrow Keys/WASD")
        self.prep_movement_text()

        # Movement Text
        self.action_text = Text(self.screen, "Fire/Sprint: Shift/CTRL")
        self.prep_action_text()

        # Level Selection Mode
        self.level_button = Button(self.hub, "Level Select")
        self.prep_level_button()

        # Exit button
        self.exit_button = Button(self.hub, "Exit Game")
        self.prep_exit_button()

    def run(self):
        self.run_event()
        self.run_update()
        self.run_draw()

    def run_event(self):
        """ Run the event on the main screen """
        for event in pygame.event.get():
            if event.type == QUIT:
                self.hub.exit_game()
            if event.type == KEYDOWN:
                if event.key == K_ESCAPE:
                    self.hub.exit_game()
            if event.type == MOUSEBUTTONDOWN:
                mouse_x, mouse_y = pygame.mouse.get_pos()
                self.check_button_clicked(mouse_x, mouse_y)

    def run_update(self):
        """ Run all instances in them main menu screen """
        pass

    def run_draw(self):
        """ Draw all the stuff onto my main menu screen"""
        self.screen.blit(self.background_image, self.background_rect)
        self.screen.blit(self.title_image, self.title_rect)
        self.movement_text.draw()
        self.action_text.draw()
        self.level_button.draw()
        self.exit_button.draw()

    def prep_title(self):
        """ Make adjusts for title screen"""
        # Rescale the title image
        self.title_image = pygame.transform.scale(self.title_image,
                                                  (self.title_rect.width * 2, self.title_rect.height * 2))
        # Set the title rect
        self.title_rect = self.title_image.get_rect()

        # Move the title screen to the middle
        self.title_rect.center = self.screen.get_rect().center
        # Create top offset
        self.title_rect.top -= 200

    def prep_movement_text(self):
        """ Make adjustments for control text """
        self.movement_text.msg_image_rect.center = self.title_rect.center
        self.movement_text.msg_image_rect.bottom += 150

    def prep_background(self):
        """ Make background adjustments """
        self.background_image = pygame.transform.scale(self.background_image,
                                                       (self.background_rect.width * 3 + 70,
                                                        self.background_rect.height * 3 + 70))
        self.background_rect = self.background_image.get_rect()

    def prep_action_text(self):
        """ Make adjustments to the action text """
        self.action_text.msg_image_rect.center = self.movement_text.msg_image_rect.center
        self.action_text.msg_image_rect.bottom += 50

    def prep_level_button(self):
        """ Make adjustments to the level button """
        self.level_button.rect.center = self.action_text.msg_image_rect.center
        self.level_button.rect.bottom += 50
        self.level_button.update_message_position()

    def prep_exit_button(self):
        """ Make adjustments to the exit button """
        self.exit_button.rect.center = self.level_button.rect.center
        self.exit_button.rect.bottom += 50
        self.exit_button.update_message_position()

    def check_button_clicked(self, mouse_x, mouse_y):
        if self.level_button.rect.collidepoint(mouse_x, mouse_y):
            # open level screen
            self.hub.screen_selector = 2
        elif self.exit_button.rect.collidepoint(mouse_x, mouse_y):
            self.hub.exit_game()