def character_selection(constants, con, panel): character_menu(con, constants['screen_width'], constants['screen_height']) libtcod.console_flush() key = libtcod.Key() mouse = libtcod.Mouse() while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event( libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse) action = handle_character_selection(key) BandL = action.get('B&L') SandV = action.get('S&V') Mix = action.get('Mix') if BandL: fighter_component = Fighter( const.Base_Line_Fighter_Component_Value['hp'], const.Base_Line_Fighter_Component_Value['defense'], const.Base_Line_Fighter_Component_Value['power']) character = const.Base_Line_Player_tile equipable_component = const.Base_Line_Equipable_Component wearable_component = const.Base_Line_Wearable_Component player, entities, game_map, message_log, game_state = get_game_variables( constants, fighter_component, character, equipable_component, wearable_component) play_game(player, entities, game_map, message_log, con, panel, constants) elif SandV: fighter_component = Fighter( const.Serve_And_Volley_Fighter_Component_Value['hp'], const.Serve_And_Volley_Fighter_Component_Value['defense'], const.Serve_And_Volley_Fighter_Component_Value['power']) character = const.Serve_And_Volley_Player_tile equipable_component = const.Serve_And_Volley_Equipable_Component wearable_component = const.Serve_And_Volley_Wearable_Component player, entities, game_map, message_log, game_state = get_game_variables( constants, fighter_component, character, equipable_component, wearable_component) play_game(player, entities, game_map, message_log, con, panel, constants) elif Mix: character = const.Mixed_Player_tile fighter_component = Fighter( const.Mixed_Fighter_Component_Value['hp'], const.Mixed_Fighter_Component_Value['defense'], const.Mixed_Fighter_Component_Value['power']) equipable_component = const.Mixed_Equipable_Component wearable_component = const.Mixed_Wearable_Component player, entities, game_map, message_log, game_state = get_game_variables( constants, fighter_component, character, equipable_component, wearable_component) play_game(player, entities, game_map, message_log, con, panel, constants)
def testMessageLog(self): constants = initialize_new_game.get_constants() new_game = initialize_new_game.get_game_variables(constants) message_log = new_game[3] self.assertTrue(message_log.messages == []) self.assertTrue(message_log.width <= constants.get('screen_width')) self.assertTrue(message_log.height <= constants.get('screen_height'))
def main(): constants = get_constants() libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GRAYSCALE | libtcod.FONT_LAYOUT_TCOD) libtcod.console_init_root(constants['screen_width'], constants['screen_height'], constants['window_title'], False) con = libtcod.console_new(constants['screen_width'], constants['screen_height']) panel = libtcod.console_new(constants['screen_width'], constants['panel_height']) player = None entities = [] game_map = None message_log = None game_state = None show_main_menu = True show_load_error_message = False main_menu_background_image = libtcod.image_load('menu_background.png') key = libtcod.Key() mouse = libtcod.Mouse() while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse) if show_main_menu: main_menu(con, main_menu_background_image, constants['screen_width'], constants['screen_height']) if show_load_error_message: message_box(con, 'No save game to load', 50, constants['screen_width'], constants['screen_height']) libtcod.console_flush() action = handle_main_menu(key) new_game = action.get('new_game') load_saved_game = action.get('load_game') exit_game = action.get('exit') if show_load_error_message and (new_game or load_saved_game or exit_game): show_load_error_message = False elif new_game: player, entities, game_map, message_log, game_state = get_game_variables(constants) game_state = GameStates.PLAYERS_TURN show_main_menu = False elif load_saved_game: try: player, entities, game_map, message_log, game_state = load_game() show_main_menu = False except FileNotFoundError: show_load_error_message = True elif exit_game: break else: libtcod.console_clear(con) play_game(player, entities, game_map, message_log, game_state, con, panel, constants) show_main_menu = True
def testMakeMap(self): #carte = game_map.GameMap(30, 30) constants = initialize_new_game.get_constants() player, entities, game_map, message_log, game_state = initialize_new_game.get_game_variables( constants) game_map.make_map(5, 5, 8, 20, 20, player, entities, constants.get('graphics')) self.assertNotEqual(len(entities), 1) for e in entities: if e.fighter: self.assertTrue(e.blocks)
def handle_main_menu_operations(con, main_menu_background_image, constants, show_load_error_message, key, mouse, player, entities, game_map, message_log, game_state, show_main_menu): exit_game_break = False main_menu(con, main_menu_background_image, constants['screen_width'], constants['screen_height'], constants['window_title'], key, mouse, game_state) if show_load_error_message: message_box(con, 'No save game to load', 50, constants['screen_width'], constants['screen_height']) libtcod.console_flush() options = get_main_menu_options() action = handle_main_menu(key, mouse, game_state, options, con, constants, player) new_game = action.get(Action.NEW_GAME) load_saved_game = action.get(Action.LOAD_GAME) exit_game = action.get(Action.EXIT) if show_load_error_message and (new_game or load_saved_game or exit_game): show_load_error_message = False elif new_game: reset_game() player, entities, game_map, message_log, game_state = get_game_variables( constants) game_state = GameStates.PLAYERS_TURN show_main_menu = False elif load_saved_game: try: player, entities, game_map, message_log, game_state = load_game() show_main_menu = False except FileNotFoundError: show_load_error_message = True elif exit_game: exit_game_break = True return exit_game_break, action, show_load_error_message, player, entities, game_map, message_log, game_state, show_main_menu
def main(): constants = get_constants() libtcod.console_set_custom_font( 'TiledFont.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD, 32, 10) libtcod.console_init_root(constants['screen_width'], constants['screen_height'], constants['window_title'], False) con = libtcod.console_new(constants['screen_width'], constants['screen_height']) panel = libtcod.console_new(constants['screen_width'], constants['panel_height']) player = None entities = [] game_map = None message_log = None game_state = None show_main_menu = True show_character_screen = False start_game = None show_load_error_message = False main_menu_background_image = libtcod.image_load('menu_background.png') key = libtcod.Key() mouse = libtcod.Mouse() while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event( libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse) if show_main_menu: main_menu(con, main_menu_background_image, constants['screen_width'], constants['screen_height']) if show_load_error_message: message_box(con, 'No save game to load', 50, constants['screen_width'], constants['screen_height']) libtcod.console_flush() action = handle_main_menu(key) new_game = action.get('new_game') load_saved_game = action.get('load_game') exit_game = action.get('exit') choose_fighter = action.get('choose_fighter') if show_load_error_message and (new_game or load_saved_game or exit_game): show_load_error_message = False elif new_game: player, entities, game_map, message_log, game_state = get_game_variables( constants, 'barbarian') game_state = GameStates.PLAYER_TURN show_main_menu = False start_game = True elif load_saved_game: try: player, entities, game_map, message_log, game_state = load_game( ) show_main_menu = False start_game = True except FileNotFoundError: show_load_error_message = True elif choose_fighter: show_main_menu = False #show_character_screen = True new_character_screen(con, main_menu_background_image, constants['screen_width'], constants['screen_height']) libtcod.console_flush() '''TODO: Задать переменную, отвечающую за то, что открыто ли окно choose_fighter или нет''' action_character_menu = handle_new_character_menu_keys(key) warrior = 'warrior' thief = 'thief' barbarian = 'barbarian' exit_character_menu = 'exit' if action_character_menu.get('warrior') == warrior: player, entities, game_map, message_log, game_state = get_game_variables( constants, warrior) game_state = GameStates.PLAYER_TURN #show_character_screen = False #show_main_menu = False #start_game = True #start_game = True choose_fighter = False elif action_character_menu.get('thief') == thief: player, entities, game_map, message_log, game_state = get_game_variables( constants, thief) #game_state = GameStates.PLAYER_TURN #show_character_screen = False choose_fighter = False elif action_character_menu.get('barbarian') == barbarian: player, entities, game_map, message_log, game_state = get_game_variables( constants, barbarian) game_state = GameStates.PLAYER_TURN #show_character_screen = False elif action_character_menu.get('exit') == exit_character_menu: show_character_screen = False show_main_menu = True main_menu(con, main_menu_background_image, constants['screen_width'], constants['screen_height']) libtcod.console_flush() show_character_screen = False elif choose_fighter == False: start_game = True game_state.PLAYER_TURN elif exit_game: break elif start_game == True: libtcod.console_clear(con) play_game(player, entities, game_map, message_log, game_state, con, panel, constants) show_main_menu = True
def main(): """ L'une des deux fonctions principales du jeu, elle est appelée une seule et unique fois : au démarrage du jeu. Elle a la charge de gérer le choix d'affichage des menus et les réactions aux inputs du joueur. Lorsque le joueur quitte un menu pour retourner en jeu, elle appelle la deuxième fonction de ce module : play_game Parametres: ---------- Aucun Renvoi: ------- Aucun """ # Initialise le jeu en commencant par afficher le menu principal constants = get_constants() # The font has 32 chars in a row, and there's a total of 10 rows. Increase the "10" when you add new rows to the sample font file libtcod.console_set_custom_font('textures.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD, 32, 10) load_customfont() libtcod.console_init_root(constants['screen_width'], constants['screen_height'], "Rogue doesn't like", False) con = libtcod.console_new(constants['screen_width'], constants['screen_height']) panel = libtcod.console_new(constants['screen_width'], constants['panel_height']) player = None entities = [] game_map = None message_log = None game_state = None show_main_menu = True show_load_error_message = False show_command_menu = False show_scores = False main_menu_background_image = libtcod.image_load('menu_background.png') play_bg_music = False bg_music = sm.choose_sound(constants.get('sound').get('background_music')) key = libtcod.Key() mouse = libtcod.Mouse() score = (1, 0) while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse) # Si le menu principal est affiche : if show_main_menu: main_menu(con, main_menu_background_image, constants['screen_width'], constants['screen_height']) if show_load_error_message: message_box(con, 'Rien a charger', 70, constants['screen_width'], constants['screen_height']) libtcod.console_flush() action = handle_main_menu(key) new_game = action.get('new_game') load_saved_game = action.get('load_game') exit_game = action.get('exit') sound = action.get('sound') command = action.get('command') back_to_game = action.get('back_to_game') scores = action.get('scores') if show_load_error_message and (new_game or load_saved_game or exit_game): show_load_error_message = False # Cree une nouvelle partie elif new_game: if score != (1, 0): save_score(score) player, entities, game_map, message_log, game_state = get_game_variables(constants) game_state = GameStates.PLAYERS_TURN show_main_menu = False # Charge une partie existante, si possible elif load_saved_game: try: player, entities, game_map, message_log, game_state, score = load_game() show_main_menu = False except FileNotFoundError: show_load_error_message = True elif exit_game: if score != (1, 0): save_game(player, entities, game_map, message_log, game_state, score) sm.close_sound() break # Lit ou arrete la musique de fond elif sound: play_bg_music = not play_bg_music bg_music.playpause() elif command: show_command_menu = True show_main_menu = False elif back_to_game and show_main_menu and game_state != GameStates.PLAYER_DEAD: show_main_menu = False elif scores: show_main_menu = False show_scores = True # Affiche le menu des commandes elif show_command_menu: action = handle_main_menu(key) command_menu(con, main_menu_background_image, constants['screen_width'], constants['screen_height']) libtcod.console_flush() back_to_game = action.get('back_to_game') if back_to_game: show_main_menu = True show_command_menu = False libtcod.console_clear(con) # Affiche les trois meilleurs scores et le dernier elif show_scores: action = handle_main_menu(key) scores_menu(con, main_menu_background_image, constants['screen_width'], constants['screen_height']) libtcod.console_flush() back_to_game = action.get('back_to_game') if back_to_game: show_main_menu = True show_scores = False libtcod.console_clear(con) # Lance une partie else: libtcod.console_clear(con) player, entities, game_map, message_log, game_state, bg_music, play_bg_music, score = play_game(player, entities, game_map, message_log, game_state, con, panel, constants, bg_music, play_bg_music, score) if game_state == GameStates.PLAYER_DEAD: show_scores = True else: show_main_menu = True
def main(): """Main function for the game.""" constants = get_constants() # setup Font font_path = '/home/bobbias/roguelike/arial10x10.png' font_flags = tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD tcod.console_set_custom_font(font_path, font_flags) # init screen # window_title = 'Python 3 libtcod tutorial' con = tcod.console_init_root(constants['screen_width'], constants['screen_height'], order='F', renderer=tcod.RENDERER_OPENGL2) panel = tcod.console_new(constants['screen_width'], constants['panel_height']) player = None entities = [] game_map = None message_log = None game_state = None show_main_menu = True show_load_error_message = False main_menu_background_imgage = tcod.image_load('menu_background.png') key = tcod.Key() mouse = tcod.Mouse() while not tcod.console_is_window_closed(): tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS | tcod.EVENT_MOUSE, key, mouse) if show_main_menu: main_menu(con, main_menu_background_imgage, constants['screen_width'], constants['screen_height']) if show_load_error_message: message_box(con, 'No save game to load!', 50, constants['screen_width'], constants['screen_height']) tcod.console_flush() action = handle_main_menu(key) new_game = action.get('new_game') load_saved_game = action.get('load_saved_game') exit_game = action.get('exit') if show_load_error_message and (new_game or load_saved_game or exit_game): show_load_error_message = False elif new_game: player, entities, game_map, message_log, game_state = get_game_variables( constants) game_state = GameStates.PLAYERS_TURN show_main_menu = False elif load_saved_game: try: player, entities, game_map, message_log, game_state = load_game( ) show_main_menu = False except FileNotFoundError: show_load_error_message = True elif exit_game: break else: tcod.console_clear(con) play_game(player, entities, game_map, message_log, game_state, con, panel, constants) show_main_menu = True
def play_game(player, entities, game_map, message_log, game_state, con, panel, constants): fov_recompute = True fov_map = initialize_fov(game_map) previous_game_state = game_state targeting_item = None message_log.add_message( Message(f'You are a ghost. You have nothing.', libtcod.white)) message_log.add_message( Message(f'Use the arrow keys to move', libtcod.white)) message_log.add_message( Message(f'Press \'p\' to possess a creature and gain its abilities...', libtcod.white)) message_log.add_message( Message(f'(Mouse over symbols for more information)', libtcod.white)) first_body = True first_inventory = True mouse_event = None while True: key_event = None left_click = None right_click = None exit_game = False for event in libtcod.event.get(): #print(f"Got Event: {event.type}") if event.type in ("QUIT"): print("QUIT event: Exiting") raise SystemExit() if event.type == "KEYDOWN": if event.sym == libtcod.event.K_ESCAPE: print(f"{event.type} K_ESCAPE: Exiting") exit_game = True else: key_event = event #print(f"Got Event: {event.type}: {key}") if event.type == "MOUSEMOTION": mouse_event = event if event.state & libtcod.event.BUTTON_LMASK: left_click = mouse_event if event.state & libtcod.event.BUTTON_RMASK: right_click = mouse_event if exit_game: break fov_radius = player.fighter.fov( ) if player.fighter else Constants.min_fov_radius if fov_recompute: recompute_fov(fov_map, player.x, player.y, fov_radius, Constants.fov_light_walls, Constants.fov_algorithm) render_all(con, panel, entities, player, game_map, fov_map, fov_recompute, message_log, Constants.screen_width, Constants.screen_height, Constants.bar_width, Constants.panel_height, Constants.panel_y, mouse_event, Constants.colors, game_state) fov_recompute = False libtcod.console_flush() clear_all(con, entities) action = handle_keys(key_event, game_state) move = action.get('move') wait = action.get('wait') pickup = action.get('pickup') show_inventory = action.get('show_inventory') drop_inventory = action.get('drop_inventory') inventory_index = action.get('inventory_index') take_stairs = action.get('take_stairs') level_up = action.get('level_up') show_character_screen = action.get('show_character_screen') exit = action.get('exit') fullscreen = action.get('fullscreen') possession = action.get('possession') #start_test_mode = action.get('start_test_mode') restart = action.get('restart') player_turn_results = [] if False: # start_test_mode: fighter_component = Fighter(hp=30, defense=2, power=8, body='god mode', xp=100, will_power=4) player.fighter = fighter_component player.fighter.owner = player player.inventory = Inventory(26) player.equipment = Equipment() player.inventory.owner = player player.equipment.owner = player equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=1) item = Entity(player.x, player.y, '/', libtcod.red, 'Small Dagger', equippable=equippable_component) entities.append(item) if restart: player, entities, game_map, message_log, game_state = get_game_variables( Constants) game_state = GameStates.PLAYERS_TURN fov_map = initialize_fov(game_map) fov_recompute = True con.clear() if possession: if not player.fighter: for entity in entities: if entity.fighter and entity.x == player.x and entity.y == player.y: if player.level.current_level >= entity.fighter.will_power: message_log.add_message( Message( f"You take control of the {entity.name}'s body...", libtcod.white)) if first_body: message_log.add_message( Message(f'(Press p to release it)', libtcod.gray)) first_body = False if entity.inventory and first_inventory: message_log.add_message( Message( f'(Press g to Get items, i for Inventory)', libtcod.gray)) first_inventory = False player.fighter = entity.fighter player.inventory = entity.inventory player.equipment = entity.equipment player.possessed_entity = entity player.fighter.owner = player player.char = entity.char player.render_order = entity.render_order player.name = f'Ghost/{entity.name}' entities.remove(entity) else: message_log.add_message( Message( f'The {entity.name} is too powerful for you to possess!', libtcod.yellow)) else: message_log.add_message( Message( f'You cast your spirit out of the {player.possessed_entity.name}, leaving a shambling husk behind...', libtcod.red)) ai_component = SlowMonster() zombie_name = f'Zombie {player.possessed_entity.name}' zombie_char = player.possessed_entity.char zombie = Entity(player.x, player.y, zombie_char, libtcod.desaturated_green, zombie_name, blocks=True, render_order=RenderOrder.ACTOR, fighter=player.fighter, ai=ai_component, inventory=player.inventory, equipment=player.equipment) zombie.fighter.xp = 5 zombie.fighter.owner = zombie entities.append(zombie) player.fighter = None player.inventory = None player.equipment = None player.char = ' ' player.render_order = RenderOrder.GHOST player.name = 'Ghost' if move and game_state == GameStates.PLAYERS_TURN: dx, dy = move destination_x = player.x + dx destination_y = player.y + dy if not game_map.is_blocked(destination_x, destination_y): target = get_blocking_entities_at_location( entities, destination_x, destination_y) if target and player.fighter: attack_results = player.fighter.attack(target) player_turn_results.extend(attack_results) else: player.move(dx, dy) fov_recompute = True over_entities = [ e for e in entities if e.x == player.x and e.y == player.y and e != player ] if over_entities: over_fighters = [e for e in over_entities if e.fighter] over_items = [ e for e in over_entities if not e.fighter ] if over_fighters: over_fighter = over_fighters[0] message_log.add_message( Message( f'Your shadow falls over the {over_fighter.name}...', libtcod.white)) elif over_items: if len(over_items) == 1: over_items_list = f'{over_items[0].name}' elif len(over_items) == 2: over_items_list = f'{over_items[1].name} and a {over_items[0].name}' else: over_items_list = [ n.name for n in over_items[:-1] ].join(', a ') over_items_list += "and a {over_items[-1].name}" message_log.add_message( Message(f'There is a {over_items_list} here.', libtcod.white)) if 'Staircase' in [e.name for e in over_items ] and player.fighter: message_log.add_message( Message( f'(Press enter/return to use stairs)', libtcod.gray)) game_state = GameStates.ENEMY_TURN elif wait: game_state = GameStates.ENEMY_TURN elif pickup and game_state == GameStates.PLAYERS_TURN: if player.inventory: for entity in entities: if entity.item and entity.x == player.x and entity.y == player.y: pickup_results = player.inventory.add_item(entity) player_turn_results.extend(pickup_results) break else: message_log.add_message( Message('There is nothing here to pick up!', libtcod.yellow)) elif player.fighter: message_log.add_message( Message('This creature cannot carry items.', libtcod.yellow)) else: message_log.add_message( Message( "You can't pick up items without a body of some kind...", libtcod.yellow)) if show_inventory: if player.inventory: previous_game_state = game_state game_state = GameStates.SHOW_INVENTORY elif player.fighter: message_log.add_message( Message('This creature cannot carry items.', libtcod.yellow)) else: message_log.add_message( Message('You lack a body to carry items...', libtcod.yellow)) if drop_inventory: previous_game_state = game_state game_state = GameStates.DROP_INVENTORY if inventory_index is not None and player.inventory and previous_game_state != GameStates.PLAYER_DEAD and inventory_index < len( player.inventory.items): item = player.inventory.items[inventory_index] if game_state == GameStates.SHOW_INVENTORY: player_turn_results.extend( player.inventory.use(item, entities=entities, fov_map=fov_map)) elif game_state == GameStates.DROP_INVENTORY: player_turn_results.extend(player.inventory.drop_item(item)) if take_stairs and game_state == GameStates.PLAYERS_TURN: for entity in entities: if entity.stairs and entity.x == player.x and entity.y == player.y: entities = game_map.next_floor(player, message_log, constants) fov_map = initialize_fov(game_map) fov_recompute = True libtcod.console_clear(con) break else: message_log.add_message( Message('There are no stairs here.', libtcod.yellow)) if level_up: if player.fighter: if level_up == 'hp': player.fighter.base_max_hp += 20 player.fighter.hp += 20 elif level_up == 'str': player.fighter.base_power += 1 elif level_up == 'def': player.fighter.base_defense += 1 game_state = previous_game_state if show_character_screen: previous_game_state = game_state game_state = GameStates.CHARACTER_SCREEN if game_state == GameStates.TARGETING: if left_click: target_x, target_y = left_click item_use_results = player.inventory.use(targeting_item, entities=entities, fov_map=fov_map, target_x=target_x, target_y=target_y) player_turn_results.extend(item_use_results) elif right_click: player_turn_results.append({'targeting_cancelled': True}) if exit: if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY, GameStates.CHARACTER_SCREEN): game_state = previous_game_state elif game_state == GameStates.TARGETING: player_turn_results.append({'targeting_cancelled': True}) else: save_game(player, entities, game_map, message_log, game_state) return True if fullscreen: libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen()) for player_turn_result in player_turn_results: message = player_turn_result.get('message') dead_entity = player_turn_result.get('dead') item_added = player_turn_result.get('item_added') item_consumed = player_turn_result.get('consumed') item_dropped = player_turn_result.get('item_dropped') equip = player_turn_result.get('equip') targeting = player_turn_result.get('targeting') targeting_cancelled = player_turn_result.get('targeting_cancelled') xp = player_turn_result.get('xp') if message: message_log.add_message(message) if targeting_cancelled: game_state = previous_game_state message_log.add_message( Message('Targeting cancelled', libtcod.yellow)) if dead_entity: if dead_entity.fighter == player.fighter: message, game_state = kill_player(dead_entity) else: message = kill_monster(dead_entity) message_log.add_message(message) if xp: leveled_up = player.level.add_xp(xp) fighter_leveled_up = player.fighter.level.add_xp(xp) message_log.add_message( Message('You gain {0} experience points.'.format(xp), libtcod.white)) if leveled_up: message_log.add_message( Message( 'You grow stronger! You reached level {0}'.format( player.level.current_level) + '!', libtcod.green)) message_log.add_message( Message('You can now possess larger creatures...', libtcod.red)) if fighter_leveled_up: previous_game_state = game_state game_state = GameStates.LEVEL_UP if item_added: entities.remove(item_added) game_state = GameStates.ENEMY_TURN if item_consumed: game_state = GameStates.ENEMY_TURN if item_dropped: entities.append(item_dropped) game_state = GameStates.ENEMY_TURN if equip: equip_results = player.equipment.toggle_equip(equip) for equip_result in equip_results: equipped = equip_result.get('equipped') dequipped = equip_result.get('dequipped') if equipped: message_log.add_message( Message('You equipped the {0}'.format( equipped.name))) if dequipped: message_log.add_message( Message('You dequipped the {0}'.format( dequipped.name))) game_state = GameStates.ENEMY_TURN if targeting: previous_game_state = GameStates.PLAYERS_TURN game_state = GameStates.TARGETING targeting_item = targeting message_log.add_message(targeting_item.item.targeting_message) if game_state == GameStates.ENEMY_TURN: for entity in entities: if entity.ai: enemy_turn_results = entity.ai.take_turn( player, fov_map, game_map, entities) for enemy_turn_result in enemy_turn_results: message = enemy_turn_result.get('message') dead_entity = enemy_turn_result.get('dead') if message: message_log.add_message(message) if dead_entity: if dead_entity.fighter == player.fighter: message, game_state = kill_player(dead_entity) else: message = kill_monster(dead_entity) message_log.add_message(message) if game_state == GameStates.PLAYER_DEAD: break if game_state == GameStates.PLAYER_DEAD: break else: game_state = GameStates.PLAYERS_TURN
def main(): arial_font_path = app_path('assets', 'images', 'arial10x10.png') libtcod.console_set_custom_font( arial_font_path, libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) libtcod.console_init_root(Constants.screen_width, Constants.screen_height, Constants.window_title, False, libtcod.RENDERER_SDL2, vsync=False) con = libtcod.console.Console(Constants.screen_width, Constants.screen_height) panel = libtcod.console.Console(Constants.screen_width, Constants.panel_height) player = None entities = [] game_map = None message_log = None game_state = None show_main_menu = True show_load_error_message = False bg_path = app_path('assets', 'images', 'menu_fire_background.png') main_menu_background_image = libtcod.image_load(bg_path) while True: key_event = None for event in libtcod.event.get(): if event.type in ("QUIT"): print("QUIT event: Exiting") raise SystemExit() if event.type == "KEYDOWN": if event.sym == libtcod.event.K_ESCAPE: print(f"{event.type} K_ESCAPE: Exiting") raise SystemExit() else: key_event = event #print(f"Got Event: {event.type}: {key_event}") if show_main_menu: main_menu(con, main_menu_background_image, Constants.screen_width, Constants.screen_height) if show_load_error_message: message_box(con, 'No save game to load', 50, Constants.screen_width, Constants.screen_height) libtcod.console_flush() action = handle_main_menu(key_event) new_game = action.get('new_game') load_saved_game = action.get('load_game') exit_game = action.get('exit') fullscreen = action.get('fullscreen') if show_load_error_message and (new_game or load_saved_game or exit_game): show_load_error_message = False elif new_game: player, entities, game_map, message_log, game_state = get_game_variables( Constants) game_state = GameStates.PLAYERS_TURN show_main_menu = False elif load_saved_game: try: player, entities, game_map, message_log, game_state = load_game( ) show_main_menu = False except FileNotFoundError: show_load_error_message = True elif exit_game: break if fullscreen: libtcod.console_set_fullscreen( not libtcod.console_is_fullscreen()) else: con.clear() play_game(player, entities, game_map, message_log, game_state, con, panel, Constants) show_main_menu = True
def main(): #define main variables constants = get_constants() # Limit FPS to 100 so we dont kill CPUs libtcod.sys_set_fps(60) # Load font and create root console (what you see) libtcod.console_set_custom_font(os.path.join(definitions.ROOT_DIR,'Nice_curses_12x12.png'), libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_ASCII_INROW) libtcod.console_init_root(constants['screen_width'], constants['screen_height'], constants['window_title'], False) # Create game area and info area, this will be drawn to our root console so that we can see them con = libtcod.console_new(constants['screen_width'], constants['screen_height']) panel = libtcod.console_new(constants['screen_width'], constants['panel_height']) player = get_dummy_player(Warrior()) entities = [] game_map = None message_log: MessageLog = None game_state = None show_main_menu = True show_game = False show_load_error_message = False main_menu_background_image = libtcod.image_load(os.path.join(definitions.ROOT_DIR,'data','menu_background.png')) # Capture keyboard and mouse input key = libtcod.Key() mouse = libtcod.Mouse() mixer.init() mixer.music.load(os.path.join(definitions.ROOT_DIR, 'data', 'music', 'title.mp3')) #mixer.music.play(loops=-1) #Our main loop while not libtcod.console_is_window_closed(): # Check for input libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse) if show_main_menu: main_menu(con, main_menu_background_image, constants['screen_width'], constants['screen_height']) if show_load_error_message: message_box(con, 'No save game to load', 50, constants['screen_width'], constants['screen_height']) libtcod.console_flush() action = handle_main_menu(key) new_game = action.get('new_game') load_saved_game = action.get('load_game') exit_game = action.get('exit') if show_load_error_message and (new_game or load_saved_game or exit_game): show_load_error_message = False elif new_game: show_main_menu = False show_game = True elif load_saved_game: try: player, entities, game_map, message_log, game_state = load_game() show_main_menu = False except FileNotFoundError: show_load_error_message = True elif exit_game: break elif show_game == True: action = handle_role_select(key) warrior = action.get('warrior') ranger = action.get('ranger') rogue = action.get('rogue') paladin = action.get('paladin') warlock = action.get('warlock') back = action.get('exit') accept = action.get('accept') libtcod.console_clear(0) role_menu(con,constants['screen_width'],constants['screen_height'], player.role) libtcod.console_flush() if warrior: player = get_dummy_player(Warrior()) role_menu(con,constants['screen_width'],constants['screen_height'], player.role) libtcod.console_flush() if ranger: player = get_dummy_player(Ranger()) role_menu(con,constants['screen_width'],constants['screen_height'], player.role) libtcod.console_flush() if rogue: player = get_dummy_player(Rogue()) role_menu(con,constants['screen_width'],constants['screen_height'], player.role) libtcod.console_flush() if paladin: player = get_dummy_player(Paladin()) role_menu(con,constants['screen_width'],constants['screen_height'], player.role) libtcod.console_flush() if warlock: player = get_dummy_player(Warlock()) role_menu(con,constants['screen_width'],constants['screen_height'], player.role) libtcod.console_flush() if accept: player, entities, game_map, message_log, game_state = get_game_variables(constants, player) show_game = False if back: show_main_menu = True else: libtcod.console_clear(con) game_state = GameStates.PLAYERS_TURN play_game(player, entities, game_map, message_log, game_state, con, panel, constants) show_main_menu = True
def main(): consts = get_constants() tcod.console_set_custom_font( 'consolas10x10_gs_tc.png', tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD) tcod.console_init_root(consts['scrn_width'], consts['scrn_height'], consts['window_title'], False) con = tcod.console_new(consts['scrn_width'], consts['scrn_height']) panel = tcod.console_new(consts['scrn_width'], consts['panel_height']) player = None entities = [] game_map = None message_log = None game_state = None show_main_menu = True show_load_err_msg = False key = tcod.Key() mouse = tcod.Mouse() while not tcod.console_is_window_closed(): tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS | tcod.EVENT_MOUSE, key, mouse) if show_main_menu: main_menu(con, consts['scrn_width'], consts['scrn_height']) if show_load_err_msg: message_box(con, 'No save game to load', 50, consts['scrn_width'], consts['scrn_height']) tcod.console_flush() action = handle_main_menu(key) new_game = action.get('new_game') load_save = action.get('load_game') exit_game = action.get('exit') if show_load_err_msg and (new_game or load_save or exit_game): show_load_err_msg = False elif new_game: player, entities, game_map, message_log, game_state = get_game_variables( consts) game_state = GameStates.PLAYER_TURN show_main_menu = False elif load_save: try: player, entities, game_map, message_log, game_state = load_game( ) show_main_menu = False except FileNotFoundError: show_load_err_msg = True elif exit_game: break else: tcod.console_clear(con) play_game(player, entities, game_map, message_log, game_state, con, panel, consts) show_main_menu = True
def main(): ''' Loads and initializes all it needs. Starts game ''' constants = get_constants() # uses custom font image libtcod.console_set_custom_font("./art/terminal8x8_gs_ro.png", libtcod.FONT_LAYOUT_ASCII_INROW) libtcod.console_init_root(constants['screen_width'], constants['screen_height'], constants['window_title'], False) con = libtcod.console_new(constants['screen_width'], constants['screen_height']) panel = libtcod.console_new(constants['screen_width'], constants['panel_height']) player = None entities = [] game_map = None message_log = None game_state = None show_main_menu = True show_load_error_message = False # uses custom background image main_menu_background_image = libtcod.image_load('./art/background.png') key = libtcod.Key() mouse = libtcod.Mouse() while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse) if show_main_menu: main_menu(con, main_menu_background_image, constants['screen_width'], constants['screen_height']) if show_load_error_message: message_box(con, 'No save game to load', 50, constants['screen_width'], constants['screen_height']) libtcod.console_flush() action = handle_main_menu(key) new_game = action.get('new_game') load_saved_game = action.get('load_game') rules_menu = action.get('rules_menu') exit_game = action.get('exit') fullscreen = action.get('fullscreen') # toggle fullscreen if fullscreen: libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen()) if show_load_error_message and (new_game or load_saved_game or exit_game): show_load_error_message = False elif new_game: player, entities, game_map, message_log, game_state = \ get_game_variables(constants) game_state = GameStates.PLAYERS_TURN show_main_menu = False elif load_saved_game: try: player, entities, game_map, message_log, game_state = load_game() show_main_menu = False except FileNotFoundError: show_load_error_message = True elif rules_menu: show_rules() elif exit_game: break else: libtcod.console_clear(con) play_game(player, entities, game_map, message_log, game_state, con, panel, constants) show_main_menu = True
def main(): # pull variables constants = get_constants() # set graphics template (source, type, layout) # --- original setup --- # libtcod.console_set_custom_font( # 'arial10x10.png', # libtcod.FONT_TYPE_GRAYSCALE | libtcod.FONT_LAYOUT_TCOD) # --- new font file --- libtcod.console_set_custom_font( 'TiledFont.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD, 32, 10) # create screen (width, height, title, fullscreen_boolean) libtcod.console_init_root(constants['screen_width'], constants['screen_height'], constants['window_title'], False) # initialize console con = libtcod.console_new(constants['screen_width'], constants['screen_height']) panel = libtcod.console_new(constants['screen_width'], constants['panel_height']) player = None entities = [] game_map = None message_log = None game_state = None show_main_menu = True show_load_error_message = False main_menu_background_image = libtcod.image_load('menu_background.png') key = libtcod.Key() mouse = libtcod.Mouse() libtcod.console_set_fullscreen(True) # mixer.music.play(-1) # music_loop = mixer.Sound('Cave_Loop.wav') # mixer.Sound.play(music_loop) mixer.init() music_loop = mixer.Sound('Cave_Loop.wav') mixer.Sound.play(music_loop, loops=-1) while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event( libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse) if show_main_menu: main_menu(con, main_menu_background_image, constants['screen_width'], constants['screen_height']) if show_load_error_message: message_box(con, 'No save game to load', 50, constants['screen_width'], constants['screen_height']) libtcod.console_flush() action = handle_main_menu(key) new_game = action.get('new_game') load_saved_game = action.get('load_game') exit_game = action.get('exit') if show_load_error_message and (new_game or load_saved_game or exit_game): show_load_error_message = False elif new_game: player, entities, game_map, message_log, game_state = get_game_variables( constants) game_state = GameStates.PLAYER_TURN show_main_menu = False elif load_saved_game: try: player, entities, game_map, message_log, game_state = load_game( ) show_main_menu = False except FileNotFoundError: show_load_error_message = True elif exit_game: break else: libtcod.console_clear(con) play_game(player, entities, game_map, message_log, game_state, con, panel, constants) show_main_menu = True
def main(): constants = get_constants() libtcod.sys_set_fps(30) # Animate anim_time = libtcod.sys_elapsed_milli() anim_frame = 0 libtcod.console_set_custom_font( 'sprite-font.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD, 32, 48) libtcod.console_init_root(constants['screen_width'], constants['screen_height'], constants['window_title'], False) libtcod.console_set_default_background(0, colors.get('dark')) load_customfont() con = libtcod.console_new(constants['map_width'] * 3, constants['map_height'] * 2) panel = libtcod.console_new(constants['panel_width'], constants['screen_height']) tooltip = libtcod.console_new(constants['screen_width'], 1) messages_pane = libtcod.console_new(constants['message_width'], 1000) inventory_pane = libtcod.console_new(constants['message_width'], 40) player = None entities = [] game_map = None message_log = None game_state = None show_main_menu = True show_load_error_message = False main_menu_background_image_0 = libtcod.image_load('menu_background_0.png') main_menu_background_image_1 = libtcod.image_load('menu_background_1.png') main_menu_background_image_2 = libtcod.image_load('menu_background_2.png') main_menu_background_image_3 = libtcod.image_load('menu_background_3.png') log_scroll = 0 inv_scroll = 0 key = libtcod.Key() mouse = libtcod.Mouse() while not libtcod.console_is_window_closed(): anim_frame, anim_time = animation(anim_frame, anim_time) if anim_frame == 0: main_menu_background_image = main_menu_background_image_0 elif anim_frame == 1: main_menu_background_image = main_menu_background_image_1 elif anim_frame == 2: main_menu_background_image = main_menu_background_image_2 else: main_menu_background_image = main_menu_background_image_3 libtcod.sys_check_for_event( libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse) if show_main_menu: main_menu(con, main_menu_background_image, constants['screen_width'], constants['screen_height'], constants['window_title']) if show_load_error_message: message_box(con, 'No save game to load', 50, constants['screen_width'], constants['screen_height']) libtcod.console_flush() action = handle_main_menu(key) new_game = action.get('new_game') load_saved_game = action.get('load_game') exit_game = action.get('exit') if show_load_error_message and (new_game or load_saved_game or exit_game): show_load_error_message = False elif new_game: player, entities, game_map, message_log, game_state = get_game_variables( constants) game_state = GameStates.PLAYERS_TURN show_main_menu = False elif load_saved_game: try: player, entities, game_map, message_log, game_state = load_game( ) show_main_menu = False except FileNotFoundError: show_load_error_message = True elif exit_game: break else: libtcod.console_clear(con) cam_x, cam_y = update_cam(player, constants) log_height, inv_height = update_panels_heights( player, constants['panel_height']) log_scroll = 0 inv_scroll = 0 inv_selected = 0 play_game(player, entities, game_map, message_log, con, panel, tooltip, messages_pane, inventory_pane, constants, cam_x, cam_y, anim_frame, anim_time, log_scroll, log_height, inv_scroll, inv_height, inv_selected) show_main_menu = True
def main(): constants = get_constants() libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) libtcod.console_init_root(constants['screen_width'], constants['screen_height'], constants['window_title'], False) con = libtcod.console_new(constants['screen_width'], constants['screen_height']) panel = libtcod.console_new(constants['screen_width'], constants['panel_height']) player = None entities = [] game_map = None message_log = None game_state = None show_main_menu = True show_load_error_message = False main_menu_background_image = libtcod.image_load('menu_background1.png') key = libtcod.Key() mouse = libtcod.Mouse() while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse) if show_main_menu: main_menu(con, main_menu_background_image, constants['screen_width'], constants['screen_height']) if show_load_error_message: message_box(con, 'No save game to load', 50, constants['screen_width'], constants['screen_height']) libtcod.console_flush() action = handle_main_menu(key) new_game = action.get('new_game') load_saved_game = action.get('load_game') exit_game = action.get('exit') if show_load_error_message and (new_game or load_saved_game or exit_game): show_load_error_message = False elif new_game: player, entities, game_map, message_log, game_state = get_game_variables(constants) game_state = GameStates.PLAYERS_TURN show_main_menu = False elif load_saved_game: try: player, entities, game_map, message_log, game_state = load_game() show_main_menu = False except FileNotFoundError: show_load_error_message = True elif exit_game: break else: libtcod.console_clear(con) play_game(player, entities, game_map, message_log, game_state, con, panel, constants) show_main_menu = True
def main(): constants = get_constants() libtcod.console_set_custom_font('images/simplerl_12x12.png', libtcod.FONT_LAYOUT_ASCII_INROW | libtcod.FONT_TYPE_GREYSCALE) libtcod.console_init_root(constants['screen_width'], constants['screen_height'], constants['window_title'], False, libtcod.RENDERER_SDL2, 'F', True) con = libtcod.console.Console(constants['screen_width'], constants['screen_height']) panel = libtcod.console.Console(constants['screen_width'], constants['panel_height']) player = None entities = [] game_map = None message_log = None game_state = None show_main_menu = True show_load_error_message = False main_menu_background_image = libtcod.image_load('images/menu_background1.png') in_handle = InputHandler() # main game loop while True: if show_main_menu: main_menu(con, main_menu_background_image, constants['screen_width'], constants['screen_height']) if show_load_error_message: message_box(con, 'No save game to load', 50, constants['screen_width'], constants['screen_height']) libtcod.console_flush() game_state = GameStates.MAIN_MENU in_handle.set_game_state(game_state) for event in tcod.event.get(): in_handle.dispatch(event) action = in_handle.get_action() new_game = action.get('new_game') load_saved_game = action.get('load_game') exit_game = action.get('exit') if show_load_error_message and (new_game or load_saved_game or exit_game): show_load_error_message = False elif new_game: player, entities, game_map, message_log, game_state = get_game_variables(constants) game_state = GameStates.PLAYERS_TURN show_main_menu = False elif load_saved_game: try: player, entities, game_map, message_log, game_state = load_game() show_main_menu = False except FileNotFoundError: show_load_error_message = True elif exit_game: break else: con.clear(fg=[63, 127, 63]) play_game(player, entities, game_map, message_log, game_state, con, panel, constants) show_main_menu = True
def main(): constants = get_constants() libtcod.console_set_custom_font( 'arial10x10.png', libtcod.FONT_TYPE_GRAYSCALE | libtcod.FONT_LAYOUT_TCOD) libtcod.console_init_root(constants['screen_width'], constants['screen_height'], constants['window_title'], fullscreen=False, renderer=libtcod.RENDERER_SDL2, vsync=False) con = libtcod.console.Console(constants['screen_width'], constants['screen_height']) panel = libtcod.console.Console(constants['screen_width'], constants['panel_height']) player = None game_map = None message_log = None game_state = None show_main_menu = True show_load_error_message = False main_menu_background_image = libtcod.image_load('menu_background.png') key = libtcod.Key() mouse = libtcod.Mouse() while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event( libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse) if show_main_menu: main_menu(con, main_menu_background_image, constants['screen_width'], constants['screen_height']) if show_load_error_message: # This a terrible hack and doing this the "right" way will require tinkering with the render functions message_box(con, 'No save game to load', 20, constants['screen_width'], constants['screen_height'] // 2) libtcod.console_flush() action = handle_main_menu(key) new_game = action.get('new_game') load_saved_game = action.get('load_game') exit_game = action.get('exit') if show_load_error_message and (new_game or load_saved_game or exit_game): show_load_error_message = False elif new_game: player, game_map, message_log, game_state = get_game_variables( constants) game_state = GameStates.PLAYERS_TURN show_main_menu = False elif load_saved_game: try: player, game_map, message_log, game_state = load_game() show_main_menu = False except FileNotFoundError: show_load_error_message = True elif exit_game: break else: con.clear(fg=(191, 0, 0)) play_game(player, game_map, message_log, game_state, con, panel, constants) show_main_menu = True
def main(): # game "constants" / "globals" setup debug_f = True omnivision = False constants = get_constants() # initial game state game_state = GameStates.MAIN_MENU show_load_error_message = False # input handling setup in_handle = InputHandler() mouse_x = 0 mouse_y = 0 # set tcod font tcod.console_set_custom_font( "arial10x10.png", tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD ) # set up ui elements panel_ui = tcod.console.Console(constants["panel_ui_width"], constants["panel_ui_height"]) panel_map = tcod.console.Console(constants["panel_map_width"], constants["panel_map_height"]) main_menu_bg = tcod.image_load("menu_background1.png") # open tcod console context with tcod.console_init_root( constants["screen_width"], constants["screen_height"], constants["window_title"], fullscreen=False, renderer=tcod.RENDERER_SDL2, vsync=False) as root_console: while True: if game_state == GameStates.MAIN_MENU: in_handle.set_game_state(game_state) main_menu(root_console, main_menu_bg, constants["screen_width"], constants["screen_height"]) if show_load_error_message: message_box(root_console, "No save game to load", 50, constants["screen_width"], constants["screen_height"]) tcod.console_flush() for event in tcod.event.get(): in_handle.dispatch(event) user_in = in_handle.get_user_input() want_exit = user_in.get("exit") new_game = user_in.get("new_game") load_save = user_in.get("load_game") if (show_load_error_message and (new_game or load_save or want_exit)): show_load_error_message = False elif want_exit: return elif new_game: # set up game "runtime global" variables from scratch g_var = get_game_variables(constants, root_console, panel_map, debug_f) (player, entities, controlled_entity, curr_entity, game_state, prev_state, message_log, game_map, timeq, next_turn, render_update, targeting_item) = g_var elif load_save: # load game "runtime global" variables from save file try: g_var = load_game(constants) except FileNotFoundError: show_load_error_message = True if not show_load_error_message: (player, entities, controlled_entity, curr_entity, game_state, prev_state, message_log, game_map, timeq, next_turn, render_update, targeting_item) = g_var else: game_state = GameStates.MAIN_MENU else: play_game(constants, root_console, panel_ui, panel_map, debug_f, omnivision, in_handle, mouse_x, mouse_y, player, entities, controlled_entity, curr_entity, game_state, prev_state, message_log, game_map, timeq, next_turn, render_update, targeting_item) game_state = GameStates.MAIN_MENU
def main(): constants = get_constants() # tell libtcod which font to use; dictate the file to read from, and the other two arguments tell libtcod which # type of file is being read libtcod.console_set_custom_font( 'arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) # create the screen with specified width and height; title; boolean value to say full screen or not libtcod.console_init_root(constants['screen_width'], constants['screen_height'], 'libtcod tutorial revised', False) con = libtcod.console_new(constants['screen_width'], constants['screen_height']) # create a new console to hold the HP bar and message log panel = libtcod.console_new(constants['screen_width'], constants['panel_height']) player = None entities = [] game_map = None message_log = None game_state = None show_main_menu = True show_load_error_message = False main_menu_background_image = libtcod.image_load('menu_background.png') key = libtcod.Key() mouse = libtcod.Mouse() while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event( libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse) if show_main_menu: main_menu(con, main_menu_background_image, constants['screen_width'], constants['screen_height']) if show_load_error_message: message_box(con, 'No save game to load', 50, constants['screen_width'], constants['screen_height']) libtcod.console_flush() action = handle_main_menu(key) new_game = action.get('new_game') load_saved_game = action.get('load_game') exit_game = action.get('exit') if show_load_error_message and (new_game or load_saved_game or exit_game): show_load_error_message = False elif new_game: player, entities, game_map, message_log, game_state = get_game_variables( constants) game_state = GameStates.PLAYERS_TURN show_main_menu = False elif load_saved_game: try: player, entities, game_map, message_log, game_state = load_game( ) show_main_menu = False except FileNotFoundError: show_load_error_message = True elif exit_game: break else: libtcod.console_clear(con) play_game(player, entities, game_map, message_log, game_state, con, panel, constants) show_main_menu = True
def main(self): # Set font libtcod.console_set_custom_font( 'dejavu_wide16x16_gs_tc.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) # Create game window libtcod.console_init_root(self.constants['screen_width'], self.constants['screen_height'], self.constants['window_title'], False) # Create a console (Drawing Layer?) con = libtcod.console_new(self.constants['screen_width'], self.constants['screen_height']) panel = libtcod.console_new(self.constants['screen_width'], self.constants['panel_height']) players = [] entity = [] game_map = None message_log = None self.game_state = None self.active_player = 0 show_main_menu = True show_load_error_message = False main_menu_background_image = libtcod.image_load('menu_background.png') # Holds keyboard and mouse input key = libtcod.Key() mouse = libtcod.Mouse() # Menu loop while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event( libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse) if show_main_menu: main_menu(con, main_menu_background_image, self.constants['screen_width'], self.constants['screen_height']) if show_load_error_message: message_box(con, 'No save game to load', 50, self.constants['screen_width'], self.constants['screen_height']) libtcod.console_flush() action = handle_main_menu(key) new_game = action.get('new_game') load_saved_game = action.get('load_game') exit_game = action.get('exit') if show_load_error_message and (new_game or load_saved_game or exit_game): show_load_error_message = False elif new_game: players, entities, game_map, message_log, self.game_state = get_game_variables( self.constants) self.game_state = GameStates.PLAYERS_TURN show_main_menu = False elif load_saved_game: try: players, entities, game_map, message_log, self.game_state, self.active_player = load_game( self.constants['player_count']) self.game_state = GameStates.PLAYERS_TURN show_main_menu = False except FileNotFoundError: show_load_error_message = True elif exit_game: break else: libtcod.console_clear(con) self.play_game(players, entities, game_map, message_log, self.game_state, con, panel, self.constants) show_main_menu = True
def main(): constants = get_constants() main_menu_background_image = tcod.image_load('menu_background.png') tcod.console_set_custom_font( 'arial10x10.png', tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD) root_con = tcod.console_init_root(constants["screen_width"], constants["screen_height"], constants["window_title"], order="C", renderer=tcod.RENDERER_SDL2, vsync=True) con = tcod.console.Console(constants['screen_width'], constants['screen_height']) panel = tcod.console.Console(constants['screen_width'], constants['panel_height']) player = None entities = [] game_map = None message_log = None game_state = None show_main_menu = True show_load_error_message = False while show_main_menu: main_menu(con, main_menu_background_image, constants['screen_width'], constants['screen_height'], root_con) if show_load_error_message: message_box(con, 'No save game to load', 50, constants['screen_width'], constants['screen_height'], root_con) tcod.console_flush() action = {} for event in tcod.event.get(): if isinstance(event, tcod.event.KeyDown): action = handle_main_menu(event) new_game = action.get('new_game') load_saved_game = action.get('load_game') exit_game = action.get('exit') if show_load_error_message and (new_game or load_saved_game or exit_game): show_load_error_message = False elif new_game: player, entities, game_map, message_log, game_state = get_game_variables( constants) game_state = GameStates.PLAYER_TURN show_main_menu = False elif load_saved_game: try: player, entities, game_map, message_log, game_state = load_game( ) show_main_menu = False except FileNotFoundError: show_load_error_message = True elif exit_game: quit() else: con.clear() play_game(player, entities, game_map, message_log, game_state, con, panel, constants, root_con) main()
def main(): constants = initialize_new_game.get_constants() position = 0 terminal.open() terminal.set("window: size=" + str(constants['screen_width']) + "x" + str(constants['screen_height']) + ', title=Space Game') terminal.set("font: fonts\courbd.ttf, size=" + constants.get('fontsize')) # terminal.set("input.filter={keyboard, mouse}") player = None entities = [] game_map = None message_log = None game_state = None while True: # show the background image, at twice the regular console resolution # clear scene especially after quitting game terminal.layer(0) terminal.clear() # show the game's title, and some credits! title = 'SPACE GAME' titlex = int(constants['screen_width'] / 2 - len(title) / 2) titley = int(constants['screen_height'] / 2) subtitle = 'Game by Eric Younkin' subtitlex = int(constants['screen_width'] / 2 - len(subtitle) / 2) subtitley = int(constants['screen_height'] / 2 + 2) terminal.color('yellow') terminal.print_(titlex, titley, '[align=center]' + title) terminal.print_(subtitlex, subtitley, '[align=center][font=0xE000]' + subtitle) # show options and wait for the player's choice options = ['Play a new game', 'Continue last game', 'Quit'] menu('', options, 30, constants['screen_width'], constants['screen_height'], position=position, type='main') key = terminal.read() action = input_handlers.handle_menu_keys(key) menupos = action.get('menupos') select = action.get('select') ex = action.get('exit') resize = action.get('resize') if ex: break elif menupos: position += menupos if position < 0: position = 0 if position >= len(options) - 1: position = len(options) - 1 elif select: if position == 0: player, entities, game_map, message_log, game_state = initialize_new_game.get_game_variables( constants) game_state = GameStates.PLAYERS_TURN play_game(player, entities, game_map, message_log, game_state, constants) elif position == 1: # load last game try: player, entities, game_map, message_log, game_state = data_loaders.load_game( ) play_game(player, entities, game_map, message_log, game_state, constants) except FileNotFoundError: message_box('No save game to load', 50, constants['screen_width'], constants['screen_height']) play_game(player, entities, game_map, message_log, game_state, constants) elif position == 2: # quit break elif resize: print(size) if size == '8': size = '12' elif size == '12:': size = '16' elif size == '16': size = '8' terminal.set("font: fonts\courbd.ttf, size=" + size)
def main(): #initialize constants, game variables, fov, message log, and font const = get_constants() player, entities, game_map, fov_recompute, fov_map, message_log, hp_regen_tick, mp_regen_tick = get_game_variables( const) # font from: http://rogueliketutorials.com/tutorials/tcod/part-0/ tcod.console_set_custom_font( 'arial10x10.png', tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD) #sets game state to be players turn to begin with game_state = GameStates.PLAYERS_TURN # main game loop. Root console being created in context with 'with' so that it closes nicely instead of freezing and crashing with tcod.console_init_root(const['screen_width'], const['screen_height'], const['window_title'], fullscreen=False, order='F', vsync=True) as root_console: # initializes main console and console for UI elements con = tcod.console.Console(const['screen_width'], const['screen_height'], order='F') panel = tcod.console.Console(const['screen_width'], const['panel_height'], order='F') # main game loop while True: # gets user input and sends input events to a handler that returns a dictionary of actions for event in tcod.event.wait(): action = event_dispatcher(event) # recomputes fov when necessary if (fov_recompute == True): recompute_fov(fov_map, player.x, player.y, player.fov_range, const['fov_light_walls'], const['fov_algorithm']) # renders whole map on console render_all(con, panel, message_log, entities, player, game_map, fov_map, fov_recompute, const['screen_width'], const['screen_height'], const['bar_width'], const['panel_height'], const['panel_y']) tcod.console_flush() # resets fov_recompute to prevent wasteful computation fov_recompute = False # clears console to avoid trails when moving clear_all(con, entities) # gets actions inputted by player from dictionary move = action.get('move') exit_game = action.get('exit_game') fullscreen = action.get('fullscreen') restart = action.get('restart') take_stairs = action.get('take_stairs') toggle_lights = action.get('toggle_lights') spell = action.get('spell') # player's turn taken only if player gives input if (move != None) and (game_state == GameStates.PLAYERS_TURN) and ( player.is_dead == False): dx, dy = move # only move player if the cell is unblocked and moving within the map if ((player.x + dx < game_map.width - 1) and (player.y + dy < game_map.height - 1) and (not game_map.is_blocked(player.x + dx, player.y + dy))): # checks for entities that block movement in destination being moved to target = get_blocking_entities_at_location( entities, player.x + dx, player.y + dy) # space is empty so player moves. if player is waiting in place it is treated as a normal move to prevent them from atacking themselves if (target == None) or (dx == 0 and dy == 0): player.move(dx, dy) # only recomputes fov when player moves to avoid unnecessary computation fov_recompute = True # attack target else: player.attack(target, message_log) # increments tick by one if the player is below full health/mp. Player must always wait for the full delay after losing hp/mp at max if (player.hp < player.max_hp): hp_regen_tick += 1 if (player.mp < player.max_mp): mp_regen_tick += 1 # player statically regenerates hp and mp periodically if (hp_regen_tick == const['hp_regen_delay']): player.heal(1) hp_regen_tick = 0 # resets tick if (mp_regen_tick == const['mp_regen_delay']): player.restore_mp(1) mp_regen_tick = 0 # resets tick # resets players fov range in case they have casted flash player.fov_range = const['default_fov_radius'] # passes turn to enemies. this happens even if player walks into a wall game_state = GameStates.ENEMY_TURN # handles spells if (spell != None) and (game_state == GameStates.PLAYERS_TURN ) and (player.is_dead == False): # f key casts a fireball spell that does damage in a radius around the player if (spell == 'fireball'): player.cast_fireball(entities, message_log) # h key casts cure which heals for a portion of players max hp elif (spell == 'cure'): player.cast_cure(message_log) # v key casts clairvoyance which reveals position of stairs elif (spell == 'clairvoyance'): player.cast_clairvoyance(game_map, message_log) # g key casts flash which increases the distance the player can see for a turn elif (spell == 'flash'): player.cast_flash(message_log) # arrow keys cast in appropriate direction elif (spell == 'tunnel_up'): player.cast_tunnel(game_map, fov_map, message_log, 0, -1) elif (spell == 'tunnel_down'): player.cast_tunnel(game_map, fov_map, message_log, 0, 1) elif (spell == 'tunnel_left'): player.cast_tunnel(game_map, fov_map, message_log, -1, 0) elif (spell == 'tunnel_right'): player.cast_tunnel(game_map, fov_map, message_log, 1, 0) # increments tick by one if the player is below full health. if (player.hp < player.max_hp): hp_regen_tick += 1 # resets mp regen tick so a player must wait full delay after casting a spell to start mp regen mp_regen_tick = 0 # hp regen unaffected by casting a spell if (hp_regen_tick == const['hp_regen_delay']): player.heal(1) hp_regen_tick = 0 # resets tick # resets player's fov range unless they cast flash. this makes flash only last one turn if (spell != 'flash'): player.fov_range = const['default_fov_radius'] # recomputes fov since some spells affect the map/fov fov_recompute = True game_state = GameStates.ENEMY_TURN # enemy's turn if (game_state == GameStates.ENEMY_TURN): # loops through all enemies for entity in entities: if (isinstance(entity, Enemy)): # enemy gets a real turn if they are within the players fov, or if they have seen the player if ((fov_map.fov[entity.y, entity.x]) or (entity.knows_player_location == True)): # attacks player if they are adjacent or moves towards player using bfs pathfinding algorithm entity.take_turn(player, game_map, entities, message_log) # enemy will continue to follow the player after being seen for the first time, regardless of fov if entity.knows_player_location == False: entity.knows_player_location = True # enemies outside of fov just move around at random else: entity.random_move(game_map, entities) # checks to see if the player died if (player.is_dead == True): game_state = GameStates.PLAYER_DEATH else: # passes turn back to player even if the enemies didn't do anything game_state = GameStates.PLAYERS_TURN # handles death of player if (game_state == GameStates.PLAYER_DEATH): message_log.add_message(Message('You Lose', tcod.darker_red)) # takes player to new floor if (take_stairs == True) and (player.x == game_map.stairs.x) and ( player.y == game_map.stairs.y): # makes new floor and resets entities list entities = game_map.stairs.take_stairs(player, game_map, entities, message_log) # resets fov fov_map = initialize_fov(game_map) fov_recompute = True # clears the console to remove the last floor from the screen clear_console(con, const['screen_width'], const['screen_height']) # player wins if they make it to the 4th floor if (game_map.depth == const['winning_floor']): game_state = GameStates.PLAYER_WINS # player wins after getting to a set floor if game_state == GameStates.PLAYER_WINS: message_log.add_message(Message('You Win!', tcod.yellow)) # restarts game if (restart == True): # resets everything to beginning state const = get_constants() player, entities, game_map, fov_recompute, fov_map, message_log, hp_regen_tick, mp_regen_tick = get_game_variables( const) # clears the console to remove the last floor from the screen clear_console(con, const['screen_width'], const['screen_height']) # new game starts with players turn game_state = GameStates.PLAYERS_TURN # toggles lights to see the whole map for deomonstration if (toggle_lights == True): game_map.lights_on = not game_map.lights_on if game_map.lights_on == False: clear_console(con, const['screen_width'], const['screen_height']) fov_recompute = True # breaks loop if player exits if (exit_game == True): raise SystemExit() # toggles fullscreen if (fullscreen == True): tcod.console_set_fullscreen(not tcod.console_is_fullscreen())
def main(): """ Main game loop Init console + wraps key events """ constants = get_constants() tcod.console_set_custom_font( "arial10x10.png", tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD) tcod.console_init_root( constants["screen_width"], constants["screen_height"], constants["window_title"], False, constants["sdl_renderer"], ) console = tcod.console.Console(constants["screen_width"], constants["screen_height"]) panel = tcod.console_new(constants["screen_width"], constants["panel_height"]) player = None entities = [] game_map = None message_log = None game_state = None show_main_menu = True show_load_error_message = False main_menu_background_image = tcod.image_load('menu_background.png') key = tcod.Key() mouse = tcod.Mouse() while not tcod.console_is_window_closed(): tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS | tcod.EVENT_MOUSE, key, mouse) if show_main_menu: main_menu(console, main_menu_background_image, constants['screen_width'], constants['screen_height']) if show_load_error_message: message_box(console, 'No save game to load', 50, constants['screen_width'], constants['screen_height']) tcod.console_flush() action = handle_main_menu(key) new_game = action.get('new_game') load_saved_game = action.get('load_game') exit_game = action.get('exit') if show_load_error_message and (new_game or load_saved_game or exit_game): show_load_error_message = False elif new_game: player, entities, game_map, message_log, game_state = get_game_variables( constants) game_state = GameStates.PLAYERS_TURN show_main_menu = False elif load_saved_game: try: player, entities, game_map, message_log, game_state = load_game( ) show_main_menu = False except FileNotFoundError: show_load_error_message = True elif exit_game: break else: tcod.console_clear(console) play_game(player, entities, game_map, message_log, game_state, console, panel, constants) show_main_menu = True
def main(): constants = get_constants() player = None entities = [] game_map = None message_log = [] game_state = None animator = None tcod.console_set_custom_font("Codepage-437.png", tcod.FONT_LAYOUT_CP437) tileset = tcod.tileset.load_tilesheet("Codepage-437.png", 16, 16, tcod.tileset.CHARMAP_CP437) panel = tcod.console.Console(constants['screen_width'], constants['panel_height']) show_main_menu = True show_load_error_message = False with tcod.console_init_root(w=constants['screen_width'], h=constants['screen_height'], title=constants['window_title'], order="F", vsync=True) as root_console: while True: if show_main_menu: main_menu(root_console, constants['screen_width'], constants['screen_height']) tcod.console_flush() if show_load_error_message: message_box(root_console, 'No save game to load', 50, constants['screen_width'], constants['screen_height']) # Handle Events for event in tcod.event.wait(): if event.type == "KEYDOWN": action: [Action, None] = handle_keys_main_menu(event.sym) if action: action_type: ActionType = action.action_type show_load_error_message = False if action_type == ActionType.NEW_GAME: player, entities, animator, turn_count, game_map, message_log, game_state = get_game_variables( constants) show_main_menu = False elif action_type == ActionType.LOAD_GAME: try: player, entities, animator, turn_count, game_map, message_log, game_state = load_game( ) show_main_menu = False except FileNotFoundError: show_load_error_message = True show_main_menu = True elif action_type == ActionType.ESCAPE: raise SystemExit() if event.type == "QUIT": raise SystemExit() else: play_game(root_console, player, entities, animator, turn_count, game_map, message_log, game_state, panel, constants)
def main(): constants = get_constants() libtcod.console_set_custom_font( 'arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) libtcod.console_init_root(constants['screen_width'], constants['screen_height'], 'rogue', False) con = libtcod.console_new(constants['screen_width'], constants['screen_height']) panel = libtcod.console_new(constants['screen_width'], constants['panel_height']) player, entities, game_map, message_log, game_state = get_game_variables( constants) fov_recompute = True fov_map = initialize_fov(game_map) key = libtcod.Key() mouse = libtcod.Mouse() previous_game_state = game_state while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event( libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse) if fov_recompute: recompute_fov(fov_map, player.x, player.y, constants['fov_radius'], constants['fov_light_walls'], constants['fov_algorithm']) render_all(con, panel, entities, player, game_map, fov_map, fov_recompute, message_log, constants['screen_width'], constants['screen_height'], constants['bar_width'], constants['panel_height'], constants['panel_y'], constants['mouse'], constants['colors'], game_state) fov_recompute = False libtcod.console_flush() clear_all(con, entities) action = handle_keys(key, game_state) mouse_action = handle_mouse(mouse) move = action.get('move') pickup = action.get('pickup') show_inventory = action.get('show_inventory') drop_inventory = action.get('drop_inventory') inventory_index = action.get('inventory_index') exit = action.get('exit') fullscreen = action.get('fullscreen') left_click = mouse_action.get('left_click') right_click = mouse_action.get('right_click') player_turn_results = [] if move and game_state == GameStates.PLAYERS_TURN: dx, dy = move destination_x = player.x + dx destination_y = player.y + dy if not game_map.is_blocked(player.x + dx, player.y + dy): target = get_blocking_entities_at_location( entities, destination_x, destination_y) if target: player.fighter.attack(target) attack_results = player.fighter.attack(target) player_turn_results.extend(attack_results) else: player.move(dx, dy) fov_recompute = True game_state = GameStates.ENEMY_TURN elif pickup and game_state == GameStates.PLAYERS_TURN: for entity in entities: if entity.item and entity.x == player.x and entity.y == player.y: pickup_results = player.inventory.add_item(entity) player_turn_results.extend(pickup_results) break else: message_log.add_message( Message('There is nothing here to pick up.', libtcod.yellow)) if show_inventory: previous_game_state = game_state game_state = GameStates.SHOW_INVENTORY if drop_inventory: previous_game_state = game_state game_state = GameStates.DROP_INVENTORY if inventory_index is not None and previous_game_state != GameStates.PLAYER_DEAD and inventory_index < len( player.inventory.items): item = player.inventory.items[inventory_index] if game_state == GameStates.SHOW_INVENTORY: player_turn_results.extend( player.inventory.use(item, entities=entities, fov_map=fov_map)) elif game_state == GameStates.DROP_INVENTORY: player_turn_results.extend(player.inventory.drop_item(item)) if game_state == GameStates.TARGETING: if left_click: target_x, target_y = left_click item_use_results = player.inventory.use(targeting_item, entities=entities, fov_map=fov_map, target_x=target_x, target_y=target_y) player_turn_results.append(item_use_results) elif right_click: player_turn_results.append({'targeting_cancelled': True}) if exit: if game_state in (game_state.SHOW_INVENTORY, game_state.DROP_INVENTORY): game_state = previous_game_state elif game_state == GameStates.TARGETING: player_turn_results.append({'targeting_cancelled': True}) else: return True if fullscreen: libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen()) for player_turn_result in player_turn_results: message = player_turn_result.get('message') dead_entity = player_turn_result.get('dead') item_added = player_turn_result.get('item_added') item_consumed = player_turn_result.get('consumed') item_dropped = player_turn_result.get('item_dropped') targeting = player_turn_result.get('targeting') targeting_cancelled = player_turn_result.get('targeting_cancelled') if message: message_log.add_message(message) if targeting_cancelled: game_state = previous_game_state message_log.add_message(Message('Targeting cancelled')) if dead_entity: if dead_entity == player: message, game_state = kill_player(dead_entity) else: message = kill_monster(dead_entity) message_log.add_message(message) if item_added: entities.remove(item_added) game_state = game_state.ENEMY_TURN if item_consumed: game_state.ENEMY_TURN if targeting: previous_game_state = GameStates.PLAYERS_TURN game_state = GameStates.TARGETING targeting_item = targeting message_log.add_message(targeting_item.item.targeting_message) if item_dropped: entities.append(item_dropped) game_state = GameStates.ENEMY_TURN if game_state == GameStates.ENEMY_TURN: for entity in entities: if entity.ai: enemy_turn_results = entity.ai.take_turn( player, fov_map, game_map, entities) for enemy_turn_result in enemy_turn_results: message = enemy_turn_result.get('message') dead_entity = enemy_turn_result.get('dead') if message: message_log.add_message(message) if dead_entity: if dead_entity == player: message, game_state = kill_player(dead_entity) else: message = kill_monster(dead_entity) message_log.add_message(message) if game_state == GameStates.PLAYER_DEAD: break if game_state == GameStates.PLAYER_DEAD: break else: game_state = GameStates.PLAYERS_TURN
def main(): constants = get_constants() names_list = get_unidentified_names() colors_list = get_render_colors() load_customfont() libtcod.console_set_custom_font( 'fontplus.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_ASCII_INROW, 16, 30) libtcod.console_init_root(constants['screen_width'], constants['screen_height'], constants['window_title'], False) con = libtcod.console.Console(constants['screen_width'], constants['screen_height']) panel = libtcod.console.Console(constants['screen_width'], constants['panel_height']) player = None entities = [] game_map = None message_log = None game_state = None show_main_menu = True show_load_error_message = False main_menu_background_image = libtcod.image_load('menu_background.png') key = libtcod.Key() mouse = libtcod.Mouse() while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event( libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse) if show_main_menu: main_menu(con, main_menu_background_image, constants['screen_width'], constants['screen_height']) if show_load_error_message: message_box(con, 'No save game to load', 50, constants['screen_width'], constants['screen_height']) libtcod.console_flush() action = handle_main_menu(key) new_game = action.get('new_game') load_saved_game = action.get('load_game') exit_game = action.get('exit') if show_load_error_message and (new_game or load_saved_game or exit_game): show_load_error_message = False elif new_game: constants = get_constants() names_list = get_unidentified_names() colors_list = get_render_colors() if intro(constants): if not game_options(constants) == "nah": if not origin_options(constants) == "nah": if not character_name(constants) == 'nah': player, entities, game_map, message_log, game_state = get_game_variables( constants, names_list, colors_list) game_state = GameStates.PLAYERS_TURN show_main_menu = False elif load_saved_game: try: player, entities, game_map, message_log, game_state, constants = load_game( ) show_main_menu = False except FileNotFoundError: show_load_error_message = True elif exit_game: break else: libtcod.console_clear(con) play_game(player, entities, game_map, message_log, game_state, con, panel, constants, names_list, colors_list) show_main_menu = True
def main(): # 定数を読み込む constants = get_constants() # フォントの指定と(libtcod.FONT_TYPE_GRAYSCALE | libtcod.FONT_LAYOUT_TCOD)でどのタイプのファイルを読み取るのかを伝える libtcod.console_set_custom_font("arial10x10.png", libtcod.FONT_TYPE_GRAYSCALE | libtcod.FONT_LAYOUT_TCOD) # ここで実際に画面を作成する、画面サイズとタイトルとフルスクリーンとレンダラーと画面の垂直同期を指定している libtcod.console_init_root(constants["screen_width"], constants["screen_height"], constants["window_title"], False) con = libtcod.console.Console(constants["screen_width"], constants["screen_height"]) panel = libtcod.console.Console(constants["screen_width"], constants["panel_height"]) player = None entities = [] game_map = None message_log = None game_state = None show_main_menu = True show_load_error_message = False main_menu_background_image = libtcod.image_load("menu_background.png") main_window = libtcod.console_is_window_closed() while True: if show_main_menu: main_menu(con, main_menu_background_image, constants["screen_width"], constants["screen_height"]) if show_load_error_message: message_box(con, "No save game to load", 50, constants["screen_width"], constants["screen_height"]) libtcod.console_flush() for events in libtcod.event.get(): if events.type == "KEYDOWN": action = handle_main_menu(events) new_game = action.get("new_game") load_saved_game = action.get("load_game") exit_game = action.get("exit") if show_load_error_message and (new_game or load_saved_game or exit_game): show_load_error_message = False elif new_game: player, entities, game_map, message_log, game_state = get_game_variables(constants) game_state = GameStates.PLAYERS_TURN show_main_menu = False elif load_saved_game: try: player, entities, game_map, message_log, game_state = load_game() show_main_menu = False except FileNotFoundError: show_load_error_message = True elif exit_game: return False else: libtcod.console_clear(con) play_game(player, entities, game_map, message_log, game_state, con, panel, constants) show_main_menu = True
def main(): constants = get_constants() tdl.set_font('arial10x10.png', greyscale=True, altLayout=True) root_console = tdl.init(constants['screen_width'], constants['screen_height'], constants['window_title']) con = tdl.Console(constants['screen_width'], constants['screen_height']) panel = tdl.Console(constants['screen_width'], constants['panel_height']) player = None entities = [] game_map = None message_log = None game_state = None show_main_menu = True show_load_error_message = False main_menu_background_image = image_load('menu_background.png') while not tdl.event.is_window_closed(): for event in tdl.event.get(): if event.type == 'KEYDOWN': user_input = event break else: user_input = None if show_main_menu: main_menu(con, root_console, main_menu_background_image, constants['screen_width'], constants['screen_height'], constants['colors']) if show_load_error_message: message_box(con, root_console, 'No save game to load', 50, constants['screen_width'], constants['screen_height']) tdl.flush() action = handle_main_menu(user_input) new_game = action.get('new_game') load_saved_game = action.get('load_game') exit_game = action.get('exit') if show_load_error_message and (new_game or load_saved_game or exit_game): show_load_error_message = False elif new_game: player, entities, game_map, message_log, game_state = get_game_variables( constants) game_state = GameStates.PLAYERS_TURN show_main_menu = False elif load_saved_game: try: player, entities, game_map, message_log, game_state = load_game( ) show_main_menu = False except FileNotFoundError: show_load_error_message = True elif exit_game: break else: root_console.clear() con.clear() panel.clear() play_game(player, entities, game_map, message_log, game_state, root_console, con, panel, constants) show_main_menu = True
def main(): constants = get_constants() tc.console_set_custom_font('arial10x10.png', tc.FONT_TYPE_GREYSCALE | tc.FONT_LAYOUT_TCOD) tc.console.Console(constants['screen_width'], constants['screen_height']) tc.console_init_root(constants['screen_width'], constants['screen_height'], constants['window_title'], False, tc.RENDERER_SDL2, "F", True) con = tc.console.Console(constants['screen_width'], constants['screen_height']) panel = tc.console.Console(constants['screen_width'], constants['screen_height']) player = None entities = [] game_map = None message_log = None game_state = None show_main_menu = True show_load_error_message = False # main_menu_background_image = tc.image_load('menu_background.png') main_menu_background_image = tc.image_load('') key = tc.Key() mouse = tc.Mouse() event = tc.event.get() # for event in tcod.event.wait(): while event != "QUIT": tc.sys_check_for_event(tc.EVENT_KEY_PRESS | tc.EVENT_MOUSE, key, mouse) if show_main_menu: con.clear() clear_all(con, entities) tc.console_blit(con, 0, 0, constants['screen_width'], constants['screen_height'], 0, 0, 0, 1.0, 1.0) main_menu(con, main_menu_background_image, constants['screen_width'], constants['screen_height']) if show_load_error_message: message_box(con, 'No save game to load', 50, constants['screen_width'], constants['screen_height']) tc.console_flush() action = handle_main_menu(key) new_game = action.get('new_game') load_saved_game = action.get('load_game') exit_game = action.get('exit') if show_load_error_message and (new_game or load_saved_game or exit_game): show_load_error_message = False elif new_game: player, entities, game_map, message_log, game_state = get_game_variables( constants) show_main_menu = False #REVERT BEFORE COMMIT # game_state = GameStates.SHOW_TUTORIAL game_state = GameStates.PLAYERS_TURN elif load_saved_game: try: player, entities, game_map, message_log, game_state = load_game( ) show_main_menu = False except FileNotFoundError: show_load_error_message = True elif exit_game: break else: con.clear() play_game(player, entities, game_map, message_log, game_state, con, panel, constants) show_main_menu = True