Example #1
0
    def __make_text(self):
        MENU.empty()
        
        text = config.load_text("settings", settings.get_language_code())
        a = make_text(text[4:], pos=MENU_CORNER, vspace=DIST_APART)

        b = make_text(
                      (
                       config.on_off(settings.SETTINGS['fullscreen']),
                       config.on_off(settings.SETTINGS['color_blind']),
                       settings.get_language_name(),
                       config.percent_str(settings.SETTINGS['music_volume']),
                       config.percent_str(settings.SETTINGS['sound_volume']),
                       "",
                       "",
                       ""
                       ),
                      pos=(MENU_CORNER[0] + DIST_APART_STATUS, MENU_CORNER[1]),
                      vspace=DIST_APART
                     )
        a[-1].center()

        self.hud_title = make_text(text[0], TITLE_LOCATION).center()
        self.menu      = SETTINGS_KEYS(*zip(a, b))
        MENU.add(self.hud_title, a, b)
Example #2
0
    def __init__(self, *args, **kwargs):
        super().__init__()
        ### Local Variables ####################################################
        text = config.load_text('menu', settings.get_language_code())
        to_game = lambda a=-1: partial(self.change_state, InGameState, time=a)
        to_screen = lambda x: partial(self.change_state, x, next=MainMenu)
        ########################################################################

        ### Object Attributes ##################################################
        self.group_list = (bg.STARS_GROUP, GRID_BG, HUD, MENU)

        self.instructions = make_text(text[:2],
                                      pos=(0, config.SCREEN_HEIGHT - 48),
                                      vspace=INSTRUCTION_DIST)
        self.menu = make_text(text[2:], pos=(0, MENU_TOP), vspace=DIST_APART)

        self.menu_actions = (
            to_game(),
            to_game(120),
            to_game(300),
            to_screen(HighScoreState),
            to_screen(HelpScreen),
            to_screen(SettingsMenu),
            to_screen(AboutScreen),
            exit,
        )
        ########################################################################

        ### Preparation ########################################################
        TITLE.rect.top = TITLE_TOP
        HUD.add(TITLE, self.hud_cursor,
                (i.center() for i in self.instructions))
        MENU.add(j.center() for j in self.menu)
        GRID_BG.add(bg.EARTH, bg.GRID)
        config.play_music('title.ogg')
Example #3
0
    def __init__(self, *args, **kwargs):
        super().__init__()
        ### Local Variables ####################################################
        text      = config.load_text('menu', settings.get_language_code())
        to_game   = lambda a=-1: partial(self.change_state, InGameState, time=a)
        to_screen = lambda x   : partial(self.change_state, x, next=MainMenu)
        ########################################################################
        
        ### Object Attributes ##################################################
        self.group_list   = (bg.STARS_GROUP, GRID_BG, HUD, MENU)

        self.instructions = make_text(text[:2], pos=(0, config.SCREEN_HEIGHT - 48), vspace=INSTRUCTION_DIST)
        self.menu = make_text(text[2:], pos=(0, MENU_TOP), vspace=DIST_APART)

        self.menu_actions = (
                            to_game()                ,
                            to_game(120)             ,
                            to_game(300)             ,
                            to_screen(HighScoreState),
                            to_screen(HelpScreen    ),
                            to_screen(SettingsMenu  ),
                            to_screen(AboutScreen   ),
                            exit                     ,
                            )
        ########################################################################
        
        ### Preparation ########################################################
        TITLE.rect.top = TITLE_TOP
        HUD.add(TITLE, self.hud_cursor, (i.center() for i in self.instructions))
        MENU.add(j.center() for j in self.menu)
        GRID_BG.add(bg.EARTH, bg.GRID)
        config.play_music('title.ogg')
