From 90d55e89b78223b820cb37b59fbf2ba2f9d6a23a Mon Sep 17 00:00:00 2001 From: franky212 Date: Mon, 28 Oct 2024 15:06:43 -0600 Subject: [PATCH] Adding in pygame, and getting a window to display/close --- .gitignore | 2 ++ constants.py | 7 +++++++ main.py | 22 ++++++++++++++++++++++ requirements.txt | 1 + 4 files changed, 32 insertions(+) create mode 100644 .gitignore create mode 100644 constants.py create mode 100644 main.py create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4ea05a1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +venv/ +__pycache__/ \ No newline at end of file diff --git a/constants.py b/constants.py new file mode 100644 index 0000000..f9e4d64 --- /dev/null +++ b/constants.py @@ -0,0 +1,7 @@ +SCREEN_WIDTH = 1280 +SCREEN_HEIGHT = 720 + +ASTEROID_MIN_RADIUS = 20 +ASTEROID_KINDS = 3 +ASTEROID_SPAWN_RATE = 0.8 # seconds +ASTEROID_MAX_RADIUS = ASTEROID_MIN_RADIUS * ASTEROID_KINDS \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..0079b64 --- /dev/null +++ b/main.py @@ -0,0 +1,22 @@ +# this allows us to use code from +# the open-source pygame library +# throughout this file +import pygame +from constants import * + +def main(): + pygame.init() + print("Starting asteroids!") + print(f"Screen width: {SCREEN_WIDTH}") + print(f"Screen height: {SCREEN_HEIGHT}") + screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) + + while True: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + return + pygame.Surface.fill(screen, (0, 0, 0)) + pygame.display.flip() + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..893ff6a --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +pygame==2.6.0 \ No newline at end of file