# HG changeset patch # User Stefano Rivera # Date 1301943933 -7200 # Node ID c455b79252128a2f218955ff9111c30b66e0a829 # Parent 12ce1d131a72cfa50ba101bdbba95360465f28ff Global options in skaapsteker.__init__ diff -r 12ce1d131a72 -r c455b7925212 skaapsteker/__init__.py --- a/skaapsteker/__init__.py Mon Apr 04 20:53:45 2011 +0200 +++ b/skaapsteker/__init__.py Mon Apr 04 21:05:33 2011 +0200 @@ -0,0 +1,4 @@ +options = { + 'debug_rects': False, + 'sound': True, +} diff -r 12ce1d131a72 -r c455b7925212 skaapsteker/__main__.py --- a/skaapsteker/__main__.py Mon Apr 04 20:53:45 2011 +0200 +++ b/skaapsteker/__main__.py Mon Apr 04 21:05:33 2011 +0200 @@ -1,17 +1,18 @@ """Game main module. """ +import sys +import optparse + +import pygame +from pygame.locals import SWSURFACE + +from . import options from .constants import SCREEN, FREQ, BITSIZE, CHANNELS, BUFFER, DEBUG from .engine import Engine from .levelscene import LevelScene from .menuscene import MenuScene -import pygame -from pygame.locals import SWSURFACE - -import sys -import optparse - def parse_args(args): parser = optparse.OptionParser() @@ -19,20 +20,23 @@ dest="sound", help="disable sound") if DEBUG: parser.add_option("--level", type="str", default=None, - dest="level", help="initial level") + dest="level", help="Initial level") parser.add_option("--no-rects", action="store_false", default=True, - dest="rects", help="disable debugging rects") + dest="rects", help="Disable debugging rects") opts, _ = parser.parse_args(args or []) - return opts + options['sound'] = opts.sound + if DEBUG: + options['debug_rects'] = opts.rects + return opts.level def main(): """Launch Nine Tales. """ - opts = parse_args(sys.argv) + level = parse_args(sys.argv) pygame.display.init() pygame.font.init() - if opts.sound: + if options['sound']: try: pygame.mixer.init(FREQ, BITSIZE, CHANNELS, BUFFER) except pygame.error, exc: @@ -48,8 +52,6 @@ # data.filepath('icons/nine_tales24x24.png'))) pygame.display.set_caption("Nine Tales") - level = getattr(opts, 'level', None) - engine = Engine() if level is not None: engine.change_scene(LevelScene(level)) diff -r 12ce1d131a72 -r c455b7925212 skaapsteker/physics.py --- a/skaapsteker/physics.py Mon Apr 04 20:53:45 2011 +0200 +++ b/skaapsteker/physics.py Mon Apr 04 21:05:33 2011 +0200 @@ -3,11 +3,14 @@ Works very closely with sprites/base.py. """ -import pygame.sprite -import pygame.draw +import time + import pygame -import time -from constants import DEBUG, EPSILON +import pygame.draw +import pygame.sprite + +from . import options +from .constants import EPSILON class Sprite(pygame.sprite.DirtySprite): @@ -162,6 +165,6 @@ def draw(self, surface): self._all.draw(surface) - if DEBUG: + if options['debug_rects']: for sprite in self._all: sprite.draw_debug(surface)