Example #4
0
 def __sync_scores(self):
     '''
     Synchronizes the leaderboard.
     '''
     if self.current_table >= len(score_tables) / 2:
     #If we're in the half of the table list that's online...
         langcode = settings.get_language_code()
         text     = config.load_text('highscore', langcode)
         error = None
         try:
             MENU.remove(self.online)
             self.__get_online()
             self.__submit_online()
         except HTTPError as e:
             error = "%s (%d)" % (e.reason, e.getcode())
         except URLError as e:
             error = text[10]
         except (SyntaxError, timeout) as e:
             error = text[11]
         except (ConnectionError, ValueError) as e:
             error = text[12]
         
         MENU.remove(self.online)
         if error is not None:
             ERROR.play()
             self.online.fail.image = make_text(' '.join([text[9], error]), surfaces=True)
             self.online.fail.rect.size  = self.online.fail.image.get_size()
             MENU.add(self.online.fail.center())
         else:
             MENU.remove(self.hud_scores[self.current_table])
             self.hud_scores = _make_tables()
             MENU.add(self.online.ok, self.hud_scores[self.current_table])
Example #5
0
    def __init__(self, *args, **kwargs):
        ### Local Variables ####################################################
        ALIEN_FRAMES = enemy.ENEMY_FRAMES_COLOR_BLIND if settings.SETTINGS["color_blind"] else enemy.ENEMY_FRAMES
        BLOCK_FRAMES = block._block_frames_color_blind if settings.SETTINGS["color_blind"] else block._block_frames
        go_back = partial(self.change_state, kwargs["next"])
        langcode = settings.get_language_code()
        AB = ALIEN_BLOCK_POS[langcode]
        ########################################################################

        ### Object Attributes ##################################################
        self.group_list = (bg.STARS_GROUP, GRID_BG, TEXT, SPRITES)
        self.key_actions = {K_ESCAPE: go_back, K_SPACE: go_back, K_RETURN: go_back}

        self.aliens = (HudObject(ALIEN_FRAMES[id(color.LIST[i])][0], (AB(i), ALIEN_Y)) for i in range(len(color.LIST)))
        self.blocks = (HudObject(BLOCK_FRAMES[id(color.LIST[j])][-1], (AB(j), BLOCK_Y)) for j in range(len(color.LIST)))
        self.ship = HudObject(player.FRAMES[0], SHIP_POS[langcode])
        self.ufo = HudObject(ufo.UFO_FRAMES[id(choice(color.LIST))][0], UFO_POS[langcode])

        self._ufoanim = 0.0
        self.hud_text = make_text(config.load_text("help", langcode), pos=TOP_LEFT, vspace=DIST_APART)
        ########################################################################

        ### Preparation ########################################################
        player.FRAMES[0].set_alpha(255)
        self.hud_text[-1].center()
        SPRITES.add(self.aliens, self.blocks, self.ship, self.ufo)
        TEXT.add(self.hud_text)
        GRID_BG.add(bg.EARTH, bg.GRID)
Example #6
0
    def __sync_scores(self):
        '''
        Synchronizes the leaderboard.
        '''
        if self.current_table >= len(score_tables) / 2:
            #If we're in the half of the table list that's online...
            langcode = settings.get_language_code()
            text = config.load_text('highscore', langcode)
            error = None
            try:
                MENU.remove(self.online)
                self.__get_online()
                self.__submit_online()
            except HTTPError as e:
                error = "%s (%d)" % (e.reason, e.getcode())
            except URLError as e:
                error = text[10]
            except (SyntaxError, timeout) as e:
                error = text[11]
            except (ConnectionError, ValueError) as e:
                error = text[12]

            MENU.remove(self.online)
            if error is not None:
                ERROR.play()
                self.online.fail.image = make_text(' '.join([text[9], error]),
                                                   surfaces=True)
                self.online.fail.rect.size = self.online.fail.image.get_size()
                MENU.add(self.online.fail.center())
            else:
                MENU.remove(self.hud_scores[self.current_table])
                self.hud_scores = _make_tables()
                MENU.add(self.online.ok, self.hud_scores[self.current_table])
