Ejemplo n.º 1
0
Archivo: game.py Proyecto: ext/sphorse
    def __init__(self, size, fullscreen=False):
        parser = argparse.ArgumentParser()
        parser.add_argument('--score', action='store_true', help="Only show scores")
        parser.add_argument('-f', '--fullscreen', dest='fullscreen', action='store_true', help="Run in fullscreen")
        parser.add_argument(      '--windowed',   dest='fullscreen', action='store_false', help="Run in window")
        parser.add_argument('name', metavar='NAME', nargs='?', help="Player name")
        args = parser.parse_args()
        
        if args.score:
            score = Hiscore('.score', 'static.sidvind.com:80', '/2011/sphorse/', 2)
            score.fetch()
            score.print_global()
            sys.exit(0)
        
        if args.name is not None:
            # fix windows codepage encoding.
            self.name = args.name.decode(sys.getfilesystemencoding())
        else:
            self.name = raw_input(u'Player name: ').decode(sys.stdin.encoding)

        flags = OPENGL|DOUBLEBUF
        if args.fullscreen:
            flags |= FULLSCREEN

        pygame.display.set_mode(size.xy(), flags)
        pygame.display.set_caption('sporse runner')
        self._running = True

        glClearColor(0,0,0,1)
        glEnable(GL_DEPTH_TEST)
        glDepthFunc(GL_LEQUAL)
        glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
        glEnable(GL_TEXTURE_2D)
        glEnable(GL_BLEND)
        glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        
        glEnable(GL_CULL_FACE)
        glCullFace(GL_BACK)

        glFogi(GL_FOG_MODE, GL_LINEAR)
        glFogfv(GL_FOG_COLOR, (0,0,0,1))
        glFogf(GL_FOG_DENSITY, 1.0)
        glHint(GL_FOG_HINT, GL_DONT_CARE)
        glFogf(GL_FOG_START, 30.0)
        glFogf(GL_FOG_END, 45.0)
        glEnable(GL_FOG)

        # Play background "music" if audio was initialized properly.
        if pygame.mixer.get_init() is not None:
            self.music = pygame.mixer.Sound('sound/nyan2.ogg')
            self.music.play(loops=-1)

        self.goal = Sprite('goal.png', 1)

        self.on_resize(size=size)
Ejemplo n.º 2
0
Archivo: game.py Proyecto: ext/sphorse
    def hiscore(self, name, t, d):
        # Load hiscore and add current to it.
        score = Hiscore('.score', 'static.sidvind.com:80', '/2011/sphorse/', 2)
        score.add(name, distance=d, time=t)
        
        # Global hiscore.
        score.push()
        score.fetch(result=(name, d, t))
        
        # Store hiscore.
        score.store()

        print 'Total time: %ds' % t
        print 'Total distance: %dm' % d
        if score.placement > 0 and score.placement < 10:
            print 'Placement: %d' % (score.placement+1)
        print
        score.print_global()