2016-05-22 7 views
0

for event in pygame.event.get():インスタンスが2つあります。それは第二のものの中では機能しません。私は関数を2回呼び出すことはできないと思います。ここで何をすべきか?ところで、ボードゲームでは、これを正方形から正方形に移動する機能です。通常は動作しません前の呼び出しからのイベントを処理しながら、複数インスタンスのpygame.event.get()

def movement_one(blit1,charac1,screen,squareblitter,boardcoord,placecheck_True): 
    global mouse1, mouse1_des 
    run1=True 
    while run1: 
     for event in pygame.event.get(): 
      if event.type == pygame.QUIT: 
       exit() 
      elif event.type == pygame.MOUSEBUTTONDOWN: 
       mouse1 = pygame.mouse.get_pos() 
       for i in range(80): 
        if squareblitter[i].collidepoint(mouse1): 
         collided = i 
         break 
       print "wow" 
       print i 
       print collided in placecheck_True 
       if collided in placecheck_True: 
        #checks if the square is occupied or not 
        print "wiw" 
        for event in pygame.event.get(): 
         print "wtf" 
         if event.type == pygame.QUIT: 
          exit() 
         elif event.type == pygame.MOUSEBUTTONDOWN: 
          mouse1_des = pygame.mouse.get_pos() 
          print "omg" 
          squareblitter[i] 
          pygame.display.update() 
          for i in range(80): 
           if squareblitter[i].collidepoint(mouse1_des): 
            screen.blit(placecheck_True[collided], squareblitter[i]) 
            placecheck_True.update[i]=placecheck_True[collided] 
            pygame.display.update() 
            run1=False 
            break 
       else: 
        break 

答えて

0

再びpygame.event.get()を呼び出します。あなたのコードから正確にあなたが達成しようとしていることは不明です。しかし、あなたが内部にあるfor eventの内側に衝突しているときにpygame.MOUSEBUTTONDOWNイベントを処理するコードを移動させてください。for eventループを外側にループしてください(そして内部はすべてfor eventループを削除します)。

は、ここで私は(もちろん、テストされていない)の意味は次のとおりです

def movement_one(blit1, charac1, screen, squareblitter, boardcoord, placecheck_True): 
    global mouse1, mouse1_des 
    run1 = True 
    while run1: 
     for event in pygame.event.get(): 
      if event.type == pygame.QUIT: 
       exit() 
      elif event.type == pygame.MOUSEBUTTONDOWN: 
       mouse1 = pygame.mouse.get_pos() 
       for i in range(80): 
        if squareblitter[i].collidepoint(mouse1): 
         collided = i 
         break 
       print "wow" 
       print i 
       print collided in placecheck_True 
       if collided in placecheck_True: 
        mouse1_des = pygame.mouse.get_pos() 
        print "omg" 
        squareblitter[i] 
        pygame.display.update() 
        for i in range(80): 
         if squareblitter[i].collidepoint(mouse1_des): 
          screen.blit(placecheck_True[collided], squareblitter[i]) 
          placecheck_True.update[i] = placecheck_True[collided] 
          pygame.display.update() 
          run1 = False # not sure you should do this... 
          break 
関連する問題