Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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