<s> from constants import * <EOL> class Menu ( object ) : <EOL> def __init__ ( self , width , height ) : <EOL> self . width = width <EOL> self . height = height <EOL> self . cursor_index = <NUM_LIT:0> <EOL> self . font = pygame . font . Font ( FILES . get_path ( "<STR_LIT>" , "<STR_LIT>" ) , <NUM_LIT:30> ) <EOL> self . text_play = self . font . render ( "<STR_LIT>" , True , WHITE ) <EOL> self . text_resume = self . font . render ( "<STR_LIT>" , True , WHITE ) <EOL> self . text_settings = self . font . render ( "<STR_LIT>" , True , WHITE ) <EOL> self . text_credits = self . font . render ( "<STR_LIT>" , True , WHITE ) <EOL> self . text_exit = self . font . render ( "<STR_LIT>" , True , WHITE ) <EOL> self . buttons_group = pygame . sprite . Group ( ) <EOL> self . assemble ( ) <EOL> def handleEvents ( self , event ) : <EOL> for button in self . buttons_group : <EOL> button . handleEvents ( event ) <EOL> if event . type == KEYDOWN : <EOL> if event . key == K_s : <EOL> self . cursor_index += <NUM_LIT:1> <EOL> elif event . key == K_w : <EOL> self . cursor_index -= <NUM_LIT:1> <EOL> if self . cursor_index < <NUM_LIT:0> : <EOL> self . cursor_index = <NUM_LIT:0> <EOL> elif self . cursor_index > <NUM_LIT:3> : <EOL> self . cursor_index = <NUM_LIT:3> <EOL> def assemble ( self ) : <EOL> button = None <EOL> for i in range ( <NUM_LIT:4> ) : <EOL> x = self . width / <NUM_LIT:2> - <NUM_LIT> / <NUM_LIT:2> <EOL> y = <NUM_LIT> + i * <NUM_LIT> <EOL> if i == <NUM_LIT:0> : <EOL> button = MenuButton ( x , y , self . text_play , "<STR_LIT>" , "<STR_LIT>" ) <EOL> elif i == <NUM_LIT:1> : <EOL> button = MenuButton ( x , y , self . text_settings , "<STR_LIT>" , "<STR_LIT>" ) <EOL> elif i == <NUM_LIT:2> : <EOL> button = MenuButton ( x , y , self . text_credits , "<STR_LIT>" , "<STR_LIT>" ) <EOL> elif i == <NUM_LIT:3> : <EOL> button = MenuButton ( x , y , self . text_exit , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . buttons_group . add ( button ) <EOL> def getActiveState ( self ) : <EOL> """<STR_LIT>""" <EOL> for button in self . buttons_group : <EOL> if button . active : <EOL> return button . state <EOL> return "<STR_LIT>" <EOL> def addResumeButton ( self ) : <EOL> """<STR_LIT>""" <EOL> for button in self . buttons_group : <EOL> if button . state == "<STR_LIT>" : <EOL> button . text = self . text_resume <EOL> def update ( self ) : <EOL> pass <EOL> class MenuButton ( pygame . sprite . Sprite ) : <EOL> def __init__ ( self , x , y , text , state , image ) : <EOL> pygame . sprite . Sprite . __init__ ( self ) <EOL> self . active = False <EOL> self . selected = False <EOL> self . state = state <EOL> self . image = pygame . Surface ( ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> self . rect = self . image . get_rect ( ) <EOL> self . rect . x = x <EOL> self . rect . y = y <EOL> self . hover_image = self . get_surface ( FILES . get_path ( "<STR_LIT>" , "<STR_LIT>" ) , <NUM_LIT> , <NUM_LIT> ) <EOL> self . inactive_image = self . get_surface ( FILES . get_path ( "<STR_LIT>" , "<STR_LIT>" ) , <NUM_LIT> , <NUM_LIT> ) <EOL> self . text = text <EOL> def handleEvents ( self , event ) : <EOL> if event . type == MOUSEMOTION : <EOL> if self . rect . collidepoint ( pygame . mouse . get_pos ( ) ) : <EOL> self . image = self . hover_image <EOL> self . active = True <EOL> else : <EOL> self . image = self . inactive_image <EOL> self . active = False <EOL> def get_surface ( self , img , width , height ) : <EOL> image = pygame . image . load ( img ) <EOL> image = pygame . transform . smoothscale ( image , ( width , height ) ) <EOL> self . rect . width = image . get_rect ( ) . width <EOL> self . rect . height = image . get_rect ( ) . height <EOL> return image <EOL> def center ( self , text ) : <EOL> textRect = text . get_rect ( ) <EOL> textRect . centerx = self . rect . centerx <EOL> textRect . centery = self . rect . centery <EOL> return textRect <EOL> def makeActive ( self , text ) : <EOL> """<STR_LIT>""" <EOL> self . text = self . font . render ( text , True , GREEN ) <EOL> self . active = True </s>
