def do_actions(self):
        while self.menu_main_running:
            bg = self.screen.blit(self.menu_main_bg, (0, 0))
            time_passed_seconds = get_time_sec(self.clock.tick(MENU_CLOCK_TICK))

            self.sprites.update(time_passed_seconds)
            self.sprites.draw(self.screen)

            self.menu_main.draw(self.screen)

            graphics.handle_mouse_cursor(self.mouse_cursor, self.screen)

            fr = self.screen.blit(self.window_frame, (0, 0))
            need_update = (bg, fr)
            pygame.display.update(need_update)
            
            events = pygame.event.get()
            self.menu_main.update(events)

            for e in events:
                if e.type == pygame.QUIT:
                    self._quit_option()
                elif e.type == pygame.KEYDOWN:
                    if self.game_opts.sound:
                        if e.key in (pygame.K_p, pygame.K_s, pygame.K_c):
                            sound_mixer.play_sound(
                                self.select_option_snd, SOUND_VOL)
                    if e.key in (pygame.K_ESCAPE, pygame.K_q):
                        self._quit_option()
                    elif e.key == pygame.K_p:
                        self._play_option()
                    elif e.key == pygame.K_s:
                        self._settings_option()
                    elif e.key == pygame.K_c:
                        self._credits_option()
    def _settings_option(self):
        '''Entry point for main menu's settings option.'''
        # each time we enter in settings
        # sub menu, set the flag to true
        self.menu_settings_running = True

        for s in self.sprites:
            s.alpha = SPRITE_ALPHA

        while self.menu_settings_running:
            bg = self.screen.blit(self.menu_settings_bg, (0, 0))

            self.menu_main.draw(self.screen)

            time_passed_seconds = get_time_sec(self.clock.tick(MENU_CLOCK_TICK))

            self.sprites.update(time_passed_seconds)
            self.sprites.draw(self.screen)
            
            menu_bg = self.screen.blit(self.menu_box_bg, (
                    (constants.SCREEN_WIDTH - self.menu_box_bg.get_width()) / 2.0,
                    (constants.SCREEN_HEIGHT - self.menu_box_bg.get_height()) / 2.0))
            self.menu_settings.draw(self.screen)

            graphics.handle_mouse_cursor(self.mouse_cursor, self.screen)
            fr = self.screen.blit(self.window_frame, (0, 0))
            need_update = (bg, menu_bg, fr)

            pygame.display.update(need_update)
            events = pygame.event.get()
            self.menu_settings.update(events)

            for e in events:
                if e.type == pygame.QUIT:
                    self._back_option()
                    self._quit_option()
                elif e.type == pygame.KEYDOWN:
                    if self.game_opts.sound:
                        if e.key in (pygame.K_f, pygame.K_s, pygame.K_m,
                                     pygame.K_b, pygame.K_ESCAPE):
                            sound_mixer.play_sound(
                                self.select_option_snd, SOUND_VOL)
                    if e.key in (pygame.K_ESCAPE, pygame.K_b):
                        self._back_option()
                    elif e.key == pygame.K_f:
                        self._toggle_fullscreen_option()
                    elif e.key == pygame.K_s:
                        self._toggle_sounds_option()
                    elif e.key == pygame.K_m:
                        self._toggle_music_option()

        for s in self.sprites:
            s.alpha = MAX_ALPHA
