Mercurial > sypikslang
comparison gamelib/main.py @ 53:655a6912e0ae
Split gui stuff out of main.py
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Mon, 07 May 2012 22:10:26 +0200 |
parents | 1d3d20bdc8b9 |
children | a253fae32a6f |
comparison
equal
deleted
inserted
replaced
52:1d3d20bdc8b9 | 53:655a6912e0ae |
---|---|
5 Feel free to put all your game code here, or in other modules in this "gamelib" | 5 Feel free to put all your game code here, or in other modules in this "gamelib" |
6 package. | 6 package. |
7 ''' | 7 ''' |
8 import pygame | 8 import pygame |
9 | 9 |
10 from gamelib.gui_base import Window | 10 from gamelib.engine import Engine |
11 from gamelib.gui import BigButton | 11 from gamelib.mainmenu import MainMenu |
12 from gamelib.engine import Engine, AddWindow, PopWindow | |
13 | 12 |
14 from gamelib.constants import WIDTH, HEIGHT, SCREEN | 13 from gamelib.constants import SCREEN |
15 | 14 |
16 | 15 |
17 pygame.init() | 16 pygame.init() |
18 | |
19 | |
20 class ExitGameButton(BigButton): | |
21 | |
22 def __init__(self): | |
23 super(ExitGameButton, self).__init__(((WIDTH - 128), 10), 'Exit') | |
24 | |
25 def on_click(self): | |
26 PopWindow.post() | |
27 | |
28 | |
29 class GameWindow(Window): | |
30 """Main window for the game""" | |
31 | |
32 def __init__(self, screen): | |
33 super(GameWindow, self).__init__(screen) | |
34 exit = ExitGameButton() | |
35 self.add_child(exit) | |
36 | |
37 | |
38 class StartButton(BigButton): | |
39 | |
40 def __init__(self, screen): | |
41 super(StartButton, self).__init__(((WIDTH - 128) / 2, HEIGHT / 2), | |
42 'Start') | |
43 self.screen = screen | |
44 | |
45 def on_click(self): | |
46 game_window = GameWindow(self.screen) | |
47 AddWindow.post(game_window) | |
48 | |
49 | |
50 class QuitButton(BigButton): | |
51 | |
52 def __init__(self): | |
53 super(QuitButton, self).__init__(((WIDTH - 128) / 2, | |
54 HEIGHT / 2 + 100), 'Quit') | |
55 | |
56 def on_click(self): | |
57 pygame.event.post(pygame.event.Event(pygame.QUIT)) | |
58 | |
59 | |
60 class MainMenu(Window): | |
61 | |
62 def __init__(self, screen): | |
63 super(MainMenu, self).__init__(screen) | |
64 self.background_colour = (0, 0, 0) | |
65 button1 = StartButton(screen) | |
66 self.add_child(button1) | |
67 button2 = QuitButton() | |
68 self.add_child(button2) | |
69 | 17 |
70 | 18 |
71 def main(): | 19 def main(): |
72 screen = pygame.display.set_mode(SCREEN) | 20 screen = pygame.display.set_mode(SCREEN) |
73 engine = Engine(screen) | 21 engine = Engine(screen) |