view gamelib/main.py @ 151:082868bea873

Refactor UI so that only a single gui.App is used. Pass all UI events via main_app. Change Toolbar table to use .td() everywhere. Move toolbar to top.
author Simon Cross <hodgestar@gmail.com>
date Thu, 03 Sep 2009 20:32:56 +0000
parents 1d73de63bd71
children 4cc0b3627f83
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

#from engine import Engine, MainMenuState
from sound import init_sound
import constants

def create_main_app(screen):
    """Create an app with a background widget."""
    app = gui.App()
    background = pygame.Surface(screen.get_size())
    widget = gui.Image(background)
    app.init(widget, screen)
    return app

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

    from engine import Engine, MainMenuState

    engine = Engine(main_app)
    try:
        engine.run(MainMenuState(engine), screen)
    except KeyboardInterrupt:
        pass