Пример #1
0
def main():
    # Parse the command line options
    parser = optparse.OptionParser()
    parser.add_option("--debug", 
                      action="store_true", 
                      dest="debug", 
                      default=False,
                      help="start game in debugging mode")
    parser.add_option("--show-fps", 
                      action="store_true", 
                      dest="show_fps",
                      default=False,
                      help="start game in debugging mode")
    
    (opts, args) = parser.parse_args()

    options.DEBUG = opts.debug
    options.SHOW_FRAMERATE = opts.show_fps

    # Setup a custom data directory
    pyglet.resource.path = ["data"]
    pyglet.resource.reindex()
	
    error.debug("Importing scene")
    import scene # Imported here, because it depends on the options used
    error.debug("Success!")
    error.debug("Importing menu")
    import menu
    error.debug("Success!")
	
    # Add two windows
    game_manager.add_window(MainWindow(width=options.window_width, height=options.window_height, 
                                       caption=options.__appname__, resizable=True), 
                            "game_draw")
    if options.DEBUG: game_manager.add_window(BasicWindow(caption="Debug"), "debug_draw")
    
    # Add one scene
    game_manager.push(menu.MainMenu())

    # Start sound recordning here. Something is wrong with wonderful,
    # leading to strange segfaults. I'm gonna see if this fixes it.
    import wonderful
    wonderful.init(options.SAMPLE_RATE, options.DFT_SIZE)
    
    # Hand control over to the Game manager
    error.debug("Hiya, I'm gonna hand control over to the game manager")
    game_manager.run()
    wonderful.terminate()
Пример #2
0
    def __init__(self):
        BaseMenu.__init__(self)
        for name in os.listdir("songs"): #hackigt ("songs"), förbättra nån gång
            path = os.path.join("songs", name)
            if os.path.isdir(path): #now we're talking!!
                data = {}
                
                for fil in os.listdir(path):
                    attr = None
                    
                    if re.search("(?!^\.)\.(mp3|ogg)$", fil): #ska sättas i options
                        attr = "sound"
                    elif re.search("(?!^\.)\.(mid|midi)$", fil):
                        attr = "midi"
                    elif re.search("(?!^\.)\.(jpg|png|bmp)$", fil):
                        attr = "image"
                    elif fil == "info.txt":
                        attr = "info"
                        
                    data[attr] = os.path.join(path, fil)
                    
                if data.has_key("sound") and data.has_key("midi"):
                    if not data.has_key("image"):
                        img = defaultimage
                    else:
                        img = pyglet.image.load(data["image"])
                    if not data.has_key("info"):
                        songname = artist = ""
                    else:
                        songname, artist = parse_info(data["info"])                      
                    picture = SpriteMenuItem(None, 0, -img.height/2, 
                                             img, self.batch)
                    songtext = TextMenuItem(None, img.width/2, -img.height/2-10,
                       songname, self.batch)
                    artisttext = TextMenuItem(None, img.width/2, 
                       songtext.y - songtext.content_height - 5, artist, self.batch)
                    select_song = lambda d: lambda: game_manager.push(scene.GameScene(d["sound"], 
                                                                                      d["midi"]))
                    item = MenuItemGroup(select_song(data), 0, 0, 0, 
                                         (picture, songtext, artisttext)) 
                    self.items.append(item)
                else:
                    pass #hoppa över blir nog lättast

        self._select(0)

        #glClearColor(0x4b/255.0, 0x4b/255.0, 0x4b/255.0, 0)
            
        glClearDepth(1.0)               # Prepare for 3d. Actually, this might as well 
                                        # be in on_resize, no? Or maybe not. I don't know.

        glDepthFunc(GL_LEQUAL)          # Change the z-priority or whatever one should call it

        glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
        glHint(GL_LINE_SMOOTH_HINT, GL_NICEST)
        glHint(GL_POINT_SMOOTH_HINT, GL_NICEST)
        glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST)
Пример #3
0
    def on_key_press(self, window, symbol, modifiers):
        
        """Handles keyboard input. The keys are defined in options.py and are
        sorted according to namespaces. See that file for further information.

        Arguments:
        window -- the window that recieved the keypress
        symbol -- the key that was pressed
        modifiers -- the modifiers (ctrl, alt, etc.) that were down 
                     when the keypress occurred

        """
        
        if symbol == kb.test.exit:
            window.close()
        elif symbol == kb.test.threadtest:
            game_manager.push(SoundTestScene())
        elif symbol == kb.test.tabtest:
            game_manager.push(GameScene("data/pokemon-melody.mid"))
        elif symbol == kb.test.maintest:
            game_manager.push(MainTestScene())
        elif symbol == kb.test.up:
            game_manager.pop()
        else:
            print "Recieved keypress:", symbol, "\t\tModifiers:", modifiers
Пример #4
0
    def __init__(self):
        bg = pyglet.resource.image("menubg.png")
        
        BaseMenu.__init__(self, bg)
        
        #add menuitems
        run_game = lambda: game_manager.push(SongSelect())
        self.items.append(TextMenuItem(run_game, options.window_width/2,
                                       options.window_height, "Song Select", self.batch))
        self.items.append(TextMenuItem(game_manager.pop, 
                                       options.window_width/2, options.window_height - 50,
                                       u"Exit", self.batch))

        #required
        self._select(0)