Files
matrixmania/game.py
T
2026-10-22 12:55:07 +02:00

38 lines
995 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import pygame
class Game:
"""Basic Pygame game loop.
Subclasses **must** implement:
* ``update_game`` – update state, return ``False`` to quit.
* ``draw_game`` – render to the screen.
"""
def __init__(self, title: str, fps: int, size: tuple[int, int]):
pygame.init()
self.screen = pygame.display.set_mode(size)
pygame.display.set_caption(title)
self.clock = pygame.time.Clock()
self.fps = fps
self.size = size
def run(self) -> None:
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
running = self.update_game()
self.draw_game()
pygame.display.flip()
self.clock.tick(self.fps)
pygame.quit()
def update_game(self) -> bool:
raise NotImplementedError
def draw_game(self) -> None:
raise NotImplementedError