<s> import copy <EOL> import pygame as pg <EOL> from . . import tools , setup <EOL> from . . import constants as c <EOL> class CreditEntry ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , level ) : <EOL> self . alpha = <NUM_LIT:0> <EOL> self . font = pg . font . Font ( setup . FONTS [ c . MAIN_FONT ] , <NUM_LIT> ) <EOL> self . credit_sprites = self . make_credits ( ) <EOL> self . index = <NUM_LIT:0> <EOL> self . current_credit = self . credit_sprites [ self . index ] <EOL> self . state_dict = self . make_state_dict ( ) <EOL> self . state = c . TRANSITION_IN <EOL> self . timer = <NUM_LIT:0.0> <EOL> self . level = level <EOL> def make_credits ( self ) : <EOL> """<STR_LIT>""" <EOL> credits = [ [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] ] <EOL> credit_sprites = [ ] <EOL> for credit in credits : <EOL> subcredit_list = [ ] <EOL> for i , subcredit in enumerate ( credit ) : <EOL> text_sprite = pg . sprite . Sprite ( ) <EOL> text_sprite . text_image = self . font . render ( subcredit , True , c . WHITE ) <EOL> text_sprite . rect = text_sprite . text_image . get_rect ( centerx = <NUM_LIT> , <EOL> y = <NUM_LIT:100> + ( i * <NUM_LIT> ) ) <EOL> text_sprite . image = pg . Surface ( text_sprite . rect . size ) . convert ( ) <EOL> text_sprite . image . set_colorkey ( c . BLACK ) <EOL> text_sprite . image . set_alpha ( self . alpha ) <EOL> subcredit_list . append ( text_sprite ) <EOL> credit_sprites . append ( subcredit_list ) <EOL> return credit_sprites <EOL> def make_state_dict ( self ) : <EOL> """<STR_LIT>""" <EOL> state_dict = { c . TRANSITION_IN : self . transition_in , <EOL> c . TRANSITION_OUT : self . transition_out , <EOL> c . NORMAL : self . normal_update } <EOL> return state_dict <EOL> def transition_in ( self ) : <EOL> for credit in self . current_credit : <EOL> credit . image = pg . Surface ( credit . rect . size ) . convert ( ) <EOL> credit . image . set_colorkey ( c . BLACK ) <EOL> credit . image . set_alpha ( self . alpha ) <EOL> credit . image . blit ( credit . text_image , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> self . alpha += <NUM_LIT:5> <EOL> if self . alpha >= <NUM_LIT:255> : <EOL> self . alpha = <NUM_LIT:255> <EOL> self . state = c . NORMAL <EOL> self . timer = self . current_time <EOL> def transition_out ( self ) : <EOL> for credit in self . current_credit : <EOL> credit . image = pg . Surface ( credit . rect . size ) . convert ( ) <EOL> credit . image . set_colorkey ( c . BLACK ) <EOL> credit . image . set_alpha ( self . alpha ) <EOL> credit . image . blit ( credit . text_image , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> self . alpha -= <NUM_LIT:5> <EOL> if self . alpha <= <NUM_LIT:0> : <EOL> self . alpha = <NUM_LIT:0> <EOL> if self . index < len ( self . credit_sprites ) - <NUM_LIT:1> : <EOL> self . index += <NUM_LIT:1> <EOL> else : <EOL> self . level . done = True <EOL> self . level . next = c . MAIN_MENU <EOL> self . current_credit = self . credit_sprites [ self . index ] <EOL> self . state = c . TRANSITION_IN <EOL> def normal_update ( self ) : <EOL> if ( self . current_time - self . timer ) > <NUM_LIT> : <EOL> self . state = c . TRANSITION_OUT <EOL> def update ( self , current_time ) : <EOL> self . current_time = current_time <EOL> update_method = self . state_dict [ self . state ] <EOL> update_method ( ) <EOL> def draw ( self , surface ) : <EOL> """<STR_LIT>""" <EOL> for credit_sprite in self . current_credit : <EOL> surface . blit ( credit_sprite . image , credit_sprite . rect ) <EOL> class Credits ( tools . _State ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> super ( Credits , self ) . __init__ ( ) <EOL> self . name = c . CREDITS <EOL> self . music_title = None <EOL> self . previous_music = None <EOL> self . music = None <EOL> self . volume = None <EOL> self . credit = None <EOL> def startup ( self , current_time , game_data ) : <EOL> """<STR_LIT>""" <EOL> self . game_data = game_data <EOL> self . music = setup . MUSIC [ '<STR_LIT>' ] <EOL> self . volume = <NUM_LIT> <EOL> self . current_time = current_time <EOL> self . background = pg . Surface ( setup . SCREEN_RECT . size ) <EOL> self . background . fill ( c . BLACK_BLUE ) <EOL> self . credit = CreditEntry ( self ) <EOL> def update ( self , surface , keys , current_time ) : <EOL> """<STR_LIT>""" <EOL> self . credit . update ( current_time ) <EOL> self . draw_scene ( surface ) <EOL> def draw_scene ( self , surface ) : <EOL> """<STR_LIT>""" <EOL> surface . blit ( self . background , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> self . credit . draw ( surface ) </s>
