def load_layer_to_map(map, x1, y1, xp_file_layer, rotation='None'): global id from MapGen import Map if not xp_file_layer['width'] or not xp_file_layer['height']: raise AttributeError( 'Attempted to call load_layer_to_console on data that didn\'t have a width or height key, check your data' ) width = xp_file_layer['width'] - 2 height = xp_file_layer['height'] - 2 for x in range(1, width + 1): for y in range(1, height + 1): cell_data = xp_file_layer['cells'][x][y] # fore_color = libtcod.Color(cell_data['fore_r'], cell_data['fore_g'], cell_data['fore_b']) # back_color = libtcod.Color(cell_data['back_r'], cell_data['back_g'], cell_data['back_b']) # libtcod.console_put_char_ex(console, x, y, cell_data['keycode'], fore_color, back_color) char = cell_data['keycode'] # print char # map[x1 + x][y1 + y].char = cell_data['keycode'] # map[x1 + x][y1 + y].f_color = fore_color # map[x1 + x][y1 + y].b_color = back_color if rotation == '90': temp_y = x temp_x = -y temp_x += height + 1 elif rotation == '270': temp_y = -x temp_x = y temp_y += width + 1 elif rotation == '180': temp_y = -y temp_x = -x temp_y += height + 1 temp_x += width + 1 elif rotation == 'None': temp_y = y temp_x = x if char == 206: Map.create_wall(x1 + temp_x - 1, y1 + temp_y - 1) elif char == 83: Map.create_shroud(x1 + temp_x - 1, y1 + temp_y - 1) elif char == 71: Map.create_glass(x1 + temp_x - 1, y1 + temp_y - 1) else: if x == 2 and y == 2: Map.create_ground(x1 + temp_x - 1, y1 + temp_y - 1, id=id) else: Map.create_ground(x1 + temp_x - 1, y1 + temp_y - 1) id += 1 return map
def load_layer_to_map(map, x1, y1, xp_file_layer, rotation='None'): global id from MapGen import Map if not xp_file_layer['width'] or not xp_file_layer['height']: raise AttributeError( 'Attempted to call load_layer_to_console on data that didn\'t have a width or height key, check your data') width = xp_file_layer['width'] - 2 height = xp_file_layer['height'] - 2 for x in range(1, width + 1): for y in range(1, height + 1): cell_data = xp_file_layer['cells'][x][y] # fore_color = libtcod.Color(cell_data['fore_r'], cell_data['fore_g'], cell_data['fore_b']) # back_color = libtcod.Color(cell_data['back_r'], cell_data['back_g'], cell_data['back_b']) # libtcod.console_put_char_ex(console, x, y, cell_data['keycode'], fore_color, back_color) char = cell_data['keycode'] # print char # map[x1 + x][y1 + y].char = cell_data['keycode'] # map[x1 + x][y1 + y].f_color = fore_color # map[x1 + x][y1 + y].b_color = back_color if rotation == '90': temp_y = x temp_x = -y temp_x += height + 1 elif rotation == '270': temp_y = -x temp_x = y temp_y += width + 1 elif rotation == '180': temp_y = -y temp_x = -x temp_y += height + 1 temp_x += width + 1 elif rotation == 'None': temp_y = y temp_x = x if char == 206: Map.create_wall(x1 + temp_x - 1, y1 + temp_y - 1) elif char == 83: Map.create_shroud(x1 + temp_x - 1, y1 + temp_y - 1) elif char == 71: Map.create_glass(x1 + temp_x - 1, y1 + temp_y - 1) else: if x == 2 and y == 2: Map.create_ground(x1 + temp_x - 1, y1 + temp_y - 1, id=id) else: Map.create_ground(x1 + temp_x - 1, y1 + temp_y - 1) id += 1 return map
def objects(): # libtcod.console_clear(consoles['entity_console']) Utils.clear_layer(layers['entity_console']) for object in Map.get_all_objects(): if object != GameState.get_player(): object.draw() GameState.get_player().draw()
def render_stat_bars(): pos = Pos(Constants.MAP_CONSOLE_WIDTH + 4, 35) # SHOW PLAYER STAT BARS render_box_bar(pos.x, pos.y, 14, '', GameState.get_player().fighter.hp, GameState.get_player().fighter.base_max_hp, libtcod.Color(178, 0, 45), libtcod.Color(64, 0, 16), layers['side_panel_console']) render_box_bar(pos.x, pos.y + 1, 14, '', GameState.get_player().fighter.sp, GameState.get_player().fighter.base_max_sp, libtcod.Color(0, 30, 255), libtcod.Color(0, 10, 64), layers['side_panel_console']) render_box_bar(pos.x, pos.y + 2, 14, '', GameState.get_player().fighter.xp, 1000, # TODO: will be NEXT_LVL_XP libtcod.Color(255, 255, 0), libtcod.Color(65, 65, 0), layers['side_panel_console']) # RENDER MONSTER HEALTH BARS temp_y = 3 for object in Map.get_visible_objects(): if object.fighter and (object is not GameState.get_player()): # and Fov.is_visible(obj=object) if temp_y < 17: # TODO: Make constant to scale UI render_box_bar(Constants.MAP_CONSOLE_WIDTH + 1, temp_y, 17, object.name, object.fighter.hp, object.fighter.max_hp, libtcod.Color(0, 255, 0), libtcod.Color(0, 64, 0), layers['side_panel_console']) temp_y += 2
def draw_object(obj, visible=True): x, y = Map.to_camera_coordinates(obj.x, obj.y) if visible: draw_char(layers['entity_console'], x, y, obj.char, obj.color, libtcod.BKGND_NONE) # draw_background(layers['entity_console'], x, y, Themes.ground_bcolor() - get_offset_color(obj.x, obj.y), libtcod.BKGND_SET) else: draw_char(layers['entity_console'], x, y, obj.char, libtcod.darker_gray, libtcod.BKGND_NONE)
def initialize(): global fov_recompute, fov_map, player # unexplored areas start black (which is the default background color) # from Render import clear_map # clear_map() map = Map.current_map() player = GameState.get_player() require_recompute() fov_map = libtcod.map_new(Constants.MAP_WIDTH, Constants.MAP_HEIGHT) for y in range(Constants.MAP_HEIGHT): for x in range(Constants.MAP_WIDTH): fov_change(x, y, map[x][y].block_sight, map[x][y].blocked)
def recompute(): global fov_recompute if fov_recompute: fov_recompute = False Map.visible_objects = None for obj in Map.get_all_objects(): if obj.name != 'player': fov_change(obj.x, obj.y, obj.blocks_sight, obj.blocks) # print "COMPUTING FOV!!!" libtcod.map_compute_fov(fov_map, player.x, player.y, Constants.TORCH_RADIUS, Constants.FOV_LIGHT_WALLS, Constants.FOV_ALGO) # Render.clear_map() return True return False
def render_stat_bars(): pos = Pos(Constants.MAP_CONSOLE_WIDTH + 4, 35) # SHOW PLAYER STAT BARS render_box_bar(pos.x, pos.y, 14, '', GameState.get_player().fighter.hp, GameState.get_player().fighter.base_max_hp, libtcod.Color(178, 0, 45), libtcod.Color(64, 0, 16), layers['side_panel_console']) render_box_bar(pos.x, pos.y + 1, 14, '', GameState.get_player().fighter.sp, GameState.get_player().fighter.base_max_sp, libtcod.Color(0, 30, 255), libtcod.Color(0, 10, 64), layers['side_panel_console']) render_box_bar( pos.x, pos.y + 2, 14, '', GameState.get_player().fighter.xp, 1000, # TODO: will be NEXT_LVL_XP libtcod.Color(255, 255, 0), libtcod.Color(65, 65, 0), layers['side_panel_console']) # RENDER MONSTER HEALTH BARS temp_y = 3 for object in Map.get_visible_objects(): if object.fighter and (object is not GameState.get_player() ): # and Fov.is_visible(obj=object) if temp_y < 17: # TODO: Make constant to scale UI render_box_bar(Constants.MAP_CONSOLE_WIDTH + 1, temp_y, 17, object.name, object.fighter.hp, object.fighter.max_hp, libtcod.Color(0, 255, 0), libtcod.Color(0, 64, 0), layers['side_panel_console']) temp_y += 2
def full_map(): if Fov.recompute(): Utils.clear_layer(0) map = Map.current_map() player = GameState.get_player() Map.move_camera(player.x, player.y) camera_x, camera_y = Map.get_camera() # Map.d_map[player.x][player.y] = 0 for y in range(Constants.MAP_CONSOLE_HEIGHT): for x in range(Constants.MAP_CONSOLE_WIDTH): map_x, map_y = (camera_x + x, camera_y + y) tile = map[map_x][map_y] visible = Fov.is_visible(pos=(map_x, map_y)) # dist = Utils.distance_between(player.x, player.y, map_x, map_y) # Map.d_map[map_x][map_y] = int(dist) if Constants.DEBUG: if Map.is_blocked(map_x, map_y): draw_char(layers['map_console'], x, y, '*', tile.f_color, libtcod.BKGND_SET) #else: if True: dist = Map.current_map()[map_x][map_y].distance_to_player char = chr(min(dist + 48, 200)) # chr(min(Map.d_map[map_x][map_y] + 48, 200)) if dist == -1: char = ' ' c_value = max(dist, 0) # max(Map.d_map[map_x][map_y] , 0) # char = hm_values[min(c_value, len(hm_values) - 1)] db_color = hm_colors[min(c_value, len(hm_colors) - 1)] draw_char(layers['map_console'], x, y, char, db_color, libtcod.BKGND_SET) else: if not visible: if tile.explored: if tile.blocked: char = tile.char f_color = libtcod.Color(50, 50, 50) b_color = libtcod.Color(10, 10, 10) else: char = '.' f_color = libtcod.Color(50, 50, 50) b_color = libtcod.Color(0, 0, 0) draw_char(layers['map_console'], x, y, char, f_color, libtcod.BKGND_SET) draw_background(layers['map_console'], x, y, b_color, flag=libtcod.BKGND_SET) #libtcod.console_put_char_ex(consoles['map_console'], x, y, char, # Themes.OUT_OF_FOV_COLOR, libtcod.BKGND_SET) else: offset_color = get_offset_color(map_x, map_y) draw_char(layers['map_console'], x, y, tile.char, tile.f_color - offset_color, libtcod.BKGND_SET) draw_background(layers['map_console'], x, y, tile.b_color - offset_color, flag=libtcod.BKGND_SET) tile.explored = True
def blank(x, y): x, y = Map.to_camera_coordinates(x, y) # libtcod.console_put_char(consoles['entity_console'], x, y, ' ', libtcod.BKGND_NONE) draw_char(layers['entity_console'], x, y, ' ', None, libtcod.BKGND_NONE)
def object_clear(): for obj in Map.get_all_objects(): obj.clear()
def full_map(): if Fov.recompute(): Utils.clear_layer(0) map = Map.current_map() player = GameState.get_player() Map.move_camera(player.x, player.y) camera_x, camera_y = Map.get_camera() # Map.d_map[player.x][player.y] = 0 for y in range(Constants.MAP_CONSOLE_HEIGHT): for x in range(Constants.MAP_CONSOLE_WIDTH): map_x, map_y = (camera_x + x, camera_y + y) tile = map[map_x][map_y] visible = Fov.is_visible(pos=(map_x, map_y)) # dist = Utils.distance_between(player.x, player.y, map_x, map_y) # Map.d_map[map_x][map_y] = int(dist) if Constants.DEBUG: if Map.is_blocked(map_x, map_y): draw_char(layers['map_console'], x, y, '*', tile.f_color, libtcod.BKGND_SET) #else: if True: dist = Map.current_map( )[map_x][map_y].distance_to_player char = chr( min(dist + 48, 200) ) # chr(min(Map.d_map[map_x][map_y] + 48, 200)) if dist == -1: char = ' ' c_value = max(dist, 0) # max(Map.d_map[map_x][map_y] , 0) # char = hm_values[min(c_value, len(hm_values) - 1)] db_color = hm_colors[min(c_value, len(hm_colors) - 1)] draw_char(layers['map_console'], x, y, char, db_color, libtcod.BKGND_SET) else: if not visible: if tile.explored: if tile.blocked: char = tile.char f_color = libtcod.Color(50, 50, 50) b_color = libtcod.Color(10, 10, 10) else: char = '.' f_color = libtcod.Color(50, 50, 50) b_color = libtcod.Color(0, 0, 0) draw_char(layers['map_console'], x, y, char, f_color, libtcod.BKGND_SET) draw_background(layers['map_console'], x, y, b_color, flag=libtcod.BKGND_SET) #libtcod.console_put_char_ex(consoles['map_console'], x, y, char, # Themes.OUT_OF_FOV_COLOR, libtcod.BKGND_SET) else: offset_color = get_offset_color(map_x, map_y) draw_char(layers['map_console'], x, y, tile.char, tile.f_color - offset_color, libtcod.BKGND_SET) draw_background(layers['map_console'], x, y, tile.b_color - offset_color, flag=libtcod.BKGND_SET) tile.explored = True