如何从精灵组中选择特定的精灵?

时间:2021-04-29 16:06:56

标签: python pygame

所以我一直在尝试为一个游戏项目创建一个迷宫布局,我希望能够从一个精灵组中选择一个特定的精灵,精灵没有一个特定的变量名,因为我已经使用了循环创建 80 个精灵。我想使用该组中的 1 个精灵作为起始位置,并在函数的参数中使用它来返回该“单元格”。但是,通过执行 find_cell((cells[0], "east"), 'cells' 作为精灵组,我收到一条错误消息:“TypeError: 'Group' object is not subscriptable”,这意味着我不能使用 [ ]. 我想知道有没有办法从精灵组中选择一个特定的精灵。

代码:

定义 Main():

WARNING: Value for scheme.headers does not match. Please report this to <https://github.com/pypa/pip/issues/9617>
distutils: /Users/<user>/.pyenv/versions/3.9.4/include/python3.9/UNKNOWN
sysconfig: /Users/<user>/.pyenv/versions/3.9.4/include/python3.9
WARNING: Additional context:
user = False
home = None
root = None
prefix = None
Requirement already satisfied: flake8 in ./.pyenv/versions/3.9.4/lib/python3.9/site-packages (3.9.1)
Requirement already satisfied: mccabe<0.7.0,>=0.6.0 in ./.pyenv/versions/3.9.4/lib/python3.9/site-packages (from flake8) (0.6.1)
Collecting pyflakes<2.4.0,>=2.3.0
  Using cached pyflakes-2.3.1-py2.py3-none-any.whl (68 kB)
Requirement already satisfied: pycodestyle<2.8.0,>=2.7.0 in ./.pyenv/versions/3.9.4/lib/python3.9/site-packages (from flake8) (2.7.0)
Installing collected packages: pyflakes
WARNING: Value for scheme.headers does not match. Please report this to <https://github.com/pypa/pip/issues/9617>
distutils: /Users/<user>/.pyenv/versions/3.9.4/include/python3.9/UNKNOWN
sysconfig: /Users/<user>/.pyenv/versions/3.9.4/include/python3.9
WARNING: Additional context:
user = False
home = None
root = None
prefix = None
Successfully installed pyflakes-2.3.1

错误: 第 56 行,在 Main find_cell(细胞[0],“东”) 类型错误:“组”对象不可下标

0 个答案:

没有答案