def draw(self,fov_map,gEngine,force_display=False):
     if libtcod.map_is_in_fov(fov_map, self.x, self.y):
         #set the color and then draw the character that represents this object at its position
         h,s,v = gEngine.console_get_char_background(self.con,self.x,self.y)
         col = libtcod.Color(0,0,0)
         libtcod.color_set_hsv(col,h,s,v)
         fr,fg,fb = self.color
         br,bg,bb = col
         gEngine.console_put_char_ex(self.con,self.x,self.y,self.char,fr,fg,fb,br,bg,bb)#self.char,self.color,col)
def HeightGradMap(World):  # ------------------------------------------------------------ Print Map (Heightmap Gradient) -------------------------------------------------------------------
    for x in xrange(WORLD_WIDTH):
        for y in xrange(WORLD_HEIGHT):          
            hm_v = World[x][y].height
            HeightColor = libtcod.Color(255,255,255)
            libtcod.color_set_hsv(HeightColor,0,0,hm_v ) #Set lightness to hm_v so higher heightmap value -> "whiter"
            libtcod.console_put_char_ex( 0, x, y + SCREEN_HEIGHT/2 - WORLD_HEIGHT/2, '\333' , HeightColor, libtcod.black)
    libtcod.console_flush()
    return
Exemple #3
0
    def __init__(self, tile_type):
        self.blocked = False
        self.block_sight = None
        self.type = tile_type

        # all tiles start unexplored
        self.explored = False

        if self.type == tile_types.CAVE_FLOOR:
            self.hot_cold = -1
            self.wet_dry = -1
            self.color_in_FOV = libtcod.light_grey
        elif self.type == tile_types.CAVE_WALL:
            self.hot_cold = -1
            self.wet_dry = -1
            self.blocked = True
            self.color_in_FOV = libtcod.grey
        elif self.type == tile_types.GRASS:
            self.hot_cold = 0
            self.wet_dry = 0
            self.color_in_FOV = libtcod.desaturated_green
        elif self.type == tile_types.SAND:
            self.hot_cold = 2
            self.wet_dry = -2
            self.color_in_FOV = libtcod.light_orange
        elif self.type == tile_types.SHALLOW_WATER:
            self.hot_cold = -4
            self.wet_dry = 5
            self.color_in_FOV = libtcod.light_sky
        elif self.type == tile_types.DEEP_WATER:
            self.hot_cold = -6
            self.wet_dry = 8
            self.blocked = True
            self.block_sight = False
            self.color_in_FOV = libtcod.dark_sky

        # the following assignments depend on assignments
        # in the tile_type tests, so they come after the tests

        # by default, a tile blocks sight if it is blocked and vice versa
        if self.block_sight is None:
            self.block_sight = self.blocked

        # set tile color outside of FOV as desaturated
        # and darker than color in FOV
        hsv = libtcod.color_get_hsv(self.color_in_FOV)  # returns [h,s,v]
        # Colors are passed by reference,
        # so we have to create a whole new Color object.
        self.color_out_FOV = libtcod.Color(self.color_in_FOV.r,
                                           self.color_in_FOV.g,
                                           self.color_in_FOV.b)
        # Desaturate and darken color (unseen by default)
        libtcod.color_set_hsv(self.color_out_FOV,
                              hsv[0], hsv[1] / 4, hsv[2] / 4)
Exemple #4
0
 def draw(self, fov_map, gEngine, force_display=False):
     if libtcod.map_is_in_fov(fov_map, self.x, self.y):
         #set the color and then draw the character that represents this object at its position
         h, s, v = gEngine.console_get_char_background(
             self.con, self.x, self.y)
         col = libtcod.Color(0, 0, 0)
         libtcod.color_set_hsv(col, h, s, v)
         fr, fg, fb = self.color
         br, bg, bb = col
         gEngine.console_put_char_ex(self.con, self.x, self.y, self.char,
                                     fr, fg, fb, br, bg,
                                     bb)  #self.char,self.color,col)
def HeightGradMap(
    World
):  # ------------------------------------------------------------ Print Map (Heightmap Gradient) -------------------------------------------------------------------
    for x in xrange(WORLD_WIDTH):
        for y in xrange(WORLD_HEIGHT):
            hm_v = World[x][y].height
            HeightColor = libtcod.Color(255, 255, 255)
            libtcod.color_set_hsv(
                HeightColor, 0, 0, hm_v
            )  #Set lightness to hm_v so higher heightmap value -> "whiter"
            libtcod.console_put_char_ex(
                0, x, y + SCREEN_HEIGHT / 2 - WORLD_HEIGHT / 2, '\333',
                HeightColor, libtcod.black)
    libtcod.console_flush()
    return
Exemple #6
0
def random_monster(x,y):
    name = random.choice(lists.monster_names)
    level = random.randint(1, dungeon_level)
    if random.randint(0,2) == 1:
        adjective = random.choice(lists.monster_attributes)
        level += random.randint(1,dungeon_level)
    else:
        adjective = None
    strength = int(round(level * (random.random()+1.0)))
    agility = int(round(level * (random.random()+1.0)))
    health = int(round(level * (random.random()+1.0)))
    hue = lists.monster_colors[name]
    color = libtcod.Color(0,0,0)
    libtcod.color_set_hsv(color, hue, 0.8, 1.0)
    sprite = Sprite(name[0], color)
    new_creature = Creature(name, adjective, x, y, sprite, ai_simple_melee(), level, strength, agility, health)
    return new_creature
