Mercurial > rinkhals
comparison gamelib/main.py @ 11:5d58a5b13731
Extremely rudimentary game engine.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Sun, 30 Aug 2009 15:11:44 +0000 |
parents | 99c4f2226314 |
children | 2afdccfb9c67 |
comparison
equal
deleted
inserted
replaced
10:0ecf1e3ab087 | 11:5d58a5b13731 |
---|---|
6 package. | 6 package. |
7 ''' | 7 ''' |
8 | 8 |
9 import pygame | 9 import pygame |
10 from pgu import gui | 10 from pgu import gui |
11 from pygame.locals import SWSURFACE, QUIT, KEYDOWN, K_ESCAPE, USEREVENT | 11 from pygame.locals import SWSURFACE |
12 | 12 |
13 from mainmenu import MainMenu | 13 from mainmenu import MainMenu |
14 from engine import Engine, MainMenuState | |
14 import constants | 15 import constants |
15 | 16 |
16 def gameloop(screen, app): | 17 def create_menu_app(): |
17 """Main game loop.""" | 18 """Create the menu app.""" |
18 clock = pygame.time.Clock() | |
19 done = False | |
20 while not done: | |
21 for e in pygame.event.get(): | |
22 if e.type is QUIT: | |
23 done = True | |
24 elif e.type is KEYDOWN and e.key == K_ESCAPE: | |
25 done = True | |
26 elif e.type is USEREVENT: | |
27 print e.event | |
28 else: | |
29 app.event(e) | |
30 | |
31 # Clear the screen and render the stars | |
32 dt = clock.tick()/1000.0 | |
33 screen.fill((0,0,0)) | |
34 app.paint(screen) | |
35 pygame.display.flip() | |
36 pygame.time.wait(10) | |
37 | |
38 | |
39 def main(): | |
40 """Main script.""" | |
41 screen = pygame.display.set_mode(constants.SCREEN, SWSURFACE) | |
42 | |
43 form = gui.Form() | |
44 app = gui.App() | 19 app = gui.App() |
45 main_menu = MainMenu() | 20 main_menu = MainMenu() |
46 | 21 |
47 c = gui.Container(align=0, valign=0) | 22 c = gui.Container(align=0, valign=0) |
48 c.add(main_menu, 0, 0) | 23 c.add(main_menu, 0, 0) |
49 | 24 |
50 app.init(c) | 25 app.init(c) |
26 return app | |
51 | 27 |
52 gameloop(screen, app) | 28 def main(): |
29 """Main script.""" | |
30 screen = pygame.display.set_mode(constants.SCREEN, SWSURFACE) | |
31 main_menu_app = create_menu_app() | |
32 engine = Engine(main_menu_app) | |
33 engine.run(MainMenuState(engine), screen) |