0

I can't make the restart button

please help me, please, I want to make a reset button in my project, but I do not know how, I want, provided that when I press r, all these games are reset, that is, if I have a record of 1500 and press r so that the record becomes 0 again, the project tetris works with pygame, if I need the code, I can throw it off when R is pressed. Call a function that resets all variables to their default values.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174

1 Answers1

1

You can detect when 'r' is pressed using keyboard events. Here is a small example:

import pygame

gameDisplay = pygame.display.set_mode((800, 600))


def main():
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_r:
                    print('r pressed!')
                    # Reset variables here or call a function to reset them

        gameDisplay.fill((255, 255, 255))
        pygame.display.update()

main()
Telan
  • 281
  • 1
  • 5