annotate gamelib/main.py @ 122:d2b19131d537

Don't continue the night if we're not doing anything anymore
author Neil Muller <drnlmuller@gmail.com>
date Wed, 02 Sep 2009 20:54:47 +0000
parents 23a8b2e49e9f
children 69fd96eafde8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
e057e9483488 Added pyweek skellington.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
1 '''Game main module.
e057e9483488 Added pyweek skellington.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
2
e057e9483488 Added pyweek skellington.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
3 Contains the entry point used by the run_game.py script.
e057e9483488 Added pyweek skellington.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
4
e057e9483488 Added pyweek skellington.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
5 Feel free to put all your game code here, or in other modules in this "gamelib"
e057e9483488 Added pyweek skellington.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
6 package.
e057e9483488 Added pyweek skellington.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
7 '''
e057e9483488 Added pyweek skellington.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
8
4
e8ddbc95cbf3 Silly (and broken) first stab at menu thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 2
diff changeset
9 import pygame
e8ddbc95cbf3 Silly (and broken) first stab at menu thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 2
diff changeset
10 from pgu import gui
11
5d58a5b13731 Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents: 7
diff changeset
11 from pygame.locals import SWSURFACE
4
e8ddbc95cbf3 Silly (and broken) first stab at menu thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 2
diff changeset
12
e8ddbc95cbf3 Silly (and broken) first stab at menu thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 2
diff changeset
13 from mainmenu import MainMenu
11
5d58a5b13731 Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents: 7
diff changeset
14 from engine import Engine, MainMenuState
90
23a8b2e49e9f Added ability to initialize sound and play sounds, and handle sound not working / file being missing etc
David Fraser <davidf@sjsoft.com>
parents: 58
diff changeset
15 from sound import init_sound
5
67b79658b047 Refactor and simplify menu.
Simon Cross <hodgestar@gmail.com>
parents: 4
diff changeset
16 import constants
4
e8ddbc95cbf3 Silly (and broken) first stab at menu thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 2
diff changeset
17
11
5d58a5b13731 Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents: 7
diff changeset
18 def create_menu_app():
5d58a5b13731 Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents: 7
diff changeset
19 """Create the menu app."""
5
67b79658b047 Refactor and simplify menu.
Simon Cross <hodgestar@gmail.com>
parents: 4
diff changeset
20 app = gui.App()
67b79658b047 Refactor and simplify menu.
Simon Cross <hodgestar@gmail.com>
parents: 4
diff changeset
21 main_menu = MainMenu()
67b79658b047 Refactor and simplify menu.
Simon Cross <hodgestar@gmail.com>
parents: 4
diff changeset
22
7
99c4f2226314 Add padding, centre menu.
Simon Cross <hodgestar@gmail.com>
parents: 6
diff changeset
23 c = gui.Container(align=0, valign=0)
5
67b79658b047 Refactor and simplify menu.
Simon Cross <hodgestar@gmail.com>
parents: 4
diff changeset
24 c.add(main_menu, 0, 0)
67b79658b047 Refactor and simplify menu.
Simon Cross <hodgestar@gmail.com>
parents: 4
diff changeset
25
67b79658b047 Refactor and simplify menu.
Simon Cross <hodgestar@gmail.com>
parents: 4
diff changeset
26 app.init(c)
11
5d58a5b13731 Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents: 7
diff changeset
27 return app
5
67b79658b047 Refactor and simplify menu.
Simon Cross <hodgestar@gmail.com>
parents: 4
diff changeset
28
11
5d58a5b13731 Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents: 7
diff changeset
29 def main():
5d58a5b13731 Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents: 7
diff changeset
30 """Main script."""
90
23a8b2e49e9f Added ability to initialize sound and play sounds, and handle sound not working / file being missing etc
David Fraser <davidf@sjsoft.com>
parents: 58
diff changeset
31 init_sound()
11
5d58a5b13731 Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents: 7
diff changeset
32 screen = pygame.display.set_mode(constants.SCREEN, SWSURFACE)
5d58a5b13731 Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents: 7
diff changeset
33 main_menu_app = create_menu_app()
5d58a5b13731 Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents: 7
diff changeset
34 engine = Engine(main_menu_app)
58
2afdccfb9c67 Hide keyboard interrupt message on Ctrl-C exit.
Simon Cross <hodgestar@gmail.com>
parents: 11
diff changeset
35 try:
2afdccfb9c67 Hide keyboard interrupt message on Ctrl-C exit.
Simon Cross <hodgestar@gmail.com>
parents: 11
diff changeset
36 engine.run(MainMenuState(engine), screen)
2afdccfb9c67 Hide keyboard interrupt message on Ctrl-C exit.
Simon Cross <hodgestar@gmail.com>
parents: 11
diff changeset
37 except KeyboardInterrupt:
2afdccfb9c67 Hide keyboard interrupt message on Ctrl-C exit.
Simon Cross <hodgestar@gmail.com>
parents: 11
diff changeset
38 pass