annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
d0de8832774b Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff changeset
1 '''Game main module.
d0de8832774b Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff changeset
2
d0de8832774b Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff changeset
3 Contains the entry point used by the run_game.py script.
d0de8832774b Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff changeset
4
d0de8832774b Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff changeset
5 Feel free to put all your game code here, or in other modules in this "gamelib"
d0de8832774b Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff changeset
6 package.
d0de8832774b Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff changeset
7 '''
37
9c4bf1f15431 gui stuff
Rizmari Versfeld <rizziepit@gmail.com>
parents: 1
diff changeset
8 import pygame
0
d0de8832774b Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff changeset
9
39
d82d3e54a4ef fixed more pep8 issues
Rizmari Versfeld <rizziepit@gmail.com>
parents: 38
diff changeset
10 from gamelib.gui_base import Window
d82d3e54a4ef fixed more pep8 issues
Rizmari Versfeld <rizziepit@gmail.com>
parents: 38
diff changeset
11 from gamelib.gui import BigButton
52
1d3d20bdc8b9 Move engine stuff into it's own file
Neil Muller <drnlmuller@gmail.com>
parents: 51
diff changeset
12 from gamelib.engine import Engine, AddWindow, PopWindow
1d3d20bdc8b9 Move engine stuff into it's own file
Neil Muller <drnlmuller@gmail.com>
parents: 51
diff changeset
13
1d3d20bdc8b9 Move engine stuff into it's own file
Neil Muller <drnlmuller@gmail.com>
parents: 51
diff changeset
14 from gamelib.constants import WIDTH, HEIGHT, SCREEN
0
d0de8832774b Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff changeset
15
1
c90a6586cd66 PEP8-ify skellington (because)
Neil Muller <drnlmuller@gmail.com>
parents: 0
diff changeset
16
37
9c4bf1f15431 gui stuff
Rizmari Versfeld <rizziepit@gmail.com>
parents: 1
diff changeset
17 pygame.init()
9c4bf1f15431 gui stuff
Rizmari Versfeld <rizziepit@gmail.com>
parents: 1
diff changeset
18
51
ac637e84f8f8 Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents: 48
diff changeset
19
43
2bdac178ec6f Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents: 39
diff changeset
20 class ExitGameButton(BigButton):
2bdac178ec6f Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents: 39
diff changeset
21
2bdac178ec6f Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents: 39
diff changeset
22 def __init__(self):
48
a2980cc9a060 Factor out some constants
Neil Muller <drnlmuller@gmail.com>
parents: 44
diff changeset
23 super(ExitGameButton, self).__init__(((WIDTH - 128), 10), 'Exit')
43
2bdac178ec6f Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents: 39
diff changeset
24
2bdac178ec6f Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents: 39
diff changeset
25 def on_click(self):
51
ac637e84f8f8 Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents: 48
diff changeset
26 PopWindow.post()
43
2bdac178ec6f Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents: 39
diff changeset
27
2bdac178ec6f Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents: 39
diff changeset
28
2bdac178ec6f Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents: 39
diff changeset
29 class GameWindow(Window):
2bdac178ec6f Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents: 39
diff changeset
30 """Main window for the game"""
2bdac178ec6f Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents: 39
diff changeset
31
2bdac178ec6f Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents: 39
diff changeset
32 def __init__(self, screen):
2bdac178ec6f Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents: 39
diff changeset
33 super(GameWindow, self).__init__(screen)
2bdac178ec6f Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents: 39
diff changeset
34 exit = ExitGameButton()
2bdac178ec6f Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents: 39
diff changeset
35 self.add_child(exit)
2bdac178ec6f Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents: 39
diff changeset
36
2bdac178ec6f Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents: 39
diff changeset
37
2bdac178ec6f Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents: 39
diff changeset
38 class StartButton(BigButton):
2bdac178ec6f Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents: 39
diff changeset
39
2bdac178ec6f Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents: 39
diff changeset
40 def __init__(self, screen):
48
a2980cc9a060 Factor out some constants
Neil Muller <drnlmuller@gmail.com>
parents: 44
diff changeset
41 super(StartButton, self).__init__(((WIDTH - 128) / 2, HEIGHT / 2),
a2980cc9a060 Factor out some constants
Neil Muller <drnlmuller@gmail.com>
parents: 44
diff changeset
42 'Start')
43
2bdac178ec6f Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents: 39
diff changeset
43 self.screen = screen
2bdac178ec6f Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents: 39
diff changeset
44
2bdac178ec6f Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents: 39
diff changeset
45 def on_click(self):
2bdac178ec6f Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents: 39
diff changeset
46 game_window = GameWindow(self.screen)
51
ac637e84f8f8 Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents: 48
diff changeset
47 AddWindow.post(game_window)
43
2bdac178ec6f Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents: 39
diff changeset
48
2bdac178ec6f Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents: 39
diff changeset
49
2bdac178ec6f Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents: 39
diff changeset
50 class QuitButton(BigButton):
2bdac178ec6f Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents: 39
diff changeset
51
2bdac178ec6f Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents: 39
diff changeset
52 def __init__(self):
48
a2980cc9a060 Factor out some constants
Neil Muller <drnlmuller@gmail.com>
parents: 44
diff changeset
53 super(QuitButton, self).__init__(((WIDTH - 128) / 2,
a2980cc9a060 Factor out some constants
Neil Muller <drnlmuller@gmail.com>
parents: 44
diff changeset
54 HEIGHT / 2 + 100), 'Quit')
43
2bdac178ec6f Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents: 39
diff changeset
55
2bdac178ec6f Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents: 39
diff changeset
56 def on_click(self):
2bdac178ec6f Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents: 39
diff changeset
57 pygame.event.post(pygame.event.Event(pygame.QUIT))
2bdac178ec6f Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents: 39
diff changeset
58
2bdac178ec6f Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents: 39
diff changeset
59
51
ac637e84f8f8 Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents: 48
diff changeset
60 class MainMenu(Window):
ac637e84f8f8 Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents: 48
diff changeset
61
ac637e84f8f8 Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents: 48
diff changeset
62 def __init__(self, screen):
ac637e84f8f8 Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents: 48
diff changeset
63 super(MainMenu, self).__init__(screen)
ac637e84f8f8 Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents: 48
diff changeset
64 self.background_colour = (0, 0, 0)
ac637e84f8f8 Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents: 48
diff changeset
65 button1 = StartButton(screen)
ac637e84f8f8 Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents: 48
diff changeset
66 self.add_child(button1)
ac637e84f8f8 Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents: 48
diff changeset
67 button2 = QuitButton()
ac637e84f8f8 Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents: 48
diff changeset
68 self.add_child(button2)
ac637e84f8f8 Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents: 48
diff changeset
69
ac637e84f8f8 Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents: 48
diff changeset
70
0
d0de8832774b Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff changeset
71 def main():
48
a2980cc9a060 Factor out some constants
Neil Muller <drnlmuller@gmail.com>
parents: 44
diff changeset
72 screen = pygame.display.set_mode(SCREEN)
51
ac637e84f8f8 Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents: 48
diff changeset
73 engine = Engine(screen)
ac637e84f8f8 Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents: 48
diff changeset
74 window = MainMenu(screen)
ac637e84f8f8 Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents: 48
diff changeset
75 engine.run(window)