def __init__(self, scr): """Input parameters: scr - Surface for drawing.""" self.scr = scr scr_rect = self.scr.get_rect() self.sliding_label = SlidingLabel(scr=self.scr, text=TEXT_MESSAGE, color=COLOR_PRIMARY, size=FONT_SIZE, slide=SLIDE_BOTTOM) self.sliding_label.set_origin_center( (scr_rect.centerx, -self.sliding_label.rect.height // 2)) self.sliding_label.set_max_progress( (scr_rect.height + self.sliding_label.rect.height) // 2) self.sliding_label.set_speed(SLIDING_SPEED) self.sliding_label.set_repeat(False) self.blinking_label = BlinkingLabel(scr=self.scr, text=TEXT_MESSAGE, color=COLOR_PRIMARY, second_color=COLOR_SECONDARY, size=FONT_SIZE) self.blinking_label.rect.center = scr_rect.center self.blinking_label.set_repeat(False) self.blinking_label.set_speed(0.25)
def __init__(self, scr): """Input parameters: scr - Surface for drawing.""" self.scr = scr scr_rect = self.scr.get_rect() self.incoming_label = SlidingLabel( scr=self.scr, text=TEXT_MESSAGE, color=COLOR_PRIMARY, size=FONT_SIZE, slide=SLIDE_RIGHT) self.incoming_label.set_origin_center(( -self.incoming_label.rect.width // 2, scr_rect.centery)) self.incoming_label.set_max_progress( (scr_rect.width + self.incoming_label.rect.width) // 2) self.incoming_label.set_speed(SLIDING_SPEED) self.incoming_label.set_repeat(False) self.outcoming_label = SlidingLabel( scr=self.scr, text=TEXT_MESSAGE, color=COLOR_PRIMARY, size=FONT_SIZE, slide=SLIDE_RIGHT) self.outcoming_label.set_origin_center(scr_rect.center) self.outcoming_label.set_max_progress( (scr_rect.width + self.outcoming_label.rect.width) // 2) self.outcoming_label.set_speed(SLIDING_SPEED) self.outcoming_label.set_repeat(False) self.blinking_label = BlinkingLabel( scr=self.scr, text=TEXT_MESSAGE, color=COLOR_PRIMARY, second_color=COLOR_SECONDARY, size=FONT_SIZE) self.blinking_label.rect.center = scr_rect.center self.blinking_label.set_repeat(False) self.blinking_label.set_speed(1)
class GameOverEffect(): def __init__(self, scr): """Input parameters: scr - Surface for drawing.""" self.scr = scr scr_rect = self.scr.get_rect() self.sliding_label = SlidingLabel(scr=self.scr, text=TEXT_MESSAGE, color=COLOR_PRIMARY, size=FONT_SIZE, slide=SLIDE_BOTTOM) self.sliding_label.set_origin_center( (scr_rect.centerx, -self.sliding_label.rect.height // 2)) self.sliding_label.set_max_progress( (scr_rect.height + self.sliding_label.rect.height) // 2) self.sliding_label.set_speed(SLIDING_SPEED) self.sliding_label.set_repeat(False) self.blinking_label = BlinkingLabel(scr=self.scr, text=TEXT_MESSAGE, color=COLOR_PRIMARY, second_color=COLOR_SECONDARY, size=FONT_SIZE) self.blinking_label.rect.center = scr_rect.center self.blinking_label.set_repeat(False) self.blinking_label.set_speed(0.25) def restart(self): """Prepares the animation effect for playing again.""" self.sliding_label.restart() self.blinking_label.restart() def _get_active_labels(self): labels = [] if self.sliding_label.finished: labels.append(self.blinking_label) else: labels.append(self.sliding_label) return labels def update(self): """Updates screen positions for text labels.""" for label in self._get_active_labels(): label.update() def draw(self): """Renders the animation effect to the specified surface.""" for label in self._get_active_labels(): label.draw() def finished(self): """Returns True if the animation effect is completed and False if it is still in progress.""" return self.blinking_label.finished
def __init__(self, scr, score=0): """Input parameters: scr - Surface for drawing; score - player's final score.""" self.scr = scr self.background = pygame.image.load( f"img/bg/{BACKGROUND_FILENAME}").convert() scr_rect = self.scr.get_rect() self.labels = [] for i in range(0, len(ENDING_TEXT)): label = FadingLabel(scr=self.scr, text=ENDING_TEXT[i], color=DEFAULT_COLOR, size=FONT_SIZE_DEFAULT) label.rect.midtop = (scr_rect.centerx, scr_rect.top + FONT_SIZE_DEFAULT * (i * 2 + 2)) label.set_repeat(False) self.labels.append(label) self.score_label = FadingLabel(scr=self.scr, text=self._get_score_text(score), color=SCORE_COLOR, size=FONT_SIZE_DEFAULT) self.score_label.rect.midtop = (scr_rect.centerx, scr_rect.top + FONT_SIZE_DEFAULT * (len(ENDING_TEXT) * 2 + 4)) self.score_label.set_repeat(False) self.labels.append(self.score_label) self.start_fading_label = FadingLabel(scr=self.scr, text=START_TEXT, color=START_COLOR_PRIMARY, size=FONT_SIZE_START) self.start_fading_label.rect.midbottom = (scr_rect.centerx, scr_rect.bottom - FONT_SIZE_START * 2) self.start_fading_label.set_repeat(False) self.labels.append(self.start_fading_label) self.start_blinking_label = BlinkingLabel( scr=self.scr, text=START_TEXT, color=START_COLOR_PRIMARY, second_color=START_COLOR_SECONDARY, size=FONT_SIZE_START) self.start_blinking_label.rect.midbottom = ( self.start_fading_label.rect.midbottom) self.labels.append(self.start_blinking_label)
def __init__(self, scr, view_point, stars): """Input parameters: scr - Surface for drawing; view_point - ViewPoint class instance; stars - Stars class instance for drawing.""" self.scr = scr self.view_pt = view_point self.stars = stars self.background = pygame.image.load( f"img/bg/{BACKGROUND_FILENAME}").convert() scr_rect = self.scr.get_rect() self.top_sliding_label = SlidingLabel( scr=self.scr, text=TOP_TITLE_TEXT, color=TITLE_COLOR_PRIMARY, size=FONT_SIZE_TITLE, typeface=TYPEFACE_3D, slide=SLIDE_RIGHT) self.top_sliding_label.set_origin_center(( -self.top_sliding_label.rect.width // 2, scr_rect.centery - FONT_SIZE_TITLE // 2)) self.top_sliding_label.set_max_progress( (scr_rect.width + self.top_sliding_label.rect.width) // 2) self.top_sliding_label.set_speed(SLIDING_SPEED) self.top_sliding_label.set_repeat(False) self.bottom_sliding_label = SlidingLabel( scr=self.scr, text=BOTTOM_TITLE_TEXT, color=TITLE_COLOR_PRIMARY, size=FONT_SIZE_TITLE, typeface=TYPEFACE_3D, slide=SLIDE_LEFT) self.bottom_sliding_label.set_origin_center(( scr_rect.width + self.bottom_sliding_label.rect.width // 2, scr_rect.centery + FONT_SIZE_TITLE // 2)) self.bottom_sliding_label.set_max_progress( (scr_rect.width + self.bottom_sliding_label.rect.width) // 2) self.bottom_sliding_label.set_speed(SLIDING_SPEED) self.bottom_sliding_label.set_repeat(False) self.top_blinking_label = BlinkingLabel( scr=self.scr, text=TOP_TITLE_TEXT, color=TITLE_COLOR_PRIMARY, second_color=TITLE_COLOR_SECONDARY, size=FONT_SIZE_TITLE, typeface=TYPEFACE_3D) self.top_blinking_label.rect.center = ( scr_rect.centerx, scr_rect.centery - FONT_SIZE_TITLE // 2) self.top_blinking_label.set_speed(0.5) self.bottom_blinking_label = BlinkingLabel( scr=self.scr, text=BOTTOM_TITLE_TEXT, color=TITLE_COLOR_PRIMARY, second_color=TITLE_COLOR_SECONDARY, size=FONT_SIZE_TITLE, typeface=TYPEFACE_3D) self.bottom_blinking_label.rect.center = ( scr_rect.centerx, scr_rect.centery + FONT_SIZE_TITLE // 2) self.bottom_blinking_label.set_speed(0.5) self.start_fading_label = FadingLabel( scr=self.scr, text=START_TEXT, color=START_COLOR_PRIMARY, size=FONT_SIZE_START) self.start_fading_label.rect.midbottom = ( scr_rect.centerx, scr_rect.bottom - FONT_SIZE_START * 2) self.start_fading_label.set_repeat(False) self.start_blinking_label = BlinkingLabel( scr=self.scr, text=START_TEXT, color=START_COLOR_PRIMARY, second_color=START_COLOR_SECONDARY, size=FONT_SIZE_START) self.start_blinking_label.rect.midbottom = ( self.start_fading_label.rect.midbottom)
class TitleScreen(): def __init__(self, scr, view_point, stars): """Input parameters: scr - Surface for drawing; view_point - ViewPoint class instance; stars - Stars class instance for drawing.""" self.scr = scr self.view_pt = view_point self.stars = stars self.background = pygame.image.load( f"img/bg/{BACKGROUND_FILENAME}").convert() scr_rect = self.scr.get_rect() self.top_sliding_label = SlidingLabel( scr=self.scr, text=TOP_TITLE_TEXT, color=TITLE_COLOR_PRIMARY, size=FONT_SIZE_TITLE, typeface=TYPEFACE_3D, slide=SLIDE_RIGHT) self.top_sliding_label.set_origin_center(( -self.top_sliding_label.rect.width // 2, scr_rect.centery - FONT_SIZE_TITLE // 2)) self.top_sliding_label.set_max_progress( (scr_rect.width + self.top_sliding_label.rect.width) // 2) self.top_sliding_label.set_speed(SLIDING_SPEED) self.top_sliding_label.set_repeat(False) self.bottom_sliding_label = SlidingLabel( scr=self.scr, text=BOTTOM_TITLE_TEXT, color=TITLE_COLOR_PRIMARY, size=FONT_SIZE_TITLE, typeface=TYPEFACE_3D, slide=SLIDE_LEFT) self.bottom_sliding_label.set_origin_center(( scr_rect.width + self.bottom_sliding_label.rect.width // 2, scr_rect.centery + FONT_SIZE_TITLE // 2)) self.bottom_sliding_label.set_max_progress( (scr_rect.width + self.bottom_sliding_label.rect.width) // 2) self.bottom_sliding_label.set_speed(SLIDING_SPEED) self.bottom_sliding_label.set_repeat(False) self.top_blinking_label = BlinkingLabel( scr=self.scr, text=TOP_TITLE_TEXT, color=TITLE_COLOR_PRIMARY, second_color=TITLE_COLOR_SECONDARY, size=FONT_SIZE_TITLE, typeface=TYPEFACE_3D) self.top_blinking_label.rect.center = ( scr_rect.centerx, scr_rect.centery - FONT_SIZE_TITLE // 2) self.top_blinking_label.set_speed(0.5) self.bottom_blinking_label = BlinkingLabel( scr=self.scr, text=BOTTOM_TITLE_TEXT, color=TITLE_COLOR_PRIMARY, second_color=TITLE_COLOR_SECONDARY, size=FONT_SIZE_TITLE, typeface=TYPEFACE_3D) self.bottom_blinking_label.rect.center = ( scr_rect.centerx, scr_rect.centery + FONT_SIZE_TITLE // 2) self.bottom_blinking_label.set_speed(0.5) self.start_fading_label = FadingLabel( scr=self.scr, text=START_TEXT, color=START_COLOR_PRIMARY, size=FONT_SIZE_START) self.start_fading_label.rect.midbottom = ( scr_rect.centerx, scr_rect.bottom - FONT_SIZE_START * 2) self.start_fading_label.set_repeat(False) self.start_blinking_label = BlinkingLabel( scr=self.scr, text=START_TEXT, color=START_COLOR_PRIMARY, second_color=START_COLOR_SECONDARY, size=FONT_SIZE_START) self.start_blinking_label.rect.midbottom = ( self.start_fading_label.rect.midbottom) def restart(self): """Prepares all animation effects for playing again.""" self.top_sliding_label.restart() self.bottom_sliding_label.restart() self.top_blinking_label.restart() self.bottom_blinking_label.restart() self.start_fading_label.restart() self.start_blinking_label.restart() self.view_pt.set_center(0, self.scr.get_rect().centery) self.stars.respawn(visible_only=True) def _get_active_labels(self): labels = [] if self.top_sliding_label.finished: if self.bottom_sliding_label.finished: labels.append(self.top_blinking_label) labels.append(self.bottom_blinking_label) if self.start_fading_label.finished: labels.append(self.start_blinking_label) else: labels.append(self.start_fading_label) else: labels.append(self.top_sliding_label) labels.append(self.bottom_sliding_label) else: labels.append(self.top_sliding_label) return labels def update(self): """Updates screen positions for text labels.""" for label in self._get_active_labels(): label.update() def draw(self): """Renders background image, stars and text labels to the specified surface.""" self.scr.blit(self.background, (0, 0)) self.stars.draw() for label in self._get_active_labels(): label.draw() def play_music(self): """Starts playing music for title screen.""" pygame.mixer.music.load(f"mus/{MUSIC_FILENAME}") pygame.mixer.music.play(loops=-1)