source: gamelib/main.py @ 5:67b79658b047

Last change on this file since 5:67b79658b047 was 5:67b79658b047, checked in by Simon Cross <hodgestar@…>, 11 years ago

Refactor and simplify menu.

File size: 1.1 KB
Line 
1'''Game main module.
2
3Contains the entry point used by the run_game.py script.
4
5Feel free to put all your game code here, or in other modules in this "gamelib"
6package.
7'''
8
9import pygame
10from pgu import gui
11from pygame.locals import SWSURFACE, QUIT, KEYDOWN, K_ESCAPE
12
13from mainmenu import MainMenu
14import constants
15
16def gameloop(screen, app):
17    """Main game loop."""
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            else:
27                app.event(e)
28
29        # Clear the screen and render the stars
30        dt = clock.tick()/1000.0
31        screen.fill((0,0,0))
32        app.paint(screen)
33        pygame.display.flip()
34        pygame.time.wait(10)
35
36
37def main():
38    """Main script."""
39    screen = pygame.display.set_mode(constants.SCREEN, SWSURFACE)
40
41    form = gui.Form()
42    app = gui.App()
43    main_menu = MainMenu()
44
45    c = gui.Container(align=-1, valign=-1)
46    c.add(main_menu, 0, 0)
47
48    app.init(c)
49
50    gameloop(screen, app)
Note: See TracBrowser for help on using the repository browser.