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 popup(con, message, width, height): dismiss = False while not dismiss: message_box(con, message, 50, width, height) libtcod.console_flush() key = libtcod.console_wait_for_keypress(True) action = handle_popup(key) dismiss = action.get('dismiss')
def shop(game_surface): from game_enums import colors from menus import choose_from_options, message_box, wait_for_input from items import items player = config.player width = config.width height = config.height options = [(name, item.print_price()) for name, item in items.items() if item.unlock_chapter <= config.player.story_chapter and not item.is_special] gold_text = "gold: $g{}".format(player.total_gold) gold, gold_rect = message_box(gold_text, (width * 5 / 6, height / 6)) game_surface.fill(colors.offblack.value) game_surface.blit(gold, gold_rect) selected = choose_from_options(game_surface, "buy somethin', will ya?", [opt[1] for opt in options], (width / 2, height / 6)) if selected == -1: return name = options[selected][0] selected_item = items[name] price = selected_item.price if player.total_gold >= price: player.total_gold -= price player.inventory[name] += 1 return # implicit else message_text = "you don't have enough money for that! now scram!" message, message_rect = message_box(message_text, (width / 2, height / 4)) game_surface.fill(colors.offblack.value) game_surface.blit(message, message_rect) pygame.display.flip() wait_for_input() game_surface.fill(colors.offblack.value) return
def main(self): self.renderer.render_root() show_main_menu = True show_load_error_message = False main_menu_background_image = tcod.image_load(screen_vars.menu_background_img) while True: if show_main_menu: main_menu(main_menu_background_image, menu_vars.main_width, self.renderer) for raw_event in tcod.event.wait(): if show_load_error_message: message_box('No save game to load', 50, self.renderer) tcod.console_flush() event = event_handler.handle_main_menu(raw_event) new_game = event.get('new_game') load_saved_game = event.get('load_saved_game') exit_game = event.get('exit_game') if show_load_error_message and (new_game or load_saved_game or exit_game): show_load_error_message = False elif new_game: self.entities, self.world_map, self.message_log, self.game_state = get_game_variables() show_main_menu = False break elif load_saved_game: try: self.entities, self.world_map, self.message_log, self.game_state = load_game() show_main_menu = False break except FileNotFoundError: show_load_error_message = True elif exit_game: raise SystemExit else: self.renderer.clear() if self.world_map.current_dungeon: self.player_location = PlayerLocations.DUNGEON self.play_game() self.player_location = PlayerLocations.WORLD_MAP show_main_menu = True
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 explore(game_surface, all_words): from map_tiles import location_types from game_enums import colors from menus import message_box, wait_for_input from backend import load_map player = config.player width = config.width height = config.height game_map = load_map() player_loc = [len(game_map) // 2, len(game_map) // 2] while player.alive: draw_map(game_surface, game_map, player_loc) pygame.display.flip() for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_BACKSPACE: return if event.key in (pygame.K_DOWN, pygame.K_UP, pygame.K_LEFT, pygame.K_RIGHT): player_loc, moved = move_player(game_map, event.key, player_loc) tile_type = game_map[player_loc[0]][player_loc[1]] enemy_chance = location_types[tile_type].level + 1 if moved and random.randint(1, 6) <= enemy_chance: tile_level = location_types[tile_type].level if tile_level >= 0: enemy_level = random.randint( tile_level + 1, tile_level + 2) battle(game_surface, enemy_level, all_words) # if player can't battle message_text = "you're passed out! you can't battle!" message, message_rect = message_box(message_text, (width / 2, height / 4)) game_surface.fill(colors.offblack.value) game_surface.blit(message, message_rect) pygame.display.flip() wait_for_input(pygame.K_RETURN) return
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(): 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(): # Initialises, returns and stores a dictionary of all constant values. constants = get_constants() # Sets the font. libtcod.console_set_custom_font( "arial10x10.png", libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) # Sets up the root console. libtcod.console_init_root(constants["screen_width"], constants["screen_height"], constants["window_title"], False) # Creates the main off-screen console. con = libtcod.console_new(constants["screen_width"], constants["screen_height"]) # Creates the hp bar/log panel. panel = libtcod.console_new(constants["screen_width"], constants["panel_height"]) # Will store the game variables. player = None entities = [] game_map = None message_log = None game_state = None show_main_menu = True show_load_error_message = False # Grabs an image from the project directory - it will be used for the main menu background. 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) # Creates the main menu and blits it to the console. 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 found", 50, constants["screen_width"], constants["screen_height"]) libtcod.console_flush() # Handles key presses. action = handle_main_menu(key) new_game = action.get("new_game") load_saved_game = action.get("load_game") exit_game = action.get("exit") # If the error message is open pressing one of the menu options will close the window. if show_load_error_message and (new_game or load_saved_game or exit_game): show_load_error_message = False # If new game is selected get_game_variables() will be called for a the default setup. # And the default PLAYERS_TURN gamestate will be set. elif new_game: player, entities, game_map, message_log, game_state = get_game_variables( constants) game_state = GameStates.PLAYERS_TURN show_main_menu = False # Loads the game using load_game(). elif load_saved_game: # Catching the possible FileNotFoundError in load_game(). try: player, entities, game_map, message_log, game_state = load_game( ) show_main_menu = False except FileNotFoundError: # Shows a message_box if the file cannot be loaded. show_load_error_message = True # Exits the game by breaking the while loop. elif exit_game: break # If show_main_menu is False the player_game function will be called using the newly obtained game variables. else: libtcod.console_clear(con) play_game(player, entities, game_map, message_log, game_state, con, panel, constants) # This is set back to True when the play_game() is finished (the user presses ESC or exits). # Brings the user back to the main menu. show_main_menu = True # Sets up the game variables using the constants and returns each to a stored variable. # E.g. sets up the player entity. player, entities, game_map, message_log, game_state = get_game_variables( constants)
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 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() 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() libtcod.console_set_custom_font('tennisOut.png', libtcod.FONT_LAYOUT_ASCII_INROW, 32, 10) libtcod.console_init_root(constants['screen_width'], constants['screen_height'], constants['window_title'], False) load_customfont() con = libtcod.console.Console(constants['screen_width'], constants['screen_height']) panel = libtcod.console.Console(constants['screen_width'], constants['panel_height']) show_main_menu = True show_load_error_message = False 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, 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 elif load_saved_game: try: player, entities, game_map, message_log, game_state = load_game( ) play_game(player, entities, game_map, message_log, con, panel, constants) show_main_menu = False except FileNotFoundError: show_load_error_message = True elif exit_game: break else: libtcod.console_clear(con) character_selection(constants, con, panel) show_main_menu = True
def main(): # How cute is a program that says "Hello World!" at the beginning? # I'll tell ya, it's 100% cute. print('Hello world!') constants = get_constants() libtcod.console_set_custom_font('Bedstead_12x20.png', libtcod.FONT_TYPE_GREYSCALE | 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 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, 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_menu_loop(root_console: tcod.console.Console) -> None: con = tcod.console.Console(constants.screen_width, constants.screen_height, order='F') panel = tcod.console.Console(constants.screen_width, constants.panel_height, order='F') player = None entities: List[Entity] = [] 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_background1.png') while True: action: UserAction = {} # We pass a 1 second timeout to wait() primarily to give a chance for # the Python interpreter to react to ^C in a relatively timely manner. for event in tcod.event.wait(1): if event.type == 'QUIT': sys.exit() elif event.type == 'KEYDOWN': action = handle_main_menu(event) if action: break if show_main_menu: main_menu(root_console, main_menu_background_image, 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() new_game = action.get('new_game') load_saved_game = action.get('load_game') exit_game = action.get('exit') fullscreen = action.get('fullscreen') if fullscreen: tcod.console_set_fullscreen(not tcod.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() show_main_menu = False elif load_saved_game: try: (player, entities, game_map, message_log, game_state) = load_game() except FileNotFoundError: show_load_error_message = True else: show_main_menu = False elif exit_game: break else: con.clear() assert player is not None assert game_map is not None assert message_log is not None assert game_state is not None play_game(player, entities, game_map, message_log, game_state, root_console, con, panel) 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(): ''' 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 show_load_error(con, show_load_error_message, screen_width, screen_height): if show_load_error_message: message_box(con, 'No save game to load', 50, screen_width, screen_height)
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() 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 = 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(): #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(): # 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(): # 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(): 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(): constants = get_constants() # Fonts tcod.console_set_custom_font( 'arial10x10.png', tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD) # Initialise console tcod.console_init_root(constants['screen_width'], constants['screen_height'], constants['window_title'], False, renderer=tcod.RENDERER_SDL2, vsync=True) # Variables for console and display panel con = tcod.console.Console(constants['screen_width'], constants['screen_height']) panel = tcod.console.Console(constants['screen_width'], constants['screen_height']) # Initalise variables 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(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']) 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: con.clear() 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(): 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
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 inventory(game_surface): from game_enums import colors from menus import choose_from_options, message_box, item_options from menus import multiple_message_box, wait_for_input, yn_question from items import items player = config.player width = config.width height = config.height if sum([item for item in player.inventory.values()]) == 0: message_text = "you don't have anything in your inventory!" else: options = [] for name, item in items.items(): amount = player.inventory[name] if amount <= 0: continue if isinstance(amount, bool): item_str = name else: # cutesy dyslexia potion if name == 'dyslexia potion': shuffled = ''.join(random.sample(name, k=len(name))) else: shuffled = name item_str = '{}x {}'.format(amount, shuffled) options.append((name, item_str)) gold_text = "gold: $g{}".format(player.total_gold) gold, gold_rect = message_box(gold_text, (width * 5 / 6, height / 6)) current_equipment = [ "{}: {}".format(slot, item or 'empty') for slot, item in player.equipment.items() ] equips, equips_rect = multiple_message_box( current_equipment, (width * 5 / 6, height * 2 / 6)) current_held = [ '{}: {}'.format(i + 1, x or 'empty') for i, x in enumerate(player.held_items) ] held, held_rect = multiple_message_box(current_held, (width / 6, height * 2 / 6)) game_surface.fill(colors.offblack.value) game_surface.blit(gold, gold_rect) game_surface.blit(equips, equips_rect) game_surface.blit(held, held_rect) selected = choose_from_options(game_surface, "{}'s inventory".format(player.name), [opt[1] for opt in options], (width / 2, height / 6)) if selected == -1: return name = options[selected][0] if name == 'dyslexia potion': shuffled = ''.join(random.sample(name, k=len(name))) else: shuffled = name action = item_options(game_surface, shuffled) if action == 'use': if items[name].is_use: player.inventory[name] -= 1 get_effect(name) message_text = "you used {}!" else: message_text = "you can't use {}!" elif action == 'hold': if items[name].is_use: # choose slot selected = choose_from_options(game_surface, 'which slot?', [str(x) for x in range(1, 7)], (width / 2, height / 3)) if name in player.held_items: idx = player.held_items.index(name) player.held_items[idx] = None player.held_items[selected] = name message_text = "you held onto {}!" else: message_text = "you can't hold onto {}!" elif action == 'equip': if items[name].is_equip: currently_equipped = player.equipment[items[name].equip_type] if currently_equipped is not None: player.inventory[currently_equipped] += 1 player.equipment[items[name].equip_type] = name player.inventory[name] -= 1 message_text = "you equipped {}!" else: message_text = "you can't equip {}!" elif action == 'discard': if not items[name].is_special: # are you sure? sure = yn_question(game_surface, 'are you sure?', (width / 2, height / 2)) if sure: player.inventory[name] -= 1 message_text = "you threw away {}." else: return else: message_text = "you can't throw {} away! it's too valuable!" elif action == -1: return message_text = message_text.format(shuffled) message, message_rect = message_box(message_text, (width / 2, height / 4)) game_surface.fill(colors.offblack.value) game_surface.blit(message, message_rect) pygame.display.flip() wait_for_input() game_surface.fill(colors.offblack.value) return
def main(): game = Game() show_load_error_message = False game.game_state: GameStates = GameStates.MAIN_MENU game.previous_state: GameStates = game.game_state blt.open() blt.composition(True) blt.set( f"window: size={CONSTANTS.screen_width}x{CONSTANTS.screen_height}, title={CONSTANTS.window_title}, cellsize=8x8" ) blt.set("input: filter={keyboard, mouse+}") blt.set(f"{CONSTANTS.map_font}") blt.set(f"{CONSTANTS.ui_font}") blt.set(f"{CONSTANTS.bar_font}") blt.set(f"{CONSTANTS.hover_font}") while game.game_running: if game.game_state == GameStates.MAIN_MENU: blt.clear() if show_load_error_message: message_box( header="No save game to load", width=50, screen_width=CONSTANTS.screen_width, screen_height=CONSTANTS.screen_height, ) main_menu(CONSTANTS.camera_width) blt.refresh() if blt.has_input(): terminal_input = blt.read() print(terminal_input) action = handle_main_menu(terminal_input) new_game: bool = action.get("new_game", False) load_saved_game: bool = action.get("load_game", False) exit_game: bool = action.get("exit_game", False) if show_load_error_message and (new_game or load_saved_game or exit_game): show_load_error_message = False elif new_game: game = game.new_game() game.map_generator.make_map( width=CONSTANTS.map_width, height=CONSTANTS.map_height, entities=game.entities, min_monsters=CONSTANTS.min_monsters, ) game.game_state = GameStates.PLAYER_TURN game.player.position = game.map_generator.player_start_point elif load_saved_game: try: game = game.load_game() except FileNotFoundError: show_load_error_message = True elif exit_game: break else: blt.clear() play_game(game) game.game_state = GameStates.MAIN_MENU