Exemplo n.º 1
0
    def __init__(self):

        
        print bool(glutInit)
        glutInit(sys.argv)
        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH)
        glutInitWindowSize(640,480)
        glutCreateWindow(name)
        
        glBlendFunc(GL_SRC_ALPHA, GL_ONE)
    
        glClearColor(0.,0.,0.,1.)
        glShadeModel(GL_SMOOTH)
        glEnable(GL_CULL_FACE)
        glCullFace(GL_BACK) 
        glEnable(GL_DEPTH_TEST)
        glDepthFunc(GL_LEQUAL)
        
        # // track material ambient and diffuse from surface color, call it before glEnable(GL_COLOR_MATERIAL)
        glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE)
        glEnable(GL_COLOR_MATERIAL)
            
        glEnable(GL_LIGHTING)
        lightZeroPosition = [10.,4.,10.,1.]
        lightZeroColor = [0.9,1.0,0.9,1.0] #green tinged
        glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition)
        glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor)
        glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.2)
        glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05)
        glEnable(GL_LIGHT0)
        
        #lightZeroPosition2 = [-10.,-4.,10.,1.]
        #lightZeroColor2 = [1.0,0.9,0.9,1.0] #green tinged
        #glLightfv(GL_LIGHT1, GL_POSITION, lightZeroPosition2)
        #glLightfv(GL_LIGHT1, GL_DIFFUSE, lightZeroColor2)
        #glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 0.2)
        #glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.05)
        #glEnable(GL_LIGHT1)
        
        MakeLists()
        
        
        glutIgnoreKeyRepeat(1)
        
        
        
        self.cheapModelTest1=Model()
        self.cheapModelTest1.loader("piece1.dat")
        
        self.cheapModelTest2=Model()
        self.cheapModelTest2.loader("piece2.dat")
        
        self.cheapModelTest3=Model()
        self.cheapModelTest3.loader("piece3.dat")
        
        self.cheapModelTest4=Model()
        self.cheapModelTest4.loader("piece4.dat")
        
        self.cheapModelTest5=Model()
        self.cheapModelTest5.loader("piece5.dat")
        
        
        
        glutSpecialFunc(self.keydownevent)
        glutSpecialUpFunc(self.keyupevent)

        glutKeyboardFunc(self.keydownevent)
        glutKeyboardUpFunc(self.keyupevent)
        glutDisplayFunc(self.display)
        #glutIdleFunc(self.display)
        
        glMatrixMode(GL_PROJECTION)
        gluPerspective(60.0,640.0/480.,0.001,20.0)
        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()
        
        
        self.initkey("zxdcfvqaopm")
        
        self.animate()
        
        glutMainLoop()

        return
Exemplo n.º 2
0
    def __init__(self, teamFile):

        print(teamFile)
        self.teams = {}

        if teamFile != None:

            try:

                line = 0
                for t in open(teamFile, "rb").read().split("\n"):
                    line += 1
                    if line == 1 and t != "TEAMNAMES":
                        raise Exception("bah not a list")
                    else:
                        if len(t) > 0 and line > 1:
                            print(t)
                            self.teams[t] = {"games": []}

            except Exception as e:
                print("dor?")
                print(e)
                self.teams = pickle.loads(open(teamFile, "rb").read())

            print(self.teams)

        else:
            self.teams["robin"] = {"games": []}
            self.teams["chris"] = {"games": []}
            self.teams["lisa"] = {"games": []}
            self.teams["burtosa"] = {"games": []}
            self.teams["sam"] = {"games": []}
            self.teams["alex"] = {"games": []}

        if teamFile != None:
            open(teamFile, "wb").write(pickle.dumps(self.teams))

        print((bool(glutInit)))
        glutInit(sys.argv)
        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH)
        glutInitWindowSize(self.WIDTH, self.HEIGHT)
        glutCreateWindow(name)

        glBlendFunc(GL_SRC_ALPHA, GL_ONE)

        glClearColor(0., 0., 0., 1.)
        glShadeModel(GL_SMOOTH)
        glEnable(GL_CULL_FACE)
        glCullFace(GL_BACK)
        glEnable(GL_DEPTH_TEST)
        glDepthFunc(GL_LEQUAL)

        glEnable(GL_LIGHTING)
        lightZeroPosition = [0, 0, 5]
        lightZeroColor = [1.0, 1.0, 1.0, 1.0]  #green tinged
        glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition)
        glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor)
        glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1)
        glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.02)
        glEnable(GL_LIGHT0)

        MakeLists()

        self.cheapModel = []

        self.cheapModel.append(Model("models/piece1.dat"))
        self.cheapModel.append(Model("models/piece2.dat"))
        self.cheapModel.append(Model("models/piece3.dat"))
        self.cheapModel.append(Model("models/piece4.dat"))
        self.cheapModel.append(Model("models/piece5.dat"))
        self.chap = Model("models/chap.dat")

        glutIgnoreKeyRepeat(1)

        glutReshapeFunc(self.reshape)

        glutSpecialFunc(self.joystick.keydownevent)
        glutSpecialUpFunc(self.joystick.keyupevent)

        glutKeyboardFunc(self.joystick.keydownevent)
        glutKeyboardUpFunc(self.joystick.keyupevent)
        glutDisplayFunc(self.display)
        #glutIdleFunc(self.display)

        glMatrixMode(GL_PROJECTION)
        gluPerspective(60.0, 640.0 / 480., 0.001, 100.0)
        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()

        ##self.initkey("zxdcfvqaopm")

        self.animate()
        self.start(yes="No")

        glutMainLoop()

        return
