예제 #1
0
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):
	# Draw all the tiles in the game map
	if fov_recompute:
		for y in range(game_map.height):
			for x in range(game_map.width):
				visible = libtcod.map_is_in_fov(fov_map, x, y)
				wall = game_map.tiles[x][y].block_sight

				if visible:
					if wall:
						libtcod.console_set_char_background(con, x, y, colors.get('light_wall'), libtcod.BKGND_SET)
					else:
						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:
						libtcod.console_set_char_background(con, x, y, colors.get('dark_wall'), libtcod.BKGND_SET)
					else:
						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)

	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:
		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_set_default_foreground(panel, libtcod.light_gray)
	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)

	if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
		if game_state == GameStates.SHOW_INVENTORY:
			inventory_title = 'Press the key next to the 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.inventory, 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)
예제 #2
0
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, colours, game_state):

    # draws tiles onto the game map
    if fov_recompute:
        for y in range(game_map.height):
            for x in range(game_map.width):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = game_map.tiles[x][y].block_sight

                if visible:
                    if wall:
                        libtcod.console_set_char_background(
                            con, x, y, colours.get("light_wall"),
                            libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_char_background(
                            con, x, y, colours.get("light_ground"),
                            libtcod.BKGND_SET)
                    game_map.tiles[x][y].explored = True
                elif game_map.tiles[x][y].explored:
                    if wall:
                        libtcod.console_set_char_background(
                            con, x, y, colours.get("dark_wall"),
                            libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_char_background(
                            con, x, y, colours.get("dark_ground"),
                            libtcod.BKGND_SET)

    entities_in_render_order = sorted(entities,
                                      key=lambda x: x.render_order.value)

    for entity in entities_in_render_order:
        draw_entity(con, entity, fov_map, game_map)

    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)

    # Prints game messages
    y = 2
    for message in message_log.messages:
        libtcod.console_set_default_foreground(panel, message.colour)
        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_set_default_foreground(panel, libtcod.light_gray)
    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)

    if game_state in (GameStates.SHOWING_INVENTORY,
                      GameStates.DROPPING_INVENTORY):
        if game_state == GameStates.SHOWING_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.LEVELED_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)
예제 #3
0
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):
    #  Draw all the tiles in game_map
    if fov_recompute:
        for y in range(game_map.height):
            for x in range(game_map.width):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = game_map.tiles[x][y].block_sight

                if visible:
                    if wall:
                        libtcod.console_set_char_background(
                            con, x, y, colors.get('light_wall'),
                            libtcod.BKGND_SET)
                    else:
                        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:
                        libtcod.console_set_char_background(
                            con, x, y, colors.get('dark_wall'),
                            libtcod.BKGND_SET)
                    else:
                        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 of the entities in 'entities'
    for entity in entities_in_render_order:
        draw_entity(con, entity, fov_map, game_map)

    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:
        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,
                             f"Dungeon Level: {game_map.dungeon_level}")

    libtcod.console_set_default_foreground(panel, libtcod.light_gray)
    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)

    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        action = 'use' if game_state == GameStates.SHOW_INVENTORY else 'drop'
        inventory_title = f'Press the key next to an item to {action} it'

        inventory_menu(con, inventory_title, player.inventory, 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)
