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')
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')
def logic(self): enemysquadron.update() blockgrid.update() self._collision_grid.update() GameState.logic(self) if self._time > -1 and self._game_running: #If this is a timed game... self._time -= 1 if not self._time: #If we run out of time... gamedata.lives = 0 enemysquadron.increase_difficulty() if self._game_running: gamedata.alarm = blockgrid.is_above_threshold() config.loop_sound(ALARM if gamedata.alarm else None) else: config.loop_sound(None) if self._game_running and (not gamedata.lives or Block.block_full): #If we run out of lives or the blocks go past the top of the screen... pygame.mixer.music.fadeout(FADE_TIME) self._ship.change_state(Ship.STATES.DYING) self._ufo.change_state(UFO.STATES.GAMEOVER) self._ufo.kill() enemysquadron.celebrate() self._game_running = False gamedata.alarm = False elif not self._game_running: #If we've gotten a Game Over... if not self._ship.respawn_time: #Once the ship's been destroyed... for i in (self._ship, self._ship.flames, self._ship.light_column): i.kill() if not pygame.mixer.music.get_busy(): #If the song has faded out... HUD.add(self.hud_text.game_over, self.hud_text.press_fire) config.play_music(GAME_OVER_PATH) self.__game_over()
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])
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)
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)