これまでは配列を単一の変数と比較していました。プレーヤーの位置:配列を比較する方法(完全一致ではない)
for position in ships:
if player_location_x > position[0]-100 and player_location_x < position[0]+100 and player_location_y > position[1]-100 and player_location_y < position[1]+100:
#Do something (e.g. draw bullets between the two locations)
これをどのようにして配列自体の値の比較にも拡張できますか? 「船」のxとyの値を比較して互いの距離をチェックし、xとyの値を「船舶」と「more_ships」の間で比較します。
ships = numpy.array([
[
shuttle_class.npc_x[0],
shuttle_class.npc_y[0],
shuttle_class.img,
shuttle_class.hp
],
[
shuttle_class.npc_x[1],
shuttle_class.npc_y[1],
shuttle_class.img,
shuttle_class.hp
],
[
shuttle_class.npc_x[2],
shuttle_class.npc_y[2],
shuttle_class.img,
shuttle_class.hp
]
])
more_ships = numpy.array([
[
shuttle_class.npc_x[3],
shuttle_class.npc_y[3],
shuttle_class.img,
shuttle_class.hp
],
[
shuttle_class.npc_x[4],
shuttle_class.npc_y[4],
shuttle_class.img,
shuttle_class.hp
],
[
shuttle_class.npc_x[5],
shuttle_class.npc_y[5],
shuttle_class.img,
shuttle_class.hp
]
])
あなたが作ることができる改善の1つは四分木を使用することです。何かが動くたびに、その位置を再計算し、距離を確認するだけで、同じグリッドセクションにあるオブジェクトをチェックするだけですあなたはそうです。 numpyでもっと良い方法があるかもしれませんが、あなたが現在行っている方法では、前にそれを実行することから、それは巨大なスピードの増加を示しています:) – Peter
私はあなたの質問を正しく理解していますか? y1)とmore_ships(配列x2、y2)を使用し、可能な組み合わせごとにペアごとに 'x1-x2'と' y1-y2'を作成しますか? – VBB
@VBBはい、それは正しいです – pytheron