Exemplo n.º 3
0
    def __init__(self,teamFile):

        print(teamFile)
        self.teams={}

        if teamFile!=None:
            ##IF TEAM FILE INCLUDED

            try:
                line=0
                for t in open(teamFile,"rb").read().splitlines():
                    line+=1
                    print((t,line))
                    if line==1 and t!="TEAMNAMES":
                        raise Exception("bah not a list")
                    else:
                        if len(t)>0 and line>1:
                            print(t)
                            self.teams[t]={"games":[], "remaining": 2, "enabled":True}

            except Exception as e:
                print("dor?")
                print (e)
                self.teams=pickle.loads(open(teamFile,"rb").read())

            print(self.teams)
            
        else:
            ##NO TEAM FILE INCLUDED
            self.teams["robin"]={"games":[]}
            self.teams["chris"]={"games":[]}
            self.teams["lisa"]={"games":[]}
            self.teams["burtosa"]={"games":[]}
            self.teams["sam"]={"games":[]}
            self.teams["alex"]={"games":[]}


        self.CURRENT_TEAM=list(self.teams.keys())[0]

        if teamFile!=None: open(teamFile,"wb").write(pickle.dumps(self.teams,protocol=2))   #pickle.dump(your_object, your_file, protocol=2)

        #INITIALIZE ACTUAL SNAKE FOR MAIN SCREEN
        self.SNAKE=[]
        for sss in range(0,5):
            self.SNAKE.append(self.shct([25,25-sss],[0,1]))
            

        print((bool(glutInit)))
        glutInit(sys.argv)
        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH)
        glutInitWindowSize(self.WIDTH,self.HEIGHT)
        glutCreateWindow(name)

        glBlendFunc(GL_SRC_ALPHA, GL_ONE)

        glClearColor(0.,0.,0.,1.)
        glShadeModel(GL_SMOOTH)
        glEnable(GL_CULL_FACE)
        glCullFace(GL_BACK)
        glEnable(GL_DEPTH_TEST)
        glDepthFunc(GL_LEQUAL)

        glEnable(GL_LIGHTING)
        lightZeroPosition = [0,0,5]
        lightZeroColor = [1.0,1.0,1.0,1.0] #green tinged
        glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition)
        glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor)
        glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1)
        glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.02)
        glEnable(GL_LIGHT0)

        ##INITIALIZE LETTERS ETC FROM MODELS
        MakeLists()

        ##READ "CHEAP MODEL" 
        self.cheapModel=[]

        self.cheapModel.append(Model("models/piece1.dat"))
        self.cheapModel.append(Model("models/piece2.dat"))
        self.cheapModel.append(Model("models/piece3.dat"))
        self.cheapModel.append(Model("models/piece4.dat"))
        self.cheapModel.append(Model("models/piece5.dat"))
        self.cheapModel.append(Model("models/piece6.dat"))
        self.chap=Model("models/chap.dat")

        glutIgnoreKeyRepeat(1)

        glutReshapeFunc(self.reshape)

        glutSpecialFunc(self.joystick.keydownevent)
        glutSpecialUpFunc(self.joystick.keyupevent)

        glutKeyboardFunc(self.joystick.keydownevent)
        glutKeyboardUpFunc(self.joystick.keyupevent)
        glutDisplayFunc(self.display)
        #glutIdleFunc(self.display)

        glMatrixMode(GL_PROJECTION)
        gluPerspective(60.0,640.0/480.,0.001,100.0)
        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()

        ##self.initkey("zxdcfvqaopm")

        self.animate()
        self.start(yes="No")

        glutMainLoop()

        return