Example #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
Example #2
0
 def draw(self):
     global connection_list
     self.clientMap.draw_map() # dibujamos el mapa
     connection_list_lock.acquire()
     [client.get('player').draw(self.clientMap) for client in connection_list] # dibujamos los clientes
     [client.get('player').clear(self.clientMap) for client in connection_list] # limpiamos los clientes
     connection_list_lock.release()
     if self.clientChat.enabled:
         self.clientChat.draw_box() # dibujamos el chatbox
     self.clientChat.draw_lines() # dibujamos las lineas del chat
     libtcod.console_clear(self.clientChat.console) # borramos el chat entero
Example #3
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'])
Example #4
0
def draw_items():
    height = 0
    libtcod.console_set_default_background(cons.items_console, libtcod.red)
    libtcod.console_set_default_foreground(cons.items_console, libtcod.white)
    libtcod.console_clear(cons.items_console)
    for item in tile_items:
        height+=libtcod.console_print_rect_ex(cons.items_console,
            0,
            height,
            libtcod.console_get_width(cons.items_console),
            libtcod.console_get_height(cons.items_console),
            libtcod.BKGND_NONE,
            libtcod.LEFT,
            item.name)

    libtcod.console_blit(cons.items_console,0,0,
        libtcod.console_get_width(cons.items_console),
        height,
        0,1,1,
        1.0,0.5)
    libtcod.console_flush()
Example #5
0
    def shoot(self):
        gun = -1
        for i in range(len(self.equipped)):
            if self.equipped[i].gun and self.equipped[i].gun.ammo > 0:
                gun = i
        if not gun==-1:
            class Target:
                def __init__(self, x, y):
                    self.x = x
                    self.y = y
            target = Target(self.x, self.y)
            libtcod.console_blit(cons.game_console,0,0,M.MAP_WIDTH,M.MAP_HEIGHT,0,0,0,1)
            libtcod.console_flush()
            key = libtcod.console_wait_for_keypress(True)
            while not key.vk == libtcod.KEY_SPACE:
                R.render()
                if key.pressed:
                    if ord('k') == key.c:
                        target.y=target.y-1
                    elif ord('j') == key.c:
                        target.y=target.y+1
                    elif ord('h') == key.c:
                        target.x=target.x-1
                    elif ord('l') == key.c:
                        target.x=target.x+1
                    elif ord('y') == key.c:
                        target.x=target.x-1
                        target.y=target.y-1
                    elif ord('u') == key.c:
                        target.x=target.x+1
                        target.y=target.y-1
                    elif ord('i') == key.c:
                        target.x=target.x-1
                        target.y=target.y+1
                    elif ord('o') == key.c:
                        target.x=target.x+1
                        target.y=target.y+1
                libtcod.line_init(self.x, self.y, target.x, target.y)
                x,y=libtcod.line_step()

                # Clear the console that shows our target line.
                libtcod.console_clear(cons.gun_console)
                # Draw the target line on the gun console.
                while (not x is None):
                    if (M.gameworld[x][y].is_floor() and
                        libtcod.map_is_in_fov (player.fov, x, y)
                       ):
                        libtcod.console_set_char_background(cons.gun_console, x, y,
                            libtcod.white, libtcod.BKGND_OVERLAY)
                        target.x=x
                        target.y=y
                        x,y=libtcod.line_step()
                    else:
                        break
                # Draw the gun console to the root console.
                libtcod.console_blit(cons.gun_console,0,0,M.MAP_WIDTH,M.MAP_HEIGHT,0,0,0,0,0.5)
                libtcod.console_flush()
                key = libtcod.console_wait_for_keypress(True)
            self.equipped[gun].gun.fire(self.x, self.y, target.x, target.y)
        else:
            S.add_status("No gun in hand!")
Example #6
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
Example #7
0
    def render(self, level, x, y, minx, miny, maxx, maxy, fov_map, main_area, *args, **kwargs):
        """
        Renders current level.

        Takes the level map and draws each tile on it, according to
        its properties.

        Since the map may be bigger (or smaller) than the screen, it
        makes some calculations to center (or try it at best) on the
        given (x,y) coordinates.

        TODO:
          - draw level objects. It just draws the map (and the player
            but just in a testing manner)
          - instead of drawing from level.mapa, ui.py should call a
            draw routing in the wrapper, which should receive the
            contents to be drawn in a specific area, without any game
            details being revealed here. This would also remove the
            previous message() method

        Arguments:
          level       : the world.level with the map to render
          (x,y)       : the coordinates to be the center of the drawing
          (minx,miny) : the minimum coordinates from the map to be drawn
          (maxx,maxy) : the maximum coordinates from the map to be drawn
          fov_map
          main_area   : the area where the map is to be drawn
        """
        from world.tile import TILETYPES
        libtcod.console_clear(main_area['con'])

        map_ = level.mapa

        # determine console coordinates to begin rendering according to map size
        (conx, cony) = ((main_area['w'] - map_.w)//2 if map_.w < main_area['w'] else 0,
                        (main_area['h'] - map_.h)//2 if map_.h < main_area['h'] else 0)

        # draw map tiles
        for my, cy in zip(range(miny, maxy), range(cony, map_.h + cony)):
            for mx, cx in zip(range(minx, maxx), range(conx, map_.w + conx)):
                try:
                    visible = libtcod.map_is_in_fov(fov_map, mx, my)
                    tile = map_.mapa[mx][my]
                except Exception as e:
                    continue
                # it's out of the player's FOV, player will see it only if explored
                if not visible:
                    if tile.explored:
                        # draw map tile with char/color <- modifications for explored/not visible
                        libtcod.console_put_char_ex(main_area['con'],
                                                    cx, cy,
                                                    ' ' if TILETYPES[tile.tipo]['just_color'] else TILETYPES[tile.tipo]['char'].encode('utf8'),
                                                    libtcod.white,
                                                    getcolorbyname(TILETYPES[tile.tipo]['nv_color']))
                    else:
                        libtcod.console_put_char_ex(main_area['con'],
                                                    cx, cy,
                                                    ' ',
                                                    libtcod.black,
                                                    libtcod.black)
                # it's visible
                else:
                    # draw map tile with char/color <- as is since it is visible
                    libtcod.console_put_char_ex(main_area['con'],
                                                cx, cy,
                                                ' ' if TILETYPES[tile.tipo]['just_color'] else TILETYPES[tile.tipo]['char'].encode('utf8'),
                                                libtcod.white,
                                                getcolorbyname(TILETYPES[tile.tipo]['color']))
                    # since now it's visible, mark it as explored
                    tile.explored = True
        for p in level.players:
            libtcod.console_set_char(main_area['con'],
                                     conx+x-minx, cony+y-miny,
                                     '@')

        # draw objects in map...

        # blit contents
        self.flush(main_area)
Example #8
0
def clear_console(con):
    ltc.console_set_default_background(con, ltc.BKGND_NONE)
    ltc.console_clear(con)
Example #9
0
 def clear(self):
     libtcod.console_clear(self.console)
Example #10
0
 def clear(self):
     libtcod.console_clear(self.win)