Mercurial > skaapsteker
changeset 105:c455b7925212
Global options in skaapsteker.__init__
author | Stefano Rivera <stefano@rivera.za.net> |
---|---|
date | Mon, 04 Apr 2011 21:05:33 +0200 |
parents | 12ce1d131a72 |
children | bf7d511d3650 |
files | skaapsteker/__init__.py skaapsteker/__main__.py skaapsteker/physics.py |
diffstat | 3 files changed, 27 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- 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, +}
--- 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))
--- 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)