Пример #1
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
Пример #2
0
class Testing:

    keys={}
    cxx,cyy,czz=0,0,8
    fxx,fyy,fzz=0,0,0   
    joystick=Joystick() 
    
    lock=False
    lastFrameTime=0
    topFPS=0

    def animate(self,FPS=24):
    
        if self.lock==True: return
    
        currentTime=time()
    
        glutPostRedisplay()
        
        glutTimerFunc(int(1000/FPS), self.animate, FPS)

        drawTime=currentTime-self.lastFrameTime
        if drawTime>0:
            self.topFPS=int(1000/(drawTime))
            if int(100*time())%100==0:
                print "draw time "+str(drawTime)+" top FPS "+str(1000/drawTime)           
                #self.tcxx,self.tcyy,self.tczz=random.randint(5,14),random.randint(5,14),random.randint(5,14)
        else:
            drawTime=1
            

        self.lastFrameTime=time()

    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




    def draw(self):
        
        self.lock=True
        global X
        
        try:
     
            glTranslate(0,0,0.0)
            glRotate(X,1,1,0)
            #glutSolidCube(1)
            #glScale(2,2,2) 
            
            #print(("hello"))
            self.cheapModelTest1.drawMe()
            self.cheapModelTest2.drawMe()
            self.cheapModelTest3.drawMe()
            self.cheapModelTest4.drawMe()
            self.cheapModelTest5.drawMe()
            
            X+=3

        except:
            pass
            
        finally:                
            self.lock=False


    def initkey(self,cl):   
    
        for c in cl:
            self.keydownevent(c.lower(),0,0)        
            self.keyupevent(c.lower(),0,0)

    def display(self):

        glLoadIdentity()
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
        
        #glClearDepth(1.0)
        #glEnable(GL_DEPTH_TEST)
        #glDepthFunc(GL_LEQUAL)

        #glLoadIdentity()
        
        gluLookAt(self.cxx,self.cyy,self.czz,
                  self.fxx,self.fyy,self.fzz,
                  0,1,0)
        
        self.draw()
        
        glutSwapBuffers()
        #glFinish()

    def keydownevent(self,c,x,y):
    
        self.keys[c.lower()]=True
        glutPostRedisplay()
        
    def keyupevent(self,c,x,y):
    
        if self.keys.has_key(c.lower()): self.keys[c.lower()]=False
        glutPostRedisplay()
Пример #3
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
Пример #4
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