Mercurial > sypikslang
view gamelib/main.py @ 52:1d3d20bdc8b9
Move engine stuff into it's own file
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Mon, 07 May 2012 21:55:55 +0200 |
parents | ac637e84f8f8 |
children | 655a6912e0ae |
line wrap: on
line source
'''Game main module. Contains the entry point used by the run_game.py script. Feel free to put all your game code here, or in other modules in this "gamelib" package. ''' import pygame from gamelib.gui_base import Window from gamelib.gui import BigButton from gamelib.engine import Engine, AddWindow, PopWindow from gamelib.constants import WIDTH, HEIGHT, SCREEN pygame.init() class ExitGameButton(BigButton): def __init__(self): super(ExitGameButton, self).__init__(((WIDTH - 128), 10), 'Exit') def on_click(self): PopWindow.post() 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__(((WIDTH - 128) / 2, HEIGHT / 2), 'Start') self.screen = screen def on_click(self): game_window = GameWindow(self.screen) AddWindow.post(game_window) class QuitButton(BigButton): def __init__(self): super(QuitButton, self).__init__(((WIDTH - 128) / 2, HEIGHT / 2 + 100), 'Quit') def on_click(self): pygame.event.post(pygame.event.Event(pygame.QUIT)) class MainMenu(Window): def __init__(self, screen): super(MainMenu, self).__init__(screen) self.background_colour = (0, 0, 0) button1 = StartButton(screen) self.add_child(button1) button2 = QuitButton() self.add_child(button2) def main(): screen = pygame.display.set_mode(SCREEN) engine = Engine(screen) window = MainMenu(screen) engine.run(window)