Mercurial > boomslang
annotate gamelib/main.py @ 128:a2f6e975af67
Nuke obsolete testing hook.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Tue, 24 Aug 2010 18:23:24 +0200 |
parents | 97322b78d1c1 |
children | 7f6b11a0d404 |
rev | line source |
---|---|
0
f2c3b516741b
Theme is 'Caught'. Start with Skellington 1.9.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
diff
changeset
|
1 '''Game main module. |
f2c3b516741b
Theme is 'Caught'. Start with Skellington 1.9.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
diff
changeset
|
2 |
f2c3b516741b
Theme is 'Caught'. Start with Skellington 1.9.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
diff
changeset
|
3 Contains the entry point used by the run_game.py script. |
f2c3b516741b
Theme is 'Caught'. Start with Skellington 1.9.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
diff
changeset
|
4 |
f2c3b516741b
Theme is 'Caught'. Start with Skellington 1.9.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
diff
changeset
|
5 ''' |
f2c3b516741b
Theme is 'Caught'. Start with Skellington 1.9.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
diff
changeset
|
6 |
102 | 7 # Albow looks for stuff in os.path[0], which isn't always where it expects. |
8 # The following horribleness fixes this. | |
9 import sys | |
10 import os.path | |
11 right_path = os.path.dirname(os.path.dirname(__file__)) | |
12 sys.path.insert(0, right_path) | |
107
5213b45fcc7e
Initial event sound support
Neil Muller <neil@dip.sun.ac.za>
parents:
105
diff
changeset
|
13 from optparse import OptionParser |
102 | 14 |
17 | 15 import pygame |
37 | 16 from pygame.locals import SWSURFACE |
17 | 17 from albow.dialogs import alert |
18 from albow.shell import Shell | |
26
0a68d137f509
Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents:
25
diff
changeset
|
19 |
17 | 20 from menu import MenuScreen |
24
9d5de13e2ac3
Add a game screen. So far, the game content looks a *lot* like the main menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
20
diff
changeset
|
21 from gamescreen import GameScreen |
107
5213b45fcc7e
Initial event sound support
Neil Muller <neil@dip.sun.ac.za>
parents:
105
diff
changeset
|
22 from constants import SCREEN, FRAME_RATE, FREQ, BITSIZE, CHANNELS, BUFFER |
5213b45fcc7e
Initial event sound support
Neil Muller <neil@dip.sun.ac.za>
parents:
105
diff
changeset
|
23 from sound import no_sound, disable_sound |
5213b45fcc7e
Initial event sound support
Neil Muller <neil@dip.sun.ac.za>
parents:
105
diff
changeset
|
24 |
5213b45fcc7e
Initial event sound support
Neil Muller <neil@dip.sun.ac.za>
parents:
105
diff
changeset
|
25 def parse_args(args): |
5213b45fcc7e
Initial event sound support
Neil Muller <neil@dip.sun.ac.za>
parents:
105
diff
changeset
|
26 parser = OptionParser() |
5213b45fcc7e
Initial event sound support
Neil Muller <neil@dip.sun.ac.za>
parents:
105
diff
changeset
|
27 parser.add_option("--no-sound", action="store_false", default=True, |
5213b45fcc7e
Initial event sound support
Neil Muller <neil@dip.sun.ac.za>
parents:
105
diff
changeset
|
28 dest="sound", help="disable sound") |
5213b45fcc7e
Initial event sound support
Neil Muller <neil@dip.sun.ac.za>
parents:
105
diff
changeset
|
29 opts, _ = parser.parse_args(args or []) |
5213b45fcc7e
Initial event sound support
Neil Muller <neil@dip.sun.ac.za>
parents:
105
diff
changeset
|
30 return opts |
17 | 31 |
124 | 32 |
17 | 33 class MainShell(Shell): |
34 def __init__(self, display): | |
35 Shell.__init__(self, display) | |
36 self.menu_screen = MenuScreen(self) | |
24
9d5de13e2ac3
Add a game screen. So far, the game content looks a *lot* like the main menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
20
diff
changeset
|
37 self.game_screen = GameScreen(self) |
105
65976205fc2d
Rough Stab at basic animation support
Neil Muller <neil@dip.sun.ac.za>
parents:
102
diff
changeset
|
38 self.set_timer(FRAME_RATE) |
17 | 39 self.show_screen(self.menu_screen) |
40 | |
0
f2c3b516741b
Theme is 'Caught'. Start with Skellington 1.9.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
diff
changeset
|
41 def main(): |
107
5213b45fcc7e
Initial event sound support
Neil Muller <neil@dip.sun.ac.za>
parents:
105
diff
changeset
|
42 opts = parse_args(sys.argv) |
25
f9e697e0c6ba
Don't initialise the entire pygame
Stefano Rivera <stefano@rivera.za.net>
parents:
24
diff
changeset
|
43 pygame.display.init() |
f9e697e0c6ba
Don't initialise the entire pygame
Stefano Rivera <stefano@rivera.za.net>
parents:
24
diff
changeset
|
44 pygame.font.init() |
107
5213b45fcc7e
Initial event sound support
Neil Muller <neil@dip.sun.ac.za>
parents:
105
diff
changeset
|
45 if opts.sound: |
5213b45fcc7e
Initial event sound support
Neil Muller <neil@dip.sun.ac.za>
parents:
105
diff
changeset
|
46 try: |
5213b45fcc7e
Initial event sound support
Neil Muller <neil@dip.sun.ac.za>
parents:
105
diff
changeset
|
47 pygame.mixer.init(FREQ, BITSIZE, CHANNELS, BUFFER) |
5213b45fcc7e
Initial event sound support
Neil Muller <neil@dip.sun.ac.za>
parents:
105
diff
changeset
|
48 except pygame.error, exc: |
5213b45fcc7e
Initial event sound support
Neil Muller <neil@dip.sun.ac.za>
parents:
105
diff
changeset
|
49 no_sound(exc) |
5213b45fcc7e
Initial event sound support
Neil Muller <neil@dip.sun.ac.za>
parents:
105
diff
changeset
|
50 else: |
5213b45fcc7e
Initial event sound support
Neil Muller <neil@dip.sun.ac.za>
parents:
105
diff
changeset
|
51 # Ensure get_sound returns nothing, so everything else just works |
5213b45fcc7e
Initial event sound support
Neil Muller <neil@dip.sun.ac.za>
parents:
105
diff
changeset
|
52 disable_sound() |
37 | 53 display = pygame.display.set_mode(SCREEN, SWSURFACE) |
17 | 54 shell = MainShell(display) |
55 shell.run() | |
56 |