view gamelib/main.py @ 6:c0abad23a055

Add start, quit and toggle fullscreen buttons to menu.
author Simon Cross <hodgestar@gmail.com>
date Sun, 30 Aug 2009 13:25:04 +0000
parents 67b79658b047
children 99c4f2226314
line wrap: on
line source

'''Game main module.

Contains the entry point used by the run_game.py script.

Feel free to put all your game code here, or in other modules in this "gamelib"
package.
'''

import pygame
from pgu import gui
from pygame.locals import SWSURFACE, QUIT, KEYDOWN, K_ESCAPE, USEREVENT

from mainmenu import MainMenu
import constants

def gameloop(screen, app):
    """Main game loop."""
    clock = pygame.time.Clock()
    done = False
    while not done:
        for e in pygame.event.get():
            if e.type is QUIT:
                done = True
            elif e.type is KEYDOWN and e.key == K_ESCAPE:
                done = True
            elif e.type is USEREVENT:
                print e.event
            else:
                app.event(e)

        # Clear the screen and render the stars
        dt = clock.tick()/1000.0
        screen.fill((0,0,0))
        app.paint(screen)
        pygame.display.flip()
        pygame.time.wait(10)


def main():
    """Main script."""
    screen = pygame.display.set_mode(constants.SCREEN, SWSURFACE)

    form = gui.Form()
    app = gui.App()
    main_menu = MainMenu()

    c = gui.Container(align=-1, valign=-1)
    c.add(main_menu, 0, 0)

    app.init(c)

    gameloop(screen, app)