Exemple #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):
    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)
                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_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)

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

    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)

    render_bar(panel, 1, 2, bar_width, "EXP", player.level.current_xp,
               player.level.experience_to_next_level, libtcod.light_blue,
               libtcod.darker_blue)

    libtcod.console_print_ex(
        panel, 1, 4, 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 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.SHOW_EQUIPMENT_INVENTORY:
        equipment_inventory_menu(
            con,
            "Press the key next to an item to equip it, or ESC to cancel.\n",
            player.equipment_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)

    elif game_state == GameStates.SHOW_BAG:
        bag_title = "Press the key next to the option to open the bag.\n"

        bag_menu(con, bag_title, player, 50, screen_width, screen_height)

    elif game_state == GameStates.HELP_MENU:
        help_menu(player, 30, 10, screen_width, screen_height)
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, kill_count, 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, 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)

    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))
    ''' Danny code to center player and have window scroll
    r = 20
    libtcod.console_blit(con, player.x - r, player.y - r, 2*r+1, 2*r+1, 0, int(screen_width/2) - r, int(screen_height/2) - r)
    '''
    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)

    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)

    render_bar(panel, 1, 2, bar_width, "EXP", player.level.current_xp,
               player.level.experience_to_next_level, libtcod.light_blue,
               libtcod.darker_blue)

    libtcod.console_print_ex(panel, 1, 4, libtcod.BKGND_NONE, libtcod.LEFT,
                             "Gold: {0}".format(player.fighter.gold))

    if player.inventory.search("Health Talisman") is not None:
        render_bar(panel, 1, 3, bar_width, "Talisman HP",
                   player.fighter.talismanhp, player.fighter.max_hp,
                   libtcod.light_purple, libtcod.darker_purple)

    libtcod.console_print_ex(
        panel, 1, 5, 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 an item to use it, or ESC to cancel.\n"
        elif game_state == GameStates.DROP_INVENTORY:
            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 in (GameStates.SHOW_EQUIPMENT_INVENTORY,
                        GameStates.DROP_EQUIPMENT):
        if game_state == GameStates.SHOW_EQUIPMENT_INVENTORY:
            inventory_title = "Press the key next to an item to equip it, or ESC to cancel.\n"
        else:
            inventory_title = "Press the key next to the equipment to drop it, or ESC to cancel.\n"

        equipment_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:\n", player, 46,
                      screen_width, screen_height)

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

    elif game_state == GameStates.SHOW_BAG:
        bag_title = "Press the key next to the option to open the bag.\n"

        bag_menu(con, bag_title, player, 50, screen_width, screen_height)

    elif game_state == GameStates.HELP_MENU:
        help_menu(player, 30, 10, screen_width, screen_height)

    elif game_state == GameStates.QUIT_MENU:
        quit_title = "ARE YOU SURE YOU WANT\n  TO QUIT THE GAME?\n"

        quit_menu(con, quit_title, player, 21, screen_width, screen_height)

    elif game_state == GameStates.DROP_MENU:
        drop_title = "Which inventory would you like to drop items from?"

        drop_menu(con, drop_title, player, 50, screen_width, screen_height)

    elif game_state == GameStates.SELL_MENU:
        shop_title = "Welcome to the Shop!\nWhat would you like to sell?\n"

        sell_menu(con, shop_title, player, 50, screen_width, screen_height)

    elif game_state == GameStates.BUY_MENU:
        shop_title = "Welcome to the Shop!\nWhat would you like to buy?\n"

        buy_menu(con, shop_title, player, 50, screen_width, screen_height)

    elif game_state == GameStates.SHOP_MENU:
        shop_title = "Welcome to the Shop!\nWhat would you like to do?\n"

        shop_menu(con, shop_title, player, 50, screen_width, screen_height)
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 in the game map
        for y in range(game_map.height):
            for x in range(game_map.width):

                visible = tc.map_is_in_fov(fov_map, x, y)
                wall = game_map.tiles[x][y].block_sight

                if visible:
                    if wall:
                        tc.console_set_char_background(con, x, y,
                                                       tc.darkest_red,
                                                       tc.BKGND_SET)
                    else:
                        tc.console_set_char_background(con, x, y,
                                                       tc.darkest_orange,
                                                       tc.BKGND_SET)

                    game_map.tiles[x][y].explored = True
                elif game_map.tiles[x][y].explored:
                    if wall:
                        tc.console_set_char_background(con, x, y,
                                                       tc.darkest_grey,
                                                       tc.BKGND_SET)
                    else:
                        tc.console_set_char_background(con, x, y,
                                                       tc.darkest_sepia,
                                                       tc.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)

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

    tc.console_set_default_background(panel, tc.black)
    panel.clear()
    y = 0

    for message in message_log.messages:

        panel.default_fg = message.color
        tc.console_print_ex(panel, 54, y, tc.BKGND_NONE, tc.LEFT, message.text)
        y += 1

    render_bar(panel, 1 - 3, 1, bar_width, 'HP', player.fighter.hp,
               player.fighter.max_hp, tc.light_red, tc.darker_red)
    tc.console_print_ex(panel, 15, 5, tc.BKGND_NONE, tc.LEFT,
                        'Dungeon level: {0}'.format(game_map.dungeon_level))

    panel.default_fg = tc.light_gray

    tc.console_blit(panel, 0, 0, screen_width, panel_height + 1, 0, 0, panel_y)

    mouse_display_panel = tc.console.Console(screen_width, 1)
    tc.console_print_ex(mouse_display_panel, 0, 0, tc.BKGND_NONE, tc.LEFT,
                        get_names_under_mouse(mouse, entities, fov_map))
    tc.console_blit(mouse_display_panel, -13, 0, screen_width,
                    panel_height + 1, 0, 0, panel_y - 1)

    head_list = list(str(player.fighter.head_hp))
    if player.fighter.head_hp < 100:
        head_list.insert(0, '0')
        if player.fighter.head_hp < 10:
            head_list.insert(0, '0')
            head_list.insert(0, '0')

    chest_list = list(str(player.fighter.chest_hp))
    if player.fighter.chest_hp < 100:
        chest_list.insert(0, '0')
        if player.fighter.chest_hp < 10:
            chest_list.insert(0, '0')
            chest_list.insert(0, '0')

    right_arm_list = list(str(player.fighter.right_arm_hp))
    if player.fighter.right_arm_hp < 100:
        right_arm_list.insert(0, '0')
        if player.fighter.right_arm_hp < 10:
            right_arm_list.insert(0, '0')
            right_arm_list.insert(0, '0')

    left_arm_list = list(str(player.fighter.left_arm_hp))
    if player.fighter.left_arm_hp < 100:
        left_arm_list.insert(0, '0')
        if player.fighter.left_arm_hp < 10:
            left_arm_list.insert(0, '0')
            left_arm_list.insert(0, '0')

    left_leg_list = list(str(player.fighter.left_leg_hp))
    if player.fighter.left_leg_hp < 100:
        left_leg_list.insert(0, '0')
        if player.fighter.left_leg_hp < 10:
            left_leg_list.insert(0, '0')
            left_leg_list.insert(0, '0')

    right_leg_list = list(str(player.fighter.right_leg_hp))
    if player.fighter.right_leg_hp < 100:
        right_leg_list.insert(0, '0')
        if player.fighter.right_leg_hp < 10:
            right_leg_list.insert(0, '0')
            right_leg_list.insert(0, '0')

    ##BODY HEALTH PANEL
    body_panel = tc.console.Console(13, 15)
    body_panel.draw_frame(0,
                          0,
                          body_panel.width,
                          body_panel.height - 1,
                          " Body",
                          False,
                          fg=tc.white,
                          bg=tc.black)

    #HEAD
    if int(player.fighter.head_hp) >= 75:
        body_panel.default_fg = tc.green
        body_panel.draw_frame(int(body_panel.width / 2) - 2, 1, 5, 4, "")
        tc.console_print_ex(
            body_panel, int(body_panel.width / 2), 3, tc.BKGND_NONE, tc.CENTER,
            '{0}'.format(head_list[0] + head_list[1] + head_list[2]))

    if int(player.fighter.head_hp) >= 50 and int(player.fighter.head_hp) <= 74:
        body_panel.default_fg = tc.yellow
        body_panel.draw_frame(int(body_panel.width / 2) - 2, 1, 5, 4, "")
        tc.console_print_ex(
            body_panel, int(body_panel.width / 2), 3, tc.BKGND_NONE, tc.CENTER,
            '{0}'.format(head_list[0] + head_list[1] + head_list[2]))

    if int(player.fighter.head_hp) >= 26 and int(player.fighter.head_hp) <= 49:
        body_panel.default_fg = tc.orange
        body_panel.draw_frame(int(body_panel.width / 2) - 2, 1, 5, 4, "")
        tc.console_print_ex(
            body_panel, int(body_panel.width / 2), 3, tc.BKGND_NONE, tc.CENTER,
            '{0}'.format(head_list[0] + head_list[1] + head_list[2]))

    if int(player.fighter.head_hp) >= 11 and int(player.fighter.head_hp) <= 25:
        body_panel.default_fg = tc.red
        body_panel.draw_frame(int(body_panel.width / 2) - 2, 1, 5, 4, "")
        tc.console_print_ex(
            body_panel, int(body_panel.width / 2), 3, tc.BKGND_NONE, tc.CENTER,
            '{0}'.format(head_list[0] + head_list[1] + head_list[2]))

    if int(player.fighter.head_hp) <= 10:
        body_panel.default_fg = tc.grey
        body_panel.draw_frame(int(body_panel.width / 2) - 2, 1, 5, 4, "")
        tc.console_print_ex(
            body_panel, int(body_panel.width / 2), 3, tc.BKGND_NONE, tc.CENTER,
            '{0}'.format(head_list[0] + head_list[1] + head_list[2]))

    #TORSO
    if int(player.fighter.chest_hp) >= 75:
        body_panel.default_fg = tc.green
        body_panel.draw_frame(int(body_panel.width / 2) - 2, 4, 5, 5, "")
        tc.console_print_ex(
            body_panel, int(body_panel.width / 2), 5, tc.BKGND_NONE, tc.CENTER,
            '{0}'.format(chest_list[0] + "\n" + chest_list[1] + "\n" +
                         chest_list[2]))

    if int(player.fighter.chest_hp) >= 50 and int(
            player.fighter.chest_hp) <= 74:
        body_panel.default_fg = tc.yellow
        body_panel.draw_frame(int(body_panel.width / 2) - 2, 4, 5, 5, "")
        tc.console_print_ex(
            body_panel, int(body_panel.width / 2), 5, tc.BKGND_NONE, tc.CENTER,
            '{0}'.format(chest_list[0] + "\n" + chest_list[1] + "\n" +
                         chest_list[2]))

    if int(player.fighter.chest_hp) >= 26 and int(
            player.fighter.chest_hp) <= 49:
        body_panel.default_fg = tc.orange
        body_panel.draw_frame(int(body_panel.width / 2) - 2, 4, 5, 5, "")
        tc.console_print_ex(
            body_panel, int(body_panel.width / 2), 5, tc.BKGND_NONE, tc.CENTER,
            '{0}'.format(chest_list[0] + "\n" + chest_list[1] + "\n" +
                         chest_list[2]))

    if int(player.fighter.chest_hp) >= 11 and int(
            player.fighter.chest_hp) <= 25:
        body_panel.default_fg = tc.red
        body_panel.draw_frame(int(body_panel.width / 2) - 2, 4, 5, 5, "")
        tc.console_print_ex(
            body_panel, int(body_panel.width / 2), 5, tc.BKGND_NONE, tc.CENTER,
            '{0}'.format(chest_list[0] + "\n" + chest_list[1] + "\n" +
                         chest_list[2]))

    if int(player.fighter.chest_hp) <= 10:
        body_panel.default_fg = tc.grey
        body_panel.draw_frame(int(body_panel.width / 2) - 2, 4, 5, 5, "")
        tc.console_print_ex(
            body_panel, int(body_panel.width / 2), 5, tc.BKGND_NONE, tc.CENTER,
            '{0}'.format(chest_list[0] + "\n" + chest_list[1] + "\n" +
                         chest_list[2]))

    ##ARMS  ##LEFT
    if int(player.fighter.left_arm_hp) >= 75:
        body_panel.default_fg = tc.green
        body_panel.draw_frame(int(body_panel.width / 2) - 4, 4, 3, 5, "")
        tc.console_print_ex(
            body_panel,
            int(body_panel.width / 2) - 3, 5, tc.BKGND_NONE, tc.CENTER,
            '{0}'.format(left_arm_list[0] + "\n" + left_arm_list[1] + "\n" +
                         left_arm_list[2]))

    if int(player.fighter.left_arm_hp) >= 50 and int(
            player.fighter.left_arm_hp) <= 74:
        body_panel.default_fg = tc.yellow
        body_panel.draw_frame(int(body_panel.width / 2) - 4, 4, 3, 5, "")
        tc.console_print_ex(
            body_panel,
            int(body_panel.width / 2) - 3, 5, tc.BKGND_NONE, tc.CENTER,
            '{0}'.format(left_arm_list[0] + "\n" + left_arm_list[1] + "\n" +
                         left_arm_list[2]))

    if int(player.fighter.left_arm_hp) >= 26 and int(
            player.fighter.left_arm_hp) <= 49:
        body_panel.default_fg = tc.orange
        body_panel.draw_frame(int(body_panel.width / 2) - 4, 4, 3, 5, "")
        tc.console_print_ex(
            body_panel,
            int(body_panel.width / 2) - 3, 5, tc.BKGND_NONE, tc.CENTER,
            '{0}'.format(left_arm_list[0] + "\n" + left_arm_list[1] + "\n" +
                         left_arm_list[2]))

    if int(player.fighter.left_arm_hp) >= 11 and int(
            player.fighter.left_arm_hp) <= 25:
        body_panel.default_fg = tc.red
        body_panel.draw_frame(int(body_panel.width / 2) - 4, 4, 3, 5, "")
        tc.console_print_ex(
            body_panel,
            int(body_panel.width / 2) - 3, 5, tc.BKGND_NONE, tc.CENTER,
            '{0}'.format(left_arm_list[0] + "\n" + left_arm_list[1] + "\n" +
                         left_arm_list[2]))

    if int(player.fighter.left_arm_hp) <= 10:
        body_panel.default_fg = tc.grey
        body_panel.draw_frame(int(body_panel.width / 2) - 4, 4, 3, 5, "")
        tc.console_print_ex(
            body_panel,
            int(body_panel.width / 2) - 3, 5, tc.BKGND_NONE, tc.CENTER,
            '{0}'.format(left_arm_list[0] + "\n" + left_arm_list[1] + "\n" +
                         left_arm_list[2]))

    ##ARMS  ##RIGHT
    if int(player.fighter.right_arm_hp) >= 75:
        body_panel.default_fg = tc.green
        body_panel.draw_frame(int(body_panel.width / 2) + 2, 4, 3, 5, "")
        tc.console_print_ex(
            body_panel,
            int(body_panel.width / 2) + 3, 5, tc.BKGND_NONE, tc.CENTER,
            '{0}'.format(right_arm_list[0] + "\n" + right_arm_list[1] + "\n" +
                         right_arm_list[2]))

    if int(player.fighter.right_arm_hp) >= 50 and int(
            player.fighter.right_arm_hp) <= 74:
        body_panel.default_fg = tc.yellow
        body_panel.draw_frame(int(body_panel.width / 2) + 2, 4, 3, 5, "")
        tc.console_print_ex(
            body_panel,
            int(body_panel.width / 2) + 3, 5, tc.BKGND_NONE, tc.CENTER,
            '{0}'.format(right_arm_list[0] + "\n" + right_arm_list[1] + "\n" +
                         right_arm_list[2]))

    if int(player.fighter.right_arm_hp) >= 26 and int(
            player.fighter.right_arm_hp) <= 49:
        body_panel.default_fg = tc.orange
        body_panel.draw_frame(int(body_panel.width / 2) + 2, 4, 3, 5, "")
        tc.console_print_ex(
            body_panel,
            int(body_panel.width / 2) + 3, 5, tc.BKGND_NONE, tc.CENTER,
            '{0}'.format(right_arm_list[0] + "\n" + right_arm_list[1] + "\n" +
                         right_arm_list[2]))

    if int(player.fighter.right_arm_hp) >= 11 and int(
            player.fighter.right_arm_hp) <= 25:
        body_panel.default_fg = tc.red
        body_panel.draw_frame(int(body_panel.width / 2) + 2, 4, 3, 5, "")
        tc.console_print_ex(
            body_panel,
            int(body_panel.width / 2) + 3, 5, tc.BKGND_NONE, tc.CENTER,
            '{0}'.format(right_arm_list[0] + "\n" + right_arm_list[1] + "\n" +
                         right_arm_list[2]))

    if int(player.fighter.right_arm_hp) <= 10:
        body_panel.default_fg = tc.grey
        body_panel.draw_frame(int(body_panel.width / 2) + 2, 4, 3, 5, "")
        tc.console_print_ex(
            body_panel,
            int(body_panel.width / 2) + 3, 5, tc.BKGND_NONE, tc.CENTER,
            '{0}'.format(right_arm_list[0] + "\n" + right_arm_list[1] + "\n" +
                         right_arm_list[2]))

    #LEGS   #LEFT
    if int(player.fighter.left_leg_hp) >= 75:
        body_panel.default_fg = tc.green
        body_panel.draw_frame(int(body_panel.width / 2) - 2, 8, 3, 5, "")
        tc.console_print_ex(
            body_panel,
            int(body_panel.width / 2) + 1, 9, tc.BKGND_NONE, tc.CENTER,
            '{0}'.format(left_leg_list[0] + "\n" + left_leg_list[1] + "\n" +
                         left_leg_list[2]))

    if int(player.fighter.left_leg_hp) >= 50 and int(
            player.fighter.left_leg_hp) <= 74:
        body_panel.default_fg = tc.yellow
        body_panel.draw_frame(int(body_panel.width / 2) - 2, 8, 3, 5, "")
        tc.console_print_ex(
            body_panel,
            int(body_panel.width / 2) + 1, 9, tc.BKGND_NONE, tc.CENTER,
            '{0}'.format(left_leg_list[0] + "\n" + left_leg_list[1] + "\n" +
                         left_leg_list[2]))

    if int(player.fighter.left_leg_hp) >= 26 and int(
            player.fighter.left_leg_hp) <= 49:
        body_panel.default_fg = tc.orange
        body_panel.draw_frame(int(body_panel.width / 2) - 2, 8, 3, 5, "")
        tc.console_print_ex(
            body_panel,
            int(body_panel.width / 2) + 1, 9, tc.BKGND_NONE, tc.CENTER,
            '{0}'.format(left_leg_list[0] + "\n" + left_leg_list[1] + "\n" +
                         left_leg_list[2]))

    if int(player.fighter.left_leg_hp) >= 11 and int(
            player.fighter.left_leg_hp) <= 25:
        body_panel.default_fg = tc.red
        body_panel.draw_frame(int(body_panel.width / 2) - 2, 8, 3, 5, "")
        tc.console_print_ex(
            body_panel,
            int(body_panel.width / 2) + 1, 9, tc.BKGND_NONE, tc.CENTER,
            '{0}'.format(left_leg_list[0] + "\n" + left_leg_list[1] + "\n" +
                         left_leg_list[2]))

    if int(player.fighter.left_leg_hp) <= 10:
        body_panel.default_fg = tc.grey
        body_panel.draw_frame(int(body_panel.width / 2) - 2, 8, 3, 5, "")
        tc.console_print_ex(
            body_panel,
            int(body_panel.width / 2) + 1, 9, tc.BKGND_NONE, tc.CENTER,
            '{0}'.format(left_leg_list[0] + "\n" + left_leg_list[1] + "\n" +
                         left_leg_list[2]))

    #LEGS   #RIGHT
    if int(player.fighter.right_leg_hp) >= 75:
        body_panel.default_fg = tc.green
        body_panel.draw_frame(int(body_panel.width / 2), 8, 3, 5, "", False)
        tc.console_print_ex(
            body_panel,
            int(body_panel.width / 2) - 1, 9, tc.BKGND_NONE, tc.CENTER,
            '{0}'.format(right_leg_list[0] + "\n" + right_leg_list[1] + "\n" +
                         right_leg_list[2]))

    if int(player.fighter.right_leg_hp) >= 50 and int(
            player.fighter.right_leg_hp) <= 74:
        body_panel.default_fg = tc.yellow
        body_panel.draw_frame(int(body_panel.width / 2), 8, 3, 5, "", False)
        tc.console_print_ex(
            body_panel,
            int(body_panel.width / 2) - 1, 9, tc.BKGND_NONE, tc.CENTER,
            '{0}'.format(right_leg_list[0] + "\n" + right_leg_list[1] + "\n" +
                         right_leg_list[2]))

    if int(player.fighter.right_leg_hp) >= 26 and int(
            player.fighter.right_leg_hp) <= 49:
        body_panel.default_fg = tc.orange
        body_panel.draw_frame(int(body_panel.width / 2), 8, 3, 5, "", False)
        tc.console_print_ex(
            body_panel,
            int(body_panel.width / 2) - 1, 9, tc.BKGND_NONE, tc.CENTER,
            '{0}'.format(right_leg_list[0] + "\n" + right_leg_list[1] + "\n" +
                         right_leg_list[2]))

    if int(player.fighter.right_leg_hp) >= 11 and int(
            player.fighter.right_leg_hp) <= 25:
        body_panel.default_fg = tc.red
        body_panel.draw_frame(int(body_panel.width / 2), 8, 3, 5, "", False)
        tc.console_print_ex(
            body_panel,
            int(body_panel.width / 2) - 1, 9, tc.BKGND_NONE, tc.CENTER,
            '{0}'.format(right_leg_list[0] + "\n" + right_leg_list[1] + "\n" +
                         right_leg_list[2]))

    if int(player.fighter.right_leg_hp) <= 10:
        body_panel.default_fg = tc.grey
        body_panel.draw_frame(int(body_panel.width / 2), 8, 3, 5, "", False)
        tc.console_print_ex(
            body_panel,
            int(body_panel.width / 2) - 1, 9, tc.BKGND_NONE, tc.CENTER,
            '{0}'.format(right_leg_list[0] + "\n" + right_leg_list[1] + "\n" +
                         right_leg_list[2]))

    tc.console_blit(body_panel, 0, 0, body_panel.width, body_panel.height, 0,
                    0, screen_height - body_panel.height + 1, 1.0, 1.0)

    ##BODY POISON/BURNING/HUNGER/THIRST PANEL
    status_panel = tc.console.Console(18, 11)
    status_panel.draw_frame(0,
                            0,
                            status_panel.width,
                            status_panel.height - 1,
                            "Status",
                            False,
                            fg=tc.white,
                            bg=tc.black)
    # tc.console_print_ex(status_panel, int(body_panel.width / 2 + 3), 3, tc.BKGND_NONE, tc.CENTER,'Hunger {0}/100'.format(player.fighter.hunger_level))
    # tc.console_print_ex(status_panel, int(body_panel.width / 2 + 3), 4, tc.BKGND_NONE, tc.CENTER,'Thirst {0}/100'.format(player.fighter.thirst_level))

    if player.fighter.is_burning == True:
        status_panel.default_fg = tc.red
        tc.console_print_ex(status_panel, int(body_panel.width / 2 + 3), 6,
                            tc.BKGND_NONE, tc.CENTER, 'BURNING')
    else:
        status_panel.default_fg = tc.black
        tc.console_print_ex(status_panel, int(body_panel.width / 2 + 3), 6,
                            tc.BKGND_NONE, tc.CENTER, 'BURNING')

    if player.fighter.is_poisoned == True:
        status_panel.default_fg = tc.green
        tc.console_print_ex(status_panel, int(body_panel.width / 2 + 3), 7,
                            tc.BKGND_NONE, tc.CENTER, 'POISONED')
    else:
        status_panel.default_fg = tc.black
        tc.console_print_ex(status_panel, int(body_panel.width / 2 + 3), 7,
                            tc.BKGND_NONE, tc.CENTER, 'POISONED')

    tc.console_blit(status_panel, 0, 0, status_panel.width,
                    status_panel.height, 0, (screen_width - screen_width) + 35,
                    screen_height - status_panel.height + 1, 1.0, 1.0)

    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        inventory_menu(con, player, 98, screen_width, screen_height)

    if game_state == GameStates.RANGED:
        if game_state == GameStates.RANGED:
            ranged_title = 'Press the key next to the ranged item you want to use, or Esc to cancel\n\n\nName               |Damage|Range|Charge|\n'
        else:
            ranged_title = 'Press the key next to the ranged item you want to use, or Esc to cancel\n\n\nName               |Damage|Range|Charge|\n'

        ranged_menu(con, ranged_title, player, 98, 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.SHOW_TUTORIAL:
        tutorial_menu(con, '', 92, screen_width, screen_height)

    elif game_state == GameStates.SHOW_HELP_MENU:
        help_menu(con, '', 92, screen_width, screen_height)
Exemple #4
0
def play_game(player, entities, game_map, message_log, game_state, con, panel,
              constants, names_list, colors_list):

    fov_recompute = True
    fov_map = initialize_fov(game_map)

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    game_state = GameStates.PLAYERS_TURN
    previous_game_state = game_state

    targeting_item = None
    ranged_weapon = None  #used to keep track of which (if any) ranged weapon is being fired

    player_turn_results = []

    #pygame.mixer.init()
    #pygame.mixer.music.load('audio/sfx/bgchatter.mp3')
    #pygame.mixer.music.play(-1)
    pygame.init()

    while not libtcod.console_is_window_closed():

        constants['tick'] = int(pygame.time.get_ticks() / 100)

        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

        if fov_recompute:
            recompute_fov(fov_map, player.x, player.y, constants['fov_radius'],
                          constants['fov_light_walls'],
                          constants['fov_algorithm'])

        render_all(con, panel, entities, player, game_map, fov_map,
                   fov_recompute, message_log, constants['screen_width'],
                   constants['screen_height'], constants['bar_width'],
                   constants['panel_height'], constants['panel_y'], mouse,
                   constants['colors'], constants['options_tutorial_enabled'],
                   game_state, names_list, colors_list, constants['tick'],
                   constants['tick_speed'])

        fov_recompute = False

        libtcod.console_flush()

        clear_all(con, entities)

        action = handle_keys(key, game_state)
        #if len(action) > 0: print(action)
        mouse_action = handle_mouse(mouse)

        move = action.get('move')

        wait = action.get('wait')
        pickup = action.get('pickup')
        show_inventory = action.get('show_inventory')
        #drop_inventory = action.get('drop_inventory')
        inventory_index = action.get('inventory_index')
        take_stairs = action.get('take_stairs')
        level_up = action.get('level_up')
        show_character_screen = action.get('show_character_screen')
        exit = action.get('exit')
        fire = action.get('fire')
        fullscreen = action.get('fullscreen')
        key_targeting = action.get('key_targeting')
        close = action.get('close')
        kick = action.get('kick')
        messagelog = action.get('messagelog')
        help = action.get('show_help')

        left_click = mouse_action.get('left_click')
        right_click = mouse_action.get('right_click')

        player_turn_results = []

        # TODO :: work on auto-walker ..
        # code below almost works.. but a-star will never END on the targeted tile, so checking for mx/my == px/py will not work
        #not sure how to solve for this at the moment.

        if left_click:
            (mx, my) = (mouse.cx, mouse.cy)

            if (mx, my) == (player.x, player.y):
                player_turn_results.extend(
                    inventory_menu(player, entities, fov_map, names_list,
                                   colors_list, message_log, constants))

        #     print(str((mx,my)))
        #     if libtcod.map_is_in_fov(fov_map, mx, my):
        #         spot = Entity(mx, my, 0, libtcod.black, 'spot')
        #         while (True):
        #             if player.x != mx and player.y != my:
        #                 player.move_astar(spot, entities, game_map)
        #                 player_turn_end(player, player_turn_results, game_map, constants, entities, message_log)
        #                 fov_recompute = True
        #                 render_refresh(con, panel, mouse, entities, player, game_map, fov_map, fov_recompute, message_log, constants, game_state, names_list, colors_list)
        #                 time.sleep(0.0255)
        #             else:
        #                 break

        if move:
            if game_state == GameStates.PLAYERS_TURN:

                dx, dy = move
                destination_x = player.x + dx
                destination_y = player.y + dy

                if not game_map.is_blocked(destination_x, destination_y):
                    target = get_blocking_entities_at_location(
                        entities, destination_x, destination_y)

                    if target:
                        if target.name == "Camera Op.":
                            (tx, ty) = (player.x, player.y)
                            player.x = target.x
                            player.y = target.y
                            target.x = tx
                            target.y = ty
                        else:
                            attack_results = player.fighter.attack(
                                target, constants)
                            player_turn_results.extend(attack_results)
                    else:
                        player.move(dx, dy)

                        fov_recompute = True
                        #dijkstra_recompute = True

                    #player_turn_end(player, player_turn_results, game_map, constants)
                    game_state = GameStates.ENEMY_TURN
                else:
                    if game_map.tiles[destination_x][destination_y].door:
                        if not game_map.tiles[destination_x][
                                destination_y].door.is_open:
                            game_map.tiles[destination_x][
                                destination_y].door.toggle_open(
                                    game_map, destination_x, destination_y)
                            fov_recompute = True
                            #dijkstra_recompute = True
                            fov_map = initialize_fov(game_map)

                player_turn_end(player, player_turn_results, game_map,
                                constants, entities, message_log)

            elif game_state == GameStates.KEYTARGETING:
                dx, dy = move
                destination_x = targeter.x + dx
                destination_y = targeter.y + dy

                if (destination_x >= 0
                        and destination_x <= constants['map_width']) and (
                            destination_y >= 0
                            and destination_y <= constants['map_height']):
                    targeter.move(dx, dy)
                    fov_recompute = True
                    libtcod.console_set_default_foreground(
                        panel, libtcod.light_gray)

        elif wait:
            player_turn_end(player, player_turn_results, game_map, constants,
                            entities, message_log)
            game_state = GameStates.ENEMY_TURN

        elif pickup and game_state == GameStates.PLAYERS_TURN:
            for entity in entities:

                if entity.item and entity.x == player.x and entity.y == player.y:
                    pickup_results = player.inventory.add_item(
                        entity, names_list)
                    player_turn_results.extend(pickup_results)

                    break
            else:
                message_log.add_message(
                    Message('There is nothing here to pick up.',
                            libtcod.yellow))

        elif key_targeting:
            previous_game_state = game_state
            game_state = GameStates.KEYTARGETING
            #create 'targeting' entity
            targeter = Entity(player.x,
                              player.y,
                              233, (204, 153, 51),
                              'Targeter',
                              blocks=False,
                              render_order=RenderOrder.TARGETING)
            entities.append(targeter)

        elif messagelog:
            message_log_history(message_log)

        elif kick:
            if game_state == GameStates.KICKING:

                dx, dy = kick

                kickx, kicky = player.x + dx, player.y + dy

                target = None
                for entity in entities:
                    if entity.x == kickx and entity.y == kicky and entity.stairs == False:
                        target = entity
                        break

                if target == None:
                    if game_map.tiles[kickx][kicky].door:
                        if game_map.tiles[kickx][kicky].door.is_open:
                            message_log.add_message(
                                Message('There is nothing there to kick.',
                                        libtcod.red))
                        else:
                            message_log.add_message(
                                Message('You kick the door. Ouch!',
                                        libtcod.red))
                            player_turn_results.extend(
                                player.fighter.take_damage(2))
                    elif game_map.tiles[kickx][kicky].blocked:
                        message_log.add_message(
                            Message('Kicking a wall does not feel good.',
                                    libtcod.red))
                        player_turn_results.extend(
                            player.fighter.take_damage(2))
                    else:
                        message_log.add_message(
                            Message('Nothing there to kick.', libtcod.yellow))
                else:
                    if target.fighter:
                        message_log.add_message(
                            Message(
                                'The  ' + target.name + ' dodges your kick.',
                                libtcod.gray))
                    else:
                        if not game_map.tiles[target.x + dx][target.y +
                                                             dy].block_sight:
                            target.move(dx, dy)
                            if game_map.tiles[kickx][kicky].door:
                                fov_recompute = True

                if previous_game_state == GameStates.PLAYERS_TURN:
                    player_turn_end(player, player_turn_results, game_map,
                                    constants, entities, message_log)
                    game_state = GameStates.ENEMY_TURN
                else:
                    game_state = previous_game_state

            else:
                previous_game_state = game_state
                game_state = GameStates.KICKING

        elif help:
            help_menu()

        elif close:
            if game_state == GameStates.CLOSING:

                dx, dy = close

                closex, closey = player.x + dx, player.y + dy

                if game_map.tiles[closex][closey].door:
                    if game_map.tiles[closex][closey].door.is_open:
                        blocked = False
                        for entity in entities:
                            if entity.x == closex and entity.y == closey:
                                blocked = True
                                break
                        if not blocked:
                            game_map.tiles[closex][closey].door.toggle_open(
                                game_map, closex, closey)
                            message_log.add_message(
                                Message('You close the door.', libtcod.white))
                            fov_map = initialize_fov(game_map)
                            fov_recompute = True
                        else:
                            message_log.add_message(
                                Message('There is something in the way.',
                                        libtcod.lighter_red))
                    else:
                        message_log.add_message(
                            Message('The door is already closed.',
                                    libtcod.white))
                else:
                    #check for chests etc .. other objects that could be closed
                    message_log.add_message(
                        Message('There is nothing there to close.',
                                libtcod.lighter_red))

                if previous_game_state == GameStates.PLAYERS_TURN:
                    player_turn_end(player, player_turn_results, game_map,
                                    constants, entities, message_log)
                    game_state = GameStates.ENEMY_TURN
                else:
                    game_state = previous_game_state

            else:
                previous_game_state = game_state
                game_state = GameStates.CLOSING

        elif fire:
            if game_state == GameStates.FIRING:

                #ranged_weapon should be assigned when game_state goes from player_turn to firing..
                #check "for eq in player.equipment.list:" loop near line 310 engine.py on error
                if not ranged_weapon:
                    print("dafuq? ... line 309 engine .. no ranged weapon?!")

                #get direction from the player_turn_results 'fire' key
                dx, dy = fire

                current_pref = constants['options_ammo_preference']

                FnP = Fire_And_Preference(player=player, constants=constants)
                if str(FnP) == "None":
                    message_log.add_message(
                        Message('You do not have anything to shoot.',
                                libtcod.light_red))

                elif str(FnP) == "exit":
                    print("Canceled")

                else:
                    if FnP != current_pref:
                        message_log.add_message(
                            Message(
                                'You have updated your default ammo preference.',
                                libtcod.light_gray))

                    ammo = None

                    for i in player.inventory.items:
                        if i.name == FnP:
                            ammo = i
                            print('pref: ' + str(i.name) + '  x' +
                                  str(i.item.count))
                            if i.item.count == 1:
                                constants['options_ammo_preference'] = None

                                for q in player.inventory.items:
                                    if q.name == 'Quiver':
                                        q.item.effect_lines = textwrap.wrap(
                                            "  Firing preference is currently unassigned.",
                                            26)
                                        break
                                print("pref reset at engine 329")

                            player.inventory.remove_item(i)
                            break

                    hit = False
                    lost = False

                    #loop through the range of the weapon in question
                    for r in range(1, ranged_weapon.item.range + 2):
                        if hit or lost: break

                        sx = player.x + (dx * r)
                        sy = player.y + (dy * r)

                        if game_map.tiles[sx][sy].block_sight or game_map.tiles[
                                sx][sy].blocked or r == ranged_weapon.item.range + 1:
                            lost = True

                            if ammo.item.ammo.retrievable:
                                ia = copy.deepcopy(ammo)
                                ia.item.count = 1
                                (ix, iy) = (sx - dx, sy - dy)
                                (ia.x, ia.y) = (ix, iy)
                                entities.append(ia)
                                break
                        else:
                            for ent in entities:
                                if ent.fighter:
                                    if ent.x == sx and ent.y == sy:
                                        hit = True

                                        player_turn_results.extend(
                                            ammo.item.ammo.hit_function.hit(
                                                shooter=player,
                                                target=ent,
                                                constants=constants))

                if previous_game_state == GameStates.PLAYERS_TURN:
                    player_turn_end(player, player_turn_results, game_map,
                                    constants, entities, message_log)
                    game_state = GameStates.ENEMY_TURN
                else:
                    game_state = previous_game_state

            else:

                for eq in player.equipment.list:

                    if eq.equippable.slot == EquipmentSlots.MAIN_HAND or eq.equippable.slot == EquipmentSlots.OFF_HAND:
                        if eq.item.range > 0:
                            ranged_weapon = eq
                            break

                if ranged_weapon:
                    previous_game_state = game_state
                    game_state = GameStates.FIRING
                else:
                    #hip firing goes here
                    message_log.add_message(
                        Message('You do not have a ranged weapon equipped.',
                                libtcod.lighter_red))

        elif show_inventory:
            player_turn_results.extend(
                inventory_menu(player, entities, fov_map, names_list,
                               colors_list, message_log, constants))

        #if inventory_index is not None and previous_game_state != GameStates.PLAYER_DEAD and inventory_index < len(
        #        player.inventory.items):
        #    item = player.inventory.items[inventory_index]
        #
        #    if game_state == GameStates.SHOW_INVENTORY:
        #        player_turn_results.extend(player.inventory.use(item, entities=entities, fov_map=fov_map, names_list=names_list, message_log=message_log))
        #    elif game_state == GameStates.DROP_INVENTORY:
        #        player_turn_results.extend(player.inventory.drop_item(item))

        elif take_stairs and game_state == GameStates.PLAYERS_TURN:
            for entity in entities:
                if entity.stairs and entity.x == player.x and entity.y == player.y:
                    entities = game_map.next_floor(player, message_log,
                                                   constants, names_list,
                                                   colors_list)
                    fov_map = initialize_fov(game_map)
                    fov_recompute = True
                    libtcod.console_clear(con)

                    break
            else:
                message_log.add_message(
                    Message('There are no stairs here.', libtcod.yellow))

        elif level_up:
            if level_up == 'hp':
                player.fighter.base_max_hp += 20
                player.fighter.hp += 20
            elif level_up == 'str':
                player.fighter.base_power += 1
            elif level_up == 'def':
                player.fighter.base_defense += 1

            game_state = previous_game_state

        elif show_character_screen:
            player_turn_results.extend(
                character_screen(player, entities, constants,
                                 game_map.dungeon_level, names_list,
                                 colors_list))

        if game_state == GameStates.TARGETING:
            if left_click:
                target_x, target_y = left_click

                item_use_results = player.inventory.use(
                    targeting_item,
                    entities=entities,
                    fov_map=fov_map,
                    target_x=target_x,
                    target_y=target_y,
                    names_list=names_list,
                    colors_list=colors_list,
                    constants=constants)
                player_turn_results.extend(item_use_results)
            elif right_click:
                player_turn_results.append({'targeting_cancelled': True})

        if exit:
            if game_state in (GameStates.SHOW_INVENTORY,
                              GameStates.DROP_INVENTORY,
                              GameStates.CHARACTER_SCREEN):
                game_state = previous_game_state
            elif game_state in (GameStates.TARGETING, GameStates.KEYTARGETING):
                if game_state == GameStates.KEYTARGETING:
                    entities.remove(targeter)
                player_turn_results.append({'targeting_cancelled': True})
            else:
                save_game(player, entities, game_map, message_log, game_state,
                          constants)

                return True

        if fullscreen:
            libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())

        for player_turn_result in player_turn_results:
            message = player_turn_result.get('message')
            dead_entity = player_turn_result.get('dead')
            item_added = player_turn_result.get('item_added')
            item_consumed = player_turn_result.get('consumed')
            item_dropped = player_turn_result.get('item_dropped')
            equip = player_turn_result.get('equip')
            targeting = player_turn_result.get('targeting')
            targeting_cancelled = player_turn_result.get('targeting_cancelled')
            xp = player_turn_result.get('xp')

            if message:
                message_log.add_message(message)

            if dead_entity:
                if dead_entity == player:
                    message, game_state = kill_player(dead_entity, game_map,
                                                      constants)
                else:
                    if dead_entity.fighter:

                        #if dead_entity.name == "Camera Op.":
                        #    boo = pygame.mixer.Sound('audio/sfx/boo1.mp3')
                        #    pygame.mixer.Sound.play(boo)

                        score_gained = int(dead_entity.fighter.xp *
                                           constants['options_xp_multiplier'] *
                                           constants['xp_to_score_ratio'])

                        #assign the camera operator to the cam variable
                        cam = None
                        for entity in entities:
                            if entity.name == "Camera Op.":
                                cam = entity
                                break

                        #if a camera operator was located ...
                        if cam:

                            #assume the camera op did not see the kill
                            seen = False

                            #check if camera op saw the kill

                            #initialize a fov around the camera operator using the same constants the player uses
                            cam_fov = initialize_fov(game_map)
                            recompute_fov(cam_fov, cam.x, cam.y,
                                          constants['fov_radius'],
                                          constants['fov_light_walls'],
                                          constants['fov_algorithm'])

                            #assign the killx/killy positions using dead_entity
                            (kill_x, kill_y) = (dead_entity.x, dead_entity.y)

                            #check if killx/killy is in the camera_fov
                            seen = libtcod.map_is_in_fov(
                                cam_fov, kill_x, kill_y)

                            # if the camera op did see the kill, multiply score gained by the 'seen kill' mulitiplier
                            if seen:
                                score_gained = int(
                                    score_gained *
                                    constants['kill_seen_by_camera_mult'])

                        #ensure each kill gives at least one point
                        if score_gained < 1: score_gained = 1

                        #add the end result to the player score
                        player.score += score_gained

                    message = kill_monster(dead_entity, player)

                message_log.add_message(message)

            if item_added:
                print('item added')
                entities.remove(item_added)

                player_turn_end(player, player_turn_results, game_map,
                                constants, entities, message_log)
                game_state = GameStates.ENEMY_TURN

            if item_consumed:
                print('item consumed')

                player_turn_end(player, player_turn_results, game_map,
                                constants, entities, message_log)
                game_state = GameStates.ENEMY_TURN

            if item_dropped:
                print('item dropped')

                entities.append(item_dropped)

                player_turn_end(player, player_turn_results, game_map,
                                constants, entities, message_log)
                game_state = GameStates.ENEMY_TURN

            if equip:
                print("equip outside of inventory?!")

            if targeting:
                previous_game_state = GameStates.PLAYERS_TURN
                game_state = GameStates.TARGETING

                targeting_item = targeting

                message_log.add_message(targeting_item.item.targeting_message)

            if targeting_cancelled:
                game_state = previous_game_state

                message_log.add_message(Message('Targeting cancelled.'))
                fov_recompute = True

            if xp:
                axp = int(xp * constants['options_xp_multiplier'])
                leveled_up = player.level.add_xp(axp)
                message_log.add_message(
                    Message('You gain {0} experience points.'.format(axp)))

                if leveled_up:
                    previous_game_state = game_state
                    game_state = GameStates.LEVEL_UP

        if game_state == GameStates.ENEMY_TURN:

            for e in entities:
                if libtcod.map_is_in_fov(fov_map, e.x, e.y):
                    print(e.name + "; (" + str(e.x) + "," + str(e.y) + ")")

            enemy_turn_results = []
            for entity in entities:
                #proccess AI and turns
                if entity.name == "Camera Op." or libtcod.map_is_in_fov(
                        fov_map, entity.x, entity.y):
                    if entity.ai:
                        if entity.fighter:
                            if player.fighter:  #if player isn't dead ..

                                entity.fighter.timer = entity.fighter.timer + entity.fighter.speed

                                while entity.fighter.timer >= player.fighter.speed:

                                    enemy_turn_results = entity.ai.take_turn(
                                        player, fov_map, game_map, entities,
                                        constants)

                                    entity.fighter.timer = entity.fighter.timer - player.fighter.speed

                                    render_refresh(con, panel, mouse, entities,
                                                   player, game_map, fov_map,
                                                   fov_recompute, message_log,
                                                   constants, game_state,
                                                   names_list, colors_list)
                                    time.sleep(0.0255)

                                    if enemy_turn_results != None:
                                        for enemy_turn_result in enemy_turn_results:
                                            message = enemy_turn_result.get(
                                                'message')
                                            dead_entity = enemy_turn_result.get(
                                                'dead')

                                            if message:
                                                message_log.add_message(
                                                    message)

                                            if dead_entity:
                                                if dead_entity == player or dead_entity.name == "Player":
                                                    message, game_state = kill_player(
                                                        dead_entity, game_map,
                                                        constants)
                                                else:
                                                    message = kill_monster(
                                                        dead_entity, player)

                                                message_log.add_message(
                                                    message)

                                                if game_state == GameStates.PLAYER_DEAD:
                                                    break

            if game_state == GameStates.PLAYER_DEAD:
                break
            else:
                game_state = GameStates.PLAYERS_TURN
