So, I want to have one part of my code refresh at a certain rate, while the other refreshes instantly.
import pygame
import random
WHITE = (255,255,255)
BLACK = (0,0,0)
RED = (255,0,0)
GREEN = (0,255,0)
BLUE = (0,0,255)
YELLOW = (255,255,0)
PINK = (255,182,193)
INDIGO = (111,0,255)
pygame.init()
pygame.display.set_caption("Game TITLE")
screen = pygame.display.set_mode((400,400))
myText = "Score: 0"
myTextScore = 0
quitVar = True
FPS = 2
fpsClock = pygame.time.Clock()
while quitVar == True:
screen.fill(WHITE)
x = (random.randrange(1, 300))
y = (random.randrange(1, 300))
red_rect = pygame.draw.rect(screen, RED, (x, y, 100, 100))
#this is the code that i want to refresh slower
font = pygame.font.Font('./Roboto-Regular.ttf',20)
text = font.render(myText, True, GREEN)
textRect = text.get_rect(center = (200,350))
screen.blit(text, textRect)
for event in pygame.event.get():
if event.type == pygame.QUIT:
quitVar = False
if event.type == pygame.MOUSEBUTTONDOWN:
position = pygame.mouse.get_pos()
#i want the code below to refresh at a faster rate than what is above
if red_rect.collidepoint(position):
myTextScore += 1
myText = "Score " + str(myTextScore)
pygame.display.update()
fpsClock.tick(FPS)
pygame.quit()
is there a way for different code fps/refreshing different parts at different rates? The fps i have currently affects EVERYTHING in the loop, but i want it to only affect a certain part, while another part goes faster, and refreshes at 10-20 fps instead of the 2 that the other code does. My GOAL is to have a square that moves around the screen, and that when the user clicks on it, their score updates. I am trying to recreate "Whack-A-Mole"