From 7bb88bbf487f5d3bb766c948ed95291ba38cbeae Mon Sep 17 00:00:00 2001 From: Skullheadx <704277@pdsb.net> Date: Mon, 16 Jan 2023 17:29:44 -0500 Subject: [PATCH] pygame window --- .gitignore | 10 ++++++++++ colours.py | 7 +++++++ display.py | 38 ++++++++++++++++++++++++++++++++++++++ main.py | 10 ++++++++++ 4 files changed, 65 insertions(+) create mode 100644 .gitignore create mode 100644 colours.py create mode 100644 display.py create mode 100644 main.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..57dde53 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +.idea/ +__pycache__/ diff --git a/colours.py b/colours.py new file mode 100644 index 0000000..370c4d9 --- /dev/null +++ b/colours.py @@ -0,0 +1,7 @@ +RED = (255, 0, 0) +GREEN = (0, 255, 0) +BLUE = (0, 0, 255) + +BLACK = (0, 0, 0) +GRAY = (128, 128, 128) +WHITE = (255, 255, 255) diff --git a/display.py b/display.py new file mode 100644 index 0000000..2bf647a --- /dev/null +++ b/display.py @@ -0,0 +1,38 @@ +from colours import * +import pygame + + +pygame.init() + + +class Display: + WIDTH, HEIGHT = 640, 640 + DIMENSIONS = pygame.Vector2(WIDTH, HEIGHT) + CENTER = pygame.Vector2(WIDTH / 2, HEIGHT / 2) + + FPS = 60 + + def __init__(self, window_name="Pygame"): + self.is_running = False + pygame.display.set_caption(window_name) + + def show(self): + screen = pygame.display.set_mode(self.DIMENSIONS) + + clock = pygame.time.Clock() + delta = 0 + self.is_running = True + while self.is_running: + self.update(delta) + self.draw(screen) + pygame.display.flip() + delta = clock.tick(self.FPS) + pygame.quit() + + def update(self, delta): + for event in pygame.event.get(): + if event.type == pygame.QUIT: + self.is_running = False + + def draw(self, surf): + surf.fill(WHITE) diff --git a/main.py b/main.py new file mode 100644 index 0000000..ee74ed5 --- /dev/null +++ b/main.py @@ -0,0 +1,10 @@ +from display import Display + + +def main(): + d = Display() + d.show() + + +if __name__ == "__main__": + main() -- 2.54.0