Exemple #5
0
def render_all(con, panel, entities, effects, game_map, fov_map, fov_radius,
               fov_recompute, message_log, screen_width, screen_height,
               bar_width, panel_height, panel_y, mouse, colors, game_state):

    colors = {
        'dark_rock_wall': libtcod.Color(0, 0, 50),
        'dark_rock_floor': libtcod.Color(30, 30, 80),
        'dark_chasm': libtcod.Color(30, 30, 30),
        'dark_smooth_floor': libtcod.Color(100, 50, 150),
        'dark_fort_wall': libtcod.Color(40, 0, 0),
        'light_rock_wall': libtcod.Color(130, 110, 50),
        'light_rock_floor': libtcod.Color(200, 180, 50),
        'light_chasm': libtcod.Color(50, 50, 50),
        'light_smooth_floor': libtcod.Color(255, 120, 0),
        'light_fort_wall': libtcod.Color(200, 20, 20)
    }

    for entity in entities:
        if entity.ai.__class__.__name__ == 'Player':
            player = entity
            break

    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)

                if visible:
                    color = 'light_' + game_map.tiles[y][x].name
                    hue = math.sqrt((player.x - x)**2 +
                                    (player.y - y)**2) / (fov_radius * 1.5)
                    libtcod.console_set_char_background(
                        con, x, y,
                        colors.get(color) * (1 - hue), libtcod.BKGND_SET)
                    game_map.tiles[y][x].explored = True

                elif game_map.tiles[y][x].explored == True:
                    color = 'dark_' + game_map.tiles[y][x].name
                    libtcod.console_set_char_background(
                        con, x, y, colors.get(color), libtcod.BKGND_SET)

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

    for effect in effects:
        draw_entity(con, effect, fov_map)

    for entity in entities_in_render_order:
        draw_entity(con, entity, fov_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)

    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.combat_aspect.hp,
               player.combat_aspect.max_hp, libtcod.light_red,
               libtcod.darker_red)

    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.inventory, 50,
                       screen_width, screen_height)

    if game_state == GameStates.HELP:
        help_menu(con, screen_width, screen_width, screen_height)

    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, effects, fov_map))

    libtcod.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0,
                         panel_y)
