Ejemplo n.º 1
0
def draw_bar(con, x, y, total_width, name, value, maximum, bar_color,
             back_color):
    # render a bar (HP, experience, etc). First calculate the width of the bar
    bar_width = int(float(value) / maximum * total_width)

    # render the background first
    ltc.console_set_default_background(con, back_color)
    ltc.console_rect(con, x, y, total_width, 1, False, ltc.BKGND_SCREEN)

    # now render the bar on top
    ltc.console_set_default_background(con, bar_color)
    if bar_width > 0:
        ltc.console_rect(con, x, y, bar_width, 1, False, ltc.BKGND_SCREEN)

    # now, centered text with values
    text = name + ':' + str(value) + '/' + str(maximum)
    dotext(con, x + total_width / 2, y, text, align=ltc.CENTER)
Ejemplo n.º 2
0
def display_status ():
    global status
    if status:
        libtcod.console_rect(status_console, 0, 0, M.SCREEN_WIDTH,
            (M.SCREEN_HEIGHT - M.MAP_HEIGHT), True)
        libtcod.console_set_default_foreground (status_console, libtcod.white)
        while len(status) > M.SCREEN_WIDTH*2:
            display_statusline(status[:M.SCREEN_WIDTH*2])
            key = libtcod.console_wait_for_keypress(True)
            while not key.vk == libtcod.KEY_SPACE:
                key = libtcod.console_wait_for_keypress(True)
            status = status[M.SCREEN_WIDTH*2:]
        display_statusline(status)
        libtcod.console_blit(status_console,0,0,M.SCREEN_WIDTH,
            (M.SCREEN_HEIGHT-M.MAP_HEIGHT-1),0,0,M.MAP_HEIGHT+1,1)
        libtcod.console_flush()
    else:
        display_statusline()
        libtcod.console_flush()
Ejemplo n.º 3
0
def render():
    libtcod.console_rect(cons.game_console, 0, 0, M.MAP_WIDTH, M.MAP_HEIGHT, True)
    for y in range (M.MAP_HEIGHT):
        for x in range (M.MAP_WIDTH):

            # Draw black for all areas the player has not seen yet
            if not M.gameworld[x][y].explored:
                libtcod.console_set_char_background(cons.game_console, x, y,
                    libtcod.black, libtcod.BKGND_SET)

            # Draw all the floors.
            if M.gameworld[x][y].is_floor () and M.gameworld[x][y].explored:
                libtcod.console_set_char_background (cons.game_console, x, y,
                    M.DARK_FLOOR_COLOR, libtcod.BKGND_SET)

            # Draw all the walls.
            elif M.gameworld[x][y].explored:
                libtcod.console_set_char_background(cons.game_console, x, y,
                    M.DARK_WALL_COLOR, libtcod.BKGND_SET)

            # Draw all the light floors.
            if (libtcod.map_is_in_fov (P.player.fov, x, y)
               and libtcod.map_is_walkable (P.player.fov, x, y)):
                libtcod.console_set_char_background (cons.game_console, x, y,
                    M.FLOOR_COLOR, libtcod.BKGND_SET)
                for item in M.gameworld[x][y].items:
                    libtcod.console_set_default_foreground (cons.game_console, item.color)
                    libtcod.console_put_char (cons.game_console, x, y,
                        item.char, libtcod.BKGND_NONE)
                for character in M.gameworld[x][y].characters:
                    libtcod.console_set_default_foreground (cons.game_console,
                        character.color)
                    libtcod.console_put_char (cons.game_console, x, y,
                        character.char, libtcod.BKGND_NONE)
                M.gameworld[x][y].explored=True

            # Draw all the light walls.
            elif libtcod.map_is_in_fov (P.player.fov, x, y):
                libtcod.console_set_char_background (cons.game_console, x, y,
                    M.WALL_COLOR, libtcod.BKGND_SET)
                M.gameworld[x][y].explored=True
    # Blits the game console to the root console.
    libtcod.console_blit(cons.game_console,0,0,M.MAP_WIDTH,M.MAP_HEIGHT,0,0,0,1)
Ejemplo n.º 4
0
def item_selector(items, default=None, equipped=[], title="INVENTORY"):
  libtcod.console_clear(cons.menu_console)
  libtcod.console_set_default_background(cons.menu_console, libtcod.black)
  libtcod.console_set_default_foreground(cons.menu_console, libtcod.white)
  libtcod.console_rect(cons.menu_console, 0, 0, M.MAP_WIDTH, M.MAP_HEIGHT, True)
  libtcod.console_print_ex(cons.menu_console,
      40, 0, libtcod.BKGND_NONE, libtcod.CENTER, title)
  libtcod.console_print_ex(cons.menu_console,
      1, M.SCREEN_HEIGHT-1, libtcod.LEFT,
    libtcod.BKGND_NONE,
    "[j / k]: Highlight item     [SPACEBAR]: Select     [q]: quit")
  count = 0
  for item in items:
    libtcod.console_print_ex(cons.menu_console,
        1, count+3, libtcod.BKGND_NONE, libtcod.LEFT, item.name)
    if item in equipped:
      libtcod.console_print_ex(cons.menu_console,
          libtcod.console_get_width(cons.menu_console)-1,
          count+3,
          libtcod.BKGND_NONE,
          libtcod.RIGHT,
          "(EQUIPPED)")
    count = count + 1
  if default:
    count = items.index(default)
  else:
    count = count -1
  key = libtcod.console_check_for_keypress(True)
  while not key.vk == libtcod.KEY_SPACE and not ord('q') == key.c:

    for i in range(len(items[count].name)):
      libtcod.console_set_char_background(cons.menu_console,
          i+1,
          count+3,
          libtcod.white)
      libtcod.console_set_char_foreground(cons.menu_console,
          i+1,
          count+3,
          libtcod.black)
    if key.pressed and key.c == ord('k') and count > 0:
      for i in range(len(items[count].name)):
        libtcod.console_set_char_background(cons.menu_console,
            i+1,
            count+3,
            libtcod.black)
        libtcod.console_set_char_foreground(cons.menu_console,
            i+1,
            count+3,
            libtcod.white)
      count = count -1
    elif key.pressed and key.c == ord('j') and count < len(items)-1:
      for i in range(len(items[count].name)):
        libtcod.console_set_char_background(cons.menu_console,
            i+1,
            count+3,
            libtcod.black)
        libtcod.console_set_char_foreground(cons.menu_console,
            i+1,
            count+3,
            libtcod.white)
      count = count +1
    key = libtcod.console_check_for_keypress(True)
    libtcod.console_blit(cons.menu_console,0,0,M.SCREEN_WIDTH,M.SCREEN_HEIGHT,0,0,0,1)
    libtcod.console_flush()

  if ord('q') == key.c:
    count=-1

  return count