def RenderEverything(): player = None for ent in ActiveEntityList: if 'ControlledByPlayer' and 'CanSee' in ent.flags: player = ent break #player = TestDummy for y in range(MAP_HEIGHT): for x in range(MAP_WIDTH): terraintile = Map[x][y] if player != None: canseetile = player.Vision.CanSee(x,y) if canseetile: libtcod.console_set_char_background(MainConsole,x,y,terraintile.bgcolour,libtcod.BKGND_SET) libtcod.console_set_default_foreground(MainConsole,terraintile.fgcolour) libtcod.console_put_char(MainConsole, x, y, terraintile.char, libtcod.BKGND_NONE) else: libtcod.console_set_char_background(MainConsole,x,y,terraintile.bgcolour*UNSEEN_TERRAIN_DARKNESS,libtcod.BKGND_SET) libtcod.console_set_default_foreground(MainConsole,terraintile.fgcolour*UNSEEN_TERRAIN_DARKNESS) libtcod.console_put_char(MainConsole, x, y, terraintile.char, libtcod.BKGND_NONE) for ent in ActiveEntityList: ent.Draw() DrawAllPaths(MainConsole) RenderGui() libtcod.console_blit(MainConsole, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0) libtcod.console_blit(GUIBottomConsole, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, GUI_BOTTOM_Y)
def draw(self): #only show if visible to the player if (libtcod.map_is_in_fov(fov_map, self.x, self.y) or (self.always_visible and map[self.x][self.y].explored) or self.name=='room number'): #set the color and then draw the character that represents this object at its position libtcod.console_set_default_foreground(con, self.color) libtcod.console_put_char(con, self.x, self.y, self.char, libtcod.BKGND_NONE)
def draw(self): #only show if it's visible to the player; or it's set to "always visible" and on an explored tile 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 then draw the character that represents this object at its position libtcod.console_set_default_foreground(con, self.color) libtcod.console_put_char(con, self.x, self.y, self.char, libtcod.BKGND_NONE)
def clear(self): """ Erase the character that represents this object. """ global con libtcod.console_put_char(con, self.x, self.y, ' ', libtcod.BKGND_NONE)
def render_all(self): # Renders everything in the game world, as needed. tcod.console_clear(0) # Start with a cleared console self.dun_level.player.check_fov() # Run through the entire map for y in xrange(self.dun_level.MAP_H): for x in xrange(self.dun_level.MAP_W): # If tile is in the player's FOV, draw it. if tcod.map_is_in_fov(self.dun_level.player.fov_map, x, y): char = self.dun_level.map[x][y].char tcod.console_set_default_foreground(0, tcod.white) tcod.console_put_char(0, x, y, char, tcod.BKGND_NONE) # Run through the objects list, and draw everything for object in self.dun_level.objects: object.draw() # Draw all actors last, so they show up on top for actor in self.dun_level.actors: actor.draw() # Update the window to show all the changes tcod.console_flush()
def draw_monsters(self): for monster in self.monsters: x, y = monster.position if libtcod.map_is_in_fov(self.fov_map, x, y): monster.draw(self.console_map) else: libtcod.console_put_char(self.console_map, x, y, ' ', libtcod.BKGND_NONE)
def put_char(self, x, y, ch): """ Puts the specified character or tile at the x, y coordinate, offset by this Canvas' offset values. ch can be either a string or integral type. """ x += self.x_offset y += self.y_offset dlib.console_put_char(self._intern, x, y, ch)
def render_all(): libtcod.map_compute_fov(path_map, player.x, player.y, 0, True, libtcod.FOV_SHADOW) libtcod.console_set_background_color(map_con, libtcod.black) libtcod.console_clear(map_con) for y in range(MAP_HEIGHT): for x in range(MAP_WIDTH): if not libtcod.map_is_in_fov(path_map, x, y): if explore_map[x][y]: libtcod.console_set_back(map_con, x, y, tile_map[x][y].hidden_color, libtcod.BKGND_SET) else: libtcod.console_set_background_color(map_con, tile_map[x][y].vis_color) libtcod.console_set_foreground_color(map_con, tile_map[x][y].char_color) libtcod.console_put_char(map_con, x, y, tile_map[x][y].char, libtcod.BKGND_SET) explore_map[x][y] = True entities = items + creatures for entity in entities: entity.sprite.render() render_panel() render_inventory() blit_consoles()
def draw(self): if libtcod.map_is_in_fov(gameconfig.FOV_MAP, self.x, self.y): libtcod.console_set_default_foreground(self.con, self.color) libtcod.console_set_char_background(self.con, self.x, self.y, self.color, libtcod.BKGND_SET) libtcod.console_put_char(self.con, self.x, self.y, self.char, libtcod.BKGND_NONE)
def render_entities(self, entities, fov_map): """Renders all passed entities""" for ent in entities: if libtcod.map_is_in_fov(fov_map, ent.x, ent.y): #render only visible objects libtcod.console_set_default_foreground(self.con, ent.color) libtcod.console_put_char(self.con, ent.x, ent.y, ent.char, libtcod.BKGND_NONE)
def draw(self): """Draws entity on console.""" if (libt.map_is_in_fov(self.handler.fov_map, self.x, self.y) or self.handler.world.map[self.x][self.y].seen and self.visible_in_fog): libt.console_set_default_foreground(self.handler.game_map, self.colour) libt.console_put_char(self.handler.game_map, self.x, self.y, self.char, libt.BKGND_NONE)
def draw(self, console, x, y): x += (camera.Camera.X / 2) y += (camera.Camera.Y / 2) libtcod.console_set_char_background(console, x, y, self.backgroundColor, libtcod.BKGND_SET) if self.symbol and self.symbolColor: libtcod.console_set_default_foreground(console, self.symbolColor) libtcod.console_put_char(console, x, y, self.symbol, libtcod.BKGND_NONE)
def refreshMessage(self): libtcod.console_set_default_foreground(self.console, libtcod.white) libtcod.console_print_ex(self.console, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT, ('{0: <' + str(self.width) + '}').format(self.message)) if self.active: libtcod.console_put_char(self.console, 1+len(self.message), 0, '_', libtcod.BKGND_NONE) else: libtcod.console_put_char(self.console, 1+len(self.message), 0, ' ', libtcod.BKGND_NONE)
def draw(self): (pos_x, pos_y) = to_camera_coordinates(self.x, self.y) if self.variation_type == "orientation": self.char = set_orientation() if pos_x is not None and self.visible == True: libtcod.console_set_default_foreground(con, self.color) libtcod.console_put_char(con, pos_x, pos_y, self.char, libtcod.BKGND_NONE)
def draw(self): if (libtcod.map_is_in_fov(settings.fov_map, self.x, self.y) or (self.always_visible and settings.map[self.x][self.y].explored)): libtcod.console_set_default_foreground(settings.con, self.color) libtcod.console_put_char(settings.con, self.x, self.y, self.char, libtcod.BKGND_NONE)
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 clear_object(player, o): """ Erase the character that represents this object. """ global _con (x, y) = ScreenCoords.fromWorldCoords(player.camera_position, o.pos) libtcod.console_put_char(_con, x, y, ' ', libtcod.BKGND_NONE)
def render_all(): global fov_map, color_dark_wall, color_light_wall, color_dark_ground, color_light_ground global fov_recompute, hunger, msg_index x_range = range(camera.x, camera.x + CAMERA_WIDTH) y_range = range(camera.y, camera.y + CAMERA_HEIGHT) if fov_recompute: # recompute FOV if need be (player movement or whatever) fov_recompute = False if 'fog' in map[player.x][player.y].mod_set: libtcod.map_compute_fov(fov_map, player.x, player.y, FOG_TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO) else: libtcod.map_compute_fov(fov_map, player.x, player.y, TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO) for y in y_range: for x in x_range: # uncomment this to return to exploration mode #visible = libtcod.map_is_in_fov(fov_map, x, y) visible = True wall = map[x][y].block_sight mods = map[x][y].mod_set if not visible: if map[x][y].explored: if wall: libtcod.console_set_char_background(con, x-camera.x, y-camera.y, color_dark_wall, libtcod.BKGND_SET) else: libtcod.console_set_char_background(con, x-camera.x, y-camera.y, color_dark_ground, libtcod.BKGND_SET) else: libtcod.console_set_char_background(con, x-camera.x, y-camera.y, libtcod.black, libtcod.BKGND_SET) else: if wall: #libtcod.console_set_default_foreground(con, libtcod.white) libtcod.console_set_char_background(con, x-camera.x, y-camera.y, color_light_wall, libtcod.BKGND_SET) else: # THIS ELIF IS FOR A DEBUG COLOR if map[x][y].h == 1: libtcod.console_set_char_background(con, x-camera.x, y-camera.y, color_blood, libtcod.BKGND_SET) else: libtcod.console_set_char_background(con, x-camera.x, y-camera.y, color_light_ground, libtcod.BKGND_SET) map[x][y].explored = True for obj in objects: # prevents drawing over the player if obj != player and (obj.x in x_range) and (obj.y in y_range): libtcod.console_set_default_foreground(con, obj.color) libtcod.console_put_char(con, obj.x-camera.x, obj.y-camera.y, obj.char, libtcod.BKGND_NONE) libtcod.console_set_default_foreground(con, player.color) libtcod.console_put_char(con, player.x-camera.x, player.y-camera.y, player.char, libtcod.BKGND_NONE) libtcod.console_blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0)
def draw(self, console, fov_map, game_map, camera_x, camera_y): if libtcod.map_is_in_fov(fov_map, self.x, self.y) or \ (self.always_visible and game_map[self.x][self.y].explored): (x, y) = render.to_camera_coordinates(self.x, self.y, camera_x, camera_y) if x is not None: libtcod.console_set_default_foreground(console, self.color) libtcod.console_put_char(console, x, y, self.char, libtcod.BKGND_NONE)
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 draw(self): # only show if it's visible to the player if libtcod.map_is_in_fov(display.fov_map, self.x, self.y): # set the color and then draw the character # that represents this object at its position libtcod.console_set_default_foreground(display.con, self.color) libtcod.console_put_char(display.con, self.x, self.y, self.char, libtcod.BKGND_NONE)
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): #if object is in visible range (x, y) = to_camera_coordinates(self.x, self.y) #set the color and then draw the character that represents this object at its position if x is not None: libtcod.console_set_default_foreground(con, self.color) libtcod.console_put_char(con, x, y, self.char, libtcod.BKGND_NONE)
def draw(self, con): y = 1 for (line, colour) in self.messages: for x in range(MSG_WIDTH): libtcod.console_put_char(con, x + MSG_X, y, ' ', libtcod.BKGND_NONE) libtcod.console_set_default_foreground(con, colour) libtcod.console_print_ex(con, MSG_X, y, libtcod.BKGND_NONE, libtcod.LEFT, line) y += 1
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_faded(self, cam_x, cam_y): pos_x = self.x - cam_x pos_y = self.y - cam_y colour = libtcod.Color(self.colour.r, self.colour.g, self.colour.b) libtcod.color_scale_HSV(colour, 0.7, 0.7) # hopefully 80% saturation. libtcod.console_set_default_foreground(R.con_char, colour) libtcod.console_put_char(R.con_char, pos_x, pos_y, self.char, libtcod.BKGND_NONE) # ADDALPHA(0.0))
def draw(self): tempx = self.x tempy = self.y for inc in range(self.length): libtcod.console_set_default_foreground(0, self.color) libtcod.console_put_char(0, tempx, tempy, self.char, libtcod.BKGND_NONE) temp_pos = self.get_relative_pos(self.dir,inc) tempx = temp_pos[0] tempy = temp_pos[1]
def DrawPath(self,console): for i in range(0,libtcod.dijkstra_size(self.currentpath)): if not i == libtcod.dijkstra_size(self.currentpath)-1: x,y = libtcod.dijkstra_get(self.currentpath,i) libtcod.console_set_default_background(console,libtcod.yellow) libtcod.console_put_char(console, x, y, '=', libtcod.BKGND_SET) else: x,y = libtcod.dijkstra_get(self.currentpath,i) libtcod.console_set_char_background(console, x, y, libtcod.blue,libtcod.BKGND_SET)
def drawPlayers(player, visibleOffsetX, visibleOffsetY): playerX, playerY = player.GetLocation() visible, screenX, screenY = getScreenCoordinates(playerX, playerY, visibleOffsetX, visibleOffsetY) if (visible == False): # cannot see me :) return libtcod.console_put_char(0, screenX, screenY, '@',libtcod.BKGND_NONE) libtcod.console_set_char_background(0, screenX, screenY, libtcod.black, libtcod.BKGND_SET)
def draw(self, cam_x, cam_y): # # if self.x >= cam_x and self.x < R.MAP_VIEW_WIDTH and self.y >= cam_y and self.y < R.MAP_VIEW_HEIGHT: # pos_x = self.x - cam_x pos_y = self.y - cam_y libtcod.console_set_default_foreground(R.con_char, self.colour) libtcod.console_put_char(R.con_char, pos_x, pos_y, self.char, libtcod.BKGND_NONE)
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 clear(self, console: tcod.console.Console): libtcod.console_put_char(console, int(self.x), int(self.y), ' ', libtcod.BKGND_NONE)
def clear(self): #TODO: Have a "below" list for stacking items on screen #So that more than one item can be on one x, y co-ord libtcod.console_put_char(con, self.x, self.y, " ", libtcod.BKGND_NONE)
def clear(self): for x in range(self.width): for y in range(self.height): libtcod.console_put_char(self.console, x, y, ' ', libtcod.BKGND_NONE)
def render_draw(objects): for obj in objects: libtcod.console_put_char(0, obj.x, obj.y, obj.symbol, libtcod.BKGND_NONE) libtcod.console_flush()
def draw(self): libtcod.console_set_default_foreground(self.con, self.color) libtcod.console_put_char(self.con, self.x, self.y, self.char, libtcod.BKGND_NONE)
def clear(self): # erase the character that represents this object (x, y) = to_camera_coordinates(self.x, self.y) if x is not None: libtcod.console_put_char(con, x, y, ' ', libtcod.BKGND_NONE)
def show(thing): libtcod.console_put_char(viewport.con, thing.x, thing.y, thing.char)
def render_all(con, panel, entities, player, game_map, fov_map, fov_recompute, message_log, screen_width, screen_height, bar_width, panel_height, panel_y, mouse, colors, game_state): #draw the map if fov_recompute: for y in range(game_map.height): for x in range(game_map.width): visible = libtcod.map_is_in_fov(fov_map, x, y) wall = game_map.tiles[x][y].block_sight if visible: if wall: libtcod.console_set_default_foreground( con, colors.get('light_wall')) libtcod.console_put_char(con, x, y, '#', libtcod.BKGND_NONE) else: libtcod.console_set_default_foreground( con, colors.get('light_ground')) libtcod.console_put_char(con, x, y, '.', libtcod.BKGND_NONE) game_map.tiles[x][y].explored = True elif game_map.tiles[x][y].explored: if wall: libtcod.console_set_default_foreground( con, colors.get('dark_wall')) libtcod.console_put_char(con, x, y, '#', libtcod.BKGND_NONE) else: libtcod.console_set_default_foreground( con, colors.get('dark_ground')) libtcod.console_put_char(con, x, y, '.', libtcod.BKGND_NONE) entities_in_render_order = sorted(entities, key=lambda x: x.render_order.value) for entity in entities_in_render_order: if entity.visible == True: draw_entity(con, entity, fov_map, game_map) libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0) libtcod.console_set_default_foreground(con, libtcod.white) libtcod.console_set_default_background(panel, libtcod.black) libtcod.console_clear(panel) #prints message log y = 1 for message in message_log.messages: libtcod.console_set_default_foreground(panel, message.color) libtcod.console_print_ex(panel, message_log.x, y, libtcod.BKGND_NONE, libtcod.LEFT, message.text) y += 1 render_bar(panel, 1, 1, bar_width, 'HP', player.fighter.hp, player.fighter.max_hp, libtcod.red, libtcod.dark_grey) render_bar(panel, 1, 2, bar_width, 'MP', player.spellcaster.mp, player.spellcaster.max_mp, libtcod.blue, libtcod.dark_grey) render_pip(panel, screen_width - 3, 1, '[', libtcod.sky, decide_color(player.equipment.armor)) render_pip(panel, screen_width - 3, 2, ']', libtcod.sky, decide_color(player.equipment.off_hand)) render_pip(panel, screen_width - 3, 3, '/', libtcod.sky, decide_color(player.equipment.main_hand)) libtcod.console_set_default_foreground(panel, libtcod.white) libtcod.console_print_ex( panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT, 'Dungeon level: {0}'.format(game_map.dungeon_level)) libtcod.console_print_ex( panel, 1, 4, libtcod.BKGND_NONE, libtcod.LEFT, 'Character Level: {0}'.format(player.level.current_level)) libtcod.console_set_default_foreground(panel, libtcod.light_grey) libtcod.console_print_ex(panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT, get_names_under_mouse(mouse, entities, fov_map)) libtcod.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_text = 'Press the key next to an item to use it, or Esc to cancel.\n' else: inventory_text = 'Press the key next to an item to drop it, or Esc to cancel.\n' inventory_menu(con, inventory_text, player, 50, screen_width, screen_height) elif game_state == GameStates.CAST_SPELL: spellcasting_text = "Press the key next to a spell to cast it, or Esc to cancel.\n" spellcasting_menu(con, spellcasting_text, player, 50, screen_width, screen_height) elif game_state == GameStates.CHARACTER_SCREEN: character_screen(player, 30, 10, screen_width, screen_height)
def clear_entity(con, entity): libtcod.console_put_char(con, entity.x, entity.y, ' ', libtcod.BKGND_NONE)
'arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'python/libtcod tutorial', False) libtcod.sys_set_fps(LIMIT_FPS) break_int = 0 dirx = 1 diry = 0 snakex = SCREEN_WIDTH / 2 snakey = SCREEN_HEIGHT / 2 applex = random.randint(2, SCREEN_WIDTH - 2) appley = random.randint(2, SCREEN_HEIGHT - 2) snakex_loop = [snakex, snakex, snakex, snakex, snakex] snakey_loop = [snakey, snakey, snakey, snakey, snakey] libtcod.console_put_char(0, applex, appley, 'O', libtcod.BKGND_NONE) while not libtcod.console_is_window_closed(): libtcod.console_set_default_foreground(0, libtcod.white) snakex_tail = snakex_loop[len(snakex_loop) - 1] snakey_tail = snakey_loop[len(snakey_loop) - 1] libtcod.console_put_char(0, snakex_tail, snakey_tail, ' ', libtcod.BKGND_NONE) snakex = snakex + dirx snakey = snakey + diry snake_loop_int = len(snakex_loop) - 1 while snake_loop_int > 0: snakex_loop[snake_loop_int] = snakex_loop[snake_loop_int - 1]
def clear(self): #erase the character that represents this object libtcod.console_put_char(con, self.x, self.y, ' ', libtcod.BKGND_NONE)
def draw(self): #set the color and then draw the character that represents this object at its position libtcod.console_set_foreground_color(con, self.color) libtcod.console_put_char(con, self.x, self.y, self.char, libtcod.BKGND_NONE)
def display_text(text): clearscreen() libtcod.console_set_default_foreground(con, text_color) x_pos = 0 y_pos = 0 wordlist = text.split() for word in wordlist: # If the word can fit on the current line, display it if word == "\\": y_pos += 2 x_pos = 0 if y_pos == view_y: libtcod.console_blit(con, 0, 0, view_x, view_y, 0, 0, 0) libtcod.console_flush() key = libtcod.console_wait_for_keypress(True) clearscreen() y_pos = 0 elif len(word) <= view_x - x_pos: for char in word: libtcod.console_put_char(con, x_pos, y_pos, char, libtcod.BKGND_SET) x_pos += 1 if x_pos < view_x - 1: libtcod.console_put_char(con, x_pos, y_pos, ' ', libtcod.BKGND_SET) x_pos += 1 # If the word is too big to fit on even a blank line, we'll need to break it up across several using dashes. elif len(word) > view_x: curr = 0 while curr < len(word): if x_pos < view_x - 1: libtcod.console_put_char(con, x_pos, y_pos, word[curr], libtcod.BKGND_SET) x_pos += 1 curr += 1 else: libtcod.console_put_char(con, x_pos, y_pos, '-', libtcod.BKGND_SET) y_pos += 1 x_pos = 0 # If we've used up the whole screen, wait for the user to press a key, then start a new page if y_pos == view_y: libtcod.console_blit(con, 0, 0, view_x, view_y, 0, 0, 0) libtcod.console_flush() key = libtcod.console_wait_for_keypress(True) clearscreen() y_pos = 0 if x_pos < view_x - 1: libtcod.console_put_char(con, x_pos, y_pos, ' ', libtcod.BKGND_SET) x_pos += 1 # The last option is a word that can't fit on the current line, but could fit on an empty one. # In that case, we want to go to a new line (or new page if needed), then copy the logic from the "it already fits" case. else: # newline y_pos += 1 if y_pos == view_y: libtcod.console_blit(con, 0, 0, view_x, view_y, 0, 0, 0) libtcod.console_flush() key = libtcod.console_wait_for_keypress(True) clearscreen() y_pos = 0 x_pos = 0 for char in word: libtcod.console_put_char(con, x_pos, y_pos, char, libtcod.BKGND_SET) x_pos += 1 if x_pos < view_x - 1: libtcod.console_put_char(con, x_pos, y_pos, ' ', libtcod.BKGND_SET) x_pos += 1 # Uncomment these to make the player have to step through by word instead of by page. #libtcod.console_blit(con, 0, 0, view_x, view_y, 0, 0, 0) #libtcod.console_flush() #key = libtcod.console_wait_for_keypress(True) # Finally, we want the player to press a key to exit the text. libtcod.console_blit(con, 0, 0, view_x, view_y, 0, 0, 0) libtcod.console_flush() key = libtcod.console_wait_for_keypress(True)
def draw(self, con, x_origin=0, y_origin=0): for y, row in enumerate(self.shape): for x, cell in enumerate(row): libtcod.console_put_char(con, x + x_origin, y + y_origin, cell)
def draw(self): #only draw if visible to player if libtcod.map_is_in_fov(fov_map, self.x, self.y): #set the color and draw char that represent object at position libtcod.console_set_default_foreground(con,self.color) libtcod.console_put_char(con,self.x,self.y,self.char,libtcod.BKGND_NONE)
def draw(self): #set the color and then draw the character that represents this object at its position if libtcod.map_is_in_fov(fov_map, self.x, self.y): libtcod.console_set_default_foreground(con, self.color) libtcod.console_put_char(con, self.x, self.y, self.char, libtcod.BKGND_NONE)
def clear_entity(con, entity): # Put blank character in spot libtcod.console_put_char(con, entity.x, entity.y, ' ', libtcod.BKGND_NONE)
def draw_entity(con, entity, fov_map, game_map): if libtcod.map_is_in_fov(fov_map, entity.x, entity.y) or ( entity.stairs and game_map.tiles[entity.x][entity.y].explored): libtcod.console_set_default_foreground(con, entity.color) libtcod.console_put_char(con, entity.x, entity.y, entity.char, libtcod.BKGND_NONE)
def draw(self): #set the color and then draw the character that represents this object at its position libtcod.console_set_default_foreground(con, self.color) libtcod.console_put_char(con, view_x / 2, view_y / 2, self.char, libtcod.BKGND_SET)
def clear_entity(con, entity): # erase the character that represents this object libtcod.console_put_char(con, entity.x, entity.y, ' ', libtcod.BKGND_NONE)
def render_rect(x1, y1, x2, y2, char): for i in range(y1, y2): for j in range(x1, x2): libtcod.console_put_char(0, j, i, char, libtcod.BKGND_NONE)
def draw_entity(con, entity, fov_map): if libtcod.map_is_in_fov(fov_map, entity.x, entity.y): libtcod.console_set_default_foreground(con, entity.color) libtcod.console_put_char(con, entity.x, entity.y, entity.char, libtcod.BKGND_NONE)
def render_clear_obj(obj): libtcod.console_put_char(0, obj.x, obj.y, ' ', libtcod.BKGND_NONE)
def render_clear(objects): for obj in objects: libtcod.console_put_char(0, obj.x, obj.y, ' ', libtcod.BKGND_NONE)
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)): libtcod.console_set_default_foreground(con, self.color) libtcod.console_put_char(con, self.x, self.y, self.char, libtcod.BKGND_NONE)
def clear_entities(self, entities): for entity in entities: if self.has_required_components(entity): pos = entity.get_component(Components.POSITION) x, y = pos.x, pos.y tcod.console_put_char(self.console, x, y, ' ', tcod.BKGND_NONE)
def render(self, map, view_centre, fov_entity): """Render map. Arguments: map - map to render view_centre - world location to centre map on when rendering fov_entity - entity to use for fov calculation """ # Generate field of view map fov_map = map.generate_fov_map(fov_entity) # Calculate bounds for rendering half_xsize = int(self.width / 2) half_ysize = int(self.height / 2) x0 = view_centre[0] - half_xsize y0 = view_centre[1] - half_ysize x1 = view_centre[0] + half_xsize + 1 y1 = view_centre[1] + half_ysize + 1 for y in range(y0, y1): for x in range(x0, x1): tile = map.tiles[x][y] visible = libtcod.map_is_in_fov(fov_map, x, y) # Calculate offset onto screen and render xt = self.x_offset + x - x0 yt = self.y_offset + y - y0 if not visible: if tile.seen: # 70% desaturation greyscale = int(tile.bcolour.r * 0.3 + tile.bcolour.g * 0.59 + tile.bcolour.b * 0.11) nonviscolour = libtcod.color_lerp( tile.bcolour, libtcod.Color(greyscale, greyscale, greyscale), 0.7) libtcod.console_set_char_background( 0, xt, yt, nonviscolour, libtcod.BKGND_SET) libtcod.console_put_char(0, xt, yt, ' ', libtcod.BKGND_NONE) else: libtcod.console_set_char_background( 0, xt, yt, libtcod.black, libtcod.BKGND_SET) libtcod.console_put_char(0, xt, yt, ' ', libtcod.BKGND_NONE) else: tile.seen = True libtcod.console_set_char_background( 0, xt, yt, tile.bcolour, libtcod.BKGND_SET) # Render entities in the world first if tile.entity: libtcod.console_set_default_foreground( 0, tile.entity.colour) libtcod.console_put_char(0, xt, yt, tile.entity.char, libtcod.BKGND_NONE) elif tile.inventory: libtcod.console_set_default_foreground( 0, tile.inventory.colour) libtcod.console_put_char(0, xt, yt, tile.inventory.char, libtcod.BKGND_NONE) elif tile.type == TileType.DOOR: libtcod.console_set_default_foreground( 0, tile.door.colour) libtcod.console_put_char(0, xt, yt, tile.door.char, libtcod.BKGND_NONE) elif tile.type == TileType.WINDOW: libtcod.console_set_default_foreground( 0, tile.window.colour) libtcod.console_put_char(0, xt, yt, tile.window.char, libtcod.BKGND_NONE) elif not tile.blocks_movement: libtcod.console_set_default_foreground( 0, libtcod.black) libtcod.console_put_char(0, xt, yt, '.', libtcod.BKGND_NONE)
def _clear_entity(con, entity): """ Erase the character that represents this object """ libtcod.console_put_char(con, entity.x, entity.y, " ", libtcod.BKGND_NONE)
def clear(self): libtcod.console_put_char(self.con, self.x, self.y, ' ', libtcod.BKGND_NONE)
def render_hline(x1, x2, y, char): for i in range(x1, x2): libtcod.console_put_char(0, i, y, char, libtcod.BKGND_NONE)