def __init__(self, tilelist, fadetime, color1, color2): self.tilelist = tilelist self.color1 = color1 self.color2 = color2 allx = map(lambda tile: tile.x, self.tilelist) ally = map(lambda tile: tile.y, self.tilelist) minx = min(allx) maxx = max(allx) miny = min(ally) maxy = max(ally) self.blitx = minx self.blity = miny width = maxx - minx + 1 height = maxy - miny + 1 EffectCon.__init__(self, width, height, fadetime) libtcod.console_set_key_color(self.console, libtcod.silver) libtcod.console_set_default_background(self.console, libtcod.silver) #key color idx = [0, self.maxduration] col = [self.color1, self.color2] self.colormap = libtcod.color_gen_map(col, idx) newcoordlist = [] for tile in self.tilelist: newcoordlist.append((tile.x - minx, tile.y - miny)) self.con_coords = newcoordlist activeeffects.append(self)
def build_map(self): upper = [libtcod.blue, libtcod.white, libtcod.grey, libtcod.lighter_grey, libtcod.blue, libtcod.blue, libtcod.blue, libtcod.blue, libtcod.blue, libtcod.green] colors = [libtcod.darker_grey, libtcod.black] index = [0, MAP_HEIGHT] gradient = libtcod.color_gen_map(colors, index) self.color_map = upper + list(gradient)
def __init__(self, **kwargs): self.bullet = False self.particle_type = 'thrust' self.index = 9 self.colormap = libtcod.color_gen_map( [ kwargs.get('sector').background, libtcod.Color(255, 144, 0), libtcod.Color(255, 222, 0) ], [ 0, self.index/2, self.index] ) self.charactermap = [176, 176, 176, 177, 177, 178, 178, 219, 219, 219] super(Fire, self).__init__(**kwargs)
def __init__(self, **kwargs): self.damage = 10 self.bullet = True self.particle_type = 'bullet' self.index = 30 self.colormap = libtcod.color_gen_map( [ libtcod.Color(0, 144, 255), libtcod.Color(0, 222, 255) ], [ 0, self.index ] ) self.charactermap = [4 for i in range(0, self.index+1)] super(BlueBullet, self).__init__(velocity=1.0, **kwargs)
def build_map(self): upper = [ libtcod.blue, libtcod.white, libtcod.grey, libtcod.lighter_grey, libtcod.blue, libtcod.blue, libtcod.blue, libtcod.blue, libtcod.blue, libtcod.green ] colors = [libtcod.darker_grey, libtcod.black] index = [0, MAP_HEIGHT] gradient = libtcod.color_gen_map(colors, index) self.color_map = upper + list(gradient)
def draw(self, con, mode): if mode == "normal": libtcod.image_blit_2x(self.image, con, 0, 0) for x in range(self.width): for y in range(self.height): tile = self.tiles[x][y] if tile.char is not None: libtcod.console_set_default_foreground(con, tile.fg_color) libtcod.console_put_char(con, x, y, tile.char, libtcod.BKGND_NONE) elif mode == "tiles": for x in range(self.width): for y in range(self.height): if self.tiles[x][y].terrain == "land": libtcod.console_set_default_background(con, libtcod.Color(40, 62, 19)) libtcod.console_put_char(con, x, y, ' ', libtcod.BKGND_SET) elif self.tiles[x][y].terrain == "water": libtcod.console_set_default_background(con, libtcod.Color(38, 50, 60)) libtcod.console_put_char(con, x, y, ' ', libtcod.BKGND_SET) elif mode == "temps": cols = [libtcod.green, libtcod.yellow, libtcod.red] col_idx = [0, 50, 100] col_map = libtcod.color_gen_map(cols, col_idx) for x in range(self.width): for y in range(self.height): libtcod.console_set_default_foreground(con, col_map[int(self.tiles[x][y].temp*100)]) libtcod.console_put_char(con, x, y, 'o', libtcod.BKGND_NONE) elif mode == "rain": cols = [libtcod.yellow, libtcod.green, libtcod.blue] col_idx = [0, 50, 100] col_map = libtcod.color_gen_map(cols, col_idx) for x in range(self.width): for y in range(self.height): libtcod.console_set_default_foreground(con, col_map[int(self.tiles[x][y].rain*100)]) libtcod.console_put_char(con, x, y, 'o', libtcod.BKGND_NONE) else: print "Invalid drawing mode passed to Map.draw: " + mode sys.exit(1)
def __init__(self, starting_index=0, **kwargs): self.bullet = False self.particle_type = 'explosion_fire_ball' self.index = 16 - starting_index self.colormap = libtcod.color_gen_map( [ kwargs.get('sector').background, libtcod.Color(81, 39, 23), libtcod.Color(247, 151, 65), libtcod.Color(255, 255, 149), libtcod.Color(255, 255, 249) ], [ 0, self.index/4, 2*self.index/4, 3*self.index/4, self.index] ) self.charactermap = [176, 176, 176, 177, 177, 177, 177, 177, 178, 178, 178, 178, 178, 219, 219, 219, 219] super(ExplosionFireBall, self).__init__(**kwargs)
def __init__(self, sector, planet_class='terran', position_x=-30, position_y=30, diameter=60, seed=3849058430, name="X", star_class=None, star_temp=None): self.name = name self.planet_class = planet_class self.star_class = star_class self.star_temp = star_temp self.seed = seed random.seed(self.seed) if self.planet_class == 'star': self.star_class = random.choice(Planet.star_classes.keys()) self.star_temp = random.randrange( Planet.star_classes[self.star_class]['temp'][0], Planet.star_classes[self.star_class]['temp'][1]) self.sector = sector self.sector_position_x = position_x self.sector_position_y = position_y self.width = diameter if (self.width % 2) != 0: self.width += 1 self.height = self.width if self.width < 13: self.icon = 15 elif 14 <= self.width < 24: self.icon = 14 elif 24 <= self.width < 34: self.icon = 13 elif 34 <= self.width < 44: self.icon = 12 elif 44 <= self.width < 54: self.icon = 11 elif 54 <= self.width < 64: self.icon = 10 elif self.width >= 64: self.icon = 9 self.terrain_rotation_index = 0 self.atmosphere_rotation_index = 0 self.last_terrain_rotation = 0.0 self.last_atmosphere_rotation = 0.0 self.selected = False self.noise_dx = 0.0 self.noise_dy = 0.0 self.noise_dz = 0.0 self.noise_hurst = libtcod.NOISE_DEFAULT_HURST self.noise_lacunarity = libtcod.NOISE_DEFAULT_LACUNARITY self.icon_color = libtcod.Color(255, 255, 255) if self.planet_class == 'terran': self.icon_color = libtcod.Color(50, 72, 200) self.height_colormap = libtcod.color_gen_map( [ libtcod.Color(39, 62, 90), libtcod.Color(50, 72, 88), libtcod.Color(116, 184, 164), libtcod.Color(142, 163, 164), libtcod.Color(71, 97, 81), libtcod.Color(149, 138, 115), libtcod.Color(199, 197, 150), libtcod.Color(220, 197, 173) ], [ 0, 15, 70, 80, 90, 200, 233, 255] ) self.noise_octaves = 6.0 self.noise_zoom = 1.0 elif self.planet_class == 'ocean': self.icon_color = libtcod.Color(27, 75, 174) self.height_colormap = collections.deque( libtcod.color_gen_map( [ libtcod.Color(13, 44, 53), libtcod.Color(18, 51, 57), libtcod.Color(16, 70, 63), libtcod.Color(31, 106, 100), libtcod.Color(92, 198, 169), libtcod.Color(170, 211, 142), libtcod.Color(78, 144, 72), libtcod.Color(24, 55, 23), ], [0, 40, 80, 130, 150, 160, 180, 200] )) self.noise_octaves = 6.0 self.noise_zoom = 1.0 elif self.planet_class == 'jungle': self.icon_color = libtcod.Color(100, 173, 22) self.height_colormap = libtcod.color_gen_map( [ libtcod.Color(29, 53, 112), libtcod.Color(69, 137, 200), libtcod.Color(61, 86, 34), libtcod.Color(42, 72, 38), libtcod.Color(52, 103, 35), libtcod.Color(29, 47, 18), libtcod.Color(75, 118, 33), libtcod.Color(100, 173, 22), ], [0, 60, 80, 110, 150, 205, 235, 255] ) self.noise_octaves = 6.0 self.noise_zoom = 3.0 elif self.planet_class == 'lava': self.icon_color = libtcod.Color(255, 52, 0) self.height_colormap = libtcod.color_gen_map( [ libtcod.Color(255, 151, 19), libtcod.Color(255, 52, 0), libtcod.Color(91, 31, 12), libtcod.Color(31, 21, 11), libtcod.Color(56, 44, 21), libtcod.Color(0, 0, 0), libtcod.Color(62, 19, 15), libtcod.Color(94, 65, 35), ], [0, 60, 80, 110, 150, 205, 235, 255] ) self.noise_octaves = 6.0 self.noise_zoom = 6.0 elif self.planet_class == 'tundra': self.icon_color = libtcod.Color(167, 157, 109) self.height_colormap = libtcod.color_gen_map( [ libtcod.Color(121, 183, 170), libtcod.Color(167, 206, 174), libtcod.Color(145, 150, 117), libtcod.Color(110, 116, 93), libtcod.Color(167, 157, 109), libtcod.Color(86, 111, 95), libtcod.Color(210, 199, 132), libtcod.Color(255, 255, 200), ], [0, 60, 75, 105, 140, 200, 235, 255] ) self.noise_octaves = 6.0 self.noise_zoom = 2.0 elif self.planet_class == 'arid': self.icon_color = libtcod.Color(235, 131, 44) self.height_colormap = libtcod.color_gen_map( [ libtcod.Color(121, 183, 170), libtcod.Color(167, 206, 174), libtcod.Color(126, 86, 36), libtcod.Color(163, 94, 45), libtcod.Color(235, 131, 44), libtcod.Color(174, 115, 29), libtcod.Color(112, 69, 35), libtcod.Color(41, 30, 20), ], [0, 60, 75, 90, 140, 180, 225, 255] ) self.noise_octaves = 6.0 self.noise_zoom = 3.0 elif self.planet_class == 'desert': self.icon_color = libtcod.Color(255, 178, 58) self.height_colormap = libtcod.color_gen_map( [ libtcod.Color(255, 178, 58), libtcod.Color(229, 163, 78), libtcod.Color(255, 150, 61), libtcod.Color(235, 131, 44), libtcod.Color(174, 115, 29), libtcod.Color(163, 94, 45), libtcod.Color(112, 69, 35), libtcod.Color(68, 47, 49), ], [0, 30, 40, 80, 140, 200, 244, 255] ) self.noise_octaves = 6.0 self.noise_zoom = 3.0 elif self.planet_class == 'artic': self.icon_color = libtcod.Color(255, 255, 240) self.height_colormap = libtcod.color_gen_map( [ libtcod.Color(255, 255, 240), libtcod.Color(221, 245, 193), libtcod.Color(157, 198, 160), libtcod.Color(134, 152, 113), libtcod.Color(154, 166, 116), libtcod.Color(208, 211, 156), libtcod.Color(172, 198, 155), libtcod.Color(255, 255, 255), ], [0, 60, 100, 120, 140, 170, 175, 255] ) self.noise_octaves = 6.0 self.noise_zoom = 1.0 elif self.planet_class == 'barren' or self.planet_class == 'asteroid': self.icon_color = libtcod.Color(151, 152, 113) self.height_colormap = libtcod.color_gen_map( [ libtcod.Color(39, 41, 44 ), libtcod.Color(88, 93, 67 ), libtcod.Color(111, 109, 78 ), libtcod.Color(151, 152, 113), libtcod.Color(151, 141, 101), libtcod.Color(198, 189, 133), libtcod.Color(100, 101, 81 ), libtcod.Color(247, 236, 177), ], [0, 30, 60, 85, 100, 120, 180, 255] ) self.noise_octaves = 6.0 self.noise_zoom = 2.5 if self.planet_class == 'gas giant': self.icon_color = libtcod.Color(112, 199, 242) self.height_colormap = libtcod.color_gen_map( [ libtcod.Color(62, 99, 120), libtcod.Color(86, 137, 173), libtcod.Color(112, 199, 242), libtcod.Color(115, 214, 255), libtcod.Color(162, 212, 234), libtcod.Color(237, 236, 255), libtcod.Color(222, 255, 255), libtcod.Color(255, 255, 255) ], [ 0, 40, 80, 100, 120, 190, 210, 255] ) self.noise_octaves = 4.0 self.noise_zoom = 3.0 elif self.planet_class == 'star': self.star_class = random.choice(Planet.star_classes.keys()) self.star_temp = random.randrange( Planet.star_classes[self.star_class]['temp'][0], Planet.star_classes[self.star_class]['temp'][1]) star_colors = Planet.star_classes[self.star_class]['colors'] self.icon = 8 self.icon_color = star_colors[2] self.height_colormap = collections.deque( libtcod.color_gen_map( star_colors * 2 + [star_colors[0]], [ 0, 42, 84, 126, 168, 210, 255] )) self.noise_octaves = 4.0 self.noise_zoom = 4.0 self.heightmap_width = self.width * 2 self.heightmap_height = self.height self.detail_width = self.width * 2 if self.detail_width > self.sector.screen_height * 1.25: self.detail_width = int(self.sector.screen_height * 1.25) if (self.detail_width % 2) != 0: self.detail_width += 1 self.detail_heightmap_width = self.detail_width * 2 self.detail_heightmap_height = self.detail_width # self.char_shades = ['.',':','!','*','o','e','&','#','%','@'] self.shades = [i/20.0 for i in range(20, -1, -1)] self.circle_mask = self.build_circle_mask(self.width) self.heightmap = self.build_heightmap(self.heightmap_width, self.heightmap_height) self.atmosphere = self.build_atmosphere(self.heightmap_width, self.heightmap_height) self.sprite = self.build_sprite(self.width) self.detail_circle_mask = self.build_circle_mask(self.detail_width) self.detail_heightmap = self.build_heightmap(self.detail_heightmap_width, self.detail_heightmap_height) self.detail_atmosphere = self.build_atmosphere(self.detail_heightmap_width, self.detail_heightmap_height) self.target_width = 12 self.target_circle_mask = self.build_circle_mask(self.target_width) self.target_heightmap = self.build_heightmap(self.target_width*2, self.target_width) self.target_atmosphere = self.build_atmosphere(self.target_width*2, self.target_width) self.target_sprite = self.build_sprite(self.target_width, circle_mask=self.target_circle_mask, heightmap=self.target_heightmap, atmosphere=self.target_atmosphere, width=self.target_width)
'NONE': ltc.KEY_NONE, 'ESCAPE': ltc.KEY_ESCAPE, 'UP': ltc.KEY_UP, 'DOWN': ltc.KEY_DOWN, 'LEFT': ltc.KEY_LEFT, 'RIGHT': ltc.KEY_RIGHT } idx = [ 0, 10, 50, 100, 255 ] # indexes of the keys col = [ ltc.Color( 255, 255, 153 ), ltc.Color( 102, 204, 0 ), ltc.Color( 153, 76, 0 ), ltc.Color( 102, 51, 0 ), ltc.Color(255,255,255) ] # colors : black, red, white land_colors = ltc.color_gen_map(col, idx) idx = [ 0, 255 ] # indexes of the keys col = [ ltc.Color( 153, 255, 255 ), ltc.Color( 0, 25, 51 ) ] # colors : black, red, white sea_colors = ltc.color_gen_map(col, idx) def init(): global SYMBOL_MAP, KEYBOARD_MAP, CON, UI, MOUSE, KEY w = config.SCREEN_WIDTH h = config.SCREEN_HEIGHT ltc.sys_set_fps(config.FPS) #ltc.console_set_custom_font(config.TILE_SET, ltc.FONT_LAYOUT_ASCII_INROW | ltc.FONT_TYPE_GREYSCALE, 16, 16) ltc.console_set_custom_font(config.TILE_SET, ltc.FONT_LAYOUT_TCOD | ltc.FONT_TYPE_GREYSCALE, 32, 8) ltc.console_init_root(w, h, config.TITLE, False)
def test_color_gen_map(): colors = libtcodpy.color_gen_map([(0, 0, 0), (255, 255, 255)], [0, 8]) assert colors[0] == libtcodpy.Color(0, 0, 0) assert colors[-1] == libtcodpy.Color(255, 255, 255)
def create_light_map(weather): weather['light_map'] = tcod.color_gen_map([ tcod.Color(c['colors'][0], c['colors'][1], c['colors'][2]) for c in weather['colors'] ], weather['color_indexes'])
'ESCAPE': ltc.KEY_ESCAPE, 'UP': ltc.KEY_UP, 'DOWN': ltc.KEY_DOWN, 'LEFT': ltc.KEY_LEFT, 'RIGHT': ltc.KEY_RIGHT } idx = [0, 10, 50, 100, 255] # indexes of the keys col = [ ltc.Color(255, 255, 153), ltc.Color(102, 204, 0), ltc.Color(153, 76, 0), ltc.Color(102, 51, 0), ltc.Color(255, 255, 255) ] # colors : black, red, white land_colors = ltc.color_gen_map(col, idx) idx = [0, 255] # indexes of the keys col = [ltc.Color(153, 255, 255), ltc.Color(0, 25, 51)] # colors : black, red, white sea_colors = ltc.color_gen_map(col, idx) def init(): global SYMBOL_MAP, KEYBOARD_MAP, CON, UI, MOUSE, KEY w = config.SCREEN_WIDTH h = config.SCREEN_HEIGHT ltc.sys_set_fps(config.FPS) #ltc.console_set_custom_font(config.TILE_SET, ltc.FONT_LAYOUT_ASCII_INROW | ltc.FONT_TYPE_GREYSCALE, 16, 16) ltc.console_set_custom_font(config.TILE_SET,
def render_all(): #renders the screen global color_dark_wall, color_light_wall, color_dark_ground, color_light_ground global fov_recompute, fov_map global game_state, map_list, current_map, current_map_name move_camera(player.x, player.y) if fov_recompute: #recomputes FOV if needed (player move, etc) fov_recompute = False libtcod.map_compute_fov(fov_map, player.x, player.y, config.TORCH_RADIUS, config.FOV_LIGHT_WALLS, config.FOV_ALGO) # for object in objects: # if libtcod.map_is_in_fov(fov_map, object.x, object.y): # if object.item: # object.always_visible = True # if object.name == 'stairs': # object.always_visible = True libtcod.console_clear(con) #draw the map for y in range(config.CAMERA_HEIGHT): for x in range(config.CAMERA_WIDTH): (map_x, map_y) = (camera_x + x, camera_y + y) visible = libtcod.map_is_in_fov(fov_map, map_x, map_y) wall = current_map[map_x][map_y].block_sight if game_state == 'dead': #reveals the map when player dies if wall: libtcod.console_set_char_background(con,x,y,color_nolight_wall,libtcod.BKGND_SET) else: libtcod.console_set_char_background(con, x, y, color_nolight_ground, libtcod.BKGND_SET) if not visible: if current_map[map_x][map_y].explored: if wall: libtcod.console_set_char_background(con,x,y,color_not_in_view_wall,libtcod.BKGND_SET) else: libtcod.console_set_char_background(con, x, y, color_not_in_view_ground, libtcod.BKGND_SET) elif game_state == 'dead': #turns off the lights if the player is dead if wall: libtcod.console_set_char_background(con,x,y,color_not_in_view_wall,libtcod.BKGND_SET) else: libtcod.console_set_char_background(con, x, y, color_not_in_view_ground, libtcod.BKGND_SET) else: if wall: #sets wall color and renders them indx = [0, config.TORCH_RADIUS - 4, config.TORCH_RADIUS - 2, config.TORCH_RADIUS] key = [config.color_light_wall, config.color_dark_wall, config.color_nolight_wall, config.color_nolight_wall] light_map = libtcod.color_gen_map(key, indx) distance_from_light = abs(int(player.distance(camera_x +x, camera_y + y))) if distance_from_light != 0: wallcolor = light_map[distance_from_light-1] else: wallcolor = config.color_dark_wall libtcod.console_set_char_background(con, x, y, wallcolor, libtcod.BKGND_SET) else: #sets tile color and renders them indx = [0, config.TORCH_RADIUS - 4, config.TORCH_RADIUS - 2, config.TORCH_RADIUS] key = [config.color_light_ground, config.color_dark_ground, config.color_nolight_ground, config.color_nolight_ground] light_map = libtcod.color_gen_map(key, indx) distance_from_light = abs(int(player.distance(camera_x +x, camera_y + y))) if distance_from_light != 0: groundcolor = light_map[distance_from_light-1] else: groundcolor = config.color_dark_ground libtcod.console_set_char_background(con,x,y,groundcolor,libtcod.BKGND_SET) #since visible, explores tile current_map[map_x][map_y].explored = True player.draw() #writes "con" console to the root console map_width = get_map_dimensions(current_map_name)[0] map_height = get_map_dimensions(current_map_name)[1] libtcod.console_blit(con,0,0,map_width,map_height,0,0,0) #prepare to render the GUI panel libtcod.console_set_default_background(panel, libtcod.black) libtcod.console_clear(panel) #print the game messages, one line at a time y = 1 for (line, color) in game_msgs: libtcod.console_set_default_foreground(panel, color) libtcod.console_print_ex(panel, config.MSG_X, y, libtcod.BKGND_NONE, libtcod.LEFT, line) y += 1 #show dungeon level libtcod.console_print_ex(panel, 1, 5, libtcod.BKGND_NONE, libtcod.LEFT, 'Dungeon level ' + str(dungeon_level)) #blit the contents of "panel" to root console libtcod.console_blit(panel, 0, 0, config.SCREEN_WIDTH, config.PANEL_HEIGHT, 0, 0, config.PANEL_Y)
def generate(self): self.owner.log.message("Generating map...", debug = True) noise = libtcod.noise_new(2, 0.5, 2.0) heightmap = libtcod.heightmap_new(2*self.width, 2*self.height) maxi = 0 mini = 0 self.tiles = [[ Tile() for y in range(self.height) ] for x in range(self.width) ] self.owner.log.message("-- creating heightmap...", debug = True) for x in range(self.width*2): for y in range(self.height*2): f = [3 * float(x) / (2*self.width), 3 * float(y) / (2*self.height)] value = (libtcod.noise_get_fbm(noise, f, 5, libtcod.NOISE_PERLIN))/2 if value > maxi: maxi = value if value < mini: mini = value libtcod.heightmap_set_value(heightmap, x, y, value) # print "-- erode the map" # libtcod.heightmap_rain_erosion(heightmap, self.width*2*self.height*2*2,0.1,0.2) self.owner.log.message("-- normalize heights...", debug = True) self.heightmap = libtcod.heightmap_new(self.width*2, self.height*2) for x in range(self.width*2): for y in range(self.height*2): value = libtcod.heightmap_get_value(heightmap, x, y) if value < 0: value += 1 mini2 = mini + 1 coeff = (value - mini2)/(1-mini2) libtcod.heightmap_set_value(self.heightmap, x, y, -coeff) else: value = value / maxi libtcod.heightmap_set_value(self.heightmap, x, y, value) self.owner.log.message("-- setting up tiles", debug = True) for x in range(self.width): for y in range(self.height): h = libtcod.heightmap_get_value(self.heightmap, x*2, y*2) if h >= 0.05: self.tiles[x][y].terrain = "land" else: self.tiles[x][y].terrain = "water" # self.owner.log.message("-- creating temperature map", debug = True) # noise2 = libtcod.noise_new(2, 0.5, 2.0) # temp_max = 0 # temp_min = 1 # for x in range(self.width): # for y in range(self.height): # f = [3 * float(x) / (self.width), 3 * float(y) / (self.height)] # value = (libtcod.noise_get_fbm(noise2, f, 5, libtcod.NOISE_PERLIN))/2 # value = (value + 1)/2 # if value < temp_min: # temp_min = value # if value > temp_max: # temp_max = value # self.tiles[x][y].temp = value # temp_max = temp_max - temp_min # height_factor = 0.5 # for x in range(self.width): # for y in range(self.height): # temp = (self.tiles[x][y].temp - temp_min)/temp_max # h = libtcod.heightmap_get_value(self.heightmap, x*2, y*2) # if h > 0: # factor = (-h)*height_factor # temp = temp + factor # temp = min(1, temp) # temp = max(0, temp) # self.tiles[x][y].temp = temp self.owner.log.message("-- creating rainfall map", debug = True) noise3 = libtcod.noise_new(2, 0.5, 2.0) self.rainmap = libtcod.heightmap_new(self.width*2, self.height*2) rain_max = 0 rain_min = 1 for x in range(self.width*2): for y in range(self.height*2): f = [5 * float(x) / (self.width*2), 5 * float(y) / (self.height*2)] value = (libtcod.noise_get_fbm(noise3, f, 5, libtcod.NOISE_PERLIN))/2 value = (value + 1)/2 if value < rain_min: rain_min = value if value > rain_max: rain_max = value self.tiles[x/2][y/2].rain = value libtcod.heightmap_set_value(self.rainmap, x, y, value) rain_max = rain_max - rain_min for x in range(self.width*2): for y in range(self.height*2): libtcod.heightmap_set_value(self.rainmap, x, y, (libtcod.heightmap_get_value(self.rainmap, x, y) - rain_min)/rain_max) self.tiles[x/2][y/2].rain = (self.tiles[x/2][y/2].rain - rain_min)/rain_max self.owner.log.message("Terrain complete", debug = True) self.owner.log.message("Painting terrain", debug = True) deep = libtcod.Color(1, 10, 27) mid = libtcod.Color(38, 50, 60) shallow = libtcod.Color(51, 83, 120) water_idx = [0, 70, 210, 255] water_cols = [deep, deep, mid, shallow] water_colormap = libtcod.color_gen_map(water_cols, water_idx) mountaintop = libtcod.Color(145, 196, 88) grass = libtcod.Color(40, 62, 19) foothill = libtcod.Color(57, 81, 34) sand = libtcod.Color(215, 185, 115) watersedge = libtcod.Color(19, 97, 101) land_idx = [0, 15, 20, 128, 255] land_cols = [watersedge, sand, grass, foothill, mountaintop] land_colormap = libtcod.color_gen_map(land_cols, land_idx) # Apply height-based colours for x in range(self.width*2): for y in range(self.height*2): value = libtcod.heightmap_get_value(self.heightmap, x, y) if value < 0: index = int(-value * 255) libtcod.image_put_pixel(self.image, x, y, water_colormap[index]) else: index = int(value * 255) libtcod.image_put_pixel(self.image, x, y, land_colormap[index]) # Adjust colours for desert-plains-forest for x in range(self.width*2): for y in range(self.height*2): if libtcod.heightmap_get_value(self.heightmap, x, y) > 0: rain = libtcod.heightmap_get_value(self.rainmap, x, y) cur_col = libtcod.image_get_pixel(self.image, x, y) cols = [libtcod.light_sepia, cur_col, cur_col, cur_col * 1.1] col_idx = [0, 100, 165, 255] col_map = libtcod.color_gen_map(cols, col_idx) index = int(rain*255) if index > 165 and libtcod.heightmap_get_value(self.heightmap, x, y) > 0.15: self.tiles[x/2][y/2].biome = "forest" self.tiles[x/2][y/2].char = 'T' self.tiles[x/2][y/2].fg_color = grass * 0.7 libtcod.image_put_pixel(self.image, x, y, col_map[index]) self.owner.log.message("-- apply normal shadows", debug = True) for x in range(self.width*2): for y in range(self.height*2): normal = libtcod.heightmap_get_normal(self.heightmap, x, y, 0) nx = normal[0] ny = normal[1] avg = (nx + ny)/2 if avg > 0: avg = 1 else: avg = avg + 1 avg = min(avg/2 + 0.5, 1) col = libtcod.image_get_pixel(self.image, x, y) * avg libtcod.image_put_pixel(self.image, x, y, col) self.owner.log.message("Placing cities", debug=True) self.owner.entities = [] max_cities = 10 num_cities = 0 for i in range(max_cities): x = libtcod.random_get_int(0, 0, self.width - 1) y = libtcod.random_get_int(0, 0, self.height - 1) if self.tiles[x][y].terrain == "land": city = entity.City(self.owner, x, y, '#', libtcod.Color(libtcod.random_get_int(0, 0, 255), libtcod.random_get_int(0, 0, 255), libtcod.random_get_int(0, 0, 255))) self.owner.entities.append(city) num_cities += 1 self.owner.log.message("-- placed " + str(num_cities) + " cities") self.owner.log.message("Map generated", debug = True) self.generated = True
def __get_color_scale(first, last, size): return tcod.color_gen_map([first, last], [0, size])
def create_light_map(weather): weather['light_map'] = tcod.color_gen_map([tcod.Color(c['colors'][0], c['colors'][1], c['colors'][2]) for c in weather['colors']], weather['color_indexes'])