예제 #4
0
def render_all(console, panel, entities, player, game_map, fov_map, fov_recompute, message_log, screen_width, screen_height, bar_width, panel_height, panel_y, mouse, game_state):
    if fov_recompute:
        for y in range(game_map.height):
            for x in range(game_map.width):
                visible = tcod.map_is_in_fov(fov_map, x, y)
                wall = game_map.tiles[x][y].block_sight
                trap = game_map.tiles[x][y].trap

                if visible:
                    if wall:
                        tcod.console_put_char_ex(console, x, y, '#', tcod.white, tcod.black)
                    elif trap:
                        tcod.console_put_char_ex(console, x, y, trap.char, trap.colour, tcod.gray)
                    else:
                        tcod.console_put_char_ex(console, x, y, ' ', tcod.white, tcod.gray)
                    
                    game_map.tiles[x][y].explored = True

                elif game_map.tiles[x][y].explored:
                    if wall:
                        tcod.console_put_char_ex(console, x, y, '#', tcod.gray, tcod.black)
                    else:
                        tcod.console_put_char_ex(console, x, y, ' ', tcod.lightest_gray, tcod.black)

    entities_in_render_order = sorted(entities, key=lambda x: x.render_order.value)

    for entity in entities_in_render_order:
        draw_entity(console, entity, fov_map, game_map)

    tcod.console_blit(console, 0, 0, screen_width, screen_height, 0, 0, 0)

    tcod.console_set_default_background(panel, tcod.black)
    tcod.console_clear(panel)

    y = 1
    for message in message_log.messages:
        tcod.console_set_default_foreground(panel, message.colour)
        tcod.console_print_ex(panel, message_log.x, y, tcod.BKGND_NONE, tcod.LEFT, message.text)
        y += 1

    render_bar(panel, 1, 1, bar_width, 'HP', player.combat_entity.hp, player.combat_entity.max_hp, tcod.light_red, tcod.darker_red)
    render_bar(panel, 1, 3, bar_width, 'MANA', player.combat_entity.mana, player.combat_entity.max_mana, tcod.light_blue, tcod.darker_blue)

    tcod.console_print_ex(panel, screen_width - bar_width, 0, tcod.BKGND_NONE, tcod.LEFT, 'Visible Enemies:')

    y = 1
    for entity in entities:
        if entity.combat_entity and entity is not player and tcod.map_is_in_fov(fov_map, entity.x, entity.y) and entity.combat_entity.hp > 0:
            render_enemy_bar(panel, screen_width - bar_width, y, bar_width, '{0} '.format(entity.name), entity.combat_entity.hp, entity.combat_entity.max_hp, tcod.light_red, tcod.darker_red)
            y += 2

    tcod.console_print_ex(panel, screen_width - bar_width - 20, 0, tcod.BKGND_NONE, tcod.LEFT, 'Dungeon Depth: {0}'.format(game_map.dungeon_depth))
    tcod.console_print_ex(panel, screen_width - bar_width - 20, 1, tcod.BKGND_NONE, tcod.LEFT, 'Score: {0}'.format(player.score))

    tcod.console_set_default_foreground(panel, tcod.light_gray)
    tcod.console_print_ex(panel, 1, 0, tcod.BKGND_NONE, tcod.LEFT, hover_names(mouse, entities, fov_map))

    tcod.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0, panel_y)

    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. Press Esc to cancel.\n'
        else:
            inventory_title = 'Press the key next to an item to drop it. Press Esc to cancel.\n'

        inventory_menu(console, inventory_title, player, 50, screen_width, screen_height)
    
    elif game_state == GameStates.SPELL_LIST:
        spell_menu(console, 'Spell List', player, 50, screen_width, screen_height)
    
    elif game_state == GameStates.LEVEL_UP:
        level_up_menu(console, '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)
    
    elif game_state == GameStates.BOOK_SCREEN:
        book_screen(player, 30, 10, screen_width, screen_height)
예제 #5
0
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)
def render_all(con, panel, player, game_map, fov_map, fov_recompute,
               message_log, screen_width, screen_height, bar_width,
               panel_height, panel_y, mouse, colors, game_state,
               targeting_item):
    if fov_recompute:
        for y in range(game_map.height):
            for x in range(game_map.width):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = game_map.tiles[x][y].block_sight

                if visible:
                    if wall:
                        libtcod.console_set_char_background(
                            con, x, y, colors.get('light_wall'),
                            libtcod.BKGND_SET)
                    else:
                        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:
                        libtcod.console_set_char_background(
                            con, x, y, colors.get('dark_wall'),
                            libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_char_background(
                            con, x, y, colors.get('dark_ground'),
                            libtcod.BKGND_SET)

    # Draw all entities in the list
    visible_entities = [
        e for e in game_map.entities if e.render_order != RenderOrder.INVISIBLE
    ]
    entities_in_render_order = sorted(visible_entities,
                                      key=lambda x: x.render_order.value)

    for entity in entities_in_render_order:
        if game_state == GameStates.TARGETING and targeting_item.valid_target(
                mouse, fov_map, entity) and entity.distance(
                    mouse.cx,
                    mouse.cy) <= targeting_item.item.targeting_radius:
            libtcod.console_set_default_foreground(con, libtcod.darkest_red)
            libtcod.console_put_char(con, entity.x, entity.y, entity.char,
                                     libtcod.BKGND_NONE)
        else:
            draw_entity(con, entity, fov_map, game_map)

    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 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,
                             '{}'.format(game_map.name))

    libtcod.console_set_default_foreground(panel, libtcod.light_gray)
    libtcod.console_print_ex(
        panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT,
        get_names_under_mouse(mouse, game_map.entities, fov_map))

    libtcod.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0,
                         panel_y)

    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)

    elif game_state == GameStates.WON_GAME:
        win_screen(con, screen_width, screen_height)
