Ejemplo n.º 1
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])