def blind_draw_map(level): for tile in chain(*level.map_grid.tiles): if not in_fov(tile.location, level): tile.explored = False elif same_location(level.player.location, tile.location): tile.explored = True if tile.explored: tcod.console_put_char_ex(con, tile.location.x, tile.location.y, tile_char(level, tile.location), tcod.color.black, tile_colour(level, "DARK", tile.location))
def draw_map(level): for tile in chain(*level.map_grid.tiles): if in_fov(tile.location, level): fov = "LIT" tile.explored = True else: fov = "DARK" if tile.explored: tcod.console_put_char_ex(con, tile.location.x, tile.location.y, tile_char(level, tile.location), tcod.color.black, tile_colour(level, fov, tile.location))
def update_monster_state(level, monster): fov = in_fov(monster.location, level) in_player_room = in_same_room(level.player.location, monster.location, level.map_grid) if monster.hp <= 0: monster.state = "DEAD" elif fov and monster.state == "SNOOZING" and randint(1, 10) < 9: monster.state = "ACTIVE" elif (fov or in_player_room) and "M" in monster.flags and randint(1, 10) < 10: monster.state = "TARGETING" elif fov and monster.state == "ACTIVE" and randint(1, 10) < 8: monster.state = "TARGETING"
def monster_move(level, monster): update_monster_state(level, monster) stationary = "S" in monster.flags is_active = monster.state == "ACTIVE" is_confused = monster.state.startswith("CONFUSED") if is_active or is_confused or is_flying_targeting(monster): x, y = movements[choice(list(movements))] _move(monster, x, y, level, stationary) elif monster.state == "TARGETING": diag = 1.95 if is_transparent(monster.location, level) else 0 try: astar = tcod.path_new_using_map(level.map_grid, diag) tcod.path_compute(astar, monster.location.x, monster.location.y, level.player.location.x, level.player.location.y) next_tile = tcod.path_get(astar, 0) except: print("ASTAR FAILURE") next_tile = (randint(-1, 1), randint(-1, 1)) x, y = (next_tile[0] - monster.location.x, next_tile[1] - monster.location.y) _move(monster, x, y, level, stationary) close = distance_to(monster.location, level.player.location) > 2 if "L" in monster.flags and close and in_fov(monster.location, level): update_screen(level) try: astar = tcod.path_new_using_map(level.map_grid, 1.95) tcod.path_compute(astar, level.player.location.x, level.player.location.y, monster.location.x, monster.location.y) next_tile = tcod.path_get(astar, 0) except: print("ASTAR FAILURE") next_tile = (randint(-1, 1), randint(-1, 1)) x, y = (next_tile[0] - level.player.location.x, next_tile[1] - level.player.location.y) _move(level.player, x, y, level)
def draw_in_map(draw_func, level, item): if ((in_fov(item.location, level) or item.found) and not (hasattr(item, "flags") and "H" in item.flags)): draw_func(item)
def find_stairs(level): if in_fov(level.stairs.location, level): level.stairs.found = True