def draw(self, con, x, y, lit=False):
     col_bg = self.lit_col_bg if lit else self.unlit_col_bg
     ltc.console_set_char_background(con, x, y, col_bg, ltc.BKGND_SET)
     if self.char:
         col_fg = self.lit_col_fg if lit else self.unlit_col_fg
         ltc.console_set_default_foreground(con, col_fg)
         ltc.console_put_char(con, x, y, self.char, ltc.BKGND_NONE)
示例#2
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)
示例#3
0
 def fire(self, x, y, dx, dy):
     # The distance this bullet has traveled.
     steps = 0
     shot_accuracy=self.accuracy
     libtcod.map_compute_fov (P.player.fov, x, y, int(P.player.view_distance*1.5),
                               True,libtcod.FOV_SHADOW)
     R.render()
     libtcod.line_init(x, y, dx, dy)
     lx,ly=libtcod.line_step()
     while (not lx is None):
         steps = steps + 1
         if not M.gameworld[lx][ly].characters:
             libtcod.console_set_char_background(
                     cons.game_console,
                     lx,
                     ly,
                     libtcod.white,
                     libtcod.BKGND_OVERLAY)
             libtcod.console_blit(cons.game_console,0,0,M.MAP_WIDTH,M.MAP_HEIGHT,0,0,0,1)
             libtcod.console_flush()
             lx,ly=libtcod.line_step()
         else:
             if random.random() <= shot_accuracy:
                 S.add_status("You hit!")
                 libtcod.console_set_char_background(
                         cons.game_console,
                         lx,
                         ly,
                         libtcod.red,
                         libtcod.BKGND_OVERLAY)
                 libtcod.console_blit(cons.game_console,0,0,M.MAP_WIDTH,M.MAP_HEIGHT,0,0,0,1)
                 libtcod.console_flush()
                 M.gameworld[lx][ly].characters[-1].take_damage(
                         int(self.damage*random.uniform(self.accuracy, 1.0)))
             else:
                 S.add_status("You fire and miss!")
             break
     self.ammo = self.ammo-1
     self.owner.name = self.owner.name.rsplit('(')[0] + '(' + str(self.ammo) + ')'
     P.player.compute_fov()
示例#4
0
    def display(self, con):
        if self.game.fov_recompute:
            #recompute FOV if needed (the player moved or something)
            self.game.fov_recompute = False
            libtcod.map_compute_fov(self.map.fov_map, 
                                    self.game.player.x, self.game.player.y, 
                                    TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO)

        for y in range(self.height):
            for x in range(self.width):
                map_x, map_y = x + self.x_offset, y + self.y_offset 
                if self.map.in_bounds(map_x, map_y):
                    visible = libtcod.map_is_in_fov(self.map.fov_map, map_x, map_y)
                    tt = self.map.tiles[map_x][map_y].type
                    
                    if visible:
                        libtcod.console_set_char_background(con, x, y, tt.bg_color_lit, libtcod.BKGND_SET)
                        libtcod.console_set_default_foreground(con, tt.fg_color_lit)
                        libtcod.console_put_char(con, x, y, tt.char, libtcod.BKGND_NONE)
                            
                        # TODO: Doing this here bugs it if the player's light radius is not on screen
                        self.map.tiles[map_x][map_y].explored = True
                    elif self.map.tiles[map_x][map_y].explored:
                        libtcod.console_set_char_background(con, x, y, tt.bg_color, libtcod.BKGND_SET)
                        libtcod.console_set_default_foreground(con, tt.fg_color)
                        libtcod.console_put_char(con, x, y, tt.char, libtcod.BKGND_NONE)

                    else:
                        libtcod.console_set_char_background(con, x, y, void_color, libtcod.BKGND_SET)
                        libtcod.console_put_char(con, x, y, ' ', libtcod.BKGND_NONE)

                else:
                    libtcod.console_set_char_background(con, x, y, void_color, libtcod.BKGND_SET)
                    libtcod.console_put_char(con, x, y, ' ', libtcod.BKGND_NONE)
                
        for object in self.map.objects:
            object.draw(con, self.x_offset, self.y_offset)
        
        libtcod.console_blit(con, 0, 0, self.width, self.height, 0, 0, 0)
        libtcod.console_flush()
示例#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!")
示例#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
示例#7
0
文件: render.py 项目: phss/playground
 def draw_background(self, color, x, y):
   libtcod.console_set_char_background(self.con, x, y, color, libtcod.BKGND_SET)