私はPythonとPygameを初めて使い、キーボードで演奏されるDance Dance Revolutionの簡単なクローンを設計しています。私は下向きの矢印とその下の静的な矢印との衝突を検出するように設定しており、衝突中に適切なキーの押下を検出するように設定しています。問題は、キープレスのうちのいくつかしか検出しないということです。私はなぜ、そしてコードが私より先に得ているのか分からない。Pygameが衝突ですべてのキーイベントを検出しない
def collisionDetect(arrow, contact_arrow):
return pygame.sprite.collide_rect(arrow, contact_arrow)
def game(list):
running = True
for i in list:
arrow = Arrow(i[0],i[1],0,0,screen,SCREEN_WIDTH,SCREEN_HEIGHT)
arrow.positionArrow()
arrows.add(arrow)
while running:
screen.fill((0,0,0))
arrowleft.drawArrowPanel()
arrowright.drawArrowPanel()
arrowup.drawArrowPanel()
arrowdown.drawArrowPanel()
for arrow in arrows:
if arrow.y < 500:
arrow.arrowFall()
arrow.positionArrow()
collisionLeft = collisionDetect(arrow, arrowleft)
collisionRight = collisionDetect(arrow, arrowright)
collisionUp = collisionDetect(arrow, arrowup)
collisionDown = collisionDetect(arrow, arrowdown)
else:
arrow.kill()
pygame.display.update()
for e in pygame.event.get():
if e.type == pygame.QUIT:
running = False
pygame.quit()
if e.type == pygame.KEYDOWN and e.key == pygame.K_LEFT and collisionLeft:
print "collided left"
if e.type == pygame.KEYDOWN and e.key == pygame.K_RIGHT and collisionRight:
print "collided right"
if e.type == pygame.KEYDOWN and e.key == pygame.K_UP and collisionUp:
print "collided up"
if e.type == pygame.KEYDOWN and e.key == pygame.K_DOWN and collisionDown:
print "collided down"
私はクラス定義をそのまま残して、要求に応じてフェッチすることができます。イベントループは、衝突中に押し下げられている下矢印を検出しますが、それ以外は何も検出しません。このための迅速な修正はありますか?それを処理するより良い方法はありますか?ありがとうございました。
ありがとうございます!完璧な意味合いがあります。 – ineptchimpanzee