Mercurial > sypikslang
changeset 43:2bdac178ec6f
Play with the gui stuff a bit
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Mon, 07 May 2012 16:51:52 +0200 |
parents | 47c7e96cf9c8 |
children | d35a3762edda |
files | gamelib/main.py |
diffstat | 1 files changed, 41 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/gamelib/main.py Mon May 07 14:00:18 2012 +0200 +++ b/gamelib/main.py Mon May 07 16:51:52 2012 +0200 @@ -25,13 +25,53 @@ MOUSE_DOWN = False +class ExitGameButton(BigButton): + + def __init__(self): + super(ExitGameButton, self).__init__(((800 - 128), 10), 'Exit') + + def on_click(self): + WINDOW_STACK.pop() + + +class GameWindow(Window): + """Main window for the game""" + + def __init__(self, screen): + super(GameWindow, self).__init__(screen) + exit = ExitGameButton() + self.add_child(exit) + + +class StartButton(BigButton): + + def __init__(self, screen): + super(StartButton, self).__init__(((800 - 128) / 2, 200), 'Start') + self.screen = screen + + def on_click(self): + game_window = GameWindow(self.screen) + WINDOW_STACK.append(game_window) + + +class QuitButton(BigButton): + + def __init__(self): + super(QuitButton, self).__init__(((800 - 128) / 2, 300), 'Quit') + + def on_click(self): + pygame.event.post(pygame.event.Event(pygame.QUIT)) + + def main(): clock = Clock() screen = pygame.display.set_mode((800, 600)) window = Window(screen) window.background_colour = (0, 0, 0) - button1 = BigButton(((800 - 128) / 2, 200), 'Start') + button1 = StartButton(screen) window.add_child(button1) + button2 = QuitButton() + window.add_child(button2) WINDOW_STACK.append(window) while GAME_IS_RUNNING: process_input()