Exemple #3
0
    def _settings_option(self):
        # each time we enter in settings
        # sub menu, set the flag to true
        self.menu_settings_running = True

        # decrease the alpha of animated sprites
        for s in self.anim_sprites:
            s.image.set_alpha(ANIM_SPRITE_ALPHA)

        # display & update screen, get all the events
        while self.menu_settings_running:
            # draw the background
            self.screen.blit(self.menu_settings_bg, (0, 0))

            # draw the main menu
            self.menu_main.draw(self.screen)

            # count time passed in seconds
            time_passed_seconds = get_time_sec(self.clock.tick(50))

            # animate the sprites
            self.anim_sprites.update(time_passed_seconds)
            rectlist = self.anim_sprites.draw(self.screen)
            
            # draw settings menu background box
            self.screen.blit(self.menu_box_bg, (
             (constants.SCREEN_WIDTH - self.menu_box_bg.get_width()) / 2.0,
             (constants.SCREEN_HEIGHT - self.menu_box_bg.get_height()) / 2.0))

            # draw the settings menu
            self.menu_settings.draw(self.screen)

            # draw the custom mouse cursor
            graphics.handle_mouse_cursor(self.mouse_cursor, self.screen)

            # draw the frame of the window
            self.screen.blit(self.window_frame, (0, 0))

            # display the screen surface
            pygame.display.update()

            # clear the sprites
            self.anim_sprites.clear(self.screen, self.menu_main_bg)

            # get all the events
            events = pygame.event.get()

            # ..... and update the settings menu
            # which needs access to those events
            self.menu_settings.update(events)

            # settings menu event loop
            for e in events:
                # quit when the close button is pressed
                if e.type == pygame.QUIT:
                    self._back_option()
                    self._quit_option()
                # handle keyboard keys
                elif e.type == pygame.KEYDOWN:
                    # play the sound if there was a menu key shortcut
                    if self.game_opts.sound:
                        if e.key in (pygame.K_f, pygame.K_s, pygame.K_m,
                                     pygame.K_b, pygame.K_ESCAPE):
                            sound_mixer.play_sound(
                                self.select_option_snd, 0.2)

                    # when user presses escape key or 'b'ack key
                    if e.key in (pygame.K_ESCAPE, pygame.K_b):
                        self._back_option()
                    # when user presses 'f'ullscreen key
                    elif e.key == pygame.K_f:
                        self._toggle_fullscreen_option()
                    # when user presses 's'ounds key
                    elif e.key == pygame.K_s:
                        self._toggle_sounds_option()
                    # when user presses 'm'usic key
                    elif e.key == pygame.K_m:
                        self._toggle_music_option()

        # restore the alpha of the animated sprites
        for s in self.anim_sprites:
            s.image.set_alpha(255)
Exemple #4
0
    def do_actions(self):

        # display & update screen, get all the events
        while self.menu_main_running:
            # draw the background
            self.screen.blit(self.menu_main_bg, (0, 0))

            # count time passed in seconds
            time_passed_seconds = get_time_sec(self.clock.tick(50))

            # animate the sprites
            self.anim_sprites.update(time_passed_seconds)
            rectlist = self.anim_sprites.draw(self.screen)

            # draw the main menu
            self.menu_main.draw(self.screen)

            # draw the custom mouse cursor
            graphics.handle_mouse_cursor(self.mouse_cursor, self.screen)

            # draw the frame of the window
            self.screen.blit(self.window_frame, (0, 0))

            # display the screen surface
            pygame.display.update()
            
            # clear the sprites 
            self.anim_sprites.clear(self.screen, self.menu_main_bg)

            # get all the events
            events = pygame.event.get()

            # ......... and update the main menu
            # which needs access to those events
            self.menu_main.update(events)

            # main menu event loop
            for e in events:
                # quit when the close button is pressed
                if e.type == pygame.QUIT:
                    self._quit_option()
                # handle keyboard keys
                elif e.type == pygame.KEYDOWN:
                    # play the sound if there was a menu key shortcut
                    if self.game_opts.sound:
                        if e.key in (pygame.K_p, pygame.K_s, pygame.K_c):
                            sound_mixer.play_sound(
                                self.select_option_snd, 0.2)

                    # when user presses escape or 'q'uit key
                    if e.key in (pygame.K_ESCAPE, pygame.K_q):
                        self._quit_option()
                    # when user presses 'p'lay key
                    elif e.key == pygame.K_p:
                        self._play_option()
                    # when user presses 's'ettings key
                    elif e.key == pygame.K_s:
                        self._settings_option()
                    # when user presses 'c'redits key
                    elif e.key == pygame.K_c:
                        self._credits_option()
Exemple #5
0
    def _settings_option(self):
        # each time we enter in settings
        # sub menu, set the flag to true
        self.menu_settings_running = True

        # decrease the alpha of animated sprites
        for s in self.anim_sprites:
            s.image.set_alpha(ANIM_SPRITE_ALPHA)

        # display & update screen, get all the events
        while self.menu_settings_running:
            # draw the background
            bg = self.screen.blit(self.menu_settings_bg, (0, 0))

            # draw the main menu
            self.menu_main.draw(self.screen)

            # count time passed in seconds
            time_passed_seconds = get_time_sec(
                self.clock.tick(MENU_CLOCK_TICK))

            # animate the sprites
            self.anim_sprites.update(time_passed_seconds)
            self.anim_sprites.draw(self.screen)

            # draw settings menu background box
            menu_bg = self.screen.blit(
                self.menu_box_bg,
                ((constants.SCREEN_WIDTH - self.menu_box_bg.get_width()) / 2.0,
                 (constants.SCREEN_HEIGHT - self.menu_box_bg.get_height()) /
                 2.0))

            # draw the settings menu
            self.menu_settings.draw(self.screen)

            # draw the custom mouse cursor
            graphics.handle_mouse_cursor(self.mouse_cursor, self.screen)

            # draw the frame of the window
            fr = self.screen.blit(self.window_frame, (0, 0))

            need_update = (bg, menu_bg, fr)

            # display the screen surface
            pygame.display.update(need_update)

            # get all the events
            events = pygame.event.get()

            # ..... and update the settings menu
            # which needs access to those events
            self.menu_settings.update(events)

            # settings menu event loop
            for e in events:
                # quit when the close button is pressed
                if e.type == pygame.QUIT:
                    self._back_option()
                    self._quit_option()
                # handle keyboard keys
                elif e.type == pygame.KEYDOWN:
                    # play the sound if there was a menu key shortcut
                    if self.game_opts.sound:
                        if e.key in (pygame.K_f, pygame.K_s, pygame.K_m,
                                     pygame.K_b, pygame.K_ESCAPE):
                            sound_mixer.play_sound(self.select_option_snd,
                                                   SOUND_VOL)

                    # when user presses escape key or 'b'ack key
                    if e.key in (pygame.K_ESCAPE, pygame.K_b):
                        self._back_option()
                    # when user presses 'f'ullscreen key
                    elif e.key == pygame.K_f:
                        self._toggle_fullscreen_option()
                    # when user presses 's'ounds key
                    elif e.key == pygame.K_s:
                        self._toggle_sounds_option()
                    # when user presses 'm'usic key
                    elif e.key == pygame.K_m:
                        self._toggle_music_option()

        # restore the alpha of the animated sprites
        for s in self.anim_sprites:
            s.image.set_alpha(MAX_ALPHA)
Exemple #6
0
    def do_actions(self):

        # display & update screen, get all the events
        while self.menu_main_running:

            # draw the background
            bg = self.screen.blit(self.menu_main_bg, (0, 0))

            # count time passed in seconds
            time_passed_seconds = get_time_sec(
                self.clock.tick(MENU_CLOCK_TICK))

            # animate the sprites
            self.anim_sprites.update(time_passed_seconds)

            # rectlist = self.anim_sprites.draw(self.screen)
            self.anim_sprites.draw(self.screen)

            # draw the main menu
            self.menu_main.draw(self.screen)

            # draw the custom mouse cursor
            graphics.handle_mouse_cursor(self.mouse_cursor, self.screen)

            # draw the frame of the window
            fr = self.screen.blit(self.window_frame, (0, 0))

            need_update = (bg, fr)

            # display the screen surface
            pygame.display.update(need_update)

            # get all the events
            events = pygame.event.get()

            # ......... and update the main menu
            # which needs access to those events
            self.menu_main.update(events)

            # main menu event loop
            for e in events:
                # quit when the close button is pressed
                if e.type == pygame.QUIT:
                    self._quit_option()
                # handle keyboard keys
                elif e.type == pygame.KEYDOWN:
                    # play the sound if there was a menu key shortcut
                    if self.game_opts.sound:
                        if e.key in (pygame.K_p, pygame.K_s, pygame.K_c):
                            sound_mixer.play_sound(self.select_option_snd,
                                                   SOUND_VOL)

                    # when user presses escape or 'q'uit key
                    if e.key in (pygame.K_ESCAPE, pygame.K_q):
                        self._quit_option()
                    # when user presses 'p'lay key
                    elif e.key == pygame.K_p:
                        self._play_option()
                    # when user presses 's'ettings key
                    elif e.key == pygame.K_s:
                        self._settings_option()
                    # when user presses 'c'redits key
                    elif e.key == pygame.K_c:
                        self._credits_option()