def setup(self): libtcod.console_set_custom_font('assets/dejavu16x16_gs_tc.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) libtcod.console_init_root(self.width, self.height, 'Pyrl', False) self.__con = libtcod.console_new(self.width, self.height) self.__map = Map(self.width, self.height, self.__con) self.__map.setup() self.__generate_entities()
def __init__(self, console, screen, camera): self.console = console self.camera = camera self.screen = screen # map_console is completely redrawn, but no need to fully recreate it each frame self.map_console = libtcod.console_new(camera.width, camera.height)
def __init__(self, player, x=0, y=0, district=None): self.x_pos = x self.y_pos = y self.panel = libtcod.console_new(PANEL_WIDTH, PANEL_HEIGHT) self.visible = True self.menu_stack = [] self.menu_stack.append( NearbyRestaurantMenu(self.panel, player, district))
def menu(header, options, width): if len(options) > 26: raise ValueError( 'Cannot have a menu with more than 26 options.') # calculate total height for the header (after auto-wrap) and one # line per option header_height = libtcod.console_get_height_rect(con, 0, 0, width, SCREEN_HEIGHT, header) if header == '': header_height = 0 height = len(options) + header_height # create an off-screen console that represents the menu's window window = libtcod.console_new(width, height) # print the header, with auto-wrap libtcod.console_set_default_foreground(window, libtcod.white) libtcod.console_print_rect_ex(window, 0, 0, width, height, libtcod.BKGND_NONE, libtcod.LEFT, header) # print all the options y = header_height letter_index = ord('a') for option_text in options: text = '(' + chr(letter_index) + ') ' + option_text libtcod.console_print_ex(window, 0, y, libtcod.BKGND_NONE, libtcod.LEFT, text) y += 1 letter_index += 1 # blit the contents of "window" to the root console x = SCREEN_WIDTH / 2 - width / 2 y = SCREEN_HEIGHT / 2 - height / 2 libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7) # present the root console to the player and wait for a key-press libtcod.console_flush() key = libtcod.console_wait_for_keypress(True) # (special case) Alt+Enter: toggle fullscreen if key.vk == libtcod.KEY_ENTER and key.lalt: libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen) # convert the ASCII code to an index; if it corresponds to an # option, return it index = key.c - ord('a') if index >= 0 and index < len(options): return index return None
def menu(header, options, width): if len(options) > 26: raise ValueError('Cannot have a menu with more than 26 options.') #calc height of header header_height = libtcod.console_height_left_rect(con, 0, 0, width, SCREEN_HEIGHT, header) if header == '': header_height = 0 height = len(options) + header_height #offscreen conolse window = libtcod.console_new(width, height) #print the header libtcod.console_set_foreground_color(window, libtcod.white) libtcod.console_print_left_rect(window, 0, 0, width, height, libtcod.BKGND_NONE, header) y = header_height letter_index = ord('a') for option_text in options: text = '(' + chr(letter_index) + ') ' + option_text libtcod.console_print_left(window, 0, y, libtcod.BKGND_NONE, text) y += 1 letter_index += 1 #blit the contents to the main console x = SCREEN_WIDTH / 2 - width / 2 y = SCREEN_HEIGHT / 2 - height / 2 libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7) #wait for keypress libtcod.console_flush() key = libtcod.console_wait_for_keypress(True) #convert ascii to index index = key.c - ord('a') if index >= 0 and index < len(options): return index return None
def menu(header, options, width): if len(options) > 26: raise ValueError('Cannot have a menu with more than 26 options.') #calculate total height for the header (after auto-wrap) and one line per option header_height = libtcod.console_height_left_rect(con, 0, 0, width, SCREEN_HEIGHT, header) height = len(options) + header_height #create an off-screen console that represents the menu's window window = libtcod.console_new(width, height) #print the header, with auto-wrap libtcod.console_set_foreground_color(window, libtcod.white) libtcod.console_print_left_rect(window, 0, 0, width, height, libtcod.BKGND_NONE, header) #print all the options y = header_height letter_index = ord('a') for option_text in options: text = '(' + chr(letter_index) + ') ' + option_text libtcod.console_print_left(window, 0, y, libtcod.BKGND_NONE, text) y += 1 letter_index += 1 #blit the contents of "window" to the root console x = SCREEN_WIDTH / 2 - width / 2 y = SCREEN_HEIGHT / 2 - height / 2 libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7) #present the root console to the player and wait for a key-press libtcod.console_flush() key = libtcod.console_wait_for_keypress(True) #convert the ASCII code to an index; if it corresponds to an option, return it index = key.c - ord('a') if index >= 0 and index < len(options): return index return None
def menu(header, options, width): if len(options) > 26: raise ValueError('Cannot have a menu with more than 26 options.') #calc height of header header_height = libtcod.console_height_left_rect(con, 0, 0, width, SCREEN_HEIGHT, header) if header == '': header_height = 0 height = len(options) + header_height #offscreen conolse window = libtcod.console_new(width, height) #print the header libtcod.console_set_foreground_color(window, libtcod.white) libtcod.console_print_left_rect(window, 0, 0, width, height, libtcod.BKGND_NONE, header) y = header_height letter_index= ord('a') for option_text in options: text = '(' + chr(letter_index) + ') ' + option_text libtcod.console_print_left(window, 0, y, libtcod.BKGND_NONE, text) y += 1 letter_index += 1 #blit the contents to the main console x = SCREEN_WIDTH/2 - width/2 y = SCREEN_HEIGHT/2 - height/2 libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7) #wait for keypress libtcod.console_flush() key = libtcod.console_wait_for_keypress(True) #convert ascii to index index = key.c - ord('a') if index >= 0 and index < len(options): return index return None
def init_libtcod(): startup_msg = ("analyzing air quality...", "calculating primordial soup..." ,"reading the future...", "carbon dating your hard drive..." ,"finding prime numbers...") print(random.choice(startup_msg)) libtcod.console_set_custom_font('data/fonts/terminal12x12_gs_ro.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_ASCII_INROW) libtcod.console_init_root(C.SCREEN_WIDTH, C.SCREEN_HEIGHT, 'top dog -- v%s' % (C.VERSION), C.FULLSCREEN) libtcod.sys_set_fps(C.LIMIT_FPS) # default font color libtcod.console_set_default_foreground(0, libtcod.white) # set color control codes for inline string formatting # listed by priority: think defcon levels # high alert, priority one libtcod.console_set_color_control(libtcod.COLCTRL_1 ,libtcod.light_red ,libtcod.black) # warning, danger will robinson libtcod.console_set_color_control(libtcod.COLCTRL_2 ,libtcod.light_yellow ,libtcod.black) # informational, you got a quest item libtcod.console_set_color_control(libtcod.COLCTRL_3 ,libtcod.light_green ,libtcod.black) # tile and npc names libtcod.console_set_color_control(C.COL4 ,libtcod.light_azure ,libtcod.black) # all other words libtcod.console_set_color_control(libtcod.COLCTRL_5 ,libtcod.white ,libtcod.black) return libtcod.console_new(C.MAP_WIDTH, C.MAP_HEIGHT)
objects = file['objects'] player = objects[file['player_index']] inventory = file['inventory'] game_msgs = file['game_msgs'] game_state = file['game_state'] file.close() initialize_fov() ######################################### # 3 INSTANTIATE OUR CLASSES FOR GAME # # # ######################################### libtcod.console_set_custom_font( 'terminal10x10_gs_tc.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'roguelike demo with libtcod', False) con = libtcod.console_new( SCREEN_WIDTH, SCREEN_HEIGHT ) #this has created an offscreen console we'll use instead of printing to the main console libtcod.sys_set_fps(LIMIT_FPS) panel = libtcod.console_new(SCREEN_WIDTH, PANEL_HEIGHT) ######################################### # 4 MAIN LOOP # # # ######################################### main_menu()
fov_recompute = True ambient_recompute = True game_state = 'playing' player_action = None frame_counter = 0 next_random_frame = random_frame() init_start() init_mechanics() init_ambience() #libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'python/libtcod tutorial', False) libtcod.sys_set_fps(LIMIT_FPS) con = libtcod.console_new(MAP_WIDTH, MAP_HEIGHT) panel = libtcod.console_new(SCREEN_WIDTH, PANEL_HEIGHT) #a warm welcoming message! message('Welcome stranger! Prepare to perish in the Tombs of the Ancient Kings.', libtcod.red) sound_general_start.play() while not libtcod.console_is_window_closed(): #render the screen render_graphics() #recompute ambient sound voumes render_ambience() #random ambient sounds
#open previously saved shelve global map, objects, player, inventory, game_msgs, game_state file = shelve.open('savegame', 'r') map = file['map'] objects = file['objects'] player = objects[file['player_index']] inventory = file['inventory'] game_msgs = file['game_msgs'] game_state = file['game_state'] file.close() initialize_fov() ######################################### # 3 INSTANTIATE OUR CLASSES FOR GAME # # # ######################################### libtcod.console_set_custom_font('terminal10x10_gs_tc.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'roguelike demo with libtcod', False) con = libtcod.console_new(SCREEN_WIDTH, SCREEN_HEIGHT) #this has created an offscreen console we'll use instead of printing to the main console libtcod.sys_set_fps(LIMIT_FPS) panel = libtcod.console_new(SCREEN_WIDTH, PANEL_HEIGHT) ######################################### # 4 MAIN LOOP # # # ######################################### main_menu()
elif key.vk >= libtcod.KEY_0 and key.vk <= libtcod.KEY_KP9: # If amulet is displayed, redirect numeric input to amulet amulet.keyboard_input(key.vk) ############################################# # Initialization & Main Loop ############################################# libtcod.console_set_custom_font( 'res/dejavu16x16_gs_tc.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'Amulet of Yelpdor', False) libtcod.sys_set_fps(LIMIT_FPS) console = libtcod.console_new(SCREEN_WIDTH, SCREEN_HEIGHT) district = District() dungeon_map = generate_city_map(MAP_WIDTH, MAP_HEIGHT, district) dungeon_map.init_fov_map() screen = Screen(width=SCREEN_WIDTH, height=SCREEN_HEIGHT) camera = Camera(CAMERA_WIDTH, CAMERA_HEIGHT, dungeon_map) renderer = Renderer(console, screen, camera) messenger = Messenger(width=MESSENGER_WIDTH, height=MESSENGER_HEIGHT, screen=screen) player = Player(dungeon_map.spawn[0], dungeon_map.spawn[1], '@', libtcod.white) dungeon_map.objects.append(player) stats = Stats(48, 3, player) amulet = Amulet(player, 48, 12, district)
game_state = 'playing' player_action = None frame_counter = 0 next_random_frame = random_frame() init_start() init_mechanics() init_ambience() #libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'python/libtcod tutorial', False) libtcod.sys_set_fps(LIMIT_FPS) con = libtcod.console_new(MAP_WIDTH, MAP_HEIGHT) panel = libtcod.console_new(SCREEN_WIDTH, PANEL_HEIGHT) #a warm welcoming message! message( 'Welcome stranger! Prepare to perish in the Tombs of the Ancient Kings.', libtcod.red) sound_general_start.play() while not libtcod.console_is_window_closed(): #render the screen render_graphics() #recompute ambient sound voumes render_ambience()
MAP_WIDTH = 70 MAP_HEIGHT = 46 FOV_ALGO = 0 FOV_LIGHT_WALLS = True TORCH_RADIUS = 10 random = libtcod.random_new() libtcod.console_set_custom_font( "terminal12x12_gs_ro.png", libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_ASCII_INROW ) libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, "rogue-one", False, libtcod.RENDERER_GLSL) con = libtcod.console_new(SCREEN_WIDTH, SCREEN_HEIGHT) map_gen = BSPGenerator(random) map = map_gen.generate_map(MAP_WIDTH, MAP_HEIGHT, 1) map_gen.run(map) world = Level(MAP_WIDTH, MAP_HEIGHT, con) tiler = TileGenerator() tiler.run(world, map) player = Entity(27, 22, "@", libtcod.white, con, world) npc = Entity(56, 27, "J", libtcod.yellow, con, world) objects = [npc, player] fov_map = libtcod.map_new(MAP_WIDTH, MAP_HEIGHT) for y in range(MAP_HEIGHT):