def console_get_char_background(self,con,x,y): if con == 0: col = libtcod.console_get_char_background(0,x,y) return libtcod.color_get_hsv(col) else: col = libtcod.console_get_char_background(self.mConsole[con-1],x,y) return libtcod.color_get_hsv(col)
def assertConsolesEqual(a, b): for y in range(libtcodpy.console_get_height(a)): for x in range(libtcodpy.console_get_width(a)): assert libtcodpy.console_get_char(a, x, y) == \ libtcodpy.console_get_char(b, x, y) assert libtcodpy.console_get_char_foreground(a, x, y) == \ libtcodpy.console_get_char_foreground(b, x, y) assert libtcodpy.console_get_char_background(a, x, y) == \ libtcodpy.console_get_char_background(b, x, y)
def test_console_rexpaint_load_test_file(console): xp_console = libtcodpy.console_from_xp('libtcod/data/rexpaint/test.xp') assert xp_console assert libtcodpy.console_get_char(xp_console, 0, 0) == ord('T') assert libtcodpy.console_get_char(xp_console, 1, 0) == ord('e') assert (libtcodpy.console_get_char_background(xp_console, 0, 1) == libtcodpy.Color(255, 0, 0)) assert (libtcodpy.console_get_char_background(xp_console, 1, 1) == libtcodpy.Color(0, 255, 0)) assert (libtcodpy.console_get_char_background(xp_console, 2, 1) == libtcodpy.Color(0, 0, 255))
def make_map(): global map # fill map with "blocked" tiles map = [[Tile(False) for y in range(MAP_HEIGHT)] for x in range(MAP_WIDTH)] for y in range(MAP_HEIGHT): for x in range(MAP_WIDTH): #col = libtcod.image_get_pixel(con, x, y) col = libtcod.console_get_char_background(con, x, y) if col == libtcod.Color(217, 208, 201): map[x][y].blocked = True # create two rooms #room1 = Rect(20, 15, 10, 15) #room2 = Rect(50, 15, 10, 15) #create_room(room1) #create_room(room2) # connect them with a tunnel #create_h_tunnel(25, 55, 23) # place the player inside the first room player.x = 1 player.y = 1
def assert_char(console, x, y, ch=None, fg=None, bg=None): if ch is not None: try: ch = ord(ch) except TypeError: pass assert libtcodpy.console_get_char(console, x, y) == ch if fg is not None: assert libtcodpy.console_get_char_foreground(console, x, y) == fg if bg is not None: assert libtcodpy.console_get_char_background(console, x, y) == bg
def display_creatures(console, creatures, func): """Display on the console a list of creatures whose coords will be put to local using the function given as parameter.""" for c in creatures: x, y = func(c.x, c.y) if c.race == 0: color_front = tcod.white else: color_picker = race_to_scale[c.race] color_front = color_picker[c.level] color_back = tcod.console_get_char_background(console, x, y) to_display = c.char tcod.console_put_char_ex(console, x, y, to_display, color_front, color_back)
def target_tile(max_range=None): # return the position of a tile left-clicked in player's FOV (optionally # in a range), or (None,None) if right-clicked. message("Use the mouse or the keyboard to select a tile...", tcod.blue) prevcolor = tcod.black mouse_lastx, mouse_lasty = (x, y) = render.prev_mouse_pos while True: # render the screen. this erases the inventory and shows the names of # objects under the mouse. render.render_all() tcod.console_flush() tcod.console_set_char_background( render.con, x, y, prevcolor, tcod.BKGND_SET ) # set last tile's bg color to normal tcod.sys_check_for_event(tcod.EVENT_MOUSE | tcod.EVENT_KEY_PRESS, key, mouse) if mouse.dx or mouse.dy: (mouse_lastx, mouse_lasty) = (x, y) = (mouse.cx, mouse.cy) x = mouse.cx y = mouse.cy x = x + render.camera_x y = y + render.camera_y key_pressed = game.get_key(key) if key_pressed in direction_keys: direction = direction_keys[key_pressed] x += direction[0] y += direction[1] if tcod.map_is_in_fov(terrain.map.fov_map, x, y): prevcolor = tcod.console_get_char_background(render.con, x, y) # for resetting the color later tcod.console_set_char_background(render.con, x, y, tcod.sky, tcod.BKGND_SET) # visualising the target tile else: x, y = game.player.x, game.player.y # if not in fov, reset it to the player coords if mouse.rbutton_pressed or key.vk == tcod.KEY_ESCAPE: tcod.console_set_char_background(render.con, x, y, prevcolor, tcod.BKGND_SET) return (None, None) # cancel if the player right-clicked or pressed Escape # accept the target if the player clicked in FOV, and in case a range # is specified, if it's in that range if ( (mouse.lbutton_pressed or key.vk == tcod.KEY_ENTER) and tcod.map_is_in_fov(terrain.map.fov_map, x, y) and (max_range is None or game.player.distance(x, y) <= max_range) ): tcod.console_set_char_background(render.con, x, y, prevcolor, tcod.BKGND_SET) return (x, y)
def test_console_fill(console): width = libtcodpy.console_get_width(console) height = libtcodpy.console_get_height(console) fill = [i % 256 for i in range(width * height)] libtcodpy.console_fill_background(console, fill, fill, fill) libtcodpy.console_fill_foreground(console, fill, fill, fill) libtcodpy.console_fill_char(console, fill) # verify fill bg, fg, ch = [], [], [] for y in range(height): for x in range(width): bg.append(libtcodpy.console_get_char_background(console, x, y)[0]) fg.append(libtcodpy.console_get_char_foreground(console, x, y)[0]) ch.append(libtcodpy.console_get_char(console, x, y)) assert fill == bg assert fill == fg assert fill == ch
def test_console_fill_numpy(console): width = libtcodpy.console_get_width(console) height = libtcodpy.console_get_height(console) fill = numpy.zeros((height, width), dtype=numpy.intc) for y in range(height): fill[y, :] = y % 256 libtcodpy.console_fill_background(console, fill, fill, fill) libtcodpy.console_fill_foreground(console, fill, fill, fill) libtcodpy.console_fill_char(console, fill) # verify fill bg = numpy.zeros((height, width), dtype=numpy.intc) fg = numpy.zeros((height, width), dtype=numpy.intc) ch = numpy.zeros((height, width), dtype=numpy.intc) for y in range(height): for x in range(width): bg[y, x] = libtcodpy.console_get_char_background(console, x, y)[0] fg[y, x] = libtcodpy.console_get_char_foreground(console, x, y)[0] ch[y, x] = libtcodpy.console_get_char(console, x, y) fill = fill.tolist() assert fill == bg.tolist() assert fill == fg.tolist() assert fill == ch.tolist()
def get_color_bg(self, position): x, y = position return libtcod.console_get_char_background(x, y)
def console_invert_color(con, x, y): col1 = libtcod.console_get_char_foreground(con, x, y) col2 = libtcod.console_get_char_background(con, x, y) libtcod.console_set_char_foreground(con, x, y, color_invert(col1)) libtcod.console_set_char_background(con, x, y, color_invert(col2))
frames = [] color_masks = [[0, 0, 255], [68,68,196], [66,66,193]] for angle in range(0, 360, 10): ship = libtcod.image_load('images/ship_{0}.png'.format(str(angle).zfill(3))) # libtcod.image_blit(ship, con, 8, 8, libtcod.BKGND_SET, 1.0, 1.0, 0) libtcod.image_blit_2x(ship, con, 0, 0) libtcod.console_blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0) frame = [] for y in range(0, SCREEN_HEIGHT): row = [] for x in range(0, SCREEN_WIDTH): b = libtcod.console_get_char_background(con,x,y) f = libtcod.console_get_char_foreground(con,x,y) c = libtcod.console_get_char(con,x,y) if c == 32: f = b c = 219 if [b[0], b[1], b[2]] in color_masks or [f[0], f[1], f[2]] in color_masks: row.append( None ) elif [b[0], b[1], b[2]] == [0,0,0] and [f[0], f[1], f[2]] == [0,0,0]: row.append( None ) else: row.append( [b, f, c] ) frame.append(row) # pp(frame) frames.append(frame)