예제 #7
0
def render_all(
    root_console: tcod.console.Console, con: tcod.console.Console,
    panel: tcod.console.Console, entities: List['Entity'], player: 'Entity',
    game_map: 'GameMap', fov_map: tcod.map.Map, fov_recompute: bool,
    message_log: MessageLog, screen_width: int, screen_height: int,
    bar_width: int, panel_height: int, panel_y: int, mouse: tcod.event.Point,
    colors: Dict[str, tcod.Color], game_state: GameStates,
    target_radius: int = 0,
) -> None:
    # Draw all the tiles in the game map
    for y in range(game_map.height):
        for x in range(game_map.width):
            visible = fov_map.fov[x, y]
            wall = game_map.tiles[x][y].block_sight
            if visible:
                if wall:
                    color = colors['light_wall']
                else:
                    if (game_state == GameStates.TARGETING and
                            math.hypot(x - mouse.x,
                                       y - mouse.y) <= target_radius):
                        color = colors['target_ground']
                    else:
                        color = colors['light_ground']
                game_map.tiles[x][y].explored = True
            elif game_map.tiles[x][y].explored:
                if wall:
                    color = colors['dark_wall']
                else:
                    color = colors['dark_ground']
            else:
                continue
            con.bg[x, y] = cast_to_color(color)

    # Draw all entities in the list
    for entity in sorted(entities, key=attrgetter('render_order.value')):
        draw_entity(con, entity, fov_map, game_map)

    con.blit(root_console, 0, 0, 0, 0, screen_width, screen_height)

    panel.clear(bg=cast_to_color(tcod.black))

    # Print the game messages, one line at a time
    for y, message in enumerate(message_log.messages, 1):
        panel.print(message_log.x, y, message.text,
                    fg=cast_to_color(message.color),
                    bg_blend=tcod.BKGND_NONE,
                    alignment=tcod.LEFT)

    panel.print(1, 0, get_names_under_mouse(mouse, entities, fov_map),
                fg=cast_to_color(tcod.light_gray),
                bg_blend=tcod.BKGND_NONE,
                alignment=tcod.LEFT)

    render_bar(panel, 1, 1, bar_width,
               'HP', player.fighter.hp, player.fighter.max_hp,
               tcod.light_red, tcod.darker_red)

    render_bar(panel, 1, 2, bar_width,
               'XP', player.level.current_xp,
               player.level.experience_to_next_level,
               tcod.light_blue, tcod.darker_blue)

    panel.print(1, 3, f'Player level: {player.level.current_level}',
                fg=cast_to_color(tcod.white),
                bg_blend=tcod.BKGND_NONE,
                alignment=tcod.LEFT)
    panel.print(1, 4, f'Dungeon level: {game_map.dungeon_level}',
                fg=cast_to_color(tcod.white),
                bg_blend=tcod.BKGND_NONE,
                alignment=tcod.LEFT)

    panel.blit(root_console, 0, panel_y, 0, 0, screen_width, panel_height)

    if game_state == GameStates.SHOW_INVENTORY:
        inventory_menu(
            root_console,
            "Press the key next to an item to use it, or Esc to cancel.\n",
            player, 50, screen_width, screen_height,
        )
    elif game_state == GameStates.DROP_INVENTORY:
        inventory_menu(
            root_console,
            "Press the key next to an item to drop it, or Esc to cancel.\n",
            player, 50, screen_width, screen_height,
        )
    elif game_state == GameStates.LEVEL_UP:
        level_up_menu(root_console, 'Level up! Choose a stat to raise:',
                      player, 40, screen_width, screen_height)
    elif game_state == GameStates.CHARACTER_SCREEN:
        character_screen(root_console, player, 30, 10,
                         screen_width, screen_height)
