我会尽量做到简明扼要。
下面是tcod Rouguelike教程的链接:
http://rogueliketutorials.com/tutorials/tcod/
我正在使用PyCharm社区版,尽管我不认为有多重要。直到第4部分结束之前,一切都进行得很顺利,在第4部分中,我们为播放器实现了一个FOV。当我尝试使用以下代码运行主引擎时(在教程中给出):
def recompute_fov(fov_map, x, y, radius=1, light_walls=True, algorithm=0):
libtcod.map_compute_fov(fov_map, x, y, radius, light_walls, algorithm)编译器输出以下错误:
File "C:\Users\drago\anaconda3\envs\Roguelike\lib\site-packages\tcod\libtcodpy.py", line 3320, in map_compute_fov
m.compute_fov(x, y, radius, light_walls, algo)
AttributeError: 'NoneType' object has no attribute 'compute_fov'
Process finished with exit code 1至少我知道的足够多,我知道它是在谈论tcod包本身。但我不明白。谢天谢地,PyCharm给了我一点见解.
所以我听从它的建议,把libtcod.map_compute_fov改成了libtcod.map.compute_fov
这又给了我一个错误:
File "C:\Users\drago\PycharmProjects\Roguelike\map_objects\fov_functions.py", line 13, in recompute_fov
libtcod.map.compute_fov(fov_map, x, y, radius, light_walls, algorithm)
TypeError: compute_fov() takes from 2 to 5 positional arguments but 6 were given
Process finished with exit code 1因此,PyCharm再次能够告诉我这个新函数,以及它如何使用不同的值。它使用的不是FOV_map,而是一个名为pov的东西,该pov需要一个由2个值组成的数组。这也与透明度有关,在这一点上,为了我想要实现的目标,透明度已经超出了我的头脑。
我仍然在学习Python,因此也就是教程。我知道数组是什么。但是我不知道如何使我现有的代码与这个新的函数/模块一起工作(我把这两个函数/模块混在一起),因为旧的代码被折旧了。
任何帮助都将不胜感激。
我也在使用Python3.8。
发布于 2020-07-14 18:47:17
我只是遇到了同样的问题
def recompute_fov(fov_map, x, y, radius, light_walls=True, algorithm=0):
libtcod.map_compute_fov(fov_map, x, y, radius, light_walls, algorithm)在fov_functions.py代码的末尾,修复了
"AttributeError:'NoneType‘对象没有属性'compute_fov'“
我和你一样有问题。
下面是教程作者(从第4部分开始)如何设置fov_functions.py:
import libtcodpy as libtcod
def initialize_fov(game_map):
fov_map = libtcod.map_new(game_map.width, game_map.height)
for y in range(game_map.height):
for x in range(game_map.width):
libtcod.map_set_properties(fov_map, x, y, not game_map.tiles[x][y].block_sight,
not game_map.tiles[x][y].blocked)
return fov_map
def recompute_fov(fov_map, x, y, radius, light_walls=True, algorithm=0):
libtcod.map_compute_fov(fov_map, x, y, radius, light_walls, algorithm)下面是指向第4部分代码的链接,作者将其放在教程的每个部分的末尾:订正/树/部分4 --这是我与我的fov_functions文件相比较的地方。
作者将代码放在每个部分的末尾:https://i.stack.imgur.com/AgjCp.png
希望这能帮到你!
https://stackoverflow.com/questions/62344344
复制相似问题