# HG changeset patch # User Neil Muller # Date 1336418634 -7200 # Node ID a2980cc9a0604feaae9ef070b65dbfadfe12f7b5 # Parent 3e3bed2ce248abf62abfa6314ec34f04acaefa5b Factor out some constants diff -r 3e3bed2ce248 -r a2980cc9a060 gamelib/constants.py --- /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 diff -r 3e3bed2ce248 -r a2980cc9a060 gamelib/main.py --- 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)