Example #7
0
 def __init__(self, num, pos):
     super().__init__(hudobject.make_text(str(num), pos=pos, surfaces=True), pos)
     self.next_state = None
     self.position   = list(pos)
     self.rect       = Rect(pos, self.image.get_size())
     self.time_left  = 0
     self.change_state(ComboCounter.STATES.IDLE)
Example #8
0
 def __change_image(self, menu_entry, new_text):
     '''
     Helper method to change a menu entry's text surface.
     
     @param menu_entry: The menu entry HudObject to change
     @param new_text: The text to change menu_entry to
     '''
     menu_entry[1].image = make_text(new_text, surfaces=True)
Example #9
0
 def __change_image(self, menu_entry, new_text):
     '''
     Helper method to change a menu entry's text surface.
     
     @param menu_entry: The menu entry HudObject to change
     @param new_text: The text to change menu_entry to
     '''
     menu_entry[1].image = make_text(new_text, surfaces=True)
Example #10
0
 def __init__(self, num, pos):
     super().__init__(hudobject.make_text(str(num), pos=pos, surfaces=True),
                      pos)
     self.next_state = None
     self.position = list(pos)
     self.rect = Rect(pos, self.image.get_size())
     self.time_left = 0
     self.change_state(ComboCounter.STATES.IDLE)
Example #11
0
    def __make_text(self):
        MENU.empty()

        text = config.load_text("settings", settings.get_language_code())
        a = make_text(text[4:], pos=MENU_CORNER, vspace=DIST_APART)

        b = make_text((config.on_off(settings.SETTINGS['fullscreen']),
                       config.on_off(settings.SETTINGS['color_blind']),
                       settings.get_language_name(),
                       config.percent_str(settings.SETTINGS['music_volume']),
                       config.percent_str(
                           settings.SETTINGS['sound_volume']), "", "", ""),
                      pos=(MENU_CORNER[0] + DIST_APART_STATUS, MENU_CORNER[1]),
                      vspace=DIST_APART)
        a[-1].center()

        self.hud_title = make_text(text[0], TITLE_LOCATION).center()
        self.menu = SETTINGS_KEYS(*zip(a, b))
        MENU.add(self.hud_title, a, b)
Example #12
0
def make_score_table(table, pos, vspace, width, surfaces=False):
    '''
    Creates a visual representation of a high score table.
    @rtype: pygame.Surfaces if surfaces else HudObjects
    @return: Graphical representations of high scores

    @param table: The HighScoreTable to take the scores from
    @param pos: The position of the top-left corner
    @param vspace: The vertical space between each line in pixels
    @param width: The width of the table in characters
    '''
    scores = tuple(SCORE_FORMAT.format(i.name, i.score) for i in table.scores)
    return tuple(j.center() for j in make_text(scores, TABLE_CORNER, font=config.FONT, vspace=V_SPACE, surfaces=surfaces))
Example #13
0
    def __init__(self, *args, **kwargs):
        go_back = partial(self.change_state, kwargs['next'])
        
        self.group_list = (bg.STARS_GROUP, GRID_BG, TEXT)
        self.key_actions = {
                            K_ESCAPE : go_back,
                            K_SPACE  : go_back,
                            K_RETURN : go_back,
                           }

        self.hud_text = make_text(config.load_text('about', settings.get_language_code()), pos=TOP_LEFT, vspace=DIST_APART)

        TEXT.add(self.hud_text)
        GRID_BG.add(bg.EARTH, bg.GRID)
        for i in (0, 1, -2, -1): self.hud_text[i].center()
Example #14
0
def make_score_table(table, pos, vspace, width, surfaces=False):
    '''
    Creates a visual representation of a high score table.
    @rtype: pygame.Surfaces if surfaces else HudObjects
    @return: Graphical representations of high scores

    @param table: The HighScoreTable to take the scores from
    @param pos: The position of the top-left corner
    @param vspace: The vertical space between each line in pixels
    @param width: The width of the table in characters
    '''
    scores = tuple(SCORE_FORMAT.format(i.name, i.score) for i in table.scores)
    return tuple(j.center() for j in make_text(scores,
                                               TABLE_CORNER,
                                               font=config.FONT,
                                               vspace=V_SPACE,
                                               surfaces=surfaces))
