changeset 6:be641ad97aaa

Create a pygame window.
author Simon Cross <hodgestar@gmail.com>
date Sun, 03 Apr 2011 15:30:22 +0200
parents 73162df1af93
children 8000358e47d9
files skaapsteker/__main__.py skaapsteker/constants.py
diffstat 2 files changed, 63 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/skaapsteker/__main__.py	Sun Apr 03 15:24:23 2011 +0200
+++ b/skaapsteker/__main__.py	Sun Apr 03 15:30:22 2011 +0200
@@ -1,4 +1,55 @@
+"""Game main module.
+   """
+
+from constants import SCREEN, FREQ, BITSIZE, CHANNELS, BUFFER, DEBUG
+
+import pygame
+from pygame.locals import SWSURFACE
+
+import sys
+import optparse
+
+
+
+def parse_args(args):
+    parser = optparse.OptionParser()
+    parser.add_option("--no-sound", action="store_false", default=True,
+            dest="sound", help="disable sound")
+    if DEBUG:
+        parser.add_option("--scene", type="str", default=None,
+            dest="scene", help="initial scene")
+        parser.add_option("--no-rects", action="store_false", default=True,
+            dest="rects", help="disable debugging rects")
+    opts, _ = parser.parse_args(args or [])
+    return opts
+
 
 def main():
-    """ your app starts here
-    """
+    """Launch Nine Tales.
+       """
+    opts = parse_args(sys.argv)
+    pygame.display.init()
+    pygame.font.init()
+    if opts.sound:
+        try:
+            pygame.mixer.init(FREQ, BITSIZE, CHANNELS, BUFFER)
+        except pygame.error, exc:
+            raise
+            # TODO: bail out to no_sound(exc)
+    else:
+        # Ensure get_sound returns nothing, so everything else just works
+        # TODO: bail out to disable_sound()
+        pass
+
+    display =  pygame.display.set_mode(SCREEN, SWSURFACE)
+    #pygame.display.set_icon(pygame.image.load(
+    #    data.filepath('icons/nine_tales24x24.png')))
+    pygame.display.set_caption("Nine Tales")
+
+    raw_input('?')
+
+    #shell = MainShell(display)
+    #try:
+    #    shell.run()
+    #except KeyboardInterrupt:
+    #    pass
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/skaapsteker/constants.py	Sun Apr 03 15:30:22 2011 +0200
@@ -0,0 +1,10 @@
+# Useful constants
+# copyright skaapsteker team (see COPYRIGHT file for details)
+
+SCREEN = (800, 600)
+FREQ = 44100   # same as audio CD
+BITSIZE = -16  # unsigned 16 bit
+CHANNELS = 2   # 1 == mono, 2 == stereo
+BUFFER = 1024  # audio buffer size in no. of samples
+
+DEBUG = False