I cant seem to understand the clock function in pygame as much i search and code it if it is possible can you help me with this code that is trying to simply make the square move with the up down left and right arrows and if possible and if you have time simply help me understand the clock system.
import pygame
import sys
pygame.init()
fps = 30
fpsclock=pygame.time.Clock()
window = pygame.display.set_mode((600, 600))
# main application loop
run = True
while run:
# limit frames per second
# event loop
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
# clear the display
window.fill(0)
# draw the scene
color = (255,0,0)
x = 275
y = 275
key_input = pygame.key.get_pressed() #key imputs
pygame.draw.rect(window, color, pygame.Rect(x,y,60,60))
pygame.display.flip()
if key_input[pygame.K_LEFT]:
x - 1
if key_input[pygame.K_RIGHT]:
x + 1
if key_input[pygame.K_DOWN]:
y + 1
if key_input[pygame.K_UP]:
y - 1
pygame.display.update()
fpsclock.tick(fps)
# update the display
pygame.display.flip()
pygame.quit()
exit()