def main(): # setup screen ltc.console_set_custom_font('lucida10x10_gs_tc.png', ltc.FONT_TYPE_GREYSCALE | ltc.FONT_LAYOUT_TCOD) ltc.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'python/ltc tutorial', fullscreen=False) ltc.sys_set_fps(LIMIT_FPS) con = ltc.console_new(LEVEL_WIDTH, LEVEL_HEIGHT) gui_panel = ltc.console_new(PANEL_WIDTH, PANEL_HEIGHT) # setup level leveldata, start_pos = leveltools.make_level(LEVEL_WIDTH, LEVEL_HEIGHT) fov_recompute = True # setup player leveldata.player = rlplayer.create_player(start_pos[0], start_pos[1]) leveldata.objects.insert(0, leveldata.player) rlmobs.populate_enemies(leveldata) rlitems.populate_items(leveldata) src.rlmsglog.m('Welcome to the dungeon!') # game state game_state = GS_PLAYING # MAIN LOOP while not ltc.console_is_window_closed(): # get user input mouse = ltc.Mouse() key = ltc.Key() ltc.sys_check_for_event(ltc.EVENT_KEY_PRESS | ltc.EVENT_MOUSE, key, mouse) if fov_recompute: leveldata.recompute_fov(TORCH_RADIUS) # draw level draw_level(con, leveldata) # noinspection PyTypeChecker draw_gui(gui_panel, con, leveldata, mouse) # display level ltc.console_blit(con, 0, 0, LEVEL_WIDTH, LEVEL_HEIGHT, 0, 0, 0) ltc.console_blit(gui_panel, 0, 0, PANEL_WIDTH, PANEL_HEIGHT, 0, 0, PANEL_Y) ltc.console_flush() clear_console(con) clear_console(gui_panel) # handle user input # noinspection PyTypeChecker player_taken_turn = handle_input(key, mouse, game_state, leveldata, con) if should_exit: break # all objects take their turn - player is first if game_state == GS_PLAYING and player_taken_turn: fov_recompute = True for o in leveldata.objects: o.take_turn(leveldata) if not leveldata.player.fighter.is_alive(): game_state = GS_DEAD
void_color = libtcod.Color(0, 0, 0) color_pairs = { "void": (libtcod.Color(0, 0, 0), libtcod.Color(0, 0, 0)), "bg_wall": (libtcod.Color(25, 25, 25), libtcod.Color(50, 50, 25)), "fg_wall": (libtcod.Color(50, 50, 50), libtcod.Color(75, 75, 50)), "bg_floor": (libtcod.Color(50, 50, 50), libtcod.Color(75, 75, 50)), "fg_floor": (libtcod.Color(75, 75, 75), libtcod.Color(100, 100, 75)), "fg_stairs": (libtcod.Color(100, 100, 75), libtcod.Color(125, 125, 75)), } libtcod.console_set_custom_font('consolas_unicode_12x12.png', libtcod.FONT_LAYOUT_ASCII_INROW | libtcod.FONT_TYPE_GREYSCALE, nb_char_horiz=32, nb_char_vertic=64) libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'rbowl', False) libtcod.sys_set_fps(LIMIT_FPS) class Game: def __init__(self): self.state = 'playing' self.player_action = None self.map = Map() self.player = Object(self.map, self.map.start_x, self.map.start_y, '@', 'player', blocks=True) self.screen = Screen(self, self.map) self.screen.move(self.map.start_x - SCREEN_WIDTH/2, self.map.start_y - SCREEN_HEIGHT/2)
import os from libtcod import libtcodpy as libtcod import map_vars as M # Set the fps. libtcod.sys_set_fps(45) # Font path font = os.path.join(b'data', b'fonts', b'consolas10x10_gs_tc.png') # Set the custom font. libtcod.console_set_custom_font(font, libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) # Initialize the root console. libtcod.console_init_root (M.SCREEN_WIDTH, M.SCREEN_HEIGHT, b'zombie.py', False) # Create the game console. game_console = libtcod.console_new(M.MAP_WIDTH, M.MAP_HEIGHT) gun_console = libtcod.console_new(M.MAP_WIDTH, M.MAP_HEIGHT) # Make the background of gun_console transparent on black. libtcod.console_set_key_color(gun_console,libtcod.black) # Create an items console items_console = libtcod.console_new(30, 40) menu_console = libtcod.console_new(M.SCREEN_WIDTH, M.SCREEN_HEIGHT)