Example #15
0
    def __init__(self, *args, **kwargs):
        go_back = partial(self.change_state, kwargs['next'])

        self.group_list = (bg.STARS_GROUP, GRID_BG, TEXT)
        self.key_actions = {
            K_ESCAPE: go_back,
            K_SPACE: go_back,
            K_RETURN: go_back,
        }

        self.hud_text = make_text(config.load_text(
            'about', settings.get_language_code()),
                                  pos=TOP_LEFT,
                                  vspace=DIST_APART)

        TEXT.add(self.hud_text)
        GRID_BG.add(bg.EARTH, bg.GRID)
        for i in (0, 1, -2, -1):
            self.hud_text[i].center()
Example #16
0
def get_combo_counter(num, pos):
    '''
    Returns a ComboCounter object, creating a new one if need be.
    
    @param num: The number to display
    @param pos: Position on-screen this ComboCounter should appear
    @type num: int
    @type pos: [float, float]
    @return: A new ComboCounter
    @rtype: ComboCounter
    '''
    if not _counters:
        _counters.add(ComboCounter(num, pos))

    counter = _counters.pop()
    counter.position = list(pos)
    counter.time_left = 0
    counter.image = hudobject.make_text(str(num), pos=pos, surfaces=True)
    counter.rect = Rect(pos, counter.image.get_size())
    return counter
Example #17
0
def get_combo_counter(num, pos):
    '''
    Returns a ComboCounter object, creating a new one if need be.
    
    @param num: The number to display
    @param pos: Position on-screen this ComboCounter should appear
    @type num: int
    @type pos: [float, float]
    @return: A new ComboCounter
    @rtype: ComboCounter
    '''
    if not _counters:
        _counters.add(ComboCounter(num, pos))
        
    counter           = _counters.pop()
    counter.position  = list(pos)
    counter.time_left = 0
    counter.image     = hudobject.make_text(str(num), pos=pos, surfaces=True)
    counter.rect      = Rect(pos, counter.image.get_size())
    return counter
Example #18
0
    def __init__(self, *args, **kwargs):
        ### Local Variables ####################################################
        ALIEN_FRAMES = enemy.ENEMY_FRAMES_COLOR_BLIND if settings.SETTINGS[
            'color_blind'] else enemy.ENEMY_FRAMES
        BLOCK_FRAMES = block._block_frames_color_blind if settings.SETTINGS[
            'color_blind'] else block._block_frames
        go_back = partial(self.change_state, kwargs['next'])
        langcode = settings.get_language_code()
        AB = ALIEN_BLOCK_POS[langcode]
        ########################################################################

        ### Object Attributes ##################################################
        self.group_list = (bg.STARS_GROUP, GRID_BG, TEXT, SPRITES)
        self.key_actions = {
            K_ESCAPE: go_back,
            K_SPACE: go_back,
            K_RETURN: go_back,
        }

        self.aliens = (HudObject(ALIEN_FRAMES[id(color.LIST[i])][0],
                                 (AB(i), ALIEN_Y))
                       for i in range(len(color.LIST)))
        self.blocks = (HudObject(BLOCK_FRAMES[id(color.LIST[j])][-1],
                                 (AB(j), BLOCK_Y))
                       for j in range(len(color.LIST)))
        self.ship = HudObject(player.FRAMES[0], SHIP_POS[langcode])
        self.ufo = HudObject(ufo.UFO_FRAMES[id(choice(color.LIST))][0],
                             UFO_POS[langcode])

        self._ufoanim = 0.0
        self.hud_text = make_text(config.load_text('help', langcode),
                                  pos=TOP_LEFT,
                                  vspace=DIST_APART)
        ########################################################################

        ### Preparation ########################################################
        player.FRAMES[0].set_alpha(255)
        self.hud_text[-1].center()
        SPRITES.add(self.aliens, self.blocks, self.ship, self.ufo)
        TEXT.add(self.hud_text)
        GRID_BG.add(bg.EARTH, bg.GRID)
