so I am learning Python via pygame
I am trying to make it that you can click on something to move it
but when (while clicked) loop start the screen freeze (it is as if it's paused) and yes the game itself is responsive and when I click again to stop the loop actually stops as it should do and the game goes on
the thing is, when I click to stop moving the ship or whatever it actually moves to where the mouse is as it should be doing
but no, when the loop is going, nothing moves on the screen, however the position of the Player is actually following the mouse, so the loop is kind of working
is there something I am missing here?
def main():
run = True
clicked = False
while run:
clock.tick(FPS)
events = pygame.event.get()
for event in events:
if event.type ==pygame.QUIT:
run = False
Draw_Background(Light_Yellow)
Draw_WIN(Player1, Player2)
Player1_move()
Player2_move()
Shooting(events)
# here it gets user click and set clicked to true
for event in events:
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button ==1:
Mouse_Pos= pygame.mouse.get_pos()
if Mouse_Pos[0]>= Player1.x and Mouse_Pos[0]<=Player1.x+Player_Ship_Width and Mouse_Pos[1]>= Player1.y and Mouse_Pos[1]<= Player1.y+Player_Ship_Hight:
print("Ship Clicked")
clicked = True
#here it should make the object follow the mouse and when clicked it stops
while clicked:
Mouse_Pos = pygame.mouse.get_pos()
Player1.x = Mouse_Pos[0]-Player_Ship_Width//2
Player1.y = Mouse_Pos[1]-Player_Ship_Hight//2
events2 = pygame.event.get()
for event in events2:
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button ==1:
Mouse_Pos = pygame.mouse.get_pos()
if Mouse_Pos[0]>= Player1.x and Mouse_Pos[0]<=Player1.x+Player_Ship_Width and Mouse_Pos[1]>= Player1.y and Mouse_Pos[1]<= Player1.y+Player_Ship_Hight:
clicked = False
print ("Stopped")
pygame.display.update()