]> Skullheadx's Git Forge - fruit-ninja.git/commitdiff
game class
authorSkullheadx <94652084+Skullheadx@users.noreply.github.com>
Thu, 1 Jun 2023 16:52:45 +0000 (12:52 -0400)
committerSkullheadx <94652084+Skullheadx@users.noreply.github.com>
Thu, 1 Jun 2023 16:52:45 +0000 (12:52 -0400)
game.py [new file with mode: 0644]
main.py
setup.py

diff --git a/game.py b/game.py
new file mode 100644 (file)
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 cd398ce7f1a22bebcd17a3d0e2b26125a0e2f57d..0b5ea1151f03595a4e73e402a35efca9d10cf4e0 100644 (file)
--- 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()
index 1d7cc6360f1f8594ffcdc97c0b6f64111e861545..b9e86c38cb75311491e6e97d58e009fbd4640de8 100644 (file)
--- 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