def render_mouse(mouse_window, mouse, screen_width, screen_height, fov_map): """ Create a 'X'in mouse_window under mouse while in FOV :param mouse_window: :param mouse: :param screen_width: :param screen_height: :param fov_map: :return: """ #todo change map_is_in_fov if libtcod.map_is_in_fov(fov_map, mouse.cx, mouse.cy): #todo update all console to new tcod console commands libtcod.console_set_char_foreground(mouse_window, mouse.cx, mouse.cy, libtcod.yellow) libtcod.console_set_char(mouse_window, mouse.cx, mouse.cy, 'X') libtcod.console_blit(mouse_window, 0, 0, screen_width, screen_height, 0, 0, 0, 1, 0) libtcod.console.Console.clear(mouse_window)
def clear_cell(con, x, y, game_map): # print the floor of a cell wall = game_map.is_blocked(x, y) door = game_map.is_door(x, y) visible = game_map.is_visible(x, y) if visible: game_map.tiles[x][y].is_seen = True tcod.console_set_char_background(con, x, y, const.base03) if game_map.tiles[x][y].is_seen: if visible: tcod.console_set_char_foreground( con, x, y, game_map.tiles[x][y].visible_color) else: tcod.console_set_char_foreground(con, x, y, game_map.tiles[x][y].hidden_color) tcod.console_set_char(con, x, y, game_map.tiles[x][y].char) else: tcod.console_set_char(con, x, y, ' ')
def draw_entity(con, entity, game_map, player): visible = game_map.is_visible(entity.x, entity.y) if visible\ or (entity.is_seen and (isinstance(entity, ent.Weapon) or isinstance(entity, ent.Feature)))\ or (isinstance(entity, ent.Monster) and isinstance(player.active_weapon, ent.TelepathicWeapon)): # are visible: what is directly visible, remembered weapon and feature. When telepathic, monster are visible too tcod.console_set_char_background(con, entity.x, entity.y, const.base03) if visible: if (isinstance(entity, ent.Monster) and entity.confusion_date): tcod.console_set_char_background(con, entity.x, entity.y, entity.visible_color) tcod.console_set_char_foreground(con, entity.x, entity.y, const.base03) else: tcod.console_set_char_foreground(con, entity.x, entity.y, entity.visible_color) else: tcod.console_set_char_foreground(con, entity.x, entity.y, entity.hidden_color) tcod.console_set_char(con, entity.x, entity.y, entity.char)
def test_console_set_char(console, ch): libtcodpy.console_set_char(console, 0, 0, ch) assert_char(console, 0, 0, ch=ch)
def test_console_set_char(console, ch): libtcodpy.console_set_char(console, 0, 0, ch) assert_char(console, 0, 0, ch=ch)
def render_all(con, panel, entities, player, game_map, fov_map, fov_recompute, message_log, screen_width, screen_height, acting_member, bar_width, panel_height, panel_y, mouse, colors, target_tiles=None): """ Draw all entities in the list :param con: destination drawing console :param panel: drawing surface for messages, etc. :param entities: list of Entity objects :param player: the player Entity object :param game_map: GameMap object :param fov_map: map of field of view :param fov_recompute: boolean :param message_log: MessageLog object containing list of messages :param screen_width: int width of screen :param screen_height: int height of screen :param acting_member: int selected member of party :param bar_width: int width of bar for panel :param panel_height: int height of panel :param panel_y: int location of panel :param mouse: tuple mouse location :param colors: dict of color tuples :param target_tiles: list of tuple tile coordinates for target tiles to be highlighted :return: None """ if fov_recompute: for y in range(game_map.height): for x in range(game_map.width): visible = libtcod.map_is_in_fov(m=fov_map, x=x, y=y) wall = game_map.tiles[x][y].block_sight if visible: if wall: libtcod.console_set_char_foreground( con=con, x=x, y=y, col=colors.get('light_ground')) libtcod.console_set_char(con=con, x=x, y=y, c='-') libtcod.console_set_char_background( con=con, x=x, y=y, col=colors.get('light_wall'), flag=libtcod.BKGND_SET) else: libtcod.console_set_char_foreground( con=con, x=x, y=y, col=colors.get('light_wall')) libtcod.console_set_char(con=con, x=x, y=y, c='.') libtcod.console_set_char_background( con=con, x=x, y=y, col=colors.get('light_ground'), flag=libtcod.BKGND_SET) game_map.tiles[x][y].explored = True elif game_map.tiles[x][y].explored: if wall: libtcod.console_set_char(con=con, x=x, y=y, c=' ') libtcod.console_set_char_background( con=con, x=x, y=y, col=colors.get('dark_wall'), flag=libtcod.BKGND_SET) else: libtcod.console_set_char(con=con, x=x, y=y, c=' ') libtcod.console_set_char_background( con=con, x=x, y=y, col=colors.get('dark_ground'), flag=libtcod.BKGND_SET) if target_tiles and (x, y) in target_tiles: libtcod.console_set_char_background( con=con, x=x, y=y, col=libtcod.lighter_red, flag=libtcod.BKGND_SET) entities_in_render_order = sorted(entities, key=lambda z: z.render_order.value) for entity in entities_in_render_order: draw_entity(con=con, entity=entity, fov_map=fov_map) # noinspection PyTypeChecker libtcod.console_blit(src=con, x=0, y=0, w=screen_width, h=screen_height, dst=0, xdst=0, ydst=0) libtcod.console_set_default_background(con=panel, col=libtcod.darker_gray) libtcod.console_clear(con=panel) # Print the game messages, one line at a time y = 1 for message in message_log.messages: # libtcod.console_set_key_color(panel, libtcod.gray) libtcod.console_set_default_foreground(con=panel, col=message.color) libtcod.console_print_ex(con=panel, x=message_log.x, y=y, flag=libtcod.BKGND_NONE, alignment=libtcod.LEFT, fmt=message.text) y += 1 # get entities under mouse text2 = None text = get_names_under_mouse(mouse=mouse, entities=entities, fov_map=fov_map) if not text: text = player.name text2 = 'Gold: {}'.format(player.party.coins) libtcod.console_set_default_foreground(con=panel, col=libtcod.white) libtcod.console_print_ex(con=panel, x=1, y=0, flag=libtcod.BKGND_NONE, alignment=libtcod.LEFT, fmt=text) if text2: libtcod.console_print_ex(con=panel, x=bar_width, y=0, flag=libtcod.BKGND_NONE, alignment=libtcod.RIGHT, fmt=text2) target = get_party_under_mouse(mouse=mouse, entities=entities, fov_map=fov_map) if not target: target = player y = 1 x = 1 for member in target.party.members: if member.cooldown > 0: text_color = libtcod.red else: text_color = libtcod.white if target == player and acting_member and member == target.party.members[ acting_member - 1]: bkg_color = libtcod.light_gray else: bkg_color = libtcod.darker_gray render_member(panel, x, y, member, width=bar_width, text_color=text_color, bkg_color=bkg_color) y += 1 # y = 1 # for member in player.party.members: # if member.cooldown > 0: # render_bar(panel=panel, x=1, y=y, total_width=bar_width, name=member.name, value=member.cooldown, # bar_color=libtcod.darker_red, back_color=libtcod.darker_red) # else: # render_bar(panel=panel, x=1, y=y, total_width=bar_width, name=member.name, value=member.cooldown, # bar_color=libtcod.darker_gray, back_color=libtcod.darker_gray) # y += 1 # noinspection PyTypeChecker libtcod.console_blit(src=panel, x=0, y=0, w=screen_width, h=panel_height, dst=0, xdst=0, ydst=panel_y)
def render_all(con, panel, entities, player, game_map, fov_map, fov_recompute, message_log, screen_width, screen_height, bar_width, panel_height, panel_y, mouse, colors, game_state): if fov_recompute: # Draw all the tiles for y in range(game_map.height): for x in range(game_map.width): #todo change map_is_in_fov visible = libtcod.map_is_in_fov(fov_map, x, y) wall = game_map.tiles[x][y].block_sight if visible: if wall: #todo change the console char setting libtcod.console_set_char_foreground(con, x, y, colors.get('light_ground')) libtcod.console_set_char(con, x, y, '=') libtcod.console_set_char_background(con, x, y, colors.get('light_wall'), libtcod.BKGND_SET) else: #todo change the console char setting libtcod.console_set_char_foreground(con, x, y, colors.get('light_wall')) libtcod.console_set_char(con, x, y, '.') libtcod.console_set_char_background(con, x, y, colors.get('light_ground'), libtcod.BKGND_SET) game_map.tiles[x][y].explored = True elif game_map.tiles[x][y].explored: if wall: #todo change the console char setting libtcod.console_set_char_foreground(con, x, y, colors.get('dark_ground')) libtcod.console_set_char(con, x, y, '=') libtcod.console_set_char_background(con, x, y, colors.get('dark_wall'), libtcod.BKGND_SET) else: #todo change the console char setting libtcod.console_set_char_foreground(con, x, y, colors.get('dark_wall')) libtcod.console_set_char(con, x, y, '.') libtcod.console_set_char_background(con, x, y, colors.get('dark_ground'), libtcod.BKGND_SET) entities_in_render_order = sorted(entities, key=lambda x: x.render_order.value) # draw all entities in the list for entity in entities_in_render_order: draw_entity(con, entity, fov_map, game_map) #todo update to new tcod commands libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0) libtcod.console_set_default_background(panel, libtcod.black) libtcod.console_clear(panel) # Print the game messages, one line at a time y = 1 for message in message_log.messages: #todo change the console char setting libtcod.console_set_default_foreground(panel, message.color) libtcod.console_print_ex(panel, message_log.x, y, libtcod.BKGND_NONE, libtcod.LEFT, message.text) y += 1 # HP Bar render_bar(panel, 1, 1, bar_width, 'HP', player.fighter.hp, player.fighter.max_hp, libtcod.light_red, libtcod.darker_red) #todo change the console char setting libtcod.console_print_ex(panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT, 'Dungeon Depth: {0}'.format(game_map.dungeon_depth)) # print output from entities under mouse #todo change the console char setting libtcod.console_set_default_foreground(panel, libtcod.white) libtcod.console_print_ex(panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT, get_names_under_mouse(mouse, entities, fov_map)) libtcod.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0, panel_y) # Inventory call if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY): if game_state == GameStates.SHOW_INVENTORY: inventory_title = 'Select from Menu or Esc to cancel.\n' else: inventory_title = 'Select from Menu or Esc to cancel.\n' inventory_menu(con, inventory_title, player, 50, screen_width, screen_height) elif game_state == GameStates.LEVEL_UP: level_up_menu(con, 'Level Up! Choose a stat to raise:', player, 40, screen_width, screen_width) elif game_state == GameStates.CHARACTER_SCREEN: character_screen(player, 30, 10, screen_width, screen_height)
def draw_cell(con, pos, char, fg, bg=None): x, y = pos if bg: tcod.console_set_char_background(con, x, y, bg) tcod.console_set_char_foreground(con, x, y, fg) tcod.console_set_char(con, x, y, char)
def render_all(con, panel, entities, player, game_map, fov_map, fov_recompute, message_log, screen_width, screen_height, bar_width, panel_height, panel_y, mouse, colors, options_tutorial_enabled, game_state, names_list, colors_list, tick, tick_speed): if fov_recompute: # Draw all the tiles in the game map for y in range(game_map.height): for x in range(game_map.width): visible = libtcod.map_is_in_fov(fov_map, x, y) door = game_map.tiles[x][y].door wall = game_map.tiles[x][y].block_sight if door: libtcod.console_set_char_foreground( con, x, y, (255, 255, 255)) libtcod.console_set_char_background( con, x, y, colors.get('light_ground'), libtcod.BKGND_SET) libtcod.console_set_char(con, x, y, game_map.tiles[x][y].door.char) elif wall: #assign characters based on blitmap if game_map.blitmap[x][y] in [10]: #east-west walls if game_map.tiles[x][ y - 1].block_sight == False and game_map.tiles[x][ y + 1].empty_space: #floor above, empty space below libtcod.console_set_char_background( con, x, y, (0, 0, 0), libtcod.BKGND_SET) libtcod.console_set_char_foreground( con, x, y, colors.get('light_wall')) elif (game_map.tiles[x][y - 1].empty_space and game_map.tiles[x][y + 1].block_sight == False) or ( game_map.tiles[x][y - 1].block_sight == False and game_map.tiles[x][y + 1].block_sight == False): #empty space above, and floor below or floor above, floor below libtcod.console_set_char_background( con, x, y, colors.get('dark_ground'), libtcod.BKGND_SET) libtcod.console_set_char_foreground( con, x, y, colors.get('light_wall')) libtcod.console_set_char(con, x, y, 223) elif game_map.blitmap[x][y] in [0, 1, 2, 8, 11]: if game_map.tiles[x][y + 1].empty_space: libtcod.console_set_char_background( con, x, y, (0, 0, 0), libtcod.BKGND_SET) libtcod.console_set_char_foreground( con, x, y, colors.get('light_wall')) else: libtcod.console_set_char_background( con, x, y, colors.get('dark_ground'), libtcod.BKGND_SET) libtcod.console_set_char_foreground( con, x, y, colors.get('light_wall')) libtcod.console_set_char(con, x, y, 223) elif game_map.blitmap[x][y] in [3, 9]: #bottom left, bottom right corners if game_map.tiles[x][y + 1].empty_space: libtcod.console_set_char_background( con, x, y, (0, 0, 0), libtcod.BKGND_SET) libtcod.console_set_char_foreground( con, x, y, colors.get('light_wall')) else: libtcod.console_set_char_background( con, x, y, colors.get('dark_ground'), libtcod.BKGND_SET) libtcod.console_set_char_foreground( con, x, y, colors.get('light_wall')) libtcod.console_set_char(con, x, y, 223) elif game_map.blitmap[x][y] in [ 4, 5, 6, 7, 12, 13, 14, 15 ]: libtcod.console_set_char_background( con, x, y, colors.get('light_wall'), libtcod.BKGND_SET) libtcod.console_set_char_foreground( con, x, y, colors.get('light_wall')) libtcod.console_set_char(con, x, y, 218) else: #floor libtcod.console_set_char_background( con, x, y, colors.get('light_ground'), libtcod.BKGND_SET) if visible: game_map.tiles[x][y].explored = True else: if game_map.tiles[x][y].explored: #explored, not visible bgcolor = ( libtcod.console_get_char_background(con, x, y) * .33) fgcolor = ( libtcod.console_get_char_foreground(con, x, y) * .33) libtcod.console_set_char_background( con, x, y, bgcolor, libtcod.BKGND_SET) libtcod.console_set_char_foreground(con, x, y, fgcolor) else: libtcod.console_set_char_background( con, x, y, (0, 0, 0), libtcod.BKGND_SET) libtcod.console_set_char_foreground( con, x, y, (0, 0, 0)) entities_in_render_order = sorted(entities, key=lambda x: x.render_order.value) # Draw all entities in the list for entity in entities_in_render_order: draw_entity(con, entity, fov_map, game_map, tick, tick_speed) libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0) libtcod.console_set_default_background(panel, libtcod.black) libtcod.console_clear(panel) libtcod.console_set_default_foreground(panel, libtcod.white) if game_state == GameStates.KEYTARGETING: if player.y >= game_map.height / 2: #player on bottom half of the screen (tx, ty) = (58, 2) else: #player on top half of the map (tx, ty) = (58, 32) libtcod.console_set_default_background(0, libtcod.lighter_blue) libtcod.console_set_default_foreground(0, libtcod.black) libtcod.console_print_ex(0, tx, ty, libtcod.BKGND_SET, libtcod.RIGHT, "Press [esc] to exit targeting.") #print mouse x/y #libtcod.console_print_ex(panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT, (str(mouse.cx) + "," + str(mouse.cy))) if options_tutorial_enabled: MAP_HEIGHT = game_map.height MAP_WIDTH = game_map.width if game_map.dungeon_level < 3: libtcod.console_set_default_background(0, libtcod.lighter_yellow) libtcod.console_set_default_foreground(0, libtcod.black) if player.y >= MAP_HEIGHT / 2: #player on bottom half of the screen (tx, ty) = (58, 2) else: #player on top half of the map (tx, ty) = (58, MAP_HEIGHT - 2) if game_state != GameStates.KEYTARGETING: if player.turn_count < 4: libtcod.console_print_ex( 0, tx, ty, libtcod.BKGND_SET, libtcod.RIGHT, "Use the numpad or arrow keys to move.") elif player.turn_count < 9: libtcod.console_print_ex( 0, tx, ty, libtcod.BKGND_SET, libtcod.RIGHT, "You can move into creatures to attack with a melee ") libtcod.console_print_ex( 0, tx, ty + 1, libtcod.BKGND_SET, libtcod.RIGHT, "weapon, or press [f] to fire a ranged weapon.") elif player.turn_count < 14: libtcod.console_print_ex( 0, tx, ty, libtcod.BKGND_SET, libtcod.RIGHT, "Press [x] to examine creatures or items on the ground." ) else: for ent in entities: if not ent.name == "Player": if ent.x == player.x and ent.y == player.y: if ent.name == "stairs": libtcod.console_print_ex( 0, tx, ty, libtcod.BKGND_SET, libtcod.RIGHT, "Press [Enter] to go down the stairs.") elif ent.item: if not game_map.tiles[ent.x][ent.y].door: libtcod.console_print_ex( 0, tx, ty, libtcod.BKGND_SET, libtcod.RIGHT, "Press [g] to grab an item.") myneighbors = [(-1, -1), (0, -1), (1, -1), (-1, 0), (1, 0), (-1, 1), (0, 1), (1, 1)] for dx, dy in myneighbors: tdx, tdy = player.x + dx, player.y + dy if game_map.tiles[tdx][tdy].door: if game_map.tiles[tdx][tdy].block_sight: libtcod.console_print_ex( 0, tx, ty, libtcod.BKGND_SET, libtcod.RIGHT, "Move into a closed door to open it.") else: libtcod.console_print_ex( 0, tx, ty, libtcod.BKGND_SET, libtcod.RIGHT, "Press [c] and then a direction to close an open door." ) # Print the game messages, one line at a time # y = 1 # for message in message_log.messages: # libtcod.console_set_default_foreground(panel, message.color) # libtcod.console_print_ex(panel, message_log.x, y, libtcod.BKGND_NONE, libtcod.LEFT, message.text) # y += 1 render_bar(panel, 1, 1, bar_width, 'HP', player.fighter.hp, player.fighter.max_hp, libtcod.light_red, libtcod.darker_red) # libtcod.console_print_ex(panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT, # 'Dungeon level: {0}'.format(game_map.dungeon_level)) # libtcod.console_print_ex(panel, 1, 4, libtcod.BKGND_NONE, libtcod.LEFT, # 'Turn : {0}'.format(player.turn_count)) #print condition icons if len(player.conditions) > 0: ind = 0 for condition in player.conditions: if condition.active: libtcod.console_print_ex(panel, 1 + ind, 2, libtcod.BKGND_SET, libtcod.LEFT, condition.char) libtcod.console_set_char_background(panel, 1 + ind, 2, condition.bgcolor, libtcod.BKGND_SET) libtcod.console_set_char_foreground(panel, 1 + ind, 2, condition.fgcolor) ind += 1 #timeline libtcod.console_set_default_foreground(panel, libtcod.dark_gray) libtcod.console_print_ex(panel, 22, 1, libtcod.BKGND_NONE, libtcod.LEFT, chr(195)) #195 > libtcod.console_print_ex(panel, 58, 1, libtcod.BKGND_NONE, libtcod.LEFT, chr(180)) #180 < for x in range(23, 58): libtcod.console_print_ex(panel, x, 1, libtcod.BKGND_NONE, libtcod.LEFT, chr(196)) #196 - libtcod.console_set_default_foreground(panel, libtcod.white) libtcod.console_print_ex(panel, 23, 1, libtcod.BKGND_NONE, libtcod.LEFT, chr(player.char)) #player char turn_order = [] for ent in entities: if not ent.name == player.name and ent.ai and libtcod.map_is_in_fov( fov_map, ent.x, ent.y): temp_enemy_timer = ent.fighter.timer + ent.fighter.speed while temp_enemy_timer >= player.fighter.speed: turn_order.append(ent) temp_enemy_timer -= player.fighter.speed x = 25 for ent in turn_order: if x < 58: libtcod.console_print_ex(panel, x, 1, libtcod.BKGND_NONE, libtcod.LEFT, chr(ent.char + 1)) x = x + 2 #check for timeline highlighting if mouse.cy == 37: if mouse.cx >= 25 and mouse.cx <= 57: timeline_index = (mouse.cx - 25) if mouse.cx % 2 == 0: timeline_index -= 1 timeline_index = int(timeline_index / 2) else: timeline_index = 99 if timeline_index <= len(turn_order) - 1 and tick % tick_speed < 2: ent = turn_order[timeline_index] libtcod.console_set_default_foreground(0, libtcod.lighter_yellow) libtcod.console_print_ex(0, ent.x, ent.y, libtcod.BKGND_NONE, libtcod.LEFT, chr(ent.char)) # TODO :: Look at this... this code was an attempt to highlight each occurance of a highlighted creature in the timeline #so if you highlight a rat, and he gets two turns, I wanted both of his sprites on the timeline to highlight. #didn't work, but it did manage to highlight the specific sprite you were hovering over on the timeline. # for e in turn_order: # if e == turn_order[timeline_index]: # ex = 25 + (2*timeline_index) # libtcod.console_set_default_foreground(panel, libtcod.lighter_yellow) # libtcod.console_print_ex(panel, ex, 1, libtcod.BKGND_NONE, libtcod.LEFT, chr(ent.char)) for ent in entities: if libtcod.map_is_in_fov( fov_map, ent.x, ent.y ) and ent.x == mouse.cx and ent.y == mouse.cy and ent.name != "Targeter" and ent.name != "Player": if ent.fighter: #print a context menu for the lil guy context_menu(game_map.width, game_map.height, ent, names_list) break else: render_tooltip(ent.x + 1, ent.y - 1, ent.name) if game_state == GameStates.KEYTARGETING: targeter = None for ent in entities: if ent.name == 'Targeter': targeter = ent if not targeter == None: #libtcod.console_set_default_foreground(panel, libtcod.light_gray) libtcod.console_print_ex( panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT, get_all_at(targeter.x, targeter.y, entities, fov_map, game_map, names_list)) for ent in entities: if libtcod.map_is_in_fov( fov_map, ent.x, ent.y ) and ent.x == targeter.x and ent.y == targeter.y and ent.name != "Targeter" and ent.name != "Player": if ent.fighter: #print a context menu for the lil guy context_menu(game_map.width, game_map.height, ent, names_list) break else: render_tooltip(ent.x + 1, ent.y - 1, ent.name) libtcod.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0, panel_y) if game_state == GameStates.PLAYERS_TURN: if len(player.conditions) > 0: if mouse.cy == 35: #the row where status icons are displayed if mouse.cx > 0 and mouse.cx <= len(player.conditions): render_tooltip(mouse.cx + 1, 36, player.conditions[mouse.cx - 1].tooltip) if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY): if game_state == GameStates.SHOW_INVENTORY: inventory_title = 'Press the key next to an item to use it, or Esc to cancel.\n' else: inventory_title = 'Press the key next to an item to drop it, or Esc to cancel.\n' inventory_menu(con, inventory_title, player, 50, screen_width, screen_height) elif game_state == GameStates.LEVEL_UP: level_up_menu(con, 'Level up! Choose a stat to raise:', player, 40, screen_width, screen_height) elif game_state == GameStates.CHARACTER_SCREEN: character_screen(player, 30, 10, screen_width, screen_height)