Fix event loop.

This commit is contained in:
Nahuel Lofeudo 2022-10-08 10:59:19 +01:00
parent 558fc39eb4
commit e914a0630e
1 changed files with 13 additions and 7 deletions

20
main.py Normal file → Executable file
View File

@ -1,5 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os
from glob import glob from glob import glob
import pygame import pygame
from pygame.locals import * from pygame.locals import *
@ -91,7 +91,6 @@ def main():
pygame.init() pygame.init()
window = init_screen(1920, 720) window = init_screen(1920, 720)
pygame.font.init() pygame.font.init()
window = pygame.display.set_mode(size=(960, 360), flags=DOUBLEBUF, display=1)
font = pygame.font.Font(TEXT_FONT, TEXT_SIZE) font = pygame.font.Font(TEXT_FONT, TEXT_SIZE)
# Paint black # Paint black
@ -102,18 +101,25 @@ def main():
# Main event loop # Main event loop
running = True running = True
while running: while running:
pygame.event.wait(timeout=1) if pygame.event.peek():
for e in pygame.event.get(): for e in pygame.event.get():
if e.type == pygame.QUIT: print(e)
running = False if e.type == pygame.QUIT:
running = False
elif e.type == pygame.KEYDOWN:
if e.key == pygame.K_ESCAPE:
running = False
#end event handling #end event handling
if update_queue.not_empty: if update_queue.qsize() > 0:
clear_screen() clear_screen()
updates = update_queue.get() updates = update_queue.get()
update_screen(updates) update_screen(updates)
pygame.display.flip() pygame.display.flip()
sleep(0.2)
pygame.quit() pygame.quit()
exit(0)
if __name__ == "__main__": if __name__ == "__main__":