Created
October 22, 2020 12:49
-
-
Save jsbueno/62f27f519fb056d0d48cc138ad4ea751 to your computer and use it in GitHub Desktop.
Pygame "Hello World"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import pygame | |
class GameOver(Exception): | |
pass | |
SIZE = 800,600 | |
def init(): | |
global Screen | |
Screen = pygame.display.set_mode(SIZE) | |
def rcolor() -> tuple: | |
return tuple(random.randrange(0, 256, 20) for _ in "rgb") | |
def process_events(): | |
for event in pygame.event.get(): | |
if event.type == pygame.KEYDOWN: | |
if event.key == pygame.K_ESCAPE: | |
raise GameOver() | |
def main(): | |
while True: | |
Screen.fill(rcolor()) | |
process_events() | |
pygame.display.flip() | |
pygame.time.delay(100) | |
if __name__ == "__main__": | |
try: | |
init() | |
main() | |
finally: | |
pygame.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment