i'm trying to build a battleship table game using pygame.
i would like to detect the events pygame.MOUSEBUTTONDOWN and and match it with the following pygame.MOUSEBUTTONUP.
i'm trying to do this because i wanted to pass the coordinates at which blitting the Ship surface on the screen.
def main():
#click=True
run=True
clock=pygame.time.Clock()
while run:
clock.tick(fps)
#print(pygame.mouse.get_pos())
for event in pygame.event.get():
l=[]
if event.type == pygame.QUIT:
pygame.quit()
return
if (event.type==pygame.MOUSEBUTTONDOWN):
pos_start=pygame.mouse.get_pos()
x_start=pos_start[0]
y_start=pos_start[1]
cell_coord_start=b.get_coord(x_start, y_start)#b is a pygame.display
l.append(cell_coord_start)
x_end=0
y_end=0
#click=True
print("start", l)
for eve in pygame.event.get():
while eve.type!=pygame.MOUSEBUTTONUP:
print("loop")
if (event.type==pygame.MOUSEBUTTONUP):
pos_end=pygame.mouse.get_pos()
x_end+=pos_end[0]
y_end+=pos_end[1]
print(x_end)
print(y_end)
#click=False
cell_coord_end=b.get_coord(x_end, y_end)
l.append(cell_coord_end)
#print("start, end", l)
#print(cell_coord_end)
the output is okay until the second event loop, where it does not seem to enter the while loop at all. what i would like to do, at least in my mind is: "after having found a buttondown event, go ahead until you find a mousebuttonup event, save its position etc"
probably the problem is that i am trying to nest event loops, but i would not know how to do this without the double loop. i suppose it would be more convenient to do all that inside a function, but the logic behind should be the same i guess so the problem would persist anyway.
thank you