<s> import copy , pickle , sys , os <EOL> import pygame as pg <EOL> from . . import setup , tools <EOL> from . . import observer <EOL> from . . components import person <EOL> from . . import constants as c <EOL> if sys . version_info [ <NUM_LIT:0> ] == <NUM_LIT:2> : <EOL> import cPickle <EOL> pickle = cPickle <EOL> class Arrow ( pg . sprite . Sprite ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , x , y ) : <EOL> super ( Arrow , self ) . __init__ ( ) <EOL> self . image = setup . GFX [ '<STR_LIT>' ] <EOL> self . rect = self . image . get_rect ( x = x , <EOL> y = y ) <EOL> self . index = <NUM_LIT:0> <EOL> self . pos_list = [ y , y + <NUM_LIT> ] <EOL> self . allow_input = False <EOL> self . observers = [ observer . SoundEffects ( ) ] <EOL> def notify ( self , event ) : <EOL> """<STR_LIT>""" <EOL> for observer in self . observers : <EOL> observer . on_notify ( event ) <EOL> def update ( self , keys ) : <EOL> """<STR_LIT>""" <EOL> if self . allow_input : <EOL> if keys [ pg . K_DOWN ] and not keys [ pg . K_UP ] and self . index == <NUM_LIT:0> : <EOL> self . index = <NUM_LIT:1> <EOL> self . allow_input = False <EOL> self . notify ( c . CLICK ) <EOL> elif keys [ pg . K_UP ] and not keys [ pg . K_DOWN ] and self . index == <NUM_LIT:1> : <EOL> self . index = <NUM_LIT:0> <EOL> self . allow_input = False <EOL> self . notify ( c . CLICK ) <EOL> self . rect . y = self . pos_list [ self . index ] <EOL> if not keys [ pg . K_DOWN ] and not keys [ pg . K_UP ] : <EOL> self . allow_input = True <EOL> class DeathScene ( tools . _State ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> super ( DeathScene , self ) . __init__ ( ) <EOL> self . next = c . TOWN <EOL> self . music = setup . MUSIC [ '<STR_LIT>' ] <EOL> self . volume = <NUM_LIT:0.5> <EOL> self . music_title = '<STR_LIT>' <EOL> def startup ( self , current_time , game_data ) : <EOL> self . game_data = game_data <EOL> self . font = pg . font . Font ( setup . FONTS [ c . MAIN_FONT ] , <NUM_LIT> ) <EOL> self . background = pg . Surface ( setup . SCREEN_RECT . size ) <EOL> self . background . fill ( c . BLACK_BLUE ) <EOL> self . player = person . Player ( '<STR_LIT>' , self . game_data , <NUM_LIT:1> , <NUM_LIT:1> , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> self . player . image = pg . transform . scale2x ( self . player . image ) <EOL> self . player . rect = self . player . image . get_rect ( ) <EOL> self . player . rect . center = setup . SCREEN_RECT . center <EOL> self . message_box = self . make_message_box ( ) <EOL> self . arrow = Arrow ( <NUM_LIT> , <NUM_LIT> ) <EOL> self . state_dict = self . make_state_dict ( ) <EOL> self . state = c . TRANSITION_IN <EOL> self . alpha = <NUM_LIT:255> <EOL> self . name = c . DEATH_SCENE <EOL> self . transition_surface = pg . Surface ( setup . SCREEN_RECT . size ) <EOL> self . transition_surface . fill ( c . BLACK_BLUE ) <EOL> self . transition_surface . set_alpha ( self . alpha ) <EOL> if not os . path . isfile ( "<STR_LIT>" ) : <EOL> game_data = tools . create_game_data_dict ( ) <EOL> pickle . dump ( game_data , open ( "<STR_LIT>" , "<STR_LIT:wb>" ) ) <EOL> self . observers = [ observer . SoundEffects ( ) ] <EOL> def notify ( self , event ) : <EOL> """<STR_LIT>""" <EOL> for observer in self . observers : <EOL> observer . on_notify ( event ) <EOL> def make_message_box ( self ) : <EOL> """<STR_LIT>""" <EOL> box_image = setup . GFX [ '<STR_LIT>' ] <EOL> box_rect = box_image . get_rect ( ) <EOL> text = '<STR_LIT>' <EOL> text_render = self . font . render ( text , True , c . NEAR_BLACK ) <EOL> text_rect = text_render . get_rect ( centerx = box_rect . centerx , <EOL> y = <NUM_LIT:30> ) <EOL> text2 = '<STR_LIT>' <EOL> text2_render = self . font . render ( text2 , True , c . NEAR_BLACK ) <EOL> text2_rect = text2_render . get_rect ( centerx = box_rect . centerx , <EOL> y = <NUM_LIT> ) <EOL> text3 = '<STR_LIT>' <EOL> text3_render = self . font . render ( text3 , True , c . NEAR_BLACK ) <EOL> text3_rect = text3_render . get_rect ( centerx = box_rect . centerx , <EOL> y = <NUM_LIT> ) <EOL> temp_surf = pg . Surface ( box_rect . size ) <EOL> temp_surf . set_colorkey ( c . BLACK ) <EOL> temp_surf . blit ( box_image , box_rect ) <EOL> temp_surf . blit ( text_render , text_rect ) <EOL> temp_surf . blit ( text2_render , text2_rect ) <EOL> temp_surf . blit ( text3_render , text3_rect ) <EOL> box_sprite = pg . sprite . Sprite ( ) <EOL> box_sprite . image = temp_surf <EOL> box_sprite . rect = temp_surf . get_rect ( bottom = <NUM_LIT> ) <EOL> return box_sprite <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 update ( self , surface , keys , * args ) : <EOL> """<STR_LIT>""" <EOL> update_level = self . state_dict [ self . state ] <EOL> update_level ( keys ) <EOL> self . draw_level ( surface ) <EOL> def transition_in ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> self . transition_surface . set_alpha ( self . alpha ) <EOL> self . alpha -= c . TRANSITION_SPEED <EOL> if self . alpha <= <NUM_LIT:0> : <EOL> self . alpha = <NUM_LIT:0> <EOL> self . state = c . NORMAL <EOL> def transition_out ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> self . transition_surface . set_alpha ( self . alpha ) <EOL> self . alpha += c . TRANSITION_SPEED <EOL> if self . alpha >= <NUM_LIT:255> : <EOL> self . done = True <EOL> def normal_update ( self , keys ) : <EOL> self . arrow . update ( keys ) <EOL> self . check_for_input ( keys ) <EOL> def check_for_input ( self , keys ) : <EOL> """<STR_LIT>""" <EOL> if keys [ pg . K_SPACE ] : <EOL> if self . arrow . index == <NUM_LIT:0> : <EOL> self . next = c . TOWN <EOL> self . game_data = pickle . load ( open ( "<STR_LIT>" , "<STR_LIT:rb>" ) ) <EOL> elif self . arrow . index == <NUM_LIT:1> : <EOL> self . next = c . MAIN_MENU <EOL> self . state = c . TRANSITION_OUT <EOL> self . notify ( c . CLICK2 ) <EOL> def draw_level ( self , surface ) : <EOL> """<STR_LIT>""" <EOL> surface . blit ( self . background , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> surface . blit ( self . player . image , self . player . rect ) <EOL> surface . blit ( self . message_box . image , self . message_box . rect ) <EOL> surface . blit ( self . arrow . image , self . arrow . rect ) <EOL> surface . blit ( self . transition_surface , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) </s>
