次のような for ループを実行するタイル マップがあります。
def Draw_Level( x, y, column, obsticles, entities, image_cache ):
#Grass#
if column == "G":
g = Grass(x, y, image_cache)
entities.add(g)
#Plain Grass#
elif column == "P":
p = Plain_Grass(x,y, image_cache)
entities.add(p)
#Grass with yellow flower#
elif column == "F":
f = Grass_Flower(x,y, image_cache)
entities.add(f)
#Grass To Sand (50/50 split block) Direct#
elif column == "Y":
q = Grass_To_SandD(x,y, image_cache)
entities.add(q)
#Example If a class
class Grass(Entity):
def __init__(self, x, y, image_cache):
Entity.__init__(self)
self.image = functions.get_image("data/images/Grass.png", image_cache)
self.image.convert()
self.rect = Rect(x, y, 32, 32)
たとえば、マウスがこれらのいずれかをクリックし、x と y が最も近い 32 (ブロックの幅と高さ) に決定されたとします。どのスプライトがクリックされたかを判断するにはどうすればよいですか? たとえば、「草」ブロックをクリックすると、その草ブロックが画面に描画される座標が表示されますが、どうすればそれを削除できますか?
Entites = すべてのエンティティを保持するリスト
エンティティ リストから呼び出す方法はありますか? リストを介してRectを呼び出すと混乱するので、行き詰まっています:S.