Created
March 2, 2024 10:32
-
-
Save damp11113/1056a613e0f1d776b302e038bd2c9643 to your computer and use it in GitHub Desktop.
pygame project template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
new update add event handle