Mercurial > rinkhals
annotate gamelib/main.py @ 31:3c4db7bba432
Add 's' as a key for starting the game from the menu.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Sun, 30 Aug 2009 18:56:09 +0000 |
parents | 5d58a5b13731 |
children | 2afdccfb9c67 |
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 |
5
67b79658b047
Refactor and simplify menu.
Simon Cross <hodgestar@gmail.com>
parents:
4
diff
changeset
|
15 import constants |
4
e8ddbc95cbf3
Silly (and broken) first stab at menu thing.
Jeremy Thurgood <firxen@gmail.com>
parents:
2
diff
changeset
|
16 |
11
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
7
diff
changeset
|
17 def create_menu_app(): |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
7
diff
changeset
|
18 """Create the menu app.""" |
5
67b79658b047
Refactor and simplify menu.
Simon Cross <hodgestar@gmail.com>
parents:
4
diff
changeset
|
19 app = gui.App() |
67b79658b047
Refactor and simplify menu.
Simon Cross <hodgestar@gmail.com>
parents:
4
diff
changeset
|
20 main_menu = MainMenu() |
67b79658b047
Refactor and simplify menu.
Simon Cross <hodgestar@gmail.com>
parents:
4
diff
changeset
|
21 |
7 | 22 c = gui.Container(align=0, valign=0) |
5
67b79658b047
Refactor and simplify menu.
Simon Cross <hodgestar@gmail.com>
parents:
4
diff
changeset
|
23 c.add(main_menu, 0, 0) |
67b79658b047
Refactor and simplify menu.
Simon Cross <hodgestar@gmail.com>
parents:
4
diff
changeset
|
24 |
67b79658b047
Refactor and simplify menu.
Simon Cross <hodgestar@gmail.com>
parents:
4
diff
changeset
|
25 app.init(c) |
11
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
7
diff
changeset
|
26 return app |
5
67b79658b047
Refactor and simplify menu.
Simon Cross <hodgestar@gmail.com>
parents:
4
diff
changeset
|
27 |
11
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
7
diff
changeset
|
28 def main(): |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
7
diff
changeset
|
29 """Main script.""" |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
7
diff
changeset
|
30 screen = pygame.display.set_mode(constants.SCREEN, SWSURFACE) |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
7
diff
changeset
|
31 main_menu_app = create_menu_app() |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
7
diff
changeset
|
32 engine = Engine(main_menu_app) |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
7
diff
changeset
|
33 engine.run(MainMenuState(engine), screen) |