Skip to content

Instantly share code, notes, and snippets.

@damp11113
Created March 2, 2024 10:32
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 damp11113/1056a613e0f1d776b302e038bd2c9643 to your computer and use it in GitHub Desktop.
Save damp11113/1056a613e0f1d776b302e038bd2c9643 to your computer and use it in GitHub Desktop.
pygame project template
import sys
import pygame
class Game:
def __init__(self):
# System Variable
self.screen = None
self.clock = None
self.running = False
def init(self):
pygame.init()
# Set up the display
self.screen = pygame.display.set_mode((1280, 720))
pygame.display.set_caption("My Game")
# -------------- add code here --------------
# -------------------------------------------
self.clock = pygame.time.Clock()
self.running = True
while self.running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.exit()
self.render()
# Update the display
pygame.display.flip()
# Cap the frame rate
self.clock.tick(60)
def render(self):
# Game logic
# Drawing
self.screen.fill((255, 255, 255))
def exit(self):
self.running = False
pygame.quit()
sys.exit()
game = Game()
game.init()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment