Mercurial > rinkhals
annotate gamelib/main.py @ 118:2c76ed47fc44
Remove chicken respawn at day start. Handle eaten chickens in henhouses better
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Wed, 02 Sep 2009 20:28:03 +0000 |
parents | 23a8b2e49e9f |
children | 69fd96eafde8 |
rev | line source |
---|---|
2 | 1 '''Game main module. |
2 | |
3 Contains the entry point used by the run_game.py script. | |
4 | |
5 Feel free to put all your game code here, or in other modules in this "gamelib" | |
6 package. | |
7 ''' | |
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 | 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 |