def draw(self, area): if lt.map_is_in_fov(area.fov_map, self.col, self.row): lt.console_set_char_foreground(area.con, self.row, self.col, self.f_color) light = area.area[self.col][self.row].b_color if light.r > 175 and light.g > 175 and light.b > 130: lt.console_set_char_foreground(area.con, self.row, self.col, lt.black) lt.console_set_char(area.con, self.row, self.col, self.char)
def move(self, new): libtcod.console_set_char_foreground(0, self.x + self.cursor_pos, self.y, WHITE) libtcod.console_set_char_background(0, self.x + self.cursor_pos, self.y, BLACK) self.flush = True self.putCursor(new)
def refresh_gui_background(self, gui): libtcod.console_clear(gui) for x in xrange(self.SCREEN_WIDTH): for y in xrange(self.SCREEN_HEIGHT): libtcod.console_set_char_background( gui, x, y, libtcod.Color(100, 100, 100)) if self.paused == True: pause_text = "***PAUSED***" for x in xrange(12): libtcod.console_set_char_background( gui, self.CAMERA_WIDTH - 15 + x, 0, libtcod.Color(100, 100, 200)) libtcod.console_put_char(gui, self.CAMERA_WIDTH - 15 + x, 0, pause_text[x], libtcod.BKGND_NONE) libtcod.console_set_char_foreground( gui, self.CAMERA_WIDTH - 15 + x, 0, libtcod.Color(255, 255, 255)) if self.loading > -1: loading_text = "***LOADING***" for x in xrange(13): libtcod.console_set_char_background( gui, 15 + x, 0, libtcod.Color(100, 100, 200)) libtcod.console_put_char(gui, 15 + x, 0, loading_text[x], libtcod.BKGND_NONE) libtcod.console_set_char_foreground( gui, 15 + x, 0, libtcod.Color(255, 255, 255))
def put_text_special_colors(con, txt, offset): # make dictionaries string_colors = { "B": 'blue', "R": 'red', "G": 'gray', "N": 'green', "Y": 'yellow', } color_strings = {} for k, v in string_colors.items(): color_strings.update({v: k}) # get a string of color data colorString = txt.lower() for replace, col in colors.colored_strings: colChar = color_strings[col] colorString = colorString.replace(replace, colChar * len(replace)) # iterate through that string, changing color on con yy = 0 xx = -1 for ch in colorString: xx += 1 if ch == '\n': xx = -1 yy += 1 continue col = string_colors.get(ch, None) if col: libtcod.console_set_char_foreground(con, offset + xx, offset + yy, COL[col])
def draw(self, con, x_origin=0, y_origin=0): super(WeaponComponent, self).draw(con, x_origin, y_origin) for y in range(1, 5): libtcod.console_put_char(con, x_origin, -y + y_origin, self.projectile) libtcod.console_set_char_foreground(con, x_origin, -y + y_origin, self.projectile_color)
def do_main_menu(key, mouse): title_panel_h = 28 title_panel = tcod.console_new(g.screen_width, title_panel_h) tcod.console_set_alignment(title_panel, tcod.LEFT) tcod.console_set_default_foreground(title_panel, tcod.blue) for x in range(0, len(g.TITLE_GRAPHIC_TOP)): tcod.console_print_ex(title_panel, 1, x + 1, tcod.BKGND_SET, tcod.LEFT, g.TITLE_GRAPHIC_TOP[x][0]) for x in range(0, len(g.TITLE_GRAPHIC_BOTTOM)): tcod.console_print_ex(title_panel, 1, x + 4 + len(g.TITLE_GRAPHIC_TOP), tcod.BKGND_SET, tcod.LEFT, g.TITLE_GRAPHIC_BOTTOM[x][0]) selection_panel = tcod.console_new(g.screen_width, g.screen_height - title_panel_h) tcod.console_set_alignment(selection_panel, tcod.LEFT) tcod.console_set_default_foreground(selection_panel, tcod.sea) title_colors = [ tcod.azure, tcod.cyan, tcod.dark_purple, tcod.dark_violet, tcod.fuchsia, tcod.light_gray, tcod.purple, tcod.sea, tcod.turquoise, ] g.lexicon_counter = 0 questions_options = { '': [ ('start', 'Start'), ('exit', 'Exit game') ] } waiting_for_response = True while waiting_for_response: for y in range(1, 1 + len(g.TITLE_GRAPHIC_TOP)): color_index = random.randint(0, len(title_colors) - 1) for x in range(0, g.screen_width): tcod.console_set_char_foreground(title_panel, x, y, title_colors[color_index]) tcod.console_blit(title_panel, 0, 0, g.screen_width, title_panel_h, 0, 0, 0) tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS, key, mouse) selection = handle_questions(selection_panel, key, mouse, questions_options, 24) if len(selection) > 0: if selection[0] == 'start': g.context = Context.TEAM_CREATION waiting_for_response = False elif selection[0] == 'exit': g.context = Context.EXIT waiting_for_response = False tcod.console_clear(title_panel) tcod.console_blit(title_panel, 0, 0, g.screen_width, title_panel_h, 0, 0, 0) tcod.console_clear(selection_panel) tcod.console_blit(selection_panel, 0, 0, g.screen_width, title_panel_h, 0, 0, 0) tcod.console_flush()
def draw(self, main_map): #Settings libtcod.console_set_default_background(self.console, libtcod.black) libtcod.console_set_alignment(self.console, libtcod.CENTER) if main_map.selected_unit: start = (self.width - 4)/2 #Draw all units in the unit image for x in range(self.width - 4): for y in range(self.width - 4): libtcod.image_put_pixel(self.unit_image, x, y, main_map.map_list[main_map.selected_unit.x + x - start][main_map.selected_unit.y + y - start].color) for u in main_map.units: if u.x == (main_map.selected_unit.x + x - start) and u.y == (main_map.selected_unit.y + y - start): libtcod.console_set_char_foreground(self.console, x + 2, y + 4, u.color) libtcod.console_set_char(self.console, x + 2, y + 4, u.char) libtcod.console_print_frame(self.console, 0, 0, self.width, self.height, False, libtcod.BKGND_NONE, main_map.selected_unit.name) libtcod.console_rect(self.console, 0,0, 20, 1, False) libtcod.image_blit_rect(self.unit_image, self.console, 2, 4, self.width - 4, self.width - 4, libtcod.BKGND_SET) libtcod.console_set_alignment(self.console, libtcod.LEFT) #Unit stats statx = self.width + 1 libtcod.console_print(self.console, 2, statx, 'Speed') libtcod.console_print(self.console, 2, statx + 1, 'Attack') libtcod.console_print(self.console, 2, statx + 2, 'Armor') libtcod.console_set_alignment(self.console, libtcod.RIGHT) libtcod.console_print(self.console, self.width - 2, statx, str(main_map.selected_unit.speed)) libtcod.console_print(self.console, self.width - 2, statx + 1, str(main_map.selected_unit.attack)) libtcod.console_print(self.console, self.width - 2, statx + 2, str(main_map.selected_unit.armor)) libtcod.console_blit(self.console, 0, 0, self.width, self.height, 0, 1, 60 - self.height/2, 1, 0.75)
def refresh_gui_background(self, console): libtcod.console_clear(console) self.background_color = DARK_GRAY for x in range(self.screen_width): for y in range(self.screen_height): libtcod.console_set_char_background(console, x, y, self.background_color) if self.paused == True: for x in range(12): libtcod.console_set_char_background(console, self.camera.width - 15 + x, 0, DARK_GRAY) libtcod.console_put_char(console, self.camera.width - 15 + x, 0, self.PAUSED_TEXT[x], libtcod.BKGND_NONE) libtcod.console_set_char_foreground(console, self.camera.width - 15 + x, 0, WHITE) if self.loading == True: for x in xrange(13): libtcod.console_set_char_background(console, 15 + x, 0, DARK_TEAL) libtcod.console_put_char(console, 15 + x, 0, self.LOADING_TEXT[x], libtcod.BKGND_NONE) libtcod.console_set_char_foreground(console, 15 + x, 0, WHITE)
def render_all(self): libtcod.console_clear(self.con) for y in range(self.CAMERA_HEIGHT): for x in range(self.CAMERA_WIDTH): #First, get the absolute map coordinates of whatever's in view (map_x, map_y) = (self.camera.x + x - self.CAMERA_WIDTH/2, self.camera.y + y - self.CAMERA_HEIGHT/2) #Then, get which chunk it's on, and where on that chunk it is chunk_count_x, chunk_count_y, local_x, local_y = self.to_chunk_and_local_coords(map_x, map_y) #Now, render the appropriate char based on the coords libtcod.console_put_char(self.con, x, y, self.map.map[chunk_count_x][chunk_count_y].chunk[local_x][local_y].char, libtcod.BKGND_NONE) libtcod.console_set_char_foreground(self.con, x, y, self.map.map[chunk_count_x][chunk_count_y].chunk[local_x][local_y].color) #Draw all objects in range of the player to be active self.active_objects = self.get_active_objects() for object in self.active_objects: self.draw_object(object) if self.cursor!= None: self.draw_object(self.cursor) #blit the contents of "con" to the root console libtcod.console_blit(self.con, 0, 0, self.SCREEN_WIDTH, self.SCREEN_HEIGHT, 0, 0, 0) #blit the infobar to the root console self.refresh_infobar(self.infobar) libtcod.console_blit(self.infobar, 0, 0, self.SCREEN_WIDTH, self.SCREEN_HEIGHT, 0, 0, self.SCREEN_HEIGHT - 1) #if we're showing the right-side menu, show it if self.show_menu == True: self.refresh_menu(self.menu) libtcod.console_blit(self.menu, 0, 0, self.SCREEN_WIDTH, self.SCREEN_HEIGHT, 0, self.SCREEN_WIDTH - self.MENU_WIDTH, 0)
def refresh_main_view(self, main_view): libtcod.console_clear(main_view) for y in xrange(self.CAMERA_HEIGHT): for x in xrange(self.CAMERA_WIDTH): #First, get the absolute map coordinates of whatever's in view (map_x, map_y) = (self.camera.x + x - self.CAMERA_WIDTH / 2, self.camera.y + y - self.CAMERA_HEIGHT / 2) #Then, get which chunk it's on, and where on that chunk it is chunk_count_x, chunk_count_y, local_x, local_y = self.to_chunk_and_local_coords( map_x, map_y) #Convert chunk coords to chunk coords relative to the player, offset southeast by 1 (because player is always at 1, 1 in active_chunks) #(and what we really want is the index of the chunk in active_chunks) active_x, active_y = self.abst_actv_chunk_coords( chunk_count_x, chunk_count_y) #Now, render the appropriate char based on the coords libtcod.console_put_char( main_view, x, y, self.active_chunks.map[active_x] [active_y].chunk[local_x][local_y].char, libtcod.BKGND_NONE) libtcod.console_set_char_foreground( main_view, x, y, self.active_chunks.map[active_x] [active_y].chunk[local_x][local_y].color) self.active_objects = self.get_active_objects() for object in self.active_objects: self.draw_object(object, main_view) if self.cursor != None: self.draw_object(self.cursor, main_view)
def _draw_what_player_sees(self, pc): world=rog.world() seer=world.component_for_entity(pc, cmp.SenseSight) rang=seer.sight pos=world.component_for_entity(pc, cmp.Position) rend=world.component_for_entity(ent, cmp.Draw) for x in range( max(0, pc.x-rang), min(self.w, pc.x+rang+1) ): for y in range( max(0, pc.y-rang), min(self.h, pc.y+rang+1) ): canSee=False if not rog.in_range(pos.x,pos.y, x,y, rang): continue if not libtcod.map_is_in_fov(seer.fov_map, x,y): continue ent=self.thingat(x, y) if (self.get_light_value(x,y) == 0 and not rog.on(pc,NVISION) ): self._draw_silhouettes(pc, x,y, ent) continue if ent: libtcod.console_put_char( self.con_map_state, x,y, rend.char) libtcod.console_set_char_foreground( self.con_map_state, x,y, rend.color) self._apply_rendered_bgcol(x,y, ent) else: libtcod.console_put_char_ex(self.con_map_state, x,y, self.get_char(x, y), self.get_color(x, y), self.get_bgcolor(x, y))
def printMsg(self, y, msg): for k, c in enumerate(msg): if k >= self.w: break x = 1 + self.x + k _y = self.y + y libtcod.console_put_char(self.console, x, _y, c) libtcod.console_set_char_foreground(self.console, x, _y, self.colText)
def draw(self): if (libtcod.map_is_in_fov(fov_map, self.x, self.y) or (self.always_visible and map[self.x, self.y].explored)): # Set the color and draw the character libtcod.console_put_char(con, self.x, self.y, self.char, libtcod.BKGND_NONE) libtcod.console_set_char_foreground(con, self.x, self.y, self.color)
def print_employee(self, console, employeeType, x, y): color = TilePainter.employeeToColor[employeeType] symbol = TilePainter.EMPLOYEE_SYMBOL libtcod.console_set_char_foreground(console, x, y, color) libtcod.console_set_char(console,x,y,symbol)
def drawCar(car, visibleOffsetX, visibleOffsetY, backgroundColor): visible, screenX, screenY = getScreenCoordinates(car.X, car.Y, visibleOffsetX, visibleOffsetY) if (visible == False): # cannot see me :) return libtcod.console_put_char(0, screenX, screenY, car.DisplayChar, libtcod.BKGND_NONE) libtcod.console_set_char_foreground(0, screenX, screenY, car.DisplayColor) libtcod.console_set_char_background(0, screenX, screenY, backgroundColor, libtcod.BKGND_SET)
def draw(self): for tile in self.currentMap.get_map_list(): tile.draw() libtcod.console_set_char_foreground(0, tile.x, tile.y, libtcod.Color(255, 0, 0)) for tile in self.get_tiles_in_fov(): self.currentMap.get_tile(tile.x, tile.y).explored = True libtcod.console_set_char_foreground(0, tile.x, tile.y, libtcod.Color(255, 255, 255))
def draw_all_tiles(): for tile in TILES: tcod.console_set_char_foreground(ITEM_WINDOW, TILES.keys().index(tile), 0, TILES[tile]['color'][0]) tcod.console_set_char_background(ITEM_WINDOW, TILES.keys().index(tile), 0, TILES[tile]['color'][1]) tcod.console_set_char(ITEM_WINDOW, TILES.keys().index(tile), 0, TILES[tile]['icon'])
def draw(self, con, x_origin = 0, y_origin = 0): super(BodyComponent, self).draw(con, x_origin, y_origin) if self.engine_single: for y in range(7): libtcod.console_put_char(con, x_origin, len(self.shape) + y + y_origin, 179) libtcod.console_set_char_foreground(con, x_origin, len(self.shape) + y + y_origin, libtcod.red * (1.0 / (y+1))) elif self.engine_double: for y in range(7): libtcod.console_put_char(con, x_origin, len(self.shape) + y + y_origin, 186) libtcod.console_set_char_foreground(con, x_origin, len(self.shape) + y + y_origin, libtcod.red * (1.0 / (y+1)))
def _draw_unseen(player, screen_x, screen_y, pos, terrain, icon): global _con current_map = player.current_map sc = terrain.unseen_color if not sc: sc = map.region_colors_unseen[current_map.region_terrain[current_map.region[pos.x][pos.y]]] libtcod.console_set_char_background(_con, screen_x, screen_y, sc, libtcod.BKGND_SET) # _debug_region(current_map, screen_x, screen_y, pos) if icon: libtcod.console_set_char_foreground(_con, screen_x, screen_y, terrain.icon_color) libtcod.console_set_char(_con, screen_x, screen_y, icon)
def refresh_gui_background(self, gui): libtcod.console_clear(gui) for x in xrange(self.SCREEN_WIDTH): for y in xrange(self.SCREEN_HEIGHT): libtcod.console_set_char_background(gui, x, y, libtcod.Color(100, 100, 100)) if self.paused == True: pause_text = "***PAUSED***" for x in xrange(12): libtcod.console_set_char_background(gui, self.CAMERA_WIDTH-15+x, 0, libtcod.Color(100, 100, 200)) libtcod.console_put_char(gui, self.CAMERA_WIDTH-15+x, 0, pause_text[x], libtcod.BKGND_NONE) libtcod.console_set_char_foreground(gui, self.CAMERA_WIDTH-15+x, 0, libtcod.Color(255, 255, 255))
def draw(self, con, x_origin = 0, y_origin = 0): super(WingComponent, self).draw(con, x_origin, y_origin) for engine in self.engines_single: for y in range(5): libtcod.console_put_char(con, engine + x_origin, len(self.shape) + y + y_origin, 179) libtcod.console_set_char_foreground(con, engine + x_origin, len(self.shape) + y + y_origin, libtcod.red * (1.0 / (y+1))) for engine in self.engines_double: for y in range(5): libtcod.console_put_char(con, engine + x_origin, len(self.shape) + y + y_origin, 186) libtcod.console_set_char_foreground(con, engine + x_origin, len(self.shape) + y + y_origin, libtcod.red * (1.0 / (y+1))) for weapon in self.weapons: weapon[0].draw(con, x_origin + weapon[1], y_origin + weapon[2])
def draw(self, in_sight, area): if in_sight: lt.console_set_char_foreground(area.con, self.row, self.col, self.f_color) lt.console_set_char_background(area.con, self.row, self.col, self.b_color) lt.console_set_char(area.con, self.row, self.col, self.char) self.explored = True elif self.explored: f_color = lt.color_lerp(area.fog, self.f_color, area.fog_density) b_color = lt.color_lerp(area.fog, self.b_color, area.fog_density) lt.console_set_char_background(area.con, self.row, self.col, b_color) lt.console_set_default_foreground(area.con, f_color) lt.console_put_char(area.con, self.row, self.col, self.char) else: lt.console_set_char_background(area.con, self.row, self.col, area.fog)
def _draw_unseen(player, screen_x, screen_y, pos, terrain, icon): global _con current_map = player.current_map sc = terrain.unseen_color if not sc: sc = map.region_colors_unseen[current_map.region_terrain[ current_map.region[pos.x][pos.y]]] libtcod.console_set_char_background(_con, screen_x, screen_y, sc, libtcod.BKGND_SET) # _debug_region(current_map, screen_x, screen_y, pos) if icon: libtcod.console_set_char_foreground(_con, screen_x, screen_y, terrain.icon_color) libtcod.console_set_char(_con, screen_x, screen_y, icon)
def renderFrame(self): for i in range(self.w + 1): x = self.x + i y1 = self.y y2 = self.y + self.h - 1 libtcod.console_put_char(self.console, x, y1, self.ch) libtcod.console_put_char(self.console, x, y2, self.ch) libtcod.console_set_char_foreground(self.console, x, y1, self.colFrame) libtcod.console_set_char_foreground(self.console, x, y2, self.colFrame) # we've already drawn the corners for j in range(1, self.h): y = self.y + j x1 = self.x x2 = self.x + self.w libtcod.console_put_char(self.console, x1, y, self.ch) libtcod.console_put_char(self.console, x2, y, self.ch) libtcod.console_set_char_foreground(self.console, x1, y, self.colFrame) libtcod.console_set_char_foreground(self.console, x2, y, self.colFrame)
def print_vehicles(con, race, player_y, distance_traveled_by_player): for n in range(0, len(race.teams)): # All vehicles are displayed vertically relative to player new_y = player_y + (int(distance_traveled_by_player) - int(race.teams[n].vehicle.distance_traveled)) race.teams[n].vehicle.y = new_y for row in range(0, len(race.teams[n].vehicle.body.rows)): for col in range(0, len(race.teams[n].vehicle.body.rows[row])): x = race.teams[n].vehicle.x + col y = race.teams[n].vehicle.y + row tcod.console_put_char( con, x, int(y), race.teams[n].vehicle.body.rows[row][col], tcod.BKGND_NONE) tcod.console_set_char_foreground(con, x, int(y), race.teams[n].vehicle.color)
def initialize_fov(): global fov_recompute, fov_map fov_recompute = True #Create the FOV map, according to the generated map fov_map = libtcod.map_new(MAP_WIDTH, MAP_HEIGHT) for y in range(MAP_HEIGHT): for x in range(MAP_WIDTH): libtcod.map_set_properties(fov_map, x, y, not map[x][y].block_sight, not map[x][y].blocked) libtcod.console_clear(con) #Unexplored areas start as black for y in range(MAP_HEIGHT): for x in range(MAP_WIDTH): libtcod.console_set_char_background(con, x, y, libtcod.black) libtcod.console_set_char_foreground(con, x, y, libtcod.darker_grey) libtcod.console_set_char(con, x, y, map[x][y].char)
def render_wall(con, x, y, color): # TODO: Think of a better way to do this # TODO: Improve outside walls if y + 1 >= consts.MAP_HEIGHT: north = False else: north = Map_Tiles[x][y + 1].blocked if y - 1 < 0: south = False else: south = Map_Tiles[x][y - 1].blocked if x + 1 >= consts.MAP_WIDTH: west = False else: west = Map_Tiles[x + 1][y].blocked if x - 1 < 0: east = False else: east = Map_Tiles[x - 1][y].blocked if north and south and east and west: wall_char = libtcod.CHAR_DCROSS elif north and not south and east and west: wall_char = libtcod.CHAR_DTEES elif not north and south and east and west: wall_char = libtcod.CHAR_DTEEN elif north and south and east and not west: wall_char = libtcod.CHAR_DTEEW elif north and south and not east and west: wall_char = libtcod.CHAR_DTEEE elif north and not south and east and not west: wall_char = libtcod.CHAR_DNE elif north and not south and not east and west: wall_char = libtcod.CHAR_DNW elif not north and south and east and not west: wall_char = libtcod.CHAR_DSE elif not north and south and not east and west: wall_char = libtcod.CHAR_DSW elif north and south: wall_char = libtcod.CHAR_DVLINE elif east and west: wall_char = libtcod.CHAR_DHLINE else: wall_char = libtcod.CHAR_DCROSS libtcod.console_set_char_foreground(con, x, y, color) libtcod.console_set_char(con, x, y, wall_char)
def draw(self, con, x_origin=0, y_origin=0): super(BodyComponent, self).draw(con, x_origin, y_origin) if self.engine_single: for y in range(7): libtcod.console_put_char(con, x_origin, len(self.shape) + y + y_origin, 179) libtcod.console_set_char_foreground( con, x_origin, len(self.shape) + y + y_origin, libtcod.red * (1.0 / (y + 1))) elif self.engine_double: for y in range(7): libtcod.console_put_char(con, x_origin, len(self.shape) + y + y_origin, 186) libtcod.console_set_char_foreground( con, x_origin, len(self.shape) + y + y_origin, libtcod.red * (1.0 / (y + 1)))
def draw(self, con, x_origin=0, y_origin=0): super(WingComponent, self).draw(con, x_origin, y_origin) for engine in self.engines_single: for y in range(5): libtcod.console_put_char(con, engine + x_origin, len(self.shape) + y + y_origin, 179) libtcod.console_set_char_foreground( con, engine + x_origin, len(self.shape) + y + y_origin, libtcod.red * (1.0 / (y + 1))) for engine in self.engines_double: for y in range(5): libtcod.console_put_char(con, engine + x_origin, len(self.shape) + y + y_origin, 186) libtcod.console_set_char_foreground( con, engine + x_origin, len(self.shape) + y + y_origin, libtcod.red * (1.0 / (y + 1))) for weapon in self.weapons: weapon[0].draw(con, x_origin + weapon[1], y_origin + weapon[2])
def refresh_main_view(self, main_view): libtcod.console_clear(main_view) self.camera.refresh_position() for y in xrange(self.CAMERA_HEIGHT): for x in xrange(self.CAMERA_WIDTH): (map_x, map_y) = (self.camera.x+x-self.CAMERA_WIDTH/2, self.camera.y+y-self.CAMERA_HEIGHT/2) if 0 <= map_x < len(self.level.map) and 0 <= map_y < len(self.level.map): libtcod.console_put_char(main_view, x, y, self.level.map[map_x][map_y].char, libtcod.BKGND_NONE) libtcod.console_set_char_foreground(main_view, x, y, self.level.map[map_x][map_y].color) elif len(self.level.map)*-1 < map_x < 0 and 0 <= map_y < len(self.level.map): libtcod.console_put_char(main_view, x, y, self.level.map[map_x*-1][map_y].char, libtcod.BKGND_NONE) libtcod.console_set_char_foreground(main_view, x, y, self.level.map[map_x*-1][map_y].color) else: libtcod.console_put_char(main_view, x, y, " ", libtcod.BKGND_NONE) for actor in self.level.actors: self.draw_actor(actor, main_view) if self.cursor!= None: self.draw_actor(self.cursor, main_view)
def render(): for y in range(R.SCREEN_HEIGHT): for x in range(R.SCREEN_WIDTH): # r = int(libtcod.heightmap_get_value(map_.hm, x, y)) # g = int(libtcod.heightmap_get_value(map_.hm, x, y)) if x < R.MAP_WIDTH and y < R.MAP_HEIGHT: b = int(map_.tiles[x][y].humidity) colour = libtcod.Color(0, 0, int(b)) libtcod.console_set_char_background(con, x, y, colour) if len(map_.wind_gen.map[x][y]) > 0: libtcod.console_set_char(con, x, y, ".") libtcod.console_set_char_foreground( con, x, y, libtcod.white) else: libtcod.console_set_char_foreground( con, x, y, libtcod.black) libtcod.console_set_char(con, x, y, " ") if x >= R.MAP_WIDTH and y < R.MAP_HEIGHT: ax = x - R.MAP_WIDTH ay = y b = int(map_.tiles[ax][y].elevation) c = b if map_.tiles[ax][ay].type != "water": c = 10 colour = libtcod.Color(int(b), int(c), int(b)) libtcod.console_set_char_background(con, x, y, colour) if x >= R.MAP_WIDTH and y >= R.MAP_HEIGHT: ax = x - R.MAP_WIDTH ay = y - R.MAP_HEIGHT b = int(map_.tiles[ax][ay].temperature) colour = libtcod.Color(int(b), int(b), int(b)) libtcod.console_set_char_background(con, x, y, colour) libtcod.console_blit(con, 0, 0, R.SCREEN_WIDTH, R.SCREEN_HEIGHT, 0, 0, 0) libtcod.console_flush()
def handle_mouse(): mouse = libtcod.mouse_get_status() (x, y) = (mouse.cx, mouse.cy) if x > R.MAP_WIDTH - 1: x = R.MAP_WIDTH - 1 if y > R.MAP_HEIGHT - 1: y = R.MAP_HEIGHT - 1 if x < 0: x = 0 if y < 0: y = 0 if x < R.MAP_WIDTH and y < R.MAP_HEIGHT: libtcod.console_set_char_foreground(con, x, y, libtcod.orange) libtcod.console_set_char(con, x, y, "#") ax = x + R.MAP_WIDTH ay = y libtcod.console_set_char_foreground(con, ax, ay, libtcod.orange) libtcod.console_set_char(con, ax, ay, "#") ax = x + R.MAP_WIDTH ay = y + R.MAP_HEIGHT libtcod.console_set_char_foreground(con, ax, ay, libtcod.orange) libtcod.console_set_char(con, ax, ay, "#")
def draw_tile(tile,pos,color): _x = pos[0]-var.camera[0] _y = pos[1]-var.camera[1] if var.output=='libtcod':# and var.player.level.outside: #print var.player.level.tmap if var.player.level.tmap[pos[0]][pos[1]]: libtcod.console_set_char_background(var.tree,_x,_y,libtcod.Color(var.player.level.tmap[pos[0]][pos[1]],0,0), flag=libtcod.BKGND_SET) if var.player.level.outside: if tile.has_key('id'): _icon = False if var.buffer[_x][_y] == tile['id'] and var.player.level.outside: return else: var.buffer[_x][_y] = tile['id'] elif tile.has_key('icon'): _icon = True if tile.has_key('limbs') and var.output=='libtcod': for __x in xrange(-6,7): for __y in xrange(-6,7): if tile['limbs'][__x][__y]: libtcod.console_set_char_background(var.tree, _x+__x, _y+__y, libtcod.Color(50,50,50), flag=libtcod.BKGND_SET) libtcod.console_set_char_foreground(var.tree, _x+__x, _y+__y, libtcod.Color(50,50,50)) libtcod.console_set_char(var.tree, _x+__x, _y+__y, '#') if var.buffer[_x][_y] == tile['icon'] and var.player.level.outside: return else: var.buffer[_x][_y] = tile['icon'] var.dirty.append((_x,_y)) if isinstance(tile['icon'],unicode): tile['icon'] = str(tile['icon']) if var.output=='pygame': var.view.putchar(tile['icon'],x=_x,y=_y,fgcolor=color[0],bgcolor=color[1]) else: _color = (var.color_codes[color[0]],var.color_codes[color[1]]) if not var.player.level.outside: libtcod.console_set_char_background(var.view, _x, _y, libtcod.Color(_color[1][0],_color[1][1],_color[1][2]), flag=libtcod.BKGND_SET) libtcod.console_set_char_foreground(var.view, _x, _y, libtcod.Color(_color[0][0],_color[0][1],_color[0][2])) libtcod.console_set_char(var.view, _x, _y, tile['icon'])
def refresh_main_view(self, main_view): libtcod.console_clear(main_view) for y in xrange(self.CAMERA_HEIGHT): for x in xrange(self.CAMERA_WIDTH): #First, get the absolute map coordinates of whatever's in view (map_x, map_y) = (self.camera.x+x-self.CAMERA_WIDTH/2, self.camera.y+y-self.CAMERA_HEIGHT/2) #Then, get which chunk it's on, and where on that chunk it is chunk_count_x, chunk_count_y, local_x, local_y = self.to_chunk_and_local_coords(map_x, map_y) #Convert chunk coords to chunk coords relative to the player, offset southeast by 1 (because player is always at 1, 1 in active_chunks) #(and what we really want is the index of the chunk in active_chunks) active_x, active_y = self.abst_actv_chunk_coords(chunk_count_x, chunk_count_y) #Now, render the appropriate char based on the coords libtcod.console_put_char(main_view, x, y, self.active_chunks.map[active_x][active_y].chunk[local_x][local_y].char, libtcod.BKGND_NONE) libtcod.console_set_char_foreground(main_view, x, y, self.active_chunks.map[active_x][active_y].chunk[local_x][local_y].color) self.active_objects = self.get_active_objects() for object in self.active_objects: self.draw_object(object, main_view) if self.cursor!= None: self.draw_object(self.cursor, main_view)
def render(): for y in range(R.SCREEN_HEIGHT): for x in range(R.SCREEN_WIDTH): # r = int(libtcod.heightmap_get_value(map_.hm, x, y)) # g = int(libtcod.heightmap_get_value(map_.hm, x, y)) if x < R.MAP_WIDTH and y < R.MAP_HEIGHT: b = int(map_.tiles[x][y].humidity) colour = libtcod.Color(0,0,int(b)) libtcod.console_set_char_background(con, x, y, colour) if len(map_.wind_gen.map[x][y]) > 0: libtcod.console_set_char(con,x,y,".") libtcod.console_set_char_foreground(con, x, y, libtcod.white) else: libtcod.console_set_char_foreground(con, x, y, libtcod.black) libtcod.console_set_char(con, x, y, " ") if x >= R.MAP_WIDTH and y < R.MAP_HEIGHT: ax = x - R.MAP_WIDTH ay = y b = int(map_.tiles[ax][y].elevation) c = b if map_.tiles[ax][ay].type != "water": c = 10 colour = libtcod.Color(int(b),int(c),int(b)) libtcod.console_set_char_background(con, x, y, colour) if x >= R.MAP_WIDTH and y >= R.MAP_HEIGHT: ax = x - R.MAP_WIDTH ay = y - R.MAP_HEIGHT b = int(map_.tiles[ax][ay].temperature) colour = libtcod.Color(int(b),int(b),int(b)) libtcod.console_set_char_background(con, x, y, colour) libtcod.console_blit(con, 0, 0, R.SCREEN_WIDTH, R.SCREEN_HEIGHT, 0, 0, 0) libtcod.console_flush()
def ui_layer(self): if self.move_range: for tile in self.game.get_reachable_list(): libtcod.console_set_char_background(self.parent().console, tile[0] + 1, tile[1] + 1, Color.GREEN) if self.game.targeting: for unit in self.game.get_target_list(): libtcod.console_set_char_background(self.parent().console, unit.get_pos()[0] + 1, unit.get_pos()[1] + 1, Color.RED) if self.game.selected_action > 0 and self.game.target: libtcod.console_set_char_background( self.parent().console, self.game.target.get_pos()[0] + 1, self.game.target.get_pos()[1] + 1, Color.LRED) libtcod.console_set_char_foreground( self.parent().console, self.game.target.get_pos()[0] + 1, self.game.target.get_pos()[1] + 1, Color.LCYAN) if self.selected: if self.game.selected_tile: libtcod.console_set_char_background( self.parent().console, self.game.get_select_tile()[0] + 1, self.game.get_select_tile()[1] + 1, Color.YELLOW) if self.game.selected_unit: libtcod.console_set_char_background( self.parent().console, self.game.selected_unit.get_pos()[0] + 1, self.game.selected_unit.get_pos()[1] + 1, Color.LCYAN)
def input(typ, con, posx, posy, min=0, max=100): command = '' x = 0 done = False key = libtcod.Key() while done is False: libtcod.sys_wait_for_event(libtcod.EVENT_KEY_PRESS, key, libtcod.Mouse(), True) if key.vk == libtcod.KEY_BACKSPACE and x > 0: libtcod.console_set_char(con, x + posx - 1, posy, chr(95)) libtcod.console_set_char_foreground(con, x + posx - 1, posy, libtcod.white) libtcod.console_set_char(con, x + posx, posy, ' ') command = command[:-1] x -= 1 elif key.vk == libtcod.KEY_ENTER: if not len(command) in range(min, max): libtcod.console_set_default_foreground(0, libtcod.dark_red) libtcod.console_print(con, 2, posy + 2, 'Player name must be between ' + str(min) + ' to ' + str(max - 1) + ' characters!') elif typ == 'chargen': if command.lower() in game.savefiles: libtcod.console_set_default_foreground(0, libtcod.dark_red) libtcod.console_rect(con, 2, posy + 2, 50, 1, True) libtcod.console_print(con, 2, posy + 2, 'That name already exist!') else: done = True else: done = True elif key.c in range(32, 127) and len(command) < 20: libtcod.console_set_char(con, x + posx, posy, chr(key.c)) # print new character at appropriate position on screen libtcod.console_set_char_foreground(con, x + posx, posy, libtcod.light_red) libtcod.console_set_char(con, x + posx + 1, posy, chr(95)) libtcod.console_set_char_foreground(con, x + posx + 1, posy, libtcod.white) command += chr(key.c) # add to the string x += 1 libtcod.console_blit(con, 0, 0, game.SCREEN_WIDTH, game.SCREEN_HEIGHT, 0, 0, 0) libtcod.console_flush() return command
def draw(self, con, x_origin = 0, y_origin = 0): super(WeaponComponent, self).draw(con, x_origin, y_origin) for y in range(1, 5): libtcod.console_put_char(con, x_origin, - y + y_origin, self.projectile) libtcod.console_set_char_foreground(con, x_origin, - y + y_origin, self.projectile_color)
def render_all(): global cam_x, cam_y, selected #clear the city locations using OLD cam position. for city in R.cities: loc = R.tiles[city.x][city.y] colour = loc.bg libtcod.console_set_char_background(con, cam_x + city.x, cam_y + city.y, colour, libtcod.BKGND_SET) libtcod.console_set_char(con, cam_x + city.x, cam_y + city.y, ord(' ')) #clear position of old object for objects in R.world_obj: objects.clear(cam_x, cam_y) #find the NEW camera position cam_x = scrolling_map(you.x, R.MAP_VIEW_WIDTH / 2, R.MAP_VIEW_WIDTH, R.MAP_WIDTH) cam_y = scrolling_map(you.y, R.MAP_VIEW_HEIGHT / 2, R.MAP_VIEW_HEIGHT, R.MAP_HEIGHT) #now draw the map! #this x and y refers to the SCREEN position. NOT map. for y in range(min(R.MAP_VIEW_HEIGHT, len(R.world.tiles[0]))): for x in range(min(R.MAP_VIEW_WIDTH, len(R.world.tiles))): #find out *actual" map-pos map_pos_x = x + cam_x map_pos_y = y + cam_y #skip if out of bounds if map_pos_x >= R.MAP_WIDTH: continue if map_pos_y >= R.MAP_HEIGHT: continue tile = R.world.tiles[map_pos_x][map_pos_y] #visible = libtcod.map_is_in_fov(fov_map, tile.x, tile.y) visible = True #wall = tile.block_sight if not visible: pass #TODO: re-do the visible/ not visible code. #if it"s not visible right the player can only see it if it"s explored #if tile.explored: #if wall: # libtcod.console_set_char_backgrnow, ound(con, x, y, color_dark_wall, libtcod.BKGND_SET) # libtcod.console_set_char(con, x, y, " ") #else: # libtcod.console_set_char_background(con, x, y, color_dark_ground, libtcod.BKGND_SET) # libtcod.console_set_char(con, x, y, " ") else: #it"s visible if tile.POI is None: if traffic: # for b&w image. v = world.get_foot_traffic(map_pos_x, map_pos_y) colour = libtcod.Color(v, v, v) libtcod.console_set_char_background(con, x, y, colour, libtcod.BKGND_SET) libtcod.console_set_char(con, x, y, " ") elif temperature: # for b&w image. v = world.get_temperature(map_pos_x, map_pos_y) v = int(v) colour = libtcod.Color(v, v, v) libtcod.console_set_char_background(con, x, y, colour, libtcod.BKGND_SET) libtcod.console_set_char(con, x, y, " ") elif continent: m = 255 / len(R.world.continents) if tile.type != "water": v = tile.continent * m colour = libtcod.Color(v, v, v) else: colour = tile.bg libtcod.console_set_char_background(con, x, y, colour, libtcod.BKGND_SET) libtcod.console_set_char(con, x, y, " ") elif pathfinding: char = " " if len(selected) > 0 and hasattr(selected[0], "ai") and selected[0].ai is not None: # and selected[0].ai.pather.end is not None: if path_to_draw == 3: draw_path = selected[0].ai.path3 pather = selected[0].ai.pather3 elif path_to_draw == 2: draw_path = selected[0].ai.path2 pather = selected[0].ai.pather2 else: draw_path = selected[0].ai.path pather = selected[0].ai.pather loc = (map_pos_x,map_pos_y) loc_str = str(loc) if path_to_draw < 3 and pather.node_costs.has_key(loc_str): v = float(pather.node_costs[loc_str]) v /= pather.largest_cost v = int( v * 255 ) colour = libtcod.Color(v, v, v) if loc in draw_path: char = "." #path tile elif path_to_draw == 3 and pather.node_costs.has_key(loc): #todo: hack for old pather, remove!!! v = float(pather.node_costs[loc]) v /= pather.largest_cost v = int( v * 255 ) colour = libtcod.Color(v, v, v) if loc in draw_path: char = "." #path tile else: if tile.type == "water": colour = libtcod.Color(0, 10, 100) elif tile.type == "grass": colour = libtcod.Color(0, 100, 10) elif tile.type == "coast": colour = libtcod.Color(50, 10, 100) elif tile.type == "path": colour = libtcod.Color(10, 60, 200) else: colour = libtcod.Color(100, 10, 0) else: if tile.type == "water": colour = libtcod.Color(0, 10, 100) elif tile.type == "grass": colour = libtcod.Color(0, 100, 10) elif tile.type == "coast": colour = libtcod.Color(50, 10, 100) elif tile.type == "path": colour = libtcod.Color(10, 60, 200) else: colour = libtcod.Color(100, 10, 0) libtcod.console_set_char_background(con, x, y, colour, libtcod.BKGND_SET) libtcod.console_set_char(con, x, y, char) else: libtcod.console_set_char(con, x, y, " ") libtcod.console_set_char_background(con, x, y, tile.bg, libtcod.BKGND_SET) #libtcod.console_set_char_foreground(con, x, y, libtcod.black) #libtcod.console_set_char(con, x, y, libtcod.CHAR_BULLET) else: libtcod.console_set_char_background(con, x, y, tile.POI.colour, libtcod.BKGND_SET) libtcod.console_set_char_foreground(con, x, y, libtcod.white) libtcod.console_set_char(con, x, y, tile.POI.char) #since it"s visible, explore it tile.explored = True #now draw all the merchants for city in cities: for merchant in city.trade_house.caravans_out: merchant.draw(cam_x, cam_y) for objects in R.world_obj: if objects.ai: # objects.clear(cam_x, cam_y) objects.draw(cam_x, cam_y) you.draw(cam_x, cam_y) #libtcod.console_print_ex(message_bar, R.SCREEN_WIDTH - R.INFO_BAR_WIDTH, 0, libtcod.BKGND_NONE, libtcod.LEFT, get_names_under_mouse()) # libtcod.console_set_default_background(con, libtcod.white) libtcod.console_blit(con, 0, 0, R.MAP_VIEW_WIDTH, R.MAP_VIEW_HEIGHT, 0, 0, 0) libtcod.console_blit(con_char, 0, 0, R.MAP_VIEW_WIDTH, R.MAP_VIEW_HEIGHT, 0, 0, 0, 1.0, 0.0) libtcod.console_blit(inf, 0, 0, R.INFO_BAR_WIDTH, R.SCREEN_HEIGHT, 0, R.MAP_VIEW_WIDTH, 0) libtcod.console_blit(minmap, 0, 0, R.INFO_BAR_WIDTH, R.PANEL_HEIGHT, 0, R.MAP_VIEW_WIDTH, R.PANEL_Y) libtcod.console_flush()
def draw(obj): libtcod.console_put_char(0, obj.x, obj.y, obj.char, libtcod.BKGND_NONE) if isinstance(obj, Cell) and getattr(obj,"solid"): libtcod.console_set_char_foreground(0, obj.x,obj.y,libtcod.red)
def render (self): tcod.console_put_char(0, self.x, self.y, self.sym, tcod.BKGND_NONE) tcod.console_set_char_foreground(0, self.x, self.y, self.color)
def set_color_fg(self, position, color, console=0): x, y = position libtcod.console_set_char_foreground(console, x, y, color)
def set_foreground(self, console, x, y): if self.foreground is not None: libtcod.console_set_char_foreground(console, x, y, self.foreground)
def render_all(con, panel, game_map, entities, player, fov_map, fov_recompute, message_log, screen_width, screen_height, bar_width, panel_height, panel_y, mouse, tile_data, game_state): entities_in_render_order = sorted(entities, key=lambda x: x.render_order.value) for entity in entities_in_render_order: draw_entity(con, entity, fov_map, game_map) if fov_recompute: stairs_x, stairs_y = stairs_location(entities) for y in range(game_map.height): for x in range(game_map.width): visible = lc.map_is_in_fov(fov_map, x, y) if visible: lc.console_set_char_background( con, x, y, tile_data.get(game_map.tiles[x][y].terrain)['light'], lc.BKGND_SET) if not (y == stairs_y and x == stairs_x): lc.console_set_char_foreground( con, x, y, tile_data.get( game_map.tiles[x][y].terrain)['dark']) lc.console_set_char(con, x, y, chr(game_map.tiles[x][y].texture)) game_map.tiles[x][y].explored = True elif game_map.tiles[x][y].explored: # lc.console_put_char(con,x,y,chr(game_map.tiles[x][y].texture),lc.BKGND_NONE) lc.console_set_char_background( con, x, y, tile_data.get(game_map.tiles[x][y].terrain)['dark'], lc.BKGND_SET) if not (y == stairs_y and x == stairs_x): lc.console_set_char_foreground(con, x, y, lc.black) lc.console_set_char(con, x, y, chr(game_map.tiles[x][y].texture)) lc.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0) lc.console_set_default_background(panel, lc.black) lc.console_clear(panel) y = 1 for message in message_log.messages: lc.console_set_default_foreground(panel, message.colour) lc.console_print_ex(panel, message_log.x, y, lc.BKGND_NONE, lc.LEFT, message.text) y += 1 render_bar(panel, 1, 1, bar_width, 'HP', player.fighter.health, player.fighter.max_health, lc.red, lc.darker_red) lc.console_print_ex(panel, 1, 3, lc.BKGND_NONE, lc.LEFT, 'Dungeon Level: {0}'.format(game_map.floor)) lc.console_set_default_background(panel, lc.light_gray) lc.console_print_ex(panel, 1, 0, lc.BKGND_NONE, lc.LEFT, get_names_under_mouse(mouse, entities, fov_map)) lc.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0, panel_y) if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY): if game_state == GameStates.SHOW_INVENTORY: inventory_title = 'Press the key next to an item to use it or Esc to cancel.\n' else: inventory_title = 'Press the key next to an item to drop it or Esc to cancel. \n' inventory_menu(con, inventory_title, player, 50, screen_width, screen_height) elif game_state == GameStates.LEVEL_UP: level_up_menu(con, 'Level up! Choose a stat to raise:', player, 40, screen_width, screen_height) elif game_state == GameStates.CHARACTER_SCREEN: character_screen(player, 30, 10, screen_width, screen_height)
def set_char_foreground(self,x,y,color): libtcod.console_set_char_foreground(self.con,x,y,color)
def render_all(): global fov_map, color_dark_wall, color_light_wall global color_dark_ground, color_light_ground global fov_recompute if fov_recompute: #Recompute FOV fov_recompute = False libtcod.map_compute_fov(fov_map, player.x, player.y, TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO) for y in range(MAP_HEIGHT): for x in range(MAP_WIDTH): visible = libtcod.map_is_in_fov(fov_map, x, y) wall = map[x][y].block_sight distance_light = TORCH_RADIUS + 1 - player.distance(x, y) #Make the light dimmer further from player distance_dark = SCREEN_WIDTH - player.distance(x, y) distance_light = abs(distance_light) ** 0.5 #Square root to make transition non linear distance_dark = abs(distance_dark) ** 0.5 if not visible: #If it's not visible right now, the player can only see it if it is already explored if map[x][y].explored: #It is out of FOV if wall: libtcod.console_set_char_background(con, x, y, color_dark_wall * (0.075) * distance_dark, libtcod.BKGND_SET) else: libtcod.console_set_char_background(con, x, y, color_dark_ground * (0.075) * distance_dark, libtcod.BKGND_SET) libtcod.console_set_char(con, x, y, ' ') else: #It's visible if wall: libtcod.console_set_char_background(con, x, y, color_light_wall * (0.35) * distance_light, libtcod.BKGND_SET) else: libtcod.console_set_char_background(con, x, y, color_light_ground * (0.35) * distance_light, libtcod.BKGND_SET) libtcod.console_set_char_foreground(con, x, y, libtcod.dark_orange) libtcod.console_set_char(con, x, y, map[x][y].char) #Since it is visible, explore it map[x][y].explored = True #draw all objects in the list for object in objects: object.draw() for tree in trees: tree.draw() player.draw() #Blit to con libtcod.console_blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0) #Prepare to render GUI panel libtcod.console_set_default_background(panel, libtcod.darkest_grey) 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, MSG_X, y, libtcod.BKGND_NONE, libtcod.LEFT, line) y += 1 #Show the player's stats render_bar(1, 1, BAR_WIDTH, 'HP', player.fighter.hp, player.fighter.max_hp, libtcod.light_red, libtcod.darker_red) level_up_xp = LEVEL_UP_BASE + player.level * LEVEL_UP_FACTOR render_bar(1, 2, BAR_WIDTH, 'XP', player.fighter.xp, level_up_xp, libtcod.darker_green, libtcod.darkest_green) #Print dungeon level libtcod.console_print_ex(panel, 1, 4, libtcod.BKGND_NONE, libtcod.LEFT, 'Dungeon Level: ' + str(dungeon_level)) libtcod.console_print_ex(panel, 1, 5, libtcod.BKGND_NONE, libtcod.LEFT, 'Player Level: ' + str(player.level)) #Display names of objects under the mouse libtcod.console_set_default_foreground(panel, libtcod.light_gray) libtcod.console_print_ex(panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT, get_names_under_mouse()) #Blit the contents of panel to root console libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0, PANEL_Y)
def render_all(): global fov_map, color_dark_wall, color_light_wall global color_dark_ground, color_light_ground global need_fov_refresh if need_fov_refresh: #recompute FOV if needed (the player moved or something) need_fov_refresh = False libtcod.map_compute_fov(fov_map, player.x, player.y, TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO) #go through all tiles, and set their background color according to the FOV for y in range(VIEWPORT_HEIGHT): for x in range(VIEWPORT_WIDTH): map_x = cam.x + x map_y = cam.y + y visible = libtcod.map_is_in_fov(fov_map, map_x, map_y) wall = map[map_x][map_y].block_sight foreground_color = map[map_x][map_y].data['foreground_color'] background_color = map[map_x][map_y].data['background_color'] tile_char = map[map_x][map_y].data['char'] if not visible: #if it's not visible right now, the player can only see it if it's explored if map[map_x][map_y].explored: foreground_color = libtcod.color_lerp( foreground_color, libtcod.black, 0.5) background_color = libtcod.color_lerp( background_color, libtcod.black, 0.5) else: foreground_color = libtcod.black background_color = libtcod.black else: #it's visible #since it's visible, explore it map[map_x][map_y].explored = True if len(tile_char) > 0: libtcod.console_put_char(con, x, y, tile_char) libtcod.console_set_char_foreground(con, x, y, foreground_color) libtcod.console_set_char_background(con, x, y, background_color) #draw all objects in the list for object in objects: if object != player: object.draw() player.draw() #blit the contents of "con" to the root console libtcod.console_blit(con, 0, 0, VIEWPORT_WIDTH, VIEWPORT_HEIGHT, 0, 0, 0) #prepare to render the GUI panel libtcod.console_set_default_background(panel, libtcod.black) libtcod.console_clear(panel) #show the player's stats render_bar(1, 1, BAR_WIDTH, 'HP', player.fighter.hp, player.fighter.max_hp, libtcod.light_red, libtcod.darker_red) #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, MSG_X, y, libtcod.BKGND_NONE, libtcod.LEFT, line) y += 1 #blit the contents of "panel" to the root console libtcod.console_blit(panel, 0, 0, VIEWPORT_WIDTH, PANEL_HEIGHT, 0, 0, PANEL_Y)
def render (self): for y, row in enumerate(self.tiles): for x, tile_type in enumerate(row): tcod.console_put_char(0, x, y, tile_types[tile_type]['sym'], tcod.BKGND_NONE) tcod.console_set_char_foreground(0, x, y, tile_types[tile_type]['color'])
t1 = time.time() lm.comp_fov(level, player_x, player_y,10) player_screen_pos = player_x-offset_x,player_y-offset_y for y,row in enumerate(levelmap[offset_y:offset_y+Settings.SCREEN_HEIGHT]): for x,cell in enumerate(row[offset_x:offset_x+Settings.SCREEN_WIDTH]): color,char,bgcolor = mapping.get(cell, (libtcod.Color(0,0,0),' ',libtcod.Color(0,0,0))) color = lm.get_color(level, x+offset_x, y+offset_y, color) bgcolor = lm.get_color(level, x+offset_x, y+offset_y, bgcolor) if (x,y) == player_screen_pos: color = libtcod.Color(128,128,100) char = '\x01' libtcod.console_set_char_foreground(con, x,y, color) libtcod.console_set_char_background(con, x,y, bgcolor) libtcod.console_set_char(con,x,y,char) print 'draw loop:', time.time()-t1 libtcod.console_print(message_con, 0,1,lm.get_tile_type(level, player_x,player_y)[0]) libtcod.console_blit(message_con, 0,0, Settings.SCREEN_WIDTH,2, 0, 0,Settings.DISPLAY_HEIGHT-2) blit_x,blit_y = 0,0 blit_w,blit_h = Settings.SCREEN_WIDTH, Settings.SCREEN_HEIGHT if blit_x + MAP_X < Settings.SCREEN_WIDTH: blit_x = (Settings.SCREEN_WIDTH - (blit_x + MAP_X))/2 blit_x = int(blit_x) blit_w = MAP_X if blit_y + MAP_Y < Settings.SCREEN_HEIGHT:
def test_console_set_char_foreground(console, fg): libtcodpy.console_set_char_foreground(console, 0, 0, fg) assert_char(console, 0, 0, fg=fg)
def draw(self): for tile in self.currentMap.get_map_list(): tile.draw() libtcod.console_set_char_foreground(0, tile.x, tile.y, libtcod.Color(255, 255, 255))
def render_all(): global cam_x, cam_y #clear the city locations using OLD cam position. for city in R.cities: loc = R.tiles[city.x][city.y] colour = loc.bg libtcod.console_set_char_background(con, cam_x+city.x, cam_y+city.y, colour, libtcod.BKGND_SET ) libtcod.console_set_char(con, cam_x+city.x, cam_y+city.y, ord(' ')) cam_x = scrolling_map(player.x, R.MAP_VIEW_WIDTH/2, R.MAP_VIEW_WIDTH, R.MAP_WIDTH) cam_y = scrolling_map(player.y, R.MAP_VIEW_HEIGHT/2, R.MAP_VIEW_HEIGHT, R.MAP_HEIGHT) #now draw the map! for y in range(min(R.MAP_VIEW_HEIGHT, len(R.world.tiles[0]))): #this refers to the SCREEN position. NOT map. for x in range(min(R.MAP_VIEW_WIDTH, len(R.world.tiles))): map_pos_x = x + cam_x map_pos_y = y + cam_y if map_pos_x >= R.MAP_WIDTH: map_pos_x = R.MAP_WIDTH -1 if map_pos_y >= R.MAP_HEIGHT: map_pos_y = R.MAP_HEIGHT - 1 tile = R.world.tiles[map_pos_x][map_pos_y] #=============================================================== # try: # tile = map[map_pos_x][map_pos_y] # except: # print str(map_pos_x) + " or " + str(map_pos_y) + " is out of bounds." # break #=============================================================== #visible = libtcod.map_is_in_fov(fov_map, tile.x, tile.y) visible = True #wall = tile.block_sight if not visible: pass #TODO: re-do the visible/ not visible code. #if it"s not visible right now, the player can only see it if it"s explored #if tile.explored: #if wall: # libtcod.console_set_char_background(con, x, y, color_dark_wall, libtcod.BKGND_SET) # libtcod.console_set_char(con, x, y, " ") #else: # libtcod.console_set_char_background(con, x, y, color_dark_ground, libtcod.BKGND_SET) # libtcod.console_set_char(con, x, y, " ") else: #it"s visible if tile.POI is None: if traffic: # for b&w image. v = world.get_foot_traffic(map_pos_x,map_pos_y) colour = libtcod.Color(v,v,v) libtcod.console_set_char_background(con, x, y, colour, libtcod.BKGND_SET ) libtcod.console_set_char(con, x, y, " ") elif temperature: # for b&w image. v = world.get_temperature(map_pos_x,map_pos_y) v = int(v) colour = libtcod.Color(v,v,v) libtcod.console_set_char_background(con, x, y, colour, libtcod.BKGND_SET ) libtcod.console_set_char(con, x, y, " ") else: colour = tile.bg libtcod.console_set_char(con, x, y, " ") libtcod.console_set_char_background(con, x, y, colour, libtcod.BKGND_SET ) #libtcod.console_set_char_foreground(con, x, y, libtcod.black) #libtcod.console_set_char(con, x, y, libtcod.CHAR_BULLET) else: libtcod.console_set_char_background(con, x, y, tile.POI.colour, libtcod.BKGND_SET ) libtcod.console_set_char_foreground(con, x, y, libtcod.white) libtcod.console_set_char(con, x, y, tile.POI.char) #since it"s visible, explore it tile.explored = True #now draw the mini map for cell_x in range(len(world.mini_map)): for cell_y in range(len(world.mini_map[cell_x])): colour = world.mini_map[cell_x][cell_y].bg libtcod.console_set_char_background(minmap, cell_x, cell_y, colour, libtcod.BKGND_SET ) #libtcod.console_set_char_foreground(con, x, y, libtcod.white) # for char in R.world_obj: # if char != player: # char.draw(cam_x, cam_y) #now draw all the merchants for city in cities: for merchant in city.trade_house.caravans_out: merchant.draw(cam_x,cam_y) for objects in R.world_obj: if objects.ai: objects.clear(cam_x,cam_y) objects.draw(cam_x,cam_y) player.draw(cam_x, cam_y) libtcod.console_clear(message_bar) libtcod.console_set_default_foreground(message_bar, libtcod.white) libtcod.console_print_ex(message_bar, 0, 0, libtcod.BKGND_NONE, libtcod.LEFT, str(date[0]) + " " + str(date[1][2]) + " " + str(date[1][0]) + " " + str(date[2][0])) # print the messages, one line at a time. y = 2 for (line, colour) in R.game_msgs: libtcod.console_set_default_foreground(message_bar, colour) libtcod.console_print_ex(message_bar, R.MSG_X, R.MSG_HEIGHT - y, libtcod.BKGND_NONE, libtcod.LEFT, line) y += 1 # y = 0 # for y in range(R.MAP_HEIGHT): # for x in range(R.MAP_WIDTH): # libtcod.console_set_char_background(con, x, y, map_[x][y].bg, libtcod.BKGND_SET) #libtcod.console_print_ex(message_bar, R.SCREEN_WIDTH - R.INFO_BAR_WIDTH, 0, libtcod.BKGND_NONE, libtcod.LEFT, get_names_under_mouse()) libtcod.console_set_default_background(con, libtcod.white) libtcod.console_blit(con, 0, 0, R.MAP_VIEW_WIDTH, R.MAP_VIEW_HEIGHT, 0, 0, 0) #libtcod.console_blit(con, mini_map_x, mini_map_y, mini_map_x+ mini_map_width, mini_map_y +mini_map_height, 0, 0, 0) libtcod.console_blit(con_char, 0, 0, R.MAP_VIEW_WIDTH, R.MAP_VIEW_HEIGHT, 0, 0, 0, 1.0, 0.0) libtcod.console_blit(inf, 0, 0, R.INFO_BAR_WIDTH, R.SCREEN_HEIGHT, 0,R.MAP_VIEW_WIDTH,0) libtcod.console_blit(minmap, 0, 0, R.INFO_BAR_WIDTH, R.PANEL_HEIGHT, 0,R.MAP_VIEW_WIDTH,R.PANEL_Y) libtcod.console_blit(message_bar, 0, 0, R.PANEL_WIDTH, R.PANEL_HEIGHT, 0 , 0, R.PANEL_Y) libtcod.console_flush()
def render_all(): global fov_map, color_dark_wall, color_light_wall global color_dark_ground, color_light_ground global need_fov_refresh if need_fov_refresh: #recompute FOV if needed (the player moved or something) need_fov_refresh = False libtcod.map_compute_fov(fov_map, player.x, player.y, TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO) #go through all tiles, and set their background color according to the FOV for y in range(VIEWPORT_HEIGHT): for x in range(VIEWPORT_WIDTH): map_x = cam.x + x map_y = cam.y + y visible = libtcod.map_is_in_fov(fov_map, map_x, map_y) wall = map[map_x][map_y].block_sight foreground_color = map[map_x][map_y].data['foreground_color'] background_color = map[map_x][map_y].data['background_color'] tile_char = map[map_x][map_y].data['char'] if not visible: #if it's not visible right now, the player can only see it if it's explored if map[map_x][map_y].explored: foreground_color = libtcod.color_lerp(foreground_color, libtcod.black, 0.5) background_color = libtcod.color_lerp(background_color, libtcod.black, 0.5) else: foreground_color = libtcod.black; background_color = libtcod.black; else: #it's visible #since it's visible, explore it map[map_x][map_y].explored = True if len(tile_char) > 0: libtcod.console_put_char(con, x, y, tile_char) libtcod.console_set_char_foreground(con, x, y, foreground_color ) libtcod.console_set_char_background(con, x, y, background_color ) #draw all objects in the list for object in objects: if object != player: object.draw() player.draw() #blit the contents of "con" to the root console libtcod.console_blit(con, 0, 0, VIEWPORT_WIDTH, VIEWPORT_HEIGHT, 0, 0, 0) #prepare to render the GUI panel libtcod.console_set_default_background(panel, libtcod.black) libtcod.console_clear(panel) #show the player's stats render_bar(1, 1, BAR_WIDTH, 'HP', player.fighter.hp, player.fighter.max_hp, libtcod.light_red, libtcod.darker_red) #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, MSG_X, y, libtcod.BKGND_NONE, libtcod.LEFT, line) y += 1 #blit the contents of "panel" to the root console libtcod.console_blit(panel, 0, 0, VIEWPORT_WIDTH, PANEL_HEIGHT, 0, 0, PANEL_Y)