Exemple #6
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, kill_count, game_state, wall_tile, floor_tile, grass_tile):
    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 game_map.dungeon_level == 0:
                    if visible:
                        if wall:
                            libtcod.console_put_char_ex(con, x, y, wall_tile, libtcod.white, libtcod.black)
                        else:
                            libtcod.console_put_char_ex(con, x, y, grass_tile, libtcod.white, libtcod.black)

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

                    elif game_map.tiles[x][y].explored:
                        if wall:
                            libtcod.console_put_char_ex(con, x, y, wall_tile, libtcod.grey, libtcod.black)
                        else:
                            libtcod.console_put_char_ex(con, x, y, grass_tile, libtcod.grey, libtcod.black)

                else:
                    if visible:
                        if wall:
                            libtcod.console_put_char_ex(con, x, y, wall_tile, libtcod.white, libtcod.black)
                        else:
                            libtcod.console_put_char_ex(con, x, y, floor_tile, libtcod.white, libtcod.black)

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

                    elif game_map.tiles[x][y].explored:
                        if wall:
                            libtcod.console_put_char_ex(con, x, y, wall_tile, libtcod.grey, libtcod.black)
                        else:
                            libtcod.console_put_char_ex(con, x, y, floor_tile, libtcod.grey, libtcod.black)

    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, floor_tile)

    libtcod.console_set_default_foreground(con, libtcod.black)

    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)

    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

