def show_player_stats(): player_stats=libtcod.console_new(20,20) libtcod.console_set_default_background(player_stats,libtcod.darkest_grey) libtcod.console_set_default_foreground(player_stats, libtcod.white) # libtcod.console_clear(player_stats) libtcod.console_print_frame(player_stats, 0, 0, libtcod.console_get_width(player_stats), libtcod.console_get_height(player_stats), clear=True) height=0 libtcod.console_print_rect(player_stats, 1, 1, libtcod.console_get_width(player_stats)-2, libtcod.console_get_height(player_stats)-2, "Name: %s \nHealth: %s/%s\nView distance: %s\nStrength: %s\nTo hit: %s\nExp: %s"# %(P.player.name,P.player.health,P.player.max_health, P.player.view_distance, P.player.strength,P.player.to_hit,P.player.exp)) libtcod.console_print_ex(player_stats, libtcod.console_get_width(player_stats)//2, 0, libtcod.BKGND_DEFAULT, libtcod.CENTER, "Player Stats") libtcod.console_print_ex(player_stats, libtcod.console_get_width(player_stats)//2, libtcod.console_get_height(player_stats)-1, libtcod.BKGND_DEFAULT, libtcod.CENTER, "[spacebar]") libtcod.console_blit(player_stats,0,0, libtcod.console_get_width(player_stats), libtcod.console_get_height(player_stats), 0,5,5, 1.0,0.1) key = libtcod.console_check_for_keypress(libtcod.KEY_PRESSED) while not (libtcod.KEY_SPACE==key.vk): key = libtcod.console_check_for_keypress(libtcod.KEY_PRESSED) libtcod.console_blit(player_stats,0,0, libtcod.console_get_width(player_stats), libtcod.console_get_height(player_stats), 0,5,5, 1.0,0.1) libtcod.console_flush() R.render()
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) self.fov_recompute = True self.con = libtcod.console_new(SCREEN_WIDTH, SCREEN_HEIGHT) libtcod.console_set_default_foreground(self.con, libtcod.white) self.pressed = set()
def __init__ (self, width, height, seed = None): """ Initialise the map """ self.width, self.height = width, height self.console = libtcod.console_new(width, height) # Setup logging and log the type of map being created self.log = getlog(str(self.__class__)) self.log.info("Generating a {}".format(self.__class__.__name__)) # Setup rng RngTrait.__init__(self, seed) # Setup tiles and fill with None self.tiles = [ [ None for x in range(self.height) ] for y in range(self.width) ] # Setup objects list self.objects = [] # Default spawn point self.spawn = (1,1)
def draw_menu(con, header, options, w, screen_w, screen_h): if len(options) > 26: raise ValueError('Menu "' + header + '" has ' + str(len(options)) + ' options but max is 26') # calculate height (header is word-wrapped) header_h = ltc.console_get_height_rect(con, 0, 0, w, screen_h, header) h = len(options) + header_h # add space for border w += 2 h += 2 # create new console window window = ltc.console_new(w, h) # draw border and header draw_panel_border(window, w, h) dotext(window, 1, 1, header) # draw options y = header_h + 1 letter_index = ord('a') for o in options: text = '(' + chr(letter_index) + ') ' + o dotext(window, 1, y, text) y += 1 letter_index += 1 # blit menu to main console x = screen_w / 2 - w / 2 y = screen_h / 2 - h / 2 ltc.console_blit(window, 0, 0, w, h, 0, x, y, 1.0, 0.7) # show menu and wait for player choice ltc.console_flush() key = ltc.console_wait_for_keypress(True) index = key.c - ord('a') return index if 0 <= index < len(options) else None
from libtcod import libtcodpy as libtcod import console as cons #import player as P import map_vars as M # Create the game status console. status = '' status_console = libtcod.console_new(M.SCREEN_WIDTH, (M.SCREEN_HEIGHT - M.MAP_HEIGHT)) libtcod.console_set_alignment(status_console, libtcod.LEFT) def add_status (new_status): global status status = ("%s %s" % (status, new_status)) display_status() def clear_status (): global status status = "" # Displays the parsed string as a status message to the user. # Doesn't display strings larger than SCREEN_WIDTH yet. def display_status (): global status if status: libtcod.console_rect(status_console, 0, 0, M.SCREEN_WIDTH, (M.SCREEN_HEIGHT - M.MAP_HEIGHT), True) libtcod.console_set_default_foreground (status_console, libtcod.white) while len(status) > M.SCREEN_WIDTH*2: display_statusline(status[:M.SCREEN_WIDTH*2]) key = libtcod.console_wait_for_keypress(True) while not key.vk == libtcod.KEY_SPACE:
if forcedim: (width, height) = libtcod.sys_get_current_resolution() (chw, chh) = libtcod.sys_get_char_size() width = (width / chw) height = (height / chh) libtcod.console_init_root(w=width, h=height, title='RogueLike', fullscreen=maximize) libtcod.sys_set_fps(LIMIT_FPS) # consoles w = width h = height*10//100 x = 0 y = 0 map_ = { 'w': w, 'h': h, 'x': x, 'y': y, 'con': libtcod.console_new(w, h), 'name': 'messages' } areas['messages'] = map_ w = width*80//100 + (1 if width % 5 != 0 else 0) h = height*80//100 + (2 if height % 10 > 5 else 1) x = 0 y = height*10//100 map_ = { 'w': w, 'h': h, 'x': x, 'y': y, 'con': libtcod.console_new(w, h), 'name': 'main' } areas['main'] = map_ w = width*20//100 h = height*80//100 + (2 if height % 10 > 5 else 1) x = width*80//100 + (1 if width % 5 != 0 else 0) y = height*10//100 map_ = { 'w': w, 'h': h, 'x': x, 'y': y, 'con': libtcod.console_new(w, h), 'name': 'playerstats' } areas['playerstats'] = map_
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
def init_map(self): self.clientMap = utils.recv_msg(self.clientSock) self.clientMap.console = libtcod.console_new(self.clientMap.width, self.clientMap.height)
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)
def new_window(self, dimensions): rows, columns = dimensions window = libtcod.console_new(columns, rows) return TCODWindow(window)
def __init__(self, width, height): self.con = libtcod.console_new(width, height) self.width = width self.height = height