Пример #1
0
    def run(self):

        print(str(bool(glutInit)))
        print("hello and weolcome")
        print(
            "if you see an error next try the unofficial binaries of pyopengl")

        print("initializing glut etc")
        glutInit(sys.argv)
        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH)
        glutInitWindowSize(640, 480)
        glutCreateWindow(name)

        print("set blend function")
        glBlendFunc(GL_SRC_ALPHA, GL_ONE)

        print("set colours and lights")
        glClearColor(0., 0., 0., 1.)
        glShadeModel(GL_SMOOTH)
        glEnable(GL_CULL_FACE)
        glEnable(GL_DEPTH_TEST)
        glEnable(GL_LIGHTING)
        glEnable(GL_NORMALIZE)

        print("set light 1")
        lightZeroPosition = [0, 0, 00, 1]
        glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition)
        lightZeroColor = [0.2, 0.2, 0.2, 0.5]  #green tinged
        glEnable(GL_LIGHT0)
        glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor)
        glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.025)
        glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.0025)

        #print ("set light 2")
        #lightZeroPosition2 = [0,1,0]
        #glLightfv(GL_LIGHT1, GL_POSITION, lightZeroPosition2)
        #lightZeroColor2 = [1,1,1,1.0] #green tinged
        #glEnable(GL_LIGHT1)
        #glLightfv(GL_LIGHT1, GL_DIFFUSE, lightZeroColor2)
        #glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 0.2)
        #glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.05)

        #print ("set light 3")
        ##self.key_light.z=5
        #self.key_light = XYZ(10,0,15)
        #glLightfv(GL_LIGHT2, GL_POSITION, [self.key_light.x,self.key_light.y,self.key_light.z,0.01])
        #glEnable(GL_LIGHT2)
        #glLightfv(GL_LIGHT2, GL_DIFFUSE, [0.8,0.8,0.8,1.0])
        #glLightfv(GL_LIGHT2, GL_AMBIENT, [0.5,0.5,0.5,1.0])
        #glLightfv(GL_LIGHT2, GL_SPECULAR, [1.0,1.0,1.0,1.0])
        #glLightf(GL_LIGHT2, GL_CONSTANT_ATTENUATION, 0.01)
        #glLightf(GL_LIGHT2, GL_LINEAR_ATTENUATION, 0.01)
        #
        #initialization of letters
        print("initialzing letters")
        self.letters = Letters.Letters()

        #for game models
        print("making model lists")
        MakeLists()

        print("ignore key repeat")
        glutIgnoreKeyRepeat(1)

        print("attach glut events to functions")
        glutSpecialFunc(self.keydownevent)
        glutSpecialUpFunc(self.keyupevent)
        glutReshapeFunc(self.reshape)

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

        print("initial projection")
        glMatrixMode(GL_PROJECTION)
        gluPerspective(60.0, 640.0 / 480., 1., 50.)
        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()

        print("generating level")
        self.level = Level.generateLevel(0)
        self.solomon = Solomon(self.level.solomon_start)

        print("keys set up")
        self.initkey("zxdcfvqaopm")
        self.animate()

        print("about to loop...")
        glutMainLoop()

        return
Пример #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
Пример #3
0
    def __init__(self):

        print((bool(glutInit)))
        glutInit(sys.argv)
        # glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH)

        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH
                            | GLUT_MULTISAMPLE)
        glEnable(GL_MULTISAMPLE)

        glClear(GL_COLOR_BUFFER_BIT)
        glEnable(GL_BLEND)
        glEnable(GL_POLYGON_SMOOTH)
        glDisable(GL_DEPTH_TEST)

        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)

        # // 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 = [0, 0, 5]
        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)

        MakeLists()

        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.reset_cam()
        self.animate()

        glutMainLoop()

        return
Пример #4
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
Пример #5
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
Пример #6
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)
        glEnable(GL_DEPTH_TEST)
        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)
        
        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.,1.,50.)
        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()
        
        '''
        self.level=Level([
            ".sssssssssssssss.",
            "s...............s",
            "s.......d.......s",
            "[email protected]",
            "s....bsbbbs.....s",
            "s...b.b343b.....s",
            "s..b..sbbbs..g..s",
            "s......bbb......s",
            "s...2.......2...s",
            "s.b.sbs.1.sbs...s",
            "s.bbbb...b.bbb..s",
            "s..b.bbbb.b.....s",
            "sb.......b......s",
            ".sssssssssssssss."])
        '''
        
        self.level=Level([
            ".sssssssssssssss.",
            "s...............s",
            "s.......d.......s",
            "s.5.............s",
            "s.....sbbbs.....s",
            "s.....b343b.....s",
            "s..g..sbbbs..g..s",
            "s......bbb......s",
            "s...2.......2...s",
            "s...sbs.1.sbs...s",
            "[email protected]",
            "s...sbs...sbs...s",
            "s...............s",
            ".sssssssssssssss."])
        
        '''
        self.level=Level([
            "sssssssssssssssss",
            "s...............s",
            "s.6.6...........s",
            "s.......4.....k.s",
            "s.ss.........bb.s",
            "s...ss.....bb...s",
            "s.....ss.bb.....s",
            "s...............s",
            "s.....bbbss.....s",
            "[email protected]",
            "s.bb.........ss.s",
            "s...............s",
            "s...............s",
            "sssssssssssssssss"]
            
        '''
        '''
        self.level=Level([
            "sssssssssssssssss",
            "s...............s",
            "s...............s",
            "s...............s",
            "s...............s",
            "s...............s",
            "s...............s",
            "s...............s",
            "s...............s",
            "[email protected]",
            "s...............s",
            "s...............s",
            "s...............s",
            "sssssssssssssssss"]
            
        '''
        
        
        self.initkey("zxdcfvqaopm")
        
        self.animate()
        
        glutMainLoop()

        return