changeset 48:a2980cc9a060

Factor out some constants
author Neil Muller <drnlmuller@gmail.com>
date Mon, 07 May 2012 21:23:54 +0200
parents 3e3bed2ce248
children 373c57ab4140
files gamelib/constants.py gamelib/main.py
diffstat 2 files changed, 13 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gamelib/constants.py	Mon May 07 21:23:54 2012 +0200
@@ -0,0 +1,6 @@
+# The usual game constants
+
+WIDTH = 800
+HEIGHT = 600
+SCREEN = (WIDTH, HEIGHT)
+FPS = 30
--- a/gamelib/main.py	Mon May 07 21:10:25 2012 +0200
+++ b/gamelib/main.py	Mon May 07 21:23:54 2012 +0200
@@ -11,12 +11,11 @@
 
 from gamelib.gui_base import Window
 from gamelib.gui import BigButton
+from gamelib.constants import WIDTH, HEIGHT, SCREEN, FPS
 
 
 pygame.init()
 
-FPS = 30
-
 GAME_IS_RUNNING = True
 
 WINDOW_STACK = []
@@ -28,7 +27,7 @@
 class ExitGameButton(BigButton):
 
     def __init__(self):
-        super(ExitGameButton, self).__init__(((800 - 128), 10), 'Exit')
+        super(ExitGameButton, self).__init__(((WIDTH - 128), 10), 'Exit')
 
     def on_click(self):
         WINDOW_STACK.pop()
@@ -46,7 +45,8 @@
 class StartButton(BigButton):
 
     def __init__(self, screen):
-        super(StartButton, self).__init__(((800 - 128) / 2, 200), 'Start')
+        super(StartButton, self).__init__(((WIDTH - 128) / 2, HEIGHT / 2),
+                'Start')
         self.screen = screen
 
     def on_click(self):
@@ -57,7 +57,8 @@
 class QuitButton(BigButton):
 
     def __init__(self):
-        super(QuitButton, self).__init__(((800 - 128) / 2, 300), 'Quit')
+        super(QuitButton, self).__init__(((WIDTH - 128) / 2,
+            HEIGHT / 2 + 100), 'Quit')
 
     def on_click(self):
         pygame.event.post(pygame.event.Event(pygame.QUIT))
@@ -65,7 +66,7 @@
 
 def main():
     clock = Clock()
-    screen = pygame.display.set_mode((800, 600))
+    screen = pygame.display.set_mode(SCREEN)
     window = Window(screen)
     window.background_colour = (0, 0, 0)
     button1 = StartButton(screen)