def __init__(self, game_opts): # initialize the state State.__init__(self, constants.SCENES['intro']) ## the game's command line options self.game_opts = game_opts ## intro slides slide_num = len(constants.FILES['graphics']['intro']['slides']) self.slides = [ graphics.load_image( constants.FILES['graphics']['intro'] ['slides'][i])[0] for i in range(slide_num) ] ## cut scenes object self.cutscenes = IntroCutScene(self.slides) # set sound volume to minimum pygame.mixer.music.set_volume(0.0) # play the background music theme sound_mixer.play_music( constants.FILES['sounds']['menu']['share']['bg'][0]) # pause or unpause music according to user preference if self.game_opts.music: pygame.mixer.music.unpause() else: pygame.mixer.music.pause() # set sound volume to maximum pygame.mixer.music.set_volume(MAX_VOLUME)
def __init__(self): # part of the borg pattern self.__dict__ = self.__shared_state # initialize the state State.__init__(self, constants.SCENES['level_one']) # the 1st level states self.states = FSM() # self.game_opts = game_opts self.states.active_state = None
def __init__(self, game_opts): State.__init__(self, constants.SCENES['intro']) self.game_opts = game_opts parser = ConfigParser(constants.MAIN_CFG, constants.CFG_XMLNS) # intro slides dir_name = parser.first_match('intro').attrib slides = [i.text for i in parser.all_matches('slide')] slides = [path.join(dir_name['dir'], i) for i in slides] slide_num = len(slides) self.slides = [ResourceManager().getImage(slides[i]) for i in range(slide_num)] self.cutscenes = IntroCutScene(self.slides) pygame.mixer.music.set_volume(0.0) sound_mixer.play_music( constants.FILES['sounds']['menu']['share']['bg'][0]) if self.game_opts.music: pygame.mixer.music.unpause() else: pygame.mixer.music.pause() pygame.mixer.music.set_volume(MAX_VOLUME)
def __init__(self, name): self.name = name # initialize the state State.__init__(self, self.name)
def __init__(self, game_opts): # initialize the state State.__init__(self, constants.SCENES['menu']) ## the game's command line options self.game_opts = game_opts ## the screen surface self.screen = pygame.display.get_surface() ## flag to control the settings menu's loop self.menu_settings_running = None ## flag to control the main menu's loop self.menu_main_running = True # enable key repeat for the menu pygame.key.set_repeat(MENU_KEY_DEL, MENU_KEY_INT) ## set the main menu's background self.menu_main_bg = graphics.load_image( constants.FILES['graphics']['menu']['main']['bg'][0])[0] ## set the settings menu's background self.menu_settings_bg = graphics.load_image( constants.FILES['graphics']['menu']['share']['bg'][0])[0] ## set the settings menu's background box self.menu_box_bg = graphics.load_image( constants.FILES['graphics']['menu']['settings']['box'][0])[0] ## set the window frame self.window_frame = graphics.load_image( constants.FILES['graphics']['menu']['share']['frame'][0])[0] ## set the mouse cursor self.mouse_cursor = graphics.load_image( constants.FILES['graphics']['menu']['share']['cursor'][0])[0] ## set the sound when a menu option is entered self.select_option_snd = sound_mixer.load_sound( constants.FILES['sounds']['menu']['share']['sel'][0]) ## create the main menu - string, callback function self.menu_main = KezMenu(self.game_opts, ['Play', self._play_option], ['Settings', self._settings_option], ['Credits', self._credits_option], ['Quit', self._quit_option]) # set the position of the main menu self.menu_main.set_position(MENU_MAIN_POS_X, MENU_MAIN_POS_Y) # set the main menu's font self.menu_main.set_font( graphics.load_font(constants.FILES['fonts']['menu']['share'][0], MAIN_FONT_SIZE)) # set the main menu's highlight color self.menu_main.set_highlight_color(MAIN_FOCUS_COLOR) ## create the settings menu - string, callback function self.menu_settings = KezMenu( self.game_opts, ['Fullscreen', self._toggle_fullscreen_option], ['Sounds', self._toggle_sounds_option], ['Music', self._toggle_music_option], ['Back', self._back_option]) # disable the menu graphic for focused options self.menu_settings.toggle_image() # set the settings menu's font self.menu_settings.set_font( graphics.load_font(constants.FILES['fonts']['menu']['share'][0], MENU_FONT_SIZE)) # set the position of the settings menu self.menu_settings.center_at(constants.SCREEN_WIDTH / 2.0, constants.SCREEN_HEIGHT / 2.0) # set the settings menu's highlight color self.menu_settings.set_highlight_color(SETTINGS_FOCUS_COLOR) ## the animated sprite group self.anim_sprites = pygame.sprite.RenderUpdates() # create the animated sprites sprite_num = len(constants.FILES['graphics']['menu']['share']['anim']) sprite_fact = SpriteFactory() for i in range(sprite_num): # create the "right" type of animated sprite using the factory r_sprite = sprite_fact.create_anim_sprite( i, constants.FILES['graphics']['menu']['share']['anim'][i], ANIM_SPRITE_SPEED) self.anim_sprites.add(r_sprite) ## create clock and track time self.clock = pygame.time.Clock()
def __init__(self, game_opts): State.__init__(self, constants.SCENES['menu']) self.game_opts = game_opts self.screen = pygame.display.get_surface() self.menu_settings_running = None self.menu_main_running = True pygame.key.set_repeat(MENU_KEY_DEL, MENU_KEY_INT) self.menu_main_bg = ResourceManager().getImage( constants.FILES['graphics']['menu']['main']['bg'][0]) self.menu_settings_bg = ResourceManager().getImage( constants.FILES['graphics']['menu']['share']['bg'][0]) self.menu_box_bg = ResourceManager().getImage( constants.FILES['graphics']['menu']['settings']['box'][0]) self.window_frame = ResourceManager().getImage( constants.FILES['graphics']['menu']['share']['frame'][0]) self.mouse_cursor = ResourceManager().getImage( constants.FILES['graphics']['menu']['share']['cursor'][0]) self.select_option_snd = sound_mixer.load_sound( constants.FILES['sounds']['menu']['share']['sel'][0]) # create the main menu - string, callback function self.menu_main = KezMenu(self.game_opts, ['Play' , self._play_option], ['Settings' , self._settings_option], ['Credits' , self._credits_option], ['Quit' , self._quit_option]) self.menu_main.set_position(MENU_MAIN_POS_X, MENU_MAIN_POS_Y) self.menu_main.set_font(graphics.load_font( constants.FILES['fonts']['menu']['share'][0], MAIN_FONT_SIZE)) self.menu_main.set_highlight_color(MAIN_FOCUS_COLOR) # create the settings menu - string, callback function self.menu_settings = KezMenu(self.game_opts, ['Fullscreen' , self._toggle_fullscreen_option], ['Sounds' , self._toggle_sounds_option], ['Music' , self._toggle_music_option], ['Back' , self._back_option]) # disable the menu graphic for focused options self.menu_settings.toggle_image() self.menu_settings.set_font(graphics.load_font( constants.FILES['fonts']['menu']['share'][0], MENU_FONT_SIZE)) self.menu_settings.center_at(constants.SCREEN_WIDTH / 2.0, constants.SCREEN_HEIGHT / 2.0) self.menu_settings.set_highlight_color(SETTINGS_FOCUS_COLOR) self.sprites = pygame.sprite.LayeredUpdates() sprites_number = len(constants.FILES['graphics']['menu']['share']['anim']) sprite_area = self.screen.get_rect() sprite_limiter = LimiterFactory().getInstance('Default') for i in range(sprites_number): sprite = MenuSprite(constants.FILES['graphics']['menu']['share']['anim'][i], (sprite_area.center), i, MAX_ALPHA, False, SPRITE_SPEED, sprite_area, 'Random') sprite.limiter = sprite_limiter self.sprites.add(sprite) self.clock = pygame.time.Clock()