From 11c3d7ae9c01d0f8aeec7451b20323e0ab399a51 Mon Sep 17 00:00:00 2001 From: Skullheadx <94652084+Skullheadx@users.noreply.github.com> Date: Thu, 1 Jun 2023 12:52:45 -0400 Subject: [PATCH] game class --- game.py | 15 +++++++++++++++ main.py | 15 ++++++++++----- setup.py | 4 ++++ 3 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 game.py diff --git a/game.py b/game.py new file mode 100644 index 0000000..b3575da --- /dev/null +++ b/game.py @@ -0,0 +1,15 @@ +from setup import * + + +class Game: + + def __init__(self): + pass + + def update(self, delta): + for event in pygame.event.get(): + if event.type == pygame.QUIT: + return COMMAND_EXIT + + def draw(self, surf): + screen.fill(WHITE) diff --git a/main.py b/main.py index cd398ce..0b5ea11 100644 --- a/main.py +++ b/main.py @@ -1,15 +1,20 @@ from setup import * +from game import Game FPS = 120 clock = pygame.time.Clock() +scene = Game() + is_running = True while is_running: - clock.tick(FPS) - for event in pygame.event.get(): - if event.type == pygame.QUIT: - is_running = False - screen.fill(WHITE) + delta = clock.tick(FPS) + status = scene.update(delta) + scene.draw(screen) pygame.display.update() + + if status == COMMAND_EXIT: + is_running = False + pygame.quit() diff --git a/setup.py b/setup.py index 1d7cc63..b9e86c3 100644 --- a/setup.py +++ b/setup.py @@ -11,3 +11,7 @@ pygame.display.set_caption("Fruit Ninja") WHITE = (255, 255, 255) BLACK = (0, 0, 0) RED = (255, 0, 0) + +# commands +COMMAND_EXIT = 0 +COMMAND_START = 1 -- 2.54.0