我正在尝试代码的一个游戏,将处理碰撞检测部分。现在看起来像这样
def collision_detection(player_x, player_y):
movment_ok=1
cannot_go_onto=[[0,20,20,40],[520,500,480,460]] #coordinates with no access. X, Y
if player_x in cannot_go_onto[0]:
location_in_array=cannot_go_onto[0].index(int(player_x))
if player_y==cannot_go_onto[1][location_in_array]:
print("collision detection")
movment_ok=0
return movment_ok
这对坐标(0,520)
、(20,500)
&;(40,460)
很好,但对坐标(20,480)
不起作用。我想这是因为排队
location_in_array=cannot_go_onto[0].index(int(player_x))
索引搜索返回1
,因为它只需要20
第一次出现在数组中两次。因此,只有位置(20,500)
在数组中首先出现时才被检查。但是我不知道怎么解决这个问题。任何想法/帮助都将不胜感激。你知道吗
仅仅有一个不可访问的坐标数组,而不是两个独立的列表,不是更简单吗。你知道吗
编辑:
相关问题 更多 >
编程相关推荐