예제 #8
0
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, colours,
               game_state):

    if fov_recompute:
        for y in range(game_map.height):
            for x in range(game_map.width):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = game_map.tiles[x][y].block_sight

                if visible:
                    if wall:
                        libtcod.console_set_char_background(con, x, y, colours.get('light_wall'), libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_char_background(con, x, y, colours.get('light_ground'), libtcod.BKGND_SET)

                    game_map.tiles[x][y].explored = True

                elif game_map.tiles[x][y].explored:
                    if wall:
                        libtcod.console_set_char_background(con, x, y, colours.get('dark_wall'), libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_char_background(con, x, y, colours.get('dark_ground'), libtcod.BKGND_SET)

    entities_in_render_order = sorted(entities, key=lambda x: x.render_order.value)
    for entity in entities_in_render_order:
        draw_entity(con, entity, fov_map, game_map)

    libtcod.console_set_default_foreground(con, libtcod.white)
    libtcod.console_print_ex(con, 1, screen_height - 2, libtcod.BKGND_NONE, libtcod.LEFT,
                             'HP: {0:02}/{1:02}'.format(player.fighter.hp, player.fighter.max_hp))

    libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)

    # --------------------------- Status panel --------------------------- #
    libtcod.console_set_default_background(panel, libtcod.black)
    libtcod.console_clear(panel)

    render_bar(panel, 1, 1, bar_width, 'HP', player.fighter.hp, player.fighter.max_hp,
               libtcod.light_red, libtcod.darker_red)

    # 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

    libtcod.console_set_default_foreground(panel, libtcod.light_gray)
    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 panel --------------------------- #

    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        inventory_header = 'Press the key next to an item to use it, or Esc to cancel.\n'
        if game_state == GameStates.DROP_INVENTORY:
            inventory_header = 'Press the key next to an item to drop it, or Esc to cancel.\n'

        inventory_menu(con, inventory_header, 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)
예제 #9
0
def render_all(con, panel, entities, player, game_map, fov_recompute,
               root_console, message_log, screen_width, screen_height,
               bar_width, panel_height, panel_y, mouse_coordinates, colors,
               game_state):
    # Draw all the tiles in the game map
    if fov_recompute:
        for x, y in game_map:
            wall = not game_map.transparent[x, y]

            if game_map.fov[x, y]:
                if wall:
                    con.draw_char(x,
                                  y,
                                  None,
                                  fg=None,
                                  bg=colors.get('light_wall'))
                else:
                    con.draw_char(x,
                                  y,
                                  None,
                                  fg=None,
                                  bg=colors.get('light_ground'))

                game_map.explored[x][y] = True
            elif game_map.explored[x][y]:
                if wall:
                    con.draw_char(x,
                                  y,
                                  None,
                                  fg=None,
                                  bg=colors.get('dark_wall'))
                else:
                    con.draw_char(x,
                                  y,
                                  None,
                                  fg=None,
                                  bg=colors.get('dark_ground'))

    # Draw all entities in the list
    entities_in_render_order = sorted(entities,
                                      key=lambda x: x.render_order.value)

    for entity in entities_in_render_order:
        draw_entity(con, entity, game_map)

    con.draw_str(
        1, screen_height - 2,
        'HP: {0:02}/{1:02}'.format(player.fighter.hp, player.fighter.max_hp))

    root_console.blit(con, 0, 0, screen_width, screen_height, 0, 0)

    panel.clear(fg=colors.get('white'), bg=colors.get('black'))

    # Print the game messages, one line at a time
    y = 1
    for message in message_log.messages:
        panel.draw_str(message_log.x,
                       y,
                       message.text,
                       bg=None,
                       fg=message.color)
        y += 1

    render_bar(panel, 1, 1, bar_width, 'HP', player.fighter.hp,
               player.fighter.max_hp, colors.get('light_red'),
               colors.get('darker_red'), colors.get('white'))

    panel.draw_str(
        1, 0, get_names_under_mouse(mouse_coordinates, entities, game_map))
    panel.draw_str(1,
                   3,
                   'Dungeon Level: {0}'.format(game_map.dungeon_level),
                   fg=colors.get('white'),
                   bg=None)

    root_console.blit(panel, 0, panel_y, screen_width, panel_height, 0, 0)

    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, root_console, inventory_title, player, 50,
                       screen_width, screen_height)

    elif game_state == GameStates.LEVEL_UP:
        level_up_menu(con, root_console, 'Level up! Choose a stat to raise:',
                      player, 40, screen_width, screen_height)

    elif game_state == GameStates.CHARACTER_SCREEN:
        character_screen(root_console, player, 30, 10, screen_width,
                         screen_height)