Example #1
0
    def __init__(self, game_opts, *menu_opts):
        # create a programmer friendly mapping stucture of the menu options
        self.options = [{'label': x[0], 'callable': x[1]} for x in menu_opts]
        self.game_opts = game_opts

        # set the default menu dimensions (these dimensions
        # are calculated depending on the font and its size)
        self.width = 0
        self.height = 0

        # set up the default coordinates of the menu
        self.x = 0
        self.y = 0

        # the topleft corner of the screen
        self.screen_topleft_offset = (0, 0)
        # set the default focused option
        self.option = 0

        # set the default previous focused option
        self.option_previous = self.option

        # set the default normal color of the menu font
        self.normal_color = pygame.Color('black')

        # set the default focused color of the menu font
        self.focus_color = pygame.Color('red')

        # default is to enable support of menu image on focused options
        self.image_enabled = True

        # default is to enable support mouse on menu
        self.mouse_enabled = True

        # set mouse focusing at unknown by default
        self.mouse_focus = None
        self._font = None

        # set a default font and its size (also fix size)
        self.font = pygame.font.Font(None, FONT_SIZE)
        self._fix_size()

        # set the default sound to play when an option is focused
        self.focus_sound = load_sound(
            constants.FILES['sounds']['menu']['share']['focus'][0])

        # set the default sound to play when an option is entered
        self.select_sound = load_sound(
            constants.FILES['sounds']['menu']['share']['sel'][0])

        # set the default graphic to display before the option label
        self.focus_graphic = ResourceManager().getImage(
            constants.FILES['graphics']['menu']['share']['focus'][0])
Example #2
0
File: menu.py Project: delmoras/tct
    def __init__(self, game_opts):
        # initialize the state
        State.__init__(self, '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], 30))

        # set the main menu's highlight color
        self.menu_main.set_highlight_color(pygame.Color('brown'))

        ## 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], 25))

        # 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(pygame.Color('orange'))

        ## the animated sprite group
        self.anim_sprites = pygame.sprite.RenderUpdates()

        # vertical sprite sample
        self.anim_sprites.add(VertAnimSprite(
                constants.FILES['graphics']['menu']['share']['anim'][0],
                [0, 0], ANIM_SPRITE_SPEED))

        # horizontal sprite sample
        self.anim_sprites.add(HorAnimSprite(
                constants.FILES['graphics']['menu']['share']['anim'][1],
                [0, 0], ANIM_SPRITE_SPEED))

        ## create clock and track time
        self.clock = pygame.time.Clock()
Example #3
0
    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()
Example #4
0
    def __init__(self, game_opts, *menu_opts):
 
        ## create a programmer friendly mapping stucture of the menu options
        self.options = [{'label': x[0], 'callable': x[1]} for x in menu_opts]

        ## store the game options
        self.game_opts = game_opts

        # set the default menu dimensions (these dimensions
        # are calculated depending on the font and its size)

        ## menu's width
        self.width = 0

        ## menu's height
        self.height = 0

        # set up the default coordinates of the menu

        ## menu's x coordinate
        self.x = 0

        ## menu's y coordinate
        self.y = 0

        ## the topleft corner of the screen
        self.screen_topleft_offset = (0, 0)

        ## set the default focused option
        self.option = 0

        ## set the default previous focused option
        self.option_previous = self.option

        ## set the default normal color of the menu font
        self.normal_color = pygame.Color('black')

        ## set the default focused color of the menu font
        self.focus_color = pygame.Color('red')

        ## default is to enable support of menu image on focused options
        self.image_enabled = True

        ## default is to enable support mouse on menu
        self.mouse_enabled = True

        ## set mouse focusing at unknown at default
        self.mouse_focus = None
        self._font = None

        ## set a default font and its size (also fix size)
        self.font = pygame.font.Font(None, FONT_SIZE)
        self._fix_size()

        ## set the default sound to play when an option is focused
        self.focus_sound = load_sound(
             constants.FILES['sounds']['menu']['share']['focus'][0])

        ## set the default sound to play when an option is entered
        self.select_sound = load_sound(
             constants.FILES['sounds']['menu']['share']['sel'][0])

        ## set the default graphic to display before the option label
        self.focus_graphic = load_image(
             constants.FILES['graphics']['menu']['share']['focus'][0])[0]
    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()
Example #6
0
    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()