How to make a variable updates itself constantly in pygame? (Making a ball not able to reach a certain height)
So basically I have this code #---------------Configuration statements------------------------------ import pygame import time pygame.init() display_width = 600 display_height = 600 gameDisplay=pygame.display.set_mode((display_width,display_height)) pygame.display.set_caption('Jump') clock = pygame.time.Clock() #-------------colors--------------- black = ((0,0,0)) white=((255,255,255)) #------------Moving objects : circle---------------------------------- x_circle = 50 y_circle = 500 y_circle_change= 0 orientationState = int(0) #0 for idle, 1 for upwards, 2 for downwards radius_circle = 20 def cercle(color,x_circle,y_circle,radius_circle): pygame.draw.circle(gameDisplay,color,[x_circle,y_circle],radius_circle) #_________Static objects : square----------------------------------- crashed = False while not crashed: for event in pygame.event.get(): if event.type == pygame.QUIT: crashed = True if event.type == pygame.KEYDOWN: if event.key==pygame.K_SPACE: y_circle_change = 10 orientationState = int(1) if event.type==pygame.KEYUP: if y_circle<=500 : y_circle_change = 10 orientationState=int(2) if y_circle>=500: orientationState = int(0) if y_circle>=500: y_circle_change = 0 y_circle = 500 orientationState = int(0) if orientationState is int(1): y_circle -= y_circle_change if orientationState is int(2): y_circle+=y_circle_change elif orientationState is int(0): y_circle+=0 pygame.display.update() clock.tick(60) gameDisplay.fill(white) cercle(black,x_circle,y_circle,50) What I am trying to do here is to prevent the circle, which is actually a ball, to be lower than a certain height, what it does instead is it let the ball fall but when I do press