How can I generate the position of a second click in Pygame?

前端 未结 3 647
耶瑟儿~
耶瑟儿~ 2021-01-21 22:40

I\'m making the Towers of Hanoi.

It should work like this: you click on the first tower, from where you want a disk to move, and then on the second where you want the d

3条回答
  •  离开以前
    2021-01-21 23:12

    What I would personally do is put a loop around your code...

    clicklocations = []
    for clicknumber in range(0,1):
        # get the position of the mouse click
        for event in pygame.event.get():
            if event.type == MOUSEBUTTONDOWN:
                mousex, mousey = pygame.mouse.get_pos()
                clicklocations.append([mousex, mousey])
    
     # code for left part of the screen
     if clicklocations[0] in left part of screen, do stuff etc. etc.
     # code for middle part of the screen
     # code for right part of the screen
    

    Something like this.

    Then, you'll have both click locations stored and won't have to rewrite your clicking code twice.

提交回复
热议问题