示例#1
0
    def handle_input(self) -> None:
        """
        Handling the events.
        Clicking on a button/quiting the game.
        """
        clock = pg.time.Clock()
        waiting = True
        running = True

        while waiting:
            clock.tick(FPS / 2)
            self.draw()
            self.x, self.y = pg.mouse.get_pos()

            for event in pg.event.get():
                self.mouseclick = pg.mouse.get_pressed()[0]

                if event.type == pg.QUIT:
                    waiting = running = False
                if event.type == pg.MOUSEBUTTONUP and self.back_btn_hover:
                    waiting = False
                if event.type == pg.MOUSEBUTTONUP and self.intro_hovered:
                    self.intro_played = not self.intro_played
            self._pixels_to_volume()
            self._save_intro_state()
            pg.display.update()
            pg.mixer.music.set_volume(get_volume())
        return running
示例#2
0
    def _wait_for_input(self) -> None:
        waiting = True

        while waiting:
            self.clock.tick(FPS / 2)
            self.homepage.draw()

            for event in pg.event.get():
                if event.type == pg.QUIT:
                    waiting = self.running = False
                if event.type == pg.MOUSEBUTTONUP and self.homepage.buttons_hover_states[
                        'play']:
                    waiting = False
                if event.type == pg.MOUSEBUTTONUP and self.homepage.buttons_hover_states[
                        'options']:
                    self.options = Options(self.screen)
                    self.running = waiting = self.options.handle_input()
                    self.homepage.update_volume()
                if event.type == pg.MOUSEBUTTONUP and self.homepage.buttons_hover_states[
                        'about']:
                    self.about = About(self.screen)
                    self.running = waiting = self.about.handle_input()
                if event.type == pg.MOUSEBUTTONUP and self.homepage.buttons_hover_states[
                        'gitlab']:
                    self.homepage.open_gitlab()
                if event.type == pg.MOUSEBUTTONUP and self.homepage.buttons_hover_states[
                        'exit']:
                    self.running = self.playing = waiting = False
            pg.mixer.music.set_volume(get_volume())
示例#3
0
    def __init__(self, screen: pg.Surface, paused: bool = False):
        """
        Constructor for the main menu page.
        """

        self.screen = screen
        self.paused = paused
        # SCREEN: 1280x720px = WxH
        # devided by 5 parts horizontally - W/5 = 256px (slice)
        # devided by 8 parts vertically - H/8 = 90px (segment)

        self.slice = WIDTH // 5     # 256px
        self.segment = HEIGHT // 8  # 90px
        self.air = self.space = 10    # px
        self.shift = 20               # px

        self.sheet = Sheet(str(PurePath(PATH_BUTTONS).joinpath(BUTTONSHEET)))
        if self.paused:
            self.background = load(str(PurePath(PATH_BACKGROUNDS).joinpath(BACKGROUND_3))).convert_alpha()
        else:
            self.background = load(str(PurePath(PATH_BACKGROUNDS).joinpath(BACKGROUND))).convert_alpha()

        self.buttons_hover_states = {'play': False, 'options': False, 'about': False, 'exit': False, 'gitlab': False}
        self.buttons_sprites = {
            'play': self.sheet.get_image(0, 0, 384, 70, True),
            'options': self.sheet.get_image(0, 70, 320, 70, True),
            'about': self.sheet.get_image(0, 140, 320, 70, True),
            'exit': self.sheet.get_image(0, 210, 320, 70, True),
            'gitlab': self.sheet.get_image(320, 70, 100, 100, True),
            'gitlab_h': self.sheet.get_image(320, 170, 100, 100, True)}

        # LOGO: 768x360px
        # horizontal - logo takes 3 parts out of 5 - W/5 * 3 = 768px
        # vertical - logo takes half of H - H/2 = 360px
        self.logo_rect = pg.Rect(self.slice, 0, self.slice * 3, HEIGHT / 2)
        self.logo_image = load(str(PurePath(PATH_IMAGES).joinpath(LOGO))).convert_alpha()

        # PLAY BUTTON (larger) 384x70px
        # horizontal - one part and half of 5 = W/5 * 1.5 = 384px
        # vertical - 7 parts of 9 (of the segment) = S/9 * 7 = 70px
        # (10px for the air on top and the bottom)
        self.play_button_rect = \
            pg.Rect(self.space, self.segment * 4 + self.air, self.slice * 1.5, self.segment - (self.air * 2))

        # other buttons 320*70px
        # horizontal - one part and quarter of 5 = W/5 * 1.25 = 320px
        # vertical - 7 parts of 9 (of the segment) = S/9 * 7 = 70px
        # (10px for the air on top and the bottom)
        self.other_button_rect = \
            pg.Rect(self.space, self.segment * 5, self.slice * 1.25, self.segment - (self.air * 2))

        self.gitlab_button_rect = pg.Rect(WIDTH - 100 - 20, HEIGHT - 100 - 20, 200, 200)
        self.buttons_dict = {'options': 5, 'about': 6, 'exit': 7}

        self.sound = HOVER_SOUND
        self.sound.set_volume(get_volume())

        self.cursor = load(str(PurePath(PATH_CURSORS).joinpath(CURSOR))).convert_alpha()
        self.cursor2 = load(str(PurePath(PATH_CURSORS).joinpath(CURSOR_HOVER))).convert_alpha()
        self.once = True
