Skip to content

Instantly share code, notes, and snippets.

@jsbueno
Created October 22, 2020 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsbueno/62f27f519fb056d0d48cc138ad4ea751 to your computer and use it in GitHub Desktop.
Save jsbueno/62f27f519fb056d0d48cc138ad4ea751 to your computer and use it in GitHub Desktop.
Pygame "Hello World"
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