# 0 - Description names under mouse
# 1 - HP
# 2 - Talisman Health
# 3 - Mana
# 4 - EXP
# 5 - Status
# 6 - Gold
# 7 - Dungeon Level

    libtcod.console_set_default_foreground(panel, libtcod.light_gray)
    libtcod.console_print_ex(panel, 0, 0, libtcod.BKGND_NONE, libtcod.LEFT, get_names_under_mouse(mouse, entities, fov_map))
    
    # BORDERS
    #render_line(panel, 0, 1, screen_width, libtcod.darkest_sky)
    #render_vert(panel, 20, 2, 1, 7, libtcod.darkest_sky)

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

    if player.inventory.search("Health Talisman") is not None:
        render_bar(panel, 0, 2, bar_width, "Talisman HP", player.fighter.talismanhp, player.fighter.max_hp, libtcod.light_red, libtcod.darker_red)
        render_bar(panel, 0, 3, bar_width, "MANA", player.fighter.mana, player.fighter.max_mana, libtcod.dark_purple, libtcod.darker_purple)
        render_bar(panel, 0, 4, bar_width, "EXP", player.level.current_xp, player.level.experience_to_next_level, libtcod.light_blue, libtcod.darker_blue)
    else:
        render_bar(panel, 0, 2, bar_width, "MANA", player.fighter.mana, player.fighter.max_mana, libtcod.dark_purple, libtcod.darker_purple)
        render_bar(panel, 0, 3, bar_width, "EXP", player.level.current_xp, player.level.experience_to_next_level, libtcod.light_blue, libtcod.darker_blue)    


    if player.fighter.status is not None:
        status = player.fighter.status.name
        libtcod.console_print_ex(panel, 0, 6, libtcod.BKGND_NONE, libtcod.LEFT, "Status: {0}".format(status))


    libtcod.console_print_ex(panel, 0, 7, libtcod.BKGND_NONE, libtcod.LEFT, "Gold: {0}".format(player.fighter.gold))
    
    if game_map.dungeon_level == 0:
        libtcod.console_print_ex(panel, 0, 8, libtcod.BKGND_NONE, libtcod.LEFT, "Village")
    else:
        libtcod.console_print_ex(panel, 0, 8, libtcod.BKGND_NONE, libtcod.LEFT, "Dungeon Level: {0}".format(game_map.dungeon_level))


    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"
        elif game_state == GameStates.DROP_INVENTORY:
            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 in (GameStates.SHOW_EQUIPMENT_INVENTORY, GameStates.DROP_EQUIPMENT):
        if game_state == GameStates.SHOW_EQUIPMENT_INVENTORY:
            inventory_title = "Press the key next to an item to equip it, or ESC to cancel.\n"
        else:
            inventory_title = "Press the key next to the equipment to drop it, or ESC to cancel.\n"

        equipment_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:\n", player, 46, screen_width, screen_height)

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

    elif game_state == GameStates.SHOW_BAG:
        bag_title = "Press the key next to the option to open the bag.\n"

        bag_menu(con, bag_title, player, 50, screen_width, screen_height)

    elif game_state == GameStates.HELP_MENU:
        help_menu(player, 30, 10, screen_width, screen_height)

    elif game_state == GameStates.QUIT_MENU:
        quit_title = "ARE YOU SURE YOU WANT\n  TO QUIT THE GAME?\n"

        quit_menu(con, quit_title, player, 21, screen_width, screen_height)

    elif game_state == GameStates.DROP_MENU:
        drop_title = "Which inventory would you like to drop items from?"

        drop_menu(con, drop_title, player, 50, screen_width, screen_height)

    elif game_state == GameStates.SELL_MENU:
        shop_title = "Welcome to the Shop!\nWhat would you like to sell?\n"

        sell_menu(con, shop_title, player, 50, screen_width, screen_height)

    elif game_state == GameStates.BUY_MENU:
        shop_title = "Welcome to the Shop!\nWhat would you like to buy?\n"

        buy_menu(con, shop_title, player, 50, screen_width, screen_height, game_map.shop_items)

    elif game_state == GameStates.SELL_EQUIPMENT_MENU:
        shop_title = "Welcome to the Shop!\nWhat would you like to sell?\n"

        sell_equipment_menu(con, shop_title, player, 50, screen_width, screen_height)

    elif game_state == GameStates.BUY_EQUIPMENT_MENU:
        shop_title = "Welcome to the Shop!\nWhat would you like to buy?\n"

        buy_equipment_menu(con, shop_title, player, 50, screen_width, screen_height, game_map.shop_equipment_items)

    elif game_state == GameStates.SHOP_MENU:
        shop_title = "Welcome to the Shop!\nWhat would you like to do?\n"

        shop_menu(con, shop_title, player, 50, screen_width, screen_height)
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 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)
                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_print_ex(panel, 1, 5, libtcod.BKGND_NONE, libtcod.LEFT,
                             'Press h for Controls')

    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 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.HELP_MENU:
        help_menu(player, 80, 24, screen_width, screen_height)