示例#4
0
    def __init__(self, screen: pg.Surface):
        """
        Constructor for the options page.
        """
        self.screen = screen
        self.background = load(
            str(PurePath(PATH_BACKGROUNDS).joinpath(BACKGROUND_3)))
        self.sound = None

        self.back_btn = load(str(PurePath(PATH_BUTTONS).joinpath(BACK_BUTTON)))
        self.back_btn_rect = pg.Rect(20, 20, self.back_btn.get_width(),
                                     self.back_btn.get_height())
        self.back_btn_hover = False

        self.x = self.y = 0
        self.mouseclick = False

        self.shift = 40
        self.cursor = load(str(
            PurePath(PATH_CURSORS).joinpath(CURSOR))).convert_alpha()
        self.cursor2 = load(str(
            PurePath(PATH_CURSORS).joinpath(CURSOR_HOVER))).convert_alpha()

        self.volume = load(str(
            PurePath(PATH_BUTTONS).joinpath(VOLUME))).convert_alpha()
        self.novolume = load(str(
            PurePath(PATH_BUTTONS).joinpath(VOLUME_NO))).convert_alpha()

        self.switch = load(str(
            PurePath(PATH_BUTTONS).joinpath(SWITCH))).convert_alpha()
        self.switch_rect = pg.Rect(self._volume_to_pixels(), 150,
                                   self.switch.get_width(),
                                   self.switch.get_height())
        self.clicked_switch = False

        self.intro_played = self._intro_state()
        self.intro_button_on = load(
            str(PurePath(PATH_BUTTONS).joinpath(
                'on_btn.png'))).convert_alpha()
        self.intro_button_off = load(
            str(PurePath(PATH_BUTTONS).joinpath(
                'off_btn.png'))).convert_alpha()
        self.intro_hovered = False

        self.on = load(str(
            PurePath(PATH_BUTTONS).joinpath('on.png'))).convert_alpha()
        self.off = load(str(
            PurePath(PATH_BUTTONS).joinpath('off.png'))).convert_alpha()
        self.intro_img = load(str(
            PurePath(PATH_BUTTONS).joinpath('intro.png'))).convert_alpha()

        self.on = pg.transform.scale(self.on, (100, 50))
        self.off = pg.transform.scale(self.off, (100, 50))

        self.sound = HOVER_SOUND
        self.sound.set_volume(get_volume())

        self.once = True
        self.mute = None
示例#5
0
    def _play_sound(self) -> None:
        """
        Playing the sound if any hoverable element is hovered.
        Ensuring the current volume coresponds to the value in the data.json file.
        """
        self.sound.set_volume(get_volume())

        if not self.back_btn_hover:
            self.once = True
        elif self.once:
            self.sound.play()
            self.once = False
示例#6
0
    def __init__(self, screen: pg.Surface):
        """
        Constructor for the about page.
        """
        self.screen = screen
        self.background = load(
            str(PurePath(PATH_BACKGROUNDS).joinpath(BACKGROUND_2)))
        self.sound = None

        self.back_btn = load(str(PurePath(PATH_BUTTONS).joinpath(BACK_BUTTON)))
        self.back_btn_rect = pg.Rect(20, 20, self.back_btn.get_width(),
                                     self.back_btn.get_height())
        self.back_btn_hover = False
        self.x = self.y = 0

        self.shift = 40
        self.cursor = load(str(
            PurePath(PATH_CURSORS).joinpath(CURSOR))).convert_alpha()
        self.cursor2 = load(str(
            PurePath(PATH_CURSORS).joinpath(CURSOR_HOVER))).convert_alpha()

        self.label = load(str(
            PurePath(PATH_IMAGES).joinpath(LABEL))).convert_alpha()

        self.python_logo = load(
            str(PurePath(PATH_IMAGES).joinpath(PYTHON_LOGO))).convert_alpha()
        self.python_logo_hover = load(
            str(PurePath(PATH_IMAGES).joinpath(
                PYTHON_LOGO_HOVER))).convert_alpha()
        self.python_logo_hovered = False

        self.misty_logo = load(
            str(PurePath(PATH_IMAGES).joinpath(
                MISTY_HATS_LOGO))).convert_alpha()
        self.misty_logo_hover = load(
            str(PurePath(PATH_IMAGES).joinpath(
                MISTY_HATS_LOGO_HOVER))).convert_alpha()
        self.misty_logo_hovered = False

        self.text_img = load(
            str(PurePath(PATH_IMAGES).joinpath(
                'text-about1.png'))).convert_alpha()

        self.sound = HOVER_SOUND
        self.sound.set_volume(get_volume())
示例#7
0
    def __init__(self, screen: pg.Surface):

        pg.mixer.init()
        self.screen = screen
        self.playing = True

        self.slides_sheet = Sheet(str(PurePath(PATH_IMAGES).joinpath('slidesheet.png')))
        self.slides = [self.slides_sheet.get_image(0, HEIGHT * i, WIDTH, HEIGHT) for i in range(0, 3)]

        self.voice_clips = [pg.mixer.Sound(str(PurePath(PATH_VOICES).joinpath(i)))
                            for i in os.listdir(str(PurePath(PATH_VOICES)))]

        volume = get_volume()
        self.voice_clips[0].set_volume(volume)
        self.voice_clips[1].set_volume(volume)
        self.voice_clips[2].set_volume(volume)

        self.durations = [i.get_length() for i in self.voice_clips]
        self.durations[0] += 1.5

        self.start_time = pg.time.get_ticks()
        self.index = 0
        self.once = True
示例#8
0
 def update_volume(self)->None:
     """
     Updating the power of the volume if needed.
     """
     self.sound.set_volume(get_volume())