Example #19
0
    def __init__(self, *args, **kwargs):
        super().__init__()
        ### Local Variables ####################################################
        cursor_up = partial(self._move_cursor, -1)
        cursor_down = partial(self._move_cursor, 1)
        ########################################################################

        ### Object Attributes ##################################################
        self.cursor_index = 0
        self.hud_cursor = make_text("\u2192", (0, 0))
        self.menu_actions = ()
        self.key_actions = {
            K_RETURN: self._enter_selection,
            K_SPACE: self._enter_selection,
            K_UP: cursor_up,
            K_w: cursor_up,
            K_DOWN: cursor_down,
            K_s: cursor_down,
            K_ESCAPE: sys.exit,
            K_PRINT: config.take_screenshot,
            K_F12: config.take_screenshot,
            K_SYSREQ: config.take_screenshot,
        }
Example #20
0
 def __init__(self, *args, **kwargs):
     super().__init__()
     ### Local Variables ####################################################
     cursor_up   = partial(self._move_cursor, -1)
     cursor_down = partial(self._move_cursor,  1)
     ########################################################################
     
     ### Object Attributes ##################################################
     self.cursor_index = 0
     self.hud_cursor   = make_text("\u2192", (0, 0))
     self.menu_actions = ()
     self.key_actions  = {
                          K_RETURN : self._enter_selection ,
                          K_SPACE  : self._enter_selection ,
                          K_UP     : cursor_up             ,
                          K_w      : cursor_up             ,
                          K_DOWN   : cursor_down           ,
                          K_s      : cursor_down           ,
                          K_ESCAPE : sys.exit              ,
                          K_PRINT  : config.take_screenshot,
                          K_F12    : config.take_screenshot,
                          K_SYSREQ : config.take_screenshot,
                         }
Example #21
0
 def render(self):  
     if self.entering_name and (self.entry_name != self.last_entry_name):
     #If we're entering our name for a high score...
         self.hud_name.image = make_text(''.join(self.entry_name), surfaces=True)
     super().render()
Example #22
0
    def __init__(self, *args, **kwargs):
        super().__init__()
        ### Local Variables ####################################################
        char_up     = partial(self.__char_move   ,  1)
        char_down   = partial(self.__char_move   , -1)
        table_left  = partial(self.__switch_table, -1)
        table_right = partial(self.__switch_table,  1)
        langcode  = settings.get_language_code()
        text      = config.load_text('highscore', langcode)
        titles    = config.load_text('menu', langcode)[2:5]
        titles   += tuple(map(lambda x: " ".join((x, text[3])), titles))
        ########################################################################
        
        ### Object Attributes ##################################################
        self._mode         = kwargs['mode'] if 'mode' in kwargs else -1
        self.current_table = score_table_dict[self._mode]
        self.entering_name = False
        self.key_actions = {
                            K_LEFT  : table_left        ,
                            K_a     : table_left        ,
                            K_RIGHT : table_right       ,
                            K_d     : table_right       ,
                            K_UP    : char_up           ,
                            K_w     : char_up           ,
                            K_DOWN  : char_down         ,
                            K_s     : char_down         ,
                            K_RETURN: self.__enter_char ,
                            K_SPACE : self.__sync_scores,
                            K_ESCAPE: partial(self.change_state, kwargs['next']),
                           }
        self.group_list    = (bg.STARS_GROUP, GRID_BG, MENU)
        self.hud_titles    = tuple(make_text(i, SCORE_TABLE_X).center() for i in titles)
        self.hud_scores    = _make_tables()
        self.online        = ONLINE_TEXT(*make_text(text[4:10], INSTRUCTIONS_X, vspace=0))
        ########################################################################

        ### Preparation ########################################################
        for i in self.online: i.center()
             
        if 'score' in kwargs:
        #If we just finished a game...
            config.play_music('score.ogg')
            #Whether or not we got a high score, play the special music.
            self.key_actions[K_SPACE] = self.__enter_char
            
            if kwargs['score'] > score_tables[score_table_dict[self._mode]].lowest_score():
            #If we just got a high score...
                self.instructions = make_text(
                                              text[:3],
                                              pos=INSTRUCTIONS_X,
                                              vspace=INSTRUCT_DIST_APART
                                             )
                self._score          = kwargs['score']
                self.alphanum_index  = 0
                self.entering_name   = True
                self.entry_name      = ['A']
                self.hud_name        = make_text(''.join(self.entry_name), ENTRY_NAME_POS)
                self.last_entry_name = self.entry_name
                self.name_index      = 0
                MENU.add(self.instructions, self.hud_name)

        m = score_table_dict[self._mode]
        MENU.add(self.hud_scores[m], self.hud_titles[m])
        GRID_BG.add(bg.EARTH, bg.GRID)
