Here is how I'm implementing my simple pygames now (I'm following a tutorial):
import pygame, sys
from pygame.locals import *
def run_game():
pygame.init()
SIZE = (640, 400)
BG_COLOUR = (0, 0, 0)
LINE_COLOUR = (255, 255, 255)
screen = pygame.display.set_mode(SIZE)
clock = pygame.time.Clock()
while True:
time_passed = clock.tick(30)
for event in pygame.event.get():
if event.type == QUIT:
exit_game()
screen.fill(BG_COLOUR)
pygame.draw.aaline(screen, LINE_COLOUR, (1, 1), (639, 399))
pygame.display.flip()
def exit_game():
sys.exit()
if __name__ == "__main__"
run_game()
I've also seen a keeprunning flag being used to exit the main event loop instead, as well as using pygame.event.poll()
instead of looping through pygame.event.get()
. Any suggestions? Anything at all like case/naming of variables, anything to make it more effective or readable. Thanks.