Exemple #7
0
def get_cylindrical_projection(stars, width=360, height=180):
    """
    Return a tcod console instance of width and height that renders an equirectangular projection of the given list of stars.
    """
    console = tcod.console_new(width, height)

    for star in stars:
        azimuthal = int((star.azimuthal * width) / (2 * math.pi))
        polar = int((star.polar / math.pi) * height)

        # Color Work
        rgb = temperature_to_rgb(random.uniform(4000, 20000))
        brightness = 1.0 - star.radial * 0.75

        color = tcod.Color(rgb[0], rgb[1], rgb[2])
        (h, s, v) = tcod.color_get_hsv(color)
        tcod.color_set_hsv(color, h, s, brightness)

        tcod.console_put_char_ex(console, azimuthal, polar, star.sprite, color,
                                 tcod.black)

    # Background Texture
    noise3d = tcod.noise_new(3)
    for map_x in range(width):
        for map_y in range(height):
            azimuthal = (map_x / (width * 1.0)) * 2.0 * math.pi
            polar = (map_y / (height * 1.0)) * math.pi
            x = math.sin(polar) * math.cos(azimuthal)
            y = math.sin(polar) * math.sin(azimuthal)
            z = math.cos(polar)
            blue = int(
                tcod.noise_get_turbulence(noise3d, [x, y, z], 32.0) * 16.0 +
                16.0)
            green = int(tcod.noise_get(noise3d, [x, y, z]) * 8.0 + 8.0)
            red = int(tcod.noise_get_fbm(noise3d, [x, y, z], 32.0) * 4.0 + 4.0)
            background = tcod.Color(red, green, blue)

            if map_y == height / 2 or map_x == 0 or map_x == width / 2:
                background = tcod.darkest_yellow

            tcod.console_set_char_background(console, map_x, map_y, background)

    tcod.noise_delete(noise3d)
    return console
Exemple #8
0
def test_color():
    color_a = libtcodpy.Color(0, 1, 2)
    assert list(color_a) == [0, 1, 2]
    assert color_a[0] == color_a.r
    assert color_a[1] == color_a.g
    assert color_a[2] == color_a.b

    color_a[1] = 3
    color_a['b'] = color_a['b']
    assert list(color_a) == [0, 3, 2]

    assert color_a == color_a

    color_b = libtcodpy.Color(255, 255, 255)
    assert color_a != color_b

    color = libtcodpy.color_lerp(color_a, color_b, 0.5)
    libtcodpy.color_set_hsv(color, 0, 0, 0)
    libtcodpy.color_get_hsv(color)
    libtcodpy.color_scale_HSV(color, 0, 0)
Exemple #9
0
def gen_colors():
    global visible_wall_color
    global visible_floor_color
    global char_wall_color
    global char_floor_color
    global wall_tile
    global floor_tile

    hue_walls = random.randint(0,359)
    sat_walls = 0.6
    val_walls = 0.6

    hue_floors = math.fmod(hue_walls + random.randint(140,220), 360)
    sat_floors = 0.6
    val_floors = 0.1
    
    libtcod.color_set_hsv(visible_wall_color, hue_walls, sat_walls, val_walls)
    libtcod.color_set_hsv(visible_floor_color, hue_floors, sat_floors, val_floors)

    libtcod.color_set_hsv(char_wall_color, hue_walls, sat_walls, val_walls + 0.1)
    libtcod.color_set_hsv(char_floor_color, hue_floors, sat_floors, val_floors + 0.1)

    wall_tile = Tile(True, '#', char_wall_color, visible_wall_color, hidden_wall_color)
    floor_tile = Tile(False, '/', char_floor_color, visible_floor_color, hidden_floor_color)
Exemple #10
0
 def draw(self, fov_map, gEngine, is_player=False, force_display=False):
     #only show if it's visible to the player
     if force_display:
         h, s, v = gEngine.console_get_char_background(
             self.con, self.x, self.y)
         #print gEngine.return_color_background(self.con,self.x,self.y)
         col = libtcod.Color(0, 0, 0)
         libtcod.color_set_hsv(col, h, s, v)
         fr, fg, fb = self.color
         br, bg, bb = col
         gEngine.console_put_char_ex(self.con, self.x, self.y, self.char,
                                     fr, fg, fb, br, bg,
                                     bb)  #self.char,self.color,col)
     elif libtcod.map_is_in_fov(fov_map, self.x, self.y):
         #set the color and then draw the character that represents this object at its position
         h, s, v = gEngine.console_get_char_background(
             self.con, self.x, self.y)
         col = libtcod.Color(0, 0, 0)
         libtcod.color_set_hsv(col, h, s, v)
         fr, fg, fb = 0, 0, 0
         if self.flashing:
             if self.flash_duration == 1:
                 c2 = libtcod.Color(0, 0, 0)
                 libtcod.color_set_hsv(c2, 0, 0, 255)
                 fr, rg, rb = c2
                 self.flash_duration = 0
                 self.flashing = False
         else:
             fr, fg, fb = self.color
             brightness = gEngine.light_mask.mask[self.x +
                                                  self.y * gEngine.w]
             fr *= brightness[0]
             fg *= brightness[1]
             fb *= brightness[2]
         br, bg, bb = col
         if is_player:
             gEngine.console_put_char_ex(self.con, gEngine.w / 2,
                                         gEngine.h / 2 - 6, self.char,
                                         int(fr), int(fg), int(fb), br, bg,
                                         bb)
         else:
             gEngine.console_put_char_ex(self.con,
                                         self.x, self.y, self.char, int(fr),
                                         int(fg), int(fb), br, bg,
                                         bb)  #self.char,self.color,col)