Esempio n. 1
0
    def message(self, queue, mess_area):
        """
        Displays a message queue in the message area.

        It takes only the last messages from the queue, depending on
        the screen area height. It also wraps up message texts when
        message length is too long.

        Arguments:
          queue     : game's messages queue
          mess_area : the screen area where messages are displayed
        """
        libtcod.console_clear(mess_area['con'])

        qmess = []
        for i in range(mess_area['h']):
            try:
                qmess.append(queue[(i + 1) * -1])
            except IndexError:
                break

        qlines = []
        for mess in qmess:
            str_lines = textwrap.wrap(mess.message, mess_area['w'])
            qlines.extend([util.Message(line, mess.properties) for line in str_lines])

        for i in range(mess_area['h']):
            try:
                libtcod.console_set_default_foreground(mess_area['con'], getcolorbyname(qlines[i].properties['color']))
                libtcod.console_print_ex(mess_area['con'], 0, mess_area['h'] - i - 1, libtcod.BKGND_NONE, libtcod.LEFT, qlines[i].message)
                self.flush(mess_area)
            except IndexError:
                break
Esempio n. 2
0
def dotext(con, x, y, text, fg=ltc.white, bg=None, flag=None, align=ltc.LEFT):
    if not flag:
        flag = ltc.BKGND_SET if bg else ltc.BKGND_NONE

    if not bg:
        bg = ltc.black

    # if there are any colour coded in the text, replace them with the libtcod colour chars
    if '$' in text:
        # replace common colour codes
        text = text.replace(colctr_stop, chr(ltc.COLCTRL_STOP))
        text = text.replace(colctr_fg, chr(ltc.COLCTRL_FORE_RGB))
        text = text.replace(colctr_bg, chr(ltc.COLCTRL_BACK_RGB))

        # note that libtcod can only handle 5 colour codes in the same print operation
        i = 1
        for code, colour in __colours__.iteritems():
            if code in text:
                if i > 5:
                    # too many colour codes, just remove the control sequences
                    text = text.replace(code, '')
                else:
                    # replace the control sequence with the libtcod code
                    # and assign the correct colour to the libtcod code
                    ltc_code = __ltc_colour_codes__[i]
                    text = text.replace(code, chr(ltc_code))
                    ltc.console_set_color_control(ltc_code, colour, bg)

    ltc.console_set_default_foreground(con, fg)
    ltc.console_set_default_background(con, bg)
    ltc.console_print_ex(con, x, y, flag, align, text)
Esempio n. 3
0
def show_player_stats():
    player_stats=libtcod.console_new(20,20)
    libtcod.console_set_default_background(player_stats,libtcod.darkest_grey)
    libtcod.console_set_default_foreground(player_stats, libtcod.white)
    #  libtcod.console_clear(player_stats)
    libtcod.console_print_frame(player_stats,
        0, 0,
        libtcod.console_get_width(player_stats),
        libtcod.console_get_height(player_stats),
        clear=True)
    height=0
    libtcod.console_print_rect(player_stats, 1, 1,
        libtcod.console_get_width(player_stats)-2,
        libtcod.console_get_height(player_stats)-2,
        "Name: %s \nHealth: %s/%s\nView distance: %s\nStrength: %s\nTo hit: %s\nExp: %s"#
        %(P.player.name,P.player.health,P.player.max_health, P.player.view_distance,
          P.player.strength,P.player.to_hit,P.player.exp))
    libtcod.console_print_ex(player_stats,
        libtcod.console_get_width(player_stats)//2,
        0,
        libtcod.BKGND_DEFAULT,
        libtcod.CENTER,
        "Player Stats")
    libtcod.console_print_ex(player_stats,
        libtcod.console_get_width(player_stats)//2,
        libtcod.console_get_height(player_stats)-1,
        libtcod.BKGND_DEFAULT,
        libtcod.CENTER,
        "[spacebar]")
    libtcod.console_blit(player_stats,0,0,
        libtcod.console_get_width(player_stats),
        libtcod.console_get_height(player_stats),
        0,5,5,
        1.0,0.1)
    key = libtcod.console_check_for_keypress(libtcod.KEY_PRESSED)
    while not (libtcod.KEY_SPACE==key.vk):
        key = libtcod.console_check_for_keypress(libtcod.KEY_PRESSED)
        libtcod.console_blit(player_stats,0,0,
          libtcod.console_get_width(player_stats),
          libtcod.console_get_height(player_stats),
          0,5,5,
          1.0,0.1)
        libtcod.console_flush()
        R.render()
Esempio n. 4
0
    def test_area(self, area, fcolor, bcolor):
        """
        Draw routines to test game areas.

        Draws some test things in a specific area.

        Arguments:
          area   : area to be tested
          fcolor : foreground color to use for test
          bcolor : background color to use for test
        """
        libtcod.console_set_default_background(area['con'], bcolor)
        libtcod.console_set_default_foreground(area['con'], fcolor)
        libtcod.console_clear(area['con'])
        libtcod.console_print_frame(area['con'], 0, 0, area['w'], area['h'], False, None, area['name'] + ": " + str(area))
        for i in range(area['h']):
            libtcod.console_print_ex(area['con'], 0, i, libtcod.BKGND_NONE, libtcod.LEFT, str(i + 1))
        libtcod.console_blit(area['con'],
                             0, 0, area['w'], area['h'],
                             0, area['x'], area['y'])
Esempio n. 5
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