source: gamelib/main.py @ 6:c0abad23a055

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

Add start, quit and toggle fullscreen buttons to menu.

File size: 1.2 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, USEREVENT
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            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
39def main():
40    """Main script."""
41    screen = pygame.display.set_mode(constants.SCREEN, SWSURFACE)
42
43    form = gui.Form()
44    app = gui.App()
45    main_menu = MainMenu()
46
47    c = gui.Container(align=-1, valign=-1)
48    c.add(main_menu, 0, 0)
49
50    app.init(c)
51
52    gameloop(screen, app)
Note: See TracBrowser for help on using the repository browser.