Source

lpc / game.py

Full commit
#!/usr/bin/env python2
# encoding: utf-8

"""The game starts the central event loop for all scenes."""

### imports

# disable pyglet gl debugging before we do anything else (2x speed hit)
import pyglet
pyglet.options['debug_gl'] = False

from core import core, __copyright__

from pyglet import app
from pyglet.window import Window
from pyglet.clock import schedule_once
from sys import argv
from optparse import OptionParser

### commandline arguments

def _help(mod=None):
    """Provide help from this main module and optionally from the selected scene.
    @param mod: module in which the selected scene is defined - this contains the second help string to use.
    """
    if mod is None or mod.__doc__ is None: 
        return __doc__
    else: 
        return mod.__doc__

### clean parsing
parser = OptionParser(usage = "Game runner", version = "0.1")

parser.add_option("-s", "--scene", type="string", dest="scene", default="scene", help="the scene to start: scene filename without extension")

parser.add_option("--width", type="int", dest="width", default=800, help="width of the window")

parser.add_option("--height", type="int", dest="height", default=600, help="height of the window")

parser.add_option("--fullscreen",
                  action="store_true", dest="fullscreen", default=False,
                  help="Run the game in fullscreen")

(options, args) = parser.parse_args()

### preparation
if options.fullscreen: 
    window = Window(fullscreen=options.fullscreen)
else: 
    window = Window(width=options.width, height=options.height)
core.win = window
core.app = app

# get the scene (might already need core settings)
scene = eval("__import__('" + options.scene.split(".")[0] + "')")

# activate tranparency for pngs
from pyglet.gl import glEnable, glBlendFunc, GL_BLEND, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

# scene running.
schedule_once(scene.start, 0.1)

core.app.run()