Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Pygame-更新敌方角色所获得的牌 问题_Python_Pygame - Fatal编程技术网

Python Pygame-更新敌方角色所获得的牌 问题

Python Pygame-更新敌方角色所获得的牌 问题,python,pygame,Python,Pygame,我有一个250+敌方外星人的滚动游戏,我想实现基本的群体行为,甚至可能是目标导向的寻路。 为此,我认为实现一个tile系统将是最好的。问题是,获取每个外星人的位置并使用它来“阻止”它所在的磁贴,对于我的实现来说太慢了。 您能否帮助我更好地实施或了解如何实现更好的性能 安装程序 我创建了一个tilemap,它是一个数组,self.tiles,包含作为字典的tile,每个tile是一个16px的矩形。(每个外星人大约16像素宽)。 为了检索每个磁贴,我有一个数组,self.chunks\u loca

我有一个250+敌方外星人的滚动游戏,我想实现基本的群体行为,甚至可能是目标导向的寻路。 为此,我认为实现一个tile系统将是最好的。问题是,获取每个外星人的位置并使用它来“阻止”它所在的磁贴,对于我的实现来说太慢了。 您能否帮助我更好地实施或了解如何实现更好的性能

安装程序 我创建了一个tilemap,它是一个数组,
self.tiles
,包含作为字典的tile,每个tile是一个16px的矩形。(每个外星人大约16像素宽)。 为了检索每个磁贴,我有一个数组,
self.chunks\u location
,包含所有磁贴坐标

每个外星人将其(x,y)传递给下面的函数,将其(x,y)转换为16的multipel。 然后在
self.chunks\u位置
中查找转换后的(x,y),检索到的索引用于在
self.tiles
中阻止相应的tile


功能:转换(x,y)

(该函数最初用于输出多个磁贴坐标,如果外星人正好位于两个磁贴之间,那么现在看起来有点奇怪。)

功能块磁贴

基于先前转换的坐标块平铺

def block_块(自身,数组):
如果len(数组)==1:
target=self.chunks\u location.index(数组[0])
self.chunks[target][“blocked”]=True
self.chunks\u blocked.append(self.chunks[target])
其他:
对于阵列中的跳线:
target=self.chunks\u location.index(跳线)
self.chunks[target][“blocked”]=True
self.chunks\u blocked.append(self.chunks[target])
请提供所需信息。显示中间结果与预期结果的偏差。我们应该能够将单个代码块粘贴到文件中,运行它,并重现您的问题。这也让我们可以在您的上下文中测试任何建议。请提供预期结果。显示中间结果与预期结果的偏差。我们应该能够将单个代码块粘贴到文件中,运行它,并重现您的问题。这也让我们可以在您的上下文中测试任何建议。
def get_chunks_from_cord(self, x, y):
    """
    Returns the chunk or chunks for the given location on the map, based on the tilesize of the map.
    Being in between chunks leads to multiple chunks being returned.

    (float or int) -> [tuple(int, int)]
    (20, 58)    ->  [[16, 68]]
    """

    """
    Adds the cords separate rounded to 16 to tilesize coordinates to the blocked list.
    """

    decimal_16 = [x % self.chunksize, y % self.chunksize]
    blocked = [[], []]  # [[x values], [y values]]
    for cnt, cord in enumerate((x, y)):
        if decimal_16[cnt] >= self.chunksize_05:
            blocked[cnt].append(cord + self.chunksize - decimal_16[cnt])
        else:
            blocked[cnt].append(cord - decimal_16[cnt])


    result = []
    for array in blocked[0]:
        for var in blocked[1]:
            result.append((round(array), round(var)))

    return result