def draw(self, con, x, y, lit=False): col_bg = self.lit_col_bg if lit else self.unlit_col_bg ltc.console_set_char_background(con, x, y, col_bg, ltc.BKGND_SET) if self.char: col_fg = self.lit_col_fg if lit else self.unlit_col_fg ltc.console_set_default_foreground(con, col_fg) ltc.console_put_char(con, x, y, self.char, ltc.BKGND_NONE)
def prints(self,x,y,char,color,flush): libtcod.console_put_char(self.console, x, y, char, libtcod.BKGND_DEFAULT) if color: libtcod.console_set_char_foreground(self.console, x, y, color) if flush: self.flush()
def display_statusline (message=""): global status # display_player_stats() for x in range (libtcod.console_get_width(status_console)): libtcod.console_put_char (status_console, x, 0, ' ', libtcod.BKGND_NONE) libtcod.console_put_char (status_console, x, 1, ' ', libtcod.BKGND_NONE) libtcod.console_print_rect_ex(status_console, 1, 0, M.SCREEN_WIDTH, 2, libtcod.BKGND_NONE, libtcod.LEFT, message[:M.SCREEN_WIDTH*2].strip()) libtcod.console_blit(status_console,0,0,M.SCREEN_WIDTH, (M.SCREEN_HEIGHT-M.MAP_HEIGHT-1),0,0,M.MAP_HEIGHT+1,1) libtcod.console_flush()
def render(): libtcod.console_rect(cons.game_console, 0, 0, M.MAP_WIDTH, M.MAP_HEIGHT, True) for y in range (M.MAP_HEIGHT): for x in range (M.MAP_WIDTH): # Draw black for all areas the player has not seen yet if not M.gameworld[x][y].explored: libtcod.console_set_char_background(cons.game_console, x, y, libtcod.black, libtcod.BKGND_SET) # Draw all the floors. if M.gameworld[x][y].is_floor () and M.gameworld[x][y].explored: libtcod.console_set_char_background (cons.game_console, x, y, M.DARK_FLOOR_COLOR, libtcod.BKGND_SET) # Draw all the walls. elif M.gameworld[x][y].explored: libtcod.console_set_char_background(cons.game_console, x, y, M.DARK_WALL_COLOR, libtcod.BKGND_SET) # Draw all the light floors. if (libtcod.map_is_in_fov (P.player.fov, x, y) and libtcod.map_is_walkable (P.player.fov, x, y)): libtcod.console_set_char_background (cons.game_console, x, y, M.FLOOR_COLOR, libtcod.BKGND_SET) for item in M.gameworld[x][y].items: libtcod.console_set_default_foreground (cons.game_console, item.color) libtcod.console_put_char (cons.game_console, x, y, item.char, libtcod.BKGND_NONE) for character in M.gameworld[x][y].characters: libtcod.console_set_default_foreground (cons.game_console, character.color) libtcod.console_put_char (cons.game_console, x, y, character.char, libtcod.BKGND_NONE) M.gameworld[x][y].explored=True # Draw all the light walls. elif libtcod.map_is_in_fov (P.player.fov, x, y): libtcod.console_set_char_background (cons.game_console, x, y, M.WALL_COLOR, libtcod.BKGND_SET) M.gameworld[x][y].explored=True # Blits the game console to the root console. libtcod.console_blit(cons.game_console,0,0,M.MAP_WIDTH,M.MAP_HEIGHT,0,0,0,1)
def display(self, con): if self.game.fov_recompute: #recompute FOV if needed (the player moved or something) self.game.fov_recompute = False libtcod.map_compute_fov(self.map.fov_map, self.game.player.x, self.game.player.y, TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO) for y in range(self.height): for x in range(self.width): map_x, map_y = x + self.x_offset, y + self.y_offset if self.map.in_bounds(map_x, map_y): visible = libtcod.map_is_in_fov(self.map.fov_map, map_x, map_y) tt = self.map.tiles[map_x][map_y].type if visible: libtcod.console_set_char_background(con, x, y, tt.bg_color_lit, libtcod.BKGND_SET) libtcod.console_set_default_foreground(con, tt.fg_color_lit) libtcod.console_put_char(con, x, y, tt.char, libtcod.BKGND_NONE) # TODO: Doing this here bugs it if the player's light radius is not on screen self.map.tiles[map_x][map_y].explored = True elif self.map.tiles[map_x][map_y].explored: libtcod.console_set_char_background(con, x, y, tt.bg_color, libtcod.BKGND_SET) libtcod.console_set_default_foreground(con, tt.fg_color) libtcod.console_put_char(con, x, y, tt.char, libtcod.BKGND_NONE) else: libtcod.console_set_char_background(con, x, y, void_color, libtcod.BKGND_SET) libtcod.console_put_char(con, x, y, ' ', libtcod.BKGND_NONE) else: libtcod.console_set_char_background(con, x, y, void_color, libtcod.BKGND_SET) libtcod.console_put_char(con, x, y, ' ', libtcod.BKGND_NONE) for object in self.map.objects: object.draw(con, self.x_offset, self.y_offset) libtcod.console_blit(con, 0, 0, self.width, self.height, 0, 0, 0) libtcod.console_flush()
def clear(self): """ Erase the character that represents this object """ libtcod.console_put_char(self.map.console, 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, only if the object is in the fov or tagged with 'allways_show' """ if self.visible: libtcod.console_set_foreground_color(self.map.console, self.color) libtcod.console_put_char(self.map.console, self.x, self.y, self.char, libtcod.BKGND_NONE)
def clear(self, con): libtcod.console_put_char(con, self.x, self.y, ' ', libtcod.BKGND_NONE)
def draw(self, con, x_off, y_off): if libtcod.map_is_in_fov(self.map.fov_map, self.x, self.y): libtcod.console_set_default_foreground(con, self.color) libtcod.console_put_char(con, self.x - x_off, self.y - y_off, self.char, libtcod.BKGND_NONE)
def mainloop(self): while 1: self.cons.clear() for x in range(self.player.x - SW,self.player.x + SW): for y in range(self.player.y - SH,self.player.y + SH): char = self.world.char(x, y) color = self.world.get(x,y).color color2 = libtcod.dark_gray color3 = libtcod.color_lerp(color,color2, (((x - self.player.x)**2) + ((y-self.player.y)**2)) / 2500.0) color = libtcod.color_lerp(color3,libtcod.white,0.1) libtcod.console_put_char(self.cons.console, (W/2 - self.player.x) + x, (H/2 - self.player.y) + y, char, libtcod.BKGND_DEFAULT) libtcod.console_set_char_foreground(self.cons.console, (W/2 - self.player.x) + x, (H/2 - self.player.y) + y, color) self.cons.prints(W/2,H/2,"@",self.player.color,False) x = W/2 - (len(self.colors) * 2) for i in range(len(self.colors)): color = self.colors[i] if i == 9: if i == self.player.ccolor: self.cons.printex(x, H - 4, ("%c+%c" % (libtcod.COLCTRL_1,libtcod.COLCTRL_STOP)) * 2, color, False) else: self.cons.printex(x, H - 2, ("%c+%c" % (libtcod.COLCTRL_1,libtcod.COLCTRL_STOP)) * 2, color, False) self.cons.printex(x, H - 3, ("%c+%c" % (libtcod.COLCTRL_1,libtcod.COLCTRL_STOP)) * 2, color, False) else: if i == self.player.ccolor: self.cons.printex(x, H - 4, ("%c#%c" % (libtcod.COLCTRL_1,libtcod.COLCTRL_STOP)) * 2, color, False) else: self.cons.printex(x, H - 2, ("%c#%c" % (libtcod.COLCTRL_1,libtcod.COLCTRL_STOP)) * 2, color, False) self.cons.printex(x, H - 3, ("%c#%c" % (libtcod.COLCTRL_1,libtcod.COLCTRL_STOP)) * 2, color, False) x += 4 self.cons.printex(0, H - 1, "%c%s%c" % (libtcod.COLCTRL_1,TITLE + " (" + DAY + ")",libtcod.COLCTRL_STOP),libtcod.flame, True) key = self.cons.key() if key.c == ord('q'): break elif self.keyparse(key): self.player.move(self.keyparse(key),self.movecheck) elif key.c == ord('x'): key = libtcod.console_wait_for_keypress(True) if self.keyparse(key): yx2 = self.keyparse(key)[0] + self.player.x yy2 = self.keyparse(key)[1] + self.player.y if self.world.get(yx2,yy2).walkable and self.world.get(yx2,yy2).chr != "~": if self.player.ccolor == 9: self.world.setCell(yx2,yy2,Door()) else: self.world.setCell(yx2,yy2,Block(self.colors[self.player.ccolor])) self.world.updateC(yx2, yy2) continue elif key.c == ord('z'): key = libtcod.console_wait_for_keypress(True) if self.keyparse(key): yx2 = self.keyparse(key)[0] + self.player.x yy2 = self.keyparse(key)[1] + self.player.y if self.world.get(yx2,yy2).diggable and not self.world.get(yx2,yy2).walkable: self.world.setCell(yx2,yy2,Dirt()) self.world.updateC(yx2, yy2) continue elif key.c == ord('c'): key = libtcod.console_wait_for_keypress(True) if self.keyparse(key): yx2 = self.keyparse(key)[0] + self.player.x yy2 = self.keyparse(key)[1] + self.player.y if self.world.get(yx2,yy2).chr == "+" or \ self.world.get(yx2,yy2).chr == "-": self.world.get(yx2,yy2).toggle() self.world.updateC(yx2, yy2) continue
def draw_panel_border(con, w, h): ltc.console_set_default_foreground(con, ltc.white) ltc.console_put_char(con, 0, 0, ltc.CHAR_RADIO_UNSET) ltc.console_put_char(con, w - 1, 0, ltc.CHAR_RADIO_UNSET) ltc.console_put_char(con, 0, h - 1, ltc.CHAR_RADIO_UNSET) ltc.console_put_char(con, w - 1, h - 1, ltc.CHAR_RADIO_UNSET) for x in xrange(w - 2): ltc.console_put_char(con, x + 1, 0, ltc.CHAR_DHLINE) ltc.console_put_char(con, x + 1, h - 1, ltc.CHAR_DHLINE) for y in xrange(h - 2): ltc.console_put_char(con, 0, y + 1, ltc.CHAR_DVLINE) ltc.console_put_char(con, w - 1, y + 1, ltc.CHAR_DVLINE)
def draw_foreground(self, char, color, x, y): libtcod.console_set_default_foreground(self.con, color) libtcod.console_put_char(self.con, x, y, char, libtcod.BKGND_NONE)