Example #23
0
 def render(self):
     if self.entering_name and (self.entry_name != self.last_entry_name):
         #If we're entering our name for a high score...
         self.hud_name.image = make_text(''.join(self.entry_name),
                                         surfaces=True)
     super().render()
Example #24
0
    def __init__(self, *args, **kwargs):
        super().__init__()
        ### Local Variables ####################################################
        char_up = partial(self.__char_move, 1)
        char_down = partial(self.__char_move, -1)
        table_left = partial(self.__switch_table, -1)
        table_right = partial(self.__switch_table, 1)
        langcode = settings.get_language_code()
        text = config.load_text('highscore', langcode)
        titles = config.load_text('menu', langcode)[2:5]
        titles += tuple(map(lambda x: " ".join((x, text[3])), titles))
        ########################################################################

        ### Object Attributes ##################################################
        self._mode = kwargs['mode'] if 'mode' in kwargs else -1
        self.current_table = score_table_dict[self._mode]
        self.entering_name = False
        self.key_actions = {
            K_LEFT: table_left,
            K_a: table_left,
            K_RIGHT: table_right,
            K_d: table_right,
            K_UP: char_up,
            K_w: char_up,
            K_DOWN: char_down,
            K_s: char_down,
            K_RETURN: self.__enter_char,
            K_SPACE: self.__sync_scores,
            K_ESCAPE: partial(self.change_state, kwargs['next']),
        }
        self.group_list = (bg.STARS_GROUP, GRID_BG, MENU)
        self.hud_titles = tuple(
            make_text(i, SCORE_TABLE_X).center() for i in titles)
        self.hud_scores = _make_tables()
        self.online = ONLINE_TEXT(
            *make_text(text[4:10], INSTRUCTIONS_X, vspace=0))
        ########################################################################

        ### Preparation ########################################################
        for i in self.online:
            i.center()

        if 'score' in kwargs:
            #If we just finished a game...
            config.play_music('score.ogg')
            #Whether or not we got a high score, play the special music.
            self.key_actions[K_SPACE] = self.__enter_char

            if kwargs['score'] > score_tables[score_table_dict[
                    self._mode]].lowest_score():
                #If we just got a high score...
                self.instructions = make_text(text[:3],
                                              pos=INSTRUCTIONS_X,
                                              vspace=INSTRUCT_DIST_APART)
                self._score = kwargs['score']
                self.alphanum_index = 0
                self.entering_name = True
                self.entry_name = ['A']
                self.hud_name = make_text(''.join(self.entry_name),
                                          ENTRY_NAME_POS)
                self.last_entry_name = self.entry_name
                self.name_index = 0
                MENU.add(self.instructions, self.hud_name)

        m = score_table_dict[self._mode]
        MENU.add(self.hud_scores[m], self.hud_titles[m])
        GRID_BG.add(bg.EARTH, bg.GRID)
