Mercurial > sypikslang
comparison gamelib/main.py @ 48:a2980cc9a060
Factor out some constants
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Mon, 07 May 2012 21:23:54 +0200 |
parents | d35a3762edda |
children | ac637e84f8f8 |
comparison
equal
deleted
inserted
replaced
47:3e3bed2ce248 | 48:a2980cc9a060 |
---|---|
9 from pygame.locals import MOUSEBUTTONDOWN, MOUSEBUTTONUP, MOUSEMOTION, QUIT | 9 from pygame.locals import MOUSEBUTTONDOWN, MOUSEBUTTONUP, MOUSEMOTION, QUIT |
10 from pygame.time import Clock | 10 from pygame.time import Clock |
11 | 11 |
12 from gamelib.gui_base import Window | 12 from gamelib.gui_base import Window |
13 from gamelib.gui import BigButton | 13 from gamelib.gui import BigButton |
14 from gamelib.constants import WIDTH, HEIGHT, SCREEN, FPS | |
14 | 15 |
15 | 16 |
16 pygame.init() | 17 pygame.init() |
17 | |
18 FPS = 30 | |
19 | 18 |
20 GAME_IS_RUNNING = True | 19 GAME_IS_RUNNING = True |
21 | 20 |
22 WINDOW_STACK = [] | 21 WINDOW_STACK = [] |
23 | 22 |
26 | 25 |
27 | 26 |
28 class ExitGameButton(BigButton): | 27 class ExitGameButton(BigButton): |
29 | 28 |
30 def __init__(self): | 29 def __init__(self): |
31 super(ExitGameButton, self).__init__(((800 - 128), 10), 'Exit') | 30 super(ExitGameButton, self).__init__(((WIDTH - 128), 10), 'Exit') |
32 | 31 |
33 def on_click(self): | 32 def on_click(self): |
34 WINDOW_STACK.pop() | 33 WINDOW_STACK.pop() |
35 | 34 |
36 | 35 |
44 | 43 |
45 | 44 |
46 class StartButton(BigButton): | 45 class StartButton(BigButton): |
47 | 46 |
48 def __init__(self, screen): | 47 def __init__(self, screen): |
49 super(StartButton, self).__init__(((800 - 128) / 2, 200), 'Start') | 48 super(StartButton, self).__init__(((WIDTH - 128) / 2, HEIGHT / 2), |
49 'Start') | |
50 self.screen = screen | 50 self.screen = screen |
51 | 51 |
52 def on_click(self): | 52 def on_click(self): |
53 game_window = GameWindow(self.screen) | 53 game_window = GameWindow(self.screen) |
54 WINDOW_STACK.append(game_window) | 54 WINDOW_STACK.append(game_window) |
55 | 55 |
56 | 56 |
57 class QuitButton(BigButton): | 57 class QuitButton(BigButton): |
58 | 58 |
59 def __init__(self): | 59 def __init__(self): |
60 super(QuitButton, self).__init__(((800 - 128) / 2, 300), 'Quit') | 60 super(QuitButton, self).__init__(((WIDTH - 128) / 2, |
61 HEIGHT / 2 + 100), 'Quit') | |
61 | 62 |
62 def on_click(self): | 63 def on_click(self): |
63 pygame.event.post(pygame.event.Event(pygame.QUIT)) | 64 pygame.event.post(pygame.event.Event(pygame.QUIT)) |
64 | 65 |
65 | 66 |
66 def main(): | 67 def main(): |
67 clock = Clock() | 68 clock = Clock() |
68 screen = pygame.display.set_mode((800, 600)) | 69 screen = pygame.display.set_mode(SCREEN) |
69 window = Window(screen) | 70 window = Window(screen) |
70 window.background_colour = (0, 0, 0) | 71 window.background_colour = (0, 0, 0) |
71 button1 = StartButton(screen) | 72 button1 = StartButton(screen) |
72 window.add_child(button1) | 73 window.add_child(button1) |
73 button2 = QuitButton() | 74 button2 = QuitButton() |