I am a beginner at coding and python and I am trying to create a simple game, where one moves a square in order to prevent small other squares that are coming from the edge of the display from hitting the larger square ("the character"). Here a part of the code:
def figure(x,y):
pygame.draw.rect(gameDisplay, black, (x,y,50,50))
notExit = True
def game_loop(x,x_change,y,y_change):
while(notExit):
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
x_change = -5
if event.key == pygame.K_RIGHT:
x_change = 5
if event.key == pygame.K_UP:
y_change = -5
if event.key == pygame.K_DOWN:
y_change = 5
if event.type == pygame. KEYUP:
x_change = 0
y_change = 0
gameDisplay.fill(white)
x = x + x_change
y = y + y_change
figure(x,y)
if x < 0 or y < 0 or x > 750 or y > 550:
crash()
pygame.display.update()
clock.tick(60)
game_loop(x,x_change,y,y_change)
The basic problem is: How can I let other squares come into the display after a certain amount of time without pausing the entire game for that time? If I use the time.sleep() function, the entire game pauses and the player cannot move the character. Is there another function I could use? Thank You!