Example #25
0
    def __init__(self, *args, **kwargs):
        '''
        @ivar _collision_grid: Objects that collide with others
        @ivar _game_running: True if we haven't gotten a Game Over
        @ivar group_list: list of pygame.Groups, rendered in ascending order
        @ivar hud_text: dict of HUD items that give info to the player
        @ivar key_actions: dict of functions to call when a given key is pressed
        @ivar _mouse_actions: dict of Blocks to drop on mouse click, only if config.DEBUG
        @ivar _ship: The player character
        @ivar _time: Time limit for the game in seconds (no limit if 0)
        @ivar _ufo: The UFO_GROUP object that, when shot, can destroy many blocks
        '''
        from game.mainmenu import MainMenu
        ### Local Variables ####################################################
        global GAME_TEXT
        GAME_TEXT = config.load_text('ingame', settings.get_language_code())
        rect      = config.SCREEN_RECT
        ########################################################################
        
        ### Object Attributes ##################################################
        self._game_running   = True
        self.group_list      = [bg.STARS_GROUP, BG, BLOCKS, UFO_GROUP, ENEMIES, ENEMY_BULLETS, PLAYER, PARTICLES, HUD]
        self._collision_grid = CollisionGrid(4, 4, 1, self.group_list)
        self.hud_text        = HUD_TEXT(
                                        make_text(''          , SCORE_LOCATION),
                                        make_text(''          , LIVES_LOCATION),
                                        make_text(''          , TIME_LOCATION ).center(),
                                        make_text(GAME_TEXT[2], GAME_OVER_LOC ).center(),
                                        make_text(GAME_TEXT[3], FIRE_LOCATION ).center(),
                                        make_text(GAME_TEXT[4], WAVE_LOCATION ).center(),
                                        make_text(GAME_TEXT[5], GAME_OVER_LOC ).center(),
                                       )
        self._ship          = Ship()
        self.key_actions    = {
                               K_ESCAPE: partial(self.change_state, MainMenu)               ,
                               K_F1    : config.toggle_fullscreen                           ,
                               K_SPACE : self._ship.on_fire_bullet                          ,
                               K_c     : null_if_debug(blockgrid.clean_up)                  ,
                               K_e     : null_if_debug(partial(self._ship.instadie, None))  ,
                               K_f     : null_if_debug(config.toggle_frame_limit)           ,
                               K_i     : null_if_debug(self.__ship_life)                    ,
                               K_k     : partial(self._ship.change_state, Ship.STATES.DYING),
                               K_p     : self._pause_game                                   ,
                               K_u     : null_if_debug(self.__add_ufo)                      ,
                               K_PRINT : config.take_screenshot,
                               K_F12   : config.take_screenshot,
                               K_SYSREQ: config.take_screenshot,
                              }
        self._mode          = kwargs['time'] if 'time' in kwargs else -1
        self._time          = self._mode * 60 + 60 #In frames
        self._ufo           = UFO()
        ########################################################################

        ### Preparation ########################################################
        PLAYER.add(self._ship, self._ship.flames, self._ship.my_bullet, self._ship.light_column)
        UFO_GROUP.add(self._ufo)
        HUD.add(self.hud_text.score, self.hud_text.wave)
        if self._mode > -1:
        #If this is a time attack mode...
            HUD.add(self.hud_text.time)
            gamedata.lives = 1
        else:
            HUD.add(self.hud_text.lives)

        global DEBUG_KEYS
        if not config.DEBUG and DEBUG_KEYS:
        #If this is a release build...
            for i in DEBUG_KEYS:
            #For every debug action...
                del self.key_actions[i]
            DEBUG_KEYS = None

        BG.add(bg.EARTH, bg.GRID)
        enemysquadron.reset()
        enemysquadron.start()
        config.play_music(MUSIC_PATHS[self._mode])