def render_dijkstra(self, dijkstra, console: Console) -> None: dijkstra = np.where(dijkstra == np.iinfo(np.int32).max, -1, dijkstra) max_distance = np.amax(dijkstra) for (x, y), value in np.ndenumerate(self.grid): if dijkstra[x, y] > 0: console.bg[x, y] = tcod.color_lerp( COLORS.get('dijkstra_near'), COLORS.get('dijkstra_far'), 0.9 * dijkstra[x, y] / max_distance)
def draw_terrain(self): hn = self.wmap.terrain_to_hm('elevation') amin, max = hn.get_minmax() for i in range(hn.width): for j in range(hn.height): color = tcod.color_lerp(tcod.dark_blue, tcod.white, hn[i, j] / max) self.world_canvas.draw_char(i, j, ' ', fg=tcod.white, bg=color)
def simulate(self): self.x += self.vx self.y += self.vy self._fadec += self.fade self.col = tcod.color_lerp(self.col, (0, 0, 0), self._fadec) self.vx += self.ax self.vy += self.ay self.life -= 1
def draw_elevations(self, as_color=True): for x in range(self.map_width): for y in range(self.map_height): if as_color: intensity = tcod.color_lerp(tcod.black, tcod.white, self.elevation[x, y]) self.map_console.buffer.background[x, y, 0] = intensity.r self.map_console.buffer.background[x, y, 1] = intensity.g self.map_console.buffer.background[x, y, 2] = intensity.b self.map_console.fill_from_buffer(False, True)
def insanize_color(color, sanity): if sanity < 50: color2 = choice([ T.black, T.white, T.green, T.yellow, T.sky, T.red, T.pink]) # 0.0 .. 0.4 d = 0.4*(1 - sanity / 50.0) color = T.color_lerp(color, color2, d) return color else: return color
def PrecipGradMap( World, ): # ------------------------------------------------------------ Print Map (Precipitation Gradient) white -> low blue -> high -------------------------------- for x in range(WORLD_WIDTH): for y in range(WORLD_HEIGHT): tempv = World[x][y].precip tempcolor = tcod.color_lerp(tcod.white, tcod.light_blue, tempv) tcod.console_put_char_ex( 0, x, y + SCREEN_HEIGHT / 2 - WORLD_HEIGHT / 2, "\333", tempcolor, tcod.black, ) tcod.console_flush() return
def TempGradMap( World, ): # ------------------------------------------------------------ Print Map (Surface Temperature Gradient) white -> cold red -> warm -------------------------------- for x in range(WORLD_WIDTH): for y in range(WORLD_HEIGHT): tempv = World[x][y].temp tempcolor = tcod.color_lerp(tcod.white, tcod.red, tempv) tcod.console_put_char_ex( 0, x, y + SCREEN_HEIGHT / 2 - WORLD_HEIGHT / 2, "\333", tempcolor, tcod.black, ) tcod.console_flush() return
def ProsperityGradMap( World, ): # ------------------------------------------------------------ Print Map (Prosperity Gradient) white -> low green -> high -------------------------------- for x in range(WORLD_WIDTH): for y in range(WORLD_HEIGHT): prosperitynv = World[x][y].prosperity prosperitycolor = tcod.color_lerp( tcod.white, tcod.darker_green, prosperitynv ) tcod.console_put_char_ex( 0, x, y + int(SCREEN_HEIGHT / 2) - int(WORLD_HEIGHT / 2), "\333", prosperitycolor, tcod.black, ) tcod.console_flush() return
def DrainageGradMap( World, ): # ------------------------------------------------------------ Print Map (Drainage Gradient) brown -> low white -> high -------------------------------- for x in range(WORLD_WIDTH): for y in range(WORLD_HEIGHT): drainv = World[x][y].drainage draincolor = tcod.color_lerp( tcod.darkest_orange, tcod.white, drainv ) tcod.console_put_char_ex( 0, x, y + SCREEN_HEIGHT / 2 - WORLD_HEIGHT / 2, "\333", draincolor, tcod.black, ) tcod.console_flush() return
def test_color(): color_a = libtcodpy.Color(0, 1, 2) assert list(color_a) == [0, 1, 2] assert color_a[0] == color_a.r assert color_a[1] == color_a.g assert color_a[2] == color_a.b color_a[1] = 3 color_a['b'] = color_a['b'] assert list(color_a) == [0, 3, 2] assert color_a == color_a color_b = libtcodpy.Color(255, 255, 255) assert color_a != color_b color = libtcodpy.color_lerp(color_a, color_b, 0.5) libtcodpy.color_set_hsv(color, 0, 0, 0) libtcodpy.color_get_hsv(color) libtcodpy.color_scale_HSV(color, 0, 0)
def render_viewport(console, mouse_pos, mouse_targets, game_map, entities, fov_map, enemy_fov_map, fov_recompute, toggle_reveal_all, view_x_start, view_x_end, view_y_start, view_y_end, viewport_width_start, viewport_height_start, default_tile=1): # print('render_viewport', fov_recompute) # if fov_recompute: # Obtain all Center Coordinates # Render Walls and Floors lerp_color = (128, 64, 64) for y in range(view_y_start, view_y_end): for x in range(view_x_start, view_x_end): try: 1 // (abs(y + 1) + y + 1) 1 // (abs(x + 1) + x + 1) tile = game_map.tileset_tiles[y][x] visible = fov_map.fov[x][ y] # Check if tile is visible at (x, y) # enemy_fov = enemy_fov_map[y][x] # Check if tile is visible to enemy at (x, y) walkable = not game_map.walkable[y][x] explored = game_map.explored[y][x] except: # except IndexError or ZeroDivisionError: # print('IndexError!') # print(view_x_start, view_x_end) # print(view_y_start, view_y_end) # print(game_map.width, game_map.height) # print('x/y:', x, y) # print(len(game_map.tileset_tiles), len(game_map.tileset_tiles)) tile = default_tile visible = False # enemy_fov = False walkable = False explored = True # sys.exit() # wall = not game_map.walkable[y][x] # Check if tile is a wall at (x, y) # Add Highlight to Entity and Entity's FOV enemy_fov = False lerp_val = 0.5 * enemy_fov * walkable # print('lerp_val:', lerp_val) # if (x, y) in room_centers: # tile = 3 tile_fg_color = game_map.tile_set[str(tile)].get( 'fg_color', tcod.white) # Select Tile if toggle_reveal_all: visible = True if visible: tile_color = game_map.tile_set[str(tile)].get('color') tile_char = game_map.tile_set[str(tile)].get('glyph') game_map.explored[y][x] = True # if enemy_fov: # Check if tile is visible to enemy at (x, y): # TODO: Lerp the value based on distance from entity lerp_val = 0.25 * enemy_fov * (not walkable) # print('lerp_val', lerp_val, enemy_fov, walkable) # lerp_val = 0.5 # Tile Has Been Seen Before, but not in Current FOV elif explored or toggle_reveal_all == 1: # Darken Color tile_color = color_lerp( game_map.tile_set[str(tile)].get('color'), (0, 0, 0), 0.75) tile_char = game_map.tile_set[str(tile)].get('glyph') tile_fg_color = color_lerp(tile_fg_color, (0, 0, 0), 0.75) # Unexplored Area else: tile = 0 tile_color = game_map.tile_set[str(tile)].get('color') tile_char = game_map.tile_set[str(tile)].get('glyph') # if 'wall' in tile_name: # mask_char_list = [35, 186, 186, 186, 205, 188, 187, 185, 205, 200, 201, 204, 205, 202, 203, 35] # tile_char = game_map.tile_set[tile_name].get(tile) # mask = 0 # for c in [(x, y - 1, 1), (x, y + 1, 2), (x - 1, y, 4), (x + 1, y, 8)]: # c1, c2, c_ind = c[0], c[1], c[2] # if game_map.is_within_map(c1, c2): # if not game_map.walkable[c2][c1]: # mask += c_ind # # # let mut mask : u8 = 0; # # # # if is_revealed_and_wall(map, x, y - 1) { mask +=1; } # # if is_revealed_and_wall(map, x, y + 1) { mask +=2; } # # if is_revealed_and_wall(map, x - 1, y) { mask +=4; } # # if is_revealed_and_wall(map, x + 1, y) { mask +=7; } # # # # walls: # # 0 => { 9 } // Pillar because no walls ○ # # 1 => { 186 } // Wall only to the north ║ # # 2 => { 186 } // Wall only to the south ║ # # 3 => { 186 } // Wall to the north and south ║ # # 4 => { 205 } // Wall only to the west ═ # # 5 => { 188 } // Wall to the north and west ╝ # # 6 => { 187 } // Wall to the south and west ╗ # # 7 => { 185 } // Wall to the north, south and west ╣ # # 8 => { 205 } // Wall only to the east ═ # # 9 => { 200 } // Wall to the north and east ╚ # # 10 => { 201 } // Wall to the south and east ╤ # # 11 => { 204 } // Wall to the north, south and east ╠ # # 12 => { 205 } // Wall to the east and west ═ # # 13 => { 202 } // Wall to the east, west, and south ╩ # # 14 => { 203 } // Wall to the east, west, and north ╦ # try: # tile_char = mask_char_list[mask] # except: # print('mask:', mask) # else: # tile_char = game_map.tile_set[tile_name].get('char') # Normalize Position correct_x = x - view_x_start - viewport_width_start correct_y = y - view_y_start - viewport_height_start # Highlight Mouse Position # TODO: Area of affect or mouse path highlighting # print("mouse_targets:", mouse_targets) is_mouse_pos = (x, y) in mouse_targets # is_mouse_pos = ((x, y) == mouse_pos) * ((x, y) in mouse_targets) color_val = color_lerp(tuple(tile_color), lerp_color, lerp_val) # highlight if within monster FOV color_val = color_lerp(color_val, tcod.white, is_mouse_pos * 0.4) # highlight if under mouse render_tile(console, correct_x, correct_y, color_val, tile_char, fg_color=tile_fg_color)
def render_object(console, object, x_offset, y_offset, viewing_mode): if viewing_mode == 0: x = 0 y = 0 for x_list in object.tiles: y = 0 for part_list in object.tiles[x]: for part in part_list: if part.sorting_index <= Part.SORTING_MAIN: char, fg, bg = part.get_render(object, x, y) console.put_char(x + x_offset, y + y_offset, char) console.fg[x + x_offset, y + y_offset] = fg if bg is not None: console.bg[x + x_offset, y + y_offset] = bg y += 1 x += 1 elif viewing_mode == 1: for room in object.gas_rooms: color = tcod.red if room.exposed else ( tcod.orange if room.calc_pressure() == 0 else tcod.color_lerp( tcod.darkest_blue, tcod.lighter_blue, room.calc_pressure() / 120)) for coord in room.tiles: console.put_char(coord[0] + x_offset, coord[1] + y_offset, ord(' ')) console.bg[coord[0] + x_offset, coord[1] + y_offset] = color elif 2 <= viewing_mode <= 8: if viewing_mode in view_dict: x = 0 y = 0 for x_list in object.tiles: y = 0 for part_list in object.tiles[x]: if len(part_list) > 0: char, fg, bg = part_list[-1].get_render(object, x, y) fg = tcod.light_gray bg = None for part in reversed(part_list): new_char, new_fg, new_bg = part.get_render( object, x, y) if view_dict[viewing_mode](part): char, fg = new_char, new_fg if viewing_mode in color_view_dict: fg = color_view_dict[viewing_mode](part, fg) else: if char == ' ' or char == '': char = new_char if new_bg and not bg: if part.sorting_index != Part.SORTING_FRAME: bg = tcod.darker_gray else: bg = new_bg if fg is not None: console.put_char(x + x_offset, y + y_offset, char) console.fg[x + x_offset, y + y_offset] = fg if bg is not None: console.bg[x + x_offset, y + y_offset] = bg y += 1 x += 1
def main_menu(): global game_state, lg_color, monsters, every_item, every_trap, esp_range, root, BORDER_STYLE, e1, nama,fov_recompute print(CTML.shell) if CTML.shell != 1: BORDER_STYLE = 1 esp_range = 0 monsters = [] every_item = [] every_trap = [] nama = 'Rodney' while not tcod.console_is_window_closed() and game_state != 'quit': # show the background image, at twice the regular console resolution color_1 = tcod.gold color_2 = tcod.darkest_green logo_color = [tcod.color_lerp(color_1, color_2, 0.0), tcod.color_lerp(color_1, color_2, 0.1), tcod.color_lerp(color_1, color_2, 0.2), tcod.color_lerp(color_1, color_2, 0.3) , tcod.color_lerp(color_1, color_2, 0.4), tcod.color_lerp(color_1, color_2, 0.5), tcod.color_lerp(color_1, color_2, 0.6), tcod.color_lerp(color_1, color_2, 0.7), tcod.color_lerp(color_1, color_2, 0.8), tcod.color_lerp(color_1, color_2, 0.9), tcod.color_lerp(color_1, color_2, 1.0), tcod.color_lerp(color_1, color_2, 1.0), tcod.color_lerp(color_1, color_2, 0.9), tcod.color_lerp(color_1, color_2, 0.8), tcod.color_lerp(color_1, color_2, 0.7), tcod.color_lerp(color_1, color_2, 0.6), tcod.color_lerp(color_1, color_2, 0.5), tcod.color_lerp(color_1, color_2, 0.4), tcod.color_lerp(color_1, color_2, 0.3), tcod.color_lerp(color_1, color_2, 0.2), tcod.color_lerp(color_1, color_2, 0.1), tcod.color_lerp(color_1, color_2, 0.0)] # show the game's title, and some credits! if lg_color > 0: time.sleep(1) tcod.console_set_default_foreground(0, logo_color[lg_color]) lg_color -= 1 elif lg_color <= 0: time.sleep(1) lg_color = 21 tcod.console_set_default_foreground(0, logo_color[lg_color]) tcod.console_print_ex(0, SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2 - 10, tcod.BKGND_NONE, tcod.CENTER, '') tcod.console_print_ex(0, SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2 - 9, tcod.BKGND_NONE, tcod.CENTER, '____ ____ _ _ ____ ____ ____ ____ ___ _ _ ____ ') tcod.console_print_ex(0, SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2 - 8, tcod.BKGND_NONE, tcod.CENTER, '| |__| | | |___ [__ | | |___ | |__| |___ ') tcod.console_print_ex(0, SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2 - 7, tcod.BKGND_NONE, tcod.CENTER, '|___ | | \/ |___ ___] |__| | | | | |___ ') tcod.console_print_ex(0, SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2 - 6, tcod.BKGND_NONE, tcod.CENTER, ' _ _ ____ ___ _ _ ____ _ _ ') tcod.console_print_ex(0, SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2 - 5, tcod.BKGND_NONE, tcod.CENTER, ' |\/| |__| | \ | | | |__| ') tcod.console_print_ex(0, SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2 - 4, tcod.BKGND_NONE, tcod.CENTER, ' | | | | |__/ |___ | |___ | | ') tcod.console_set_default_foreground(0, tcod.gold) tcod.console_print_ex(0, SCREEN_WIDTH // 2, SCREEN_HEIGHT - 4, tcod.BKGND_NONE, tcod.CENTER, 'By Gabriel_cmf') # show options and wait for the player's choice choice = menu('', ['New game', 'Continue game', 'High scores', 'Quit'], 24, False, None, False, False) if choice == 0: # new game try: #print(abc) CTML.load_game except: master = tk.Tk() tk.Label(master, text="Name").grid(row=0) e1 = tk.Entry(master) e1.grid(row=0, column=1) e1.delete(0, tk.END) tk.Button(master, text='Show', command=set_name).grid(row=3, column=1, sticky=tk.W, pady=4) tk.mainloop() CTML.new_game() CTML.play_game() else: # render_all() choice = menu( 'A save file has been detected, starting a new game will erase it, do you wish to proceed', ['No', 'Yes'], 24, True, 'WARNING', tcod.red) if choice == 1: tcod.console_flush() master = tk.Tk() tk.Label(master, text="Name").grid(row=0) e1 = tk.Entry(master) e1.grid(row=0, column=1) tk.Button(master, text='Show', command=set_name).grid(row=3, column=1, sticky=tk.W, pady=4) tk.mainloop() master.mainloop() if nama != None: CTML.new_game() CTML.play_game() return 'wait' if choice == 1: # load last game try: print('hello') CTML.load_game '''tcod.console_flush() CTML.render_all()''' except: print('no game to load') msgbox('\n No saved game to load.\n', 24) else: print('load') CTML.load_game() CTML.play_game() return 'wait' #fov_recompute = True if choice == 2: try: print('ei') # load_scores() except: msgbox('\n No high scores where found.\n', 24) return 'wait' if choice == 3: # quit break