Skip to content

Instantly share code, notes, and snippets.

@natebot13
Created August 15, 2017 18:51
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 natebot13/bd8fba5084aa77273cf5a08b4355dc39 to your computer and use it in GitHub Desktop.
Save natebot13/bd8fba5084aa77273cf5a08b4355dc39 to your computer and use it in GitHub Desktop.
Pygame Basic Template
import pygame
# initialize game engine
pygame.init()
# set screen width/height and caption
WIDTH = 640
HEIGHT = 480
SIZE = (WIDTH, HEIGHT)
screen = pygame.display.set_mode(SIZE)
pygame.display.set_caption('My Game')
# initialize clock. used later in the loop.
CLOCK = pygame.time.Clock()
FPS = 60
# Loop until the user clicks close button
running = True
while running:
# write event handlers here
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# write game logic here
# clear the screen before drawing
screen.fill((255, 255, 255))
# write draw code here
# display what’s drawn. this might change.
pygame.display.update()
# run at 20 fps
CLOCK.tick(FPS)
# close the window and quit
pygame.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment