def __init__(self):
        print("began")
        self.taskMgr = taskMgr
        with open('config.json') as data_file:    
            self.conf = json.load(data_file)
        self.ServerConnection = ServerConnection()#uncomment when going live
        self.ServerConnection.connect(self.conf['host'],self.conf['port'])#uncomment when going live
        props = WindowProperties( )
        props.setTitle( 'Log In' )
        props.setFixedSize(True)
        props.setSize(1280,740)
        props.setOrigin(-2,-2)
        base.win.requestProperties( props )
        self.base = ShowBase
        self.main_theme = base.loader.loadSfx("assets/sounds/terminator_theme.ogg")
        self.main_theme.play()
        
        self.username = ""
        
        self.authConnection = AuthConnectionModel(self)#uncomment when going live
        
        self.heartbeatConnection = HeartbeatConnectionModel()#uncomment when going live
        
        self.ServerConnection.setupConnectionModel(self.heartbeatConnection)#uncomment when going live
        
        self.globalChatConnection = ChatConnectionModel(self)
        self.ServerConnection.setupConnectionModel(self.globalChatConnection)
        
        self.queueConnection = QueueConnectionModel(self)
        self.ServerConnection.setupConnectionModel(self.authConnection)#uncomment when going live
        
        self.friendConnection = FriendConnectionModel(self)
        self.ServerConnection.setupConnectionModel(self.friendConnection)
        
        
        self.taskMgr.doMethodLater(self.conf['heartbeatRate'], self.doHeartbeat, "heartbeat")#uncomment when going live
        
        self.taskMgr.doMethodLater(self.conf['heartbeatRate'], self.doHeartbeat, "heartbeat")
        
        self.screen = Login(self)#uncomment when going live
        #self.screen = Menu(self)#comment this one when you are trying to log into it like normal

        self.ServerConnection.setupConnectionModel(self.queueConnection)
        
        self.taskMgr.doMethodLater(self.conf['heartbeatRate'], self.doHeartbeat, "heartbeat")
        
        self.taskMgr.doMethodLater(1, self.doSong, "song")
        
        self.screenType = "login"
        self.screen.run()
示例#2
0
    def __init__(self):
        self.taskMgr = taskMgr
        self.CharacterManager = CharacterManager(self, render, base,loader)
        base.disableMouse()
        
        base.setBackgroundColor(0,0,0)
        self.backgroundImage = OnscreenImage(parent=render2dp,image="assets/screens/renderpipeline03-full.jpg",scale=(4,1,1),pos=(0,-20,0))
        base.cam2dp.node().getDisplayRegion(0).setSort(-20)
        self.backgroundImage.posInterval(70,Point3(2, 0, 0),startPos=Point3(-2,0,0)).start()
        
        base.cTrav = CollisionTraverser()
        self.pusher = CollisionHandlerPusher()
        self.floor = CollisionHandlerFloor()
        floorNode = render.attachNewNode("Floor NodePath")
        # Create a collision plane solid.
        collPlane = CollisionPlane(Plane(Vec3(0, 0, 1), Point3(0, 0, 0)))
        # Call our function that creates a nodepath with a collision node

        floorCollisionNP = self.makeCollisionNodePath(floorNode, collPlane)
        with open('config.json') as data_file:    
            self.config = json.load(data_file)
        
        self.bypassServer = self.config['bypassServer']
        self.jumpTo = self.config['jumpTo']
        self.ServerConnection = ServerConnection()
        self.NotificationScreen = NotificationScreen(self)
        self.CharacterListScreen = CharacterListScreen(self)
        self.CharacterListScreen.hideScreen()
        
        
        if not self.bypassServer:
            self.ServerConnection.connect(self.config['host'],self.config['port'])
       
        
        if self.jumpTo == 1:
            self.doAuthScreen()
        elif self.jumpTo == 2:
            self.doSelectionScreen()
        elif self.jumpTo == 3:
            self.setPlayerCharacter(RalphCharacter(self,render,base,loader))
            self.doGameScreen()
        else:
            self.doAuthScreen()
示例#3
0
class World(DirectObject):

    def __init__(self):
        self.taskMgr = taskMgr
        self.CharacterManager = CharacterManager(self, render, base,loader)
        base.disableMouse()
        
        base.setBackgroundColor(0,0,0)
        self.backgroundImage = OnscreenImage(parent=render2dp,image="assets/screens/renderpipeline03-full.jpg",scale=(4,1,1),pos=(0,-20,0))
        base.cam2dp.node().getDisplayRegion(0).setSort(-20)
        self.backgroundImage.posInterval(70,Point3(2, 0, 0),startPos=Point3(-2,0,0)).start()
        
        base.cTrav = CollisionTraverser()
        self.pusher = CollisionHandlerPusher()
        self.floor = CollisionHandlerFloor()
        floorNode = render.attachNewNode("Floor NodePath")
        # Create a collision plane solid.
        collPlane = CollisionPlane(Plane(Vec3(0, 0, 1), Point3(0, 0, 0)))
        # Call our function that creates a nodepath with a collision node

        floorCollisionNP = self.makeCollisionNodePath(floorNode, collPlane)
        with open('config.json') as data_file:    
            self.config = json.load(data_file)
        
        self.bypassServer = self.config['bypassServer']
        self.jumpTo = self.config['jumpTo']
        self.ServerConnection = ServerConnection()
        self.NotificationScreen = NotificationScreen(self)
        self.CharacterListScreen = CharacterListScreen(self)
        self.CharacterListScreen.hideScreen()
        
        
        if not self.bypassServer:
            self.ServerConnection.connect(self.config['host'],self.config['port'])
       
        
        if self.jumpTo == 1:
            self.doAuthScreen()
        elif self.jumpTo == 2:
            self.doSelectionScreen()
        elif self.jumpTo == 3:
            self.setPlayerCharacter(RalphCharacter(self,render,base,loader))
            self.doGameScreen()
        else:
            self.doAuthScreen()
        
    def setPlayerCharacter(self,Character):
        self.Character = Character
        self.Character.placeAt((random.uniform(-10.0,10.0),random.uniform(-10.0,10.0),0))
        self.MoveManager = MoveManager(self)
        
    def doAuthScreen(self):
        self.authScreen = AuthScreen(self,render,base)
        
    def doSelectionScreen(self):
        self.characterModels = []
        self.characterModels.append(["Ralph",RalphCharacter(self,render,base,loader)])
        self.characterModels.append(["Panda",PandaCharacter(self,render,base,loader)])
        self.characterModels.append(["Motocycle",VehicleCharacter(self,render,base,loader)])
        
        self.selectScreen = CharacterSelectScreen(self,render,base,camera)
    
    def doGameScreen(self):
        self.heartbeatConnection = HeartbeatConnectionModel()
        self.ServerConnection.setupConnectionModel(self.heartbeatConnection)
        self.accept("tab",self.CharacterListScreen.toggleScreen)
        self.stopHeartbeat = False
        self.stopSendingMovement = False
        
        self.backgroundImage.destroy()
        self.Character.setControls()
        self.Character.actor.setHpr(0,0,0)
        taskMgr.add(self.Character.move,"moveTask")
        
        
        self.inst = []
        self.inst.append(addInstructions(0.95, "[ESC]: Quit/Close Chat Window"))
        self.inst.append(addInstructions(0.90, "[a]: Rotate Player Left"))
        self.inst.append(addInstructions(0.85, "[d]: Rotate Player Right"))
        self.inst.append(addInstructions(0.80, "[w]: Move Player Forward"))
        self.inst.append(addInstructions(0.75, "[s]: Move Player Backward"))
        self.inst.append(addInstructions(0.70, "[shift+w]: Move Player Fast"))
        self.inst.append(addInstructions(0.65, "[q]: Rotate Camera Left"))
        self.inst.append(addInstructions(0.60, "[e]: Rotate Camera Right"))
        self.inst.append(addInstructions(0.55, "[tab]: Show players"))
        if not self.bypassServer:
            self.inst.append(addInstructions(0.50, "[t]: Display Chat Window"))
            self.inst.append(addInstructions(0.45, "[p]: Display PM Window")) 
        
        # Set up the environment
        self.environ = loader.loadModel("models/square")
        self.environ.reparentTo(render)
        self.environ.setPos(0,0,0)
        self.environ.setScale(100,100,1)
        self.moon_tex = loader.loadTexture("models/moon_1k_tex.jpg")
        self.environ.setTexture(self.moon_tex, 1)
        
        self.staticRefSun = StaticModelSun(self,render,base,loader)
        self.staticRefVenus = StaticModelVenus(self,render,base,loader)
        self.staticRefEarth = StaticModelEarth(self,render,base,loader)

        self.sun = self.staticRefSun.getSun()
        self.venus = self.staticRefVenus.getVenus()
        self.earth = self.staticRefEarth.getEarth()
        
        taskMgr.add(self.staticRefSun.rotateSun,"rotateSun")
        taskMgr.add(self.staticRefVenus.rotateVenus,"rotateVenus")
        taskMgr.add(self.staticRefEarth.rotateEarth,"rotateEarth")
        taskMgr.add(self.staticRefEarth.stopRotateEarth,"stopRotateEarth")
        taskMgr.add(self.staticRefSun.stopRotateSun,"stopRotateSun")
        taskMgr.add(self.staticRefVenus.stopRotateVenus,"stopRotateVenus")
        taskMgr.add(self.setToGround, "setToGround")
        
        if not self.bypassServer:
            taskMgr.doMethodLater(self.config['heartbeatRate'],self.doHeartbeat,"heartbeat")
            taskMgr.doMethodLater(self.config['sendMoveRate'],self.MoveManager.sendMoves,"movement")
        
        #Change Camera Position Later
        base.camera.setPos(self.Character.actor.getX(),self.Character.actor.getY()+10,2)

        # Create some lighting
        ambientLight = AmbientLight("ambientLight")
        ambientLight.setColor(Vec4(.3, .3, .3, 1))
        directionalLight = DirectionalLight("directionalLight")
        directionalLight.setDirection(Vec3(-5, -5, -5))
        directionalLight.setColor(Vec4(1, 1, 1, 1))
        directionalLight.setSpecularColor(Vec4(1, 1, 1, 1))
        render.setLight(render.attachNewNode(ambientLight))
        render.setLight(render.attachNewNode(directionalLight))
        
        if not self.bypassServer:
            self.chatScreen = ChatScreen(self,render,base)            
            self.pChatScreen = PrivateChatScreen(self,render,base)
            self.chatScreen.hideScreen()
            self.pChatScreen.hideScreen()
        
    def doHeartbeat(self,task):
        if self.stopHeartbeat:
            return None
        self.heartbeatConnection.sendHeartbeat()
        return task.again
    
    def makeCollisionNodePath(self, nodepath, solid):
        '''
        Creates a collision node and attaches the collision solid to the
        supplied NodePath. Returns the nodepath of the collision node.
        '''
        # Creates a collision node named after the name of the NodePath.
        collNode = CollisionNode("%s c_node" % nodepath.getName())
        collNode.addSolid(solid)
        collisionNodepath = nodepath.attachNewNode(collNode)
        return collisionNodepath
    
    def setToGround(self, task):
        self.sun.setZ(0)
        self.venus.setZ(0)
        self.earth.setZ(0)
        return task.cont
    
    def endSession(self):
        self.stopHeartbeat = True
        self.stopSendingMovement = True
        self.endSession = EndSessionConnectionModel(self.exit)
        self.ServerConnection.setupConnectionModel(self.endSession)
        
        if not self.bypassServer:
            self.endSession.sendMessage(self.Character.actor.getPos(),self.Character.actor.getH())
        
        #Forces an exit
        taskMgr.doMethodLater(3,self.exit,"forceExit")
        
    def exit(self,data):
        if data != 1:
            print "Houston, we got a problem"
        sys.exit()
 def sendMessage(self,pos,h):
     request = self.buildRequestPackage(self.CODE_SEND_SAVE)
     request.addString(str(pos[0])+","+str(pos[1])+","+str(pos[2])+","+str(h))
     ServerConnection.sendMessage(self,request)
示例#5
0
class World(DirectObject):
    #client side making it easier and not having to log in everytime for debuging just follow the comments
    def __init__(self):
        print("began")
        self.taskMgr = taskMgr
        with open('config.json') as data_file:    
            self.conf = json.load(data_file)
        self.ServerConnection = ServerConnection()#uncomment when going live
        self.ServerConnection.connect(self.conf['host'],self.conf['port'])#uncomment when going live
        props = WindowProperties( )
        props.setTitle( 'Log In' )
        props.setFixedSize(True)
        props.setSize(1280,740)
        props.setOrigin(-2,-2)
        base.win.requestProperties( props )
        self.base = ShowBase
        self.main_theme = base.loader.loadSfx("assets/sounds/terminator_theme.ogg")
        self.main_theme.play()
        
        self.username = ""
        self.balance = "900000"

        self.authConnection = AuthConnectionModel(self)#uncomment when going live
        self.authConnection.setHandler(self.parseAuthResponse, self.parseRegResponse)
        self.ServerConnection.setupConnectionModel(self.authConnection)#uncomment when going live
       
        
        self.heartbeatConnection = HeartbeatConnectionModel()#uncomment when going live
        
        self.ServerConnection.setupConnectionModel(self.heartbeatConnection)#uncomment when going live
        
        
        self.taskMgr.doMethodLater(self.conf['heartbeatRate'], self.doHeartbeat, "heartbeat")#uncomment when going live
        
        self.taskMgr.doMethodLater(self.conf['heartbeatRate'], self.doHeartbeat, "heartbeat")
        
        self.screen = Login(self)#uncomment when going live
        #self.screen = Menu(self)#comment this one when you are trying to log into it like normal

        
        self.taskMgr.doMethodLater(self.conf['heartbeatRate'], self.doHeartbeat, "heartbeat")
        
        self.taskMgr.doMethodLater(1, self.doSong, "song")
        
        self.screenType = "login"
        self.screen.run()
    
    def doHeartbeat(self,task):
        self.heartbeatConnection.sendHeartbeat()
        return task.again
    
    def doSong(self,task):
        if self.main_theme.status() == self.main_theme.READY:
            self.main_theme.play()
        return task.again
    
    def doMenu(self):
        print("doing menu")
        self.screen.unloadScreen()
        self.screenType = "menu"
        self.screen = Menu(self)
    
    def parseAuthResponse(self,data):
        if data == 1:
            print("unloading")
            self.doMenu()
        else: 
            if data == 2:
                self.screen.setStatusText("Already logged in")
            else:
                self.screen.setStatusText("Invalid username/password")   
            self.screen.enter_btn['state'] = DGG.NORMAL
            self.screen.register_btn['state'] = DGG.NORMAL        
        
    def parseRegResponse(self,data):
        if data == 1:
            print("unloading")
            self.doMenu()
        else:
            self.screen.setStatusText("User already exists")   
            self.screen.cancel_btn['state'] = DGG.NORMAL
            self.screen.register_btn['state'] = DGG.NORMAL
 def sendHeartbeat(self):
     request = self.buildRequestPackage(self.CODE_SEND_MSG)
     ServerConnection.sendMessage(self,request)
 def sendRegisterRequest(self,username,password):
     request = self.buildRequestPackage(self.CODE_SEND_REG)
     request.addString(username)
     request.addString(password)
     ServerConnection.sendMessage(self,request)
 def sendDetail(self,carId,typeId):
     request = self.buildRequestPackage(self.CODE_SEND_DETAILS)
     request.addInt32(carId)
     request.addInt32(typeId)
     ServerConnection.sendMessage(self,request)
 def sendReadyMessage(self, message):
     request = self.buildRequestPackage(self.CODE_READY_MSG)
     request.addInt32(message)
     ServerConnection.sendMessage(self,request)
 def sendFriendListRequest(self):
     request = self.buildRequestPackage(self.CODE_SEND_LIST_MSG)
     ServerConnection.sendMessage(self,request)
 def sendUpdateMessage(self,username, status):
     #status is 0 if accepting a request, 1 if removing a friend or rejecting request
     request = self.buildRequestPackage(self.CODE_SEND_UPDATE_MSG)
     request.addString(username)
     request.addInt32(status)
     ServerConnection.sendMessage(self,request)
 def sendRequestMessage(self,username):
     request = self.buildRequestPackage(self.CODE_SEND_REQUEST_MSG)
     request.addString(username)
     ServerConnection.sendMessage(self,request)
 def sendNull(self):
     request = self.buildRequestPackage(self.CODE_SEND_NULL)
     ServerConnection.sendMessage(self,request)
 def sendCurrency(self):
     request = self.buildRequestPackage(self.CODE_SEND_CURRENCY)
     ServerConnection.sendMessage(self,request)
 def sendPurchase(self,carId,typeId):
     request = self.buildRequestPackage(self.CODE_SEND_PURCHASE)
     request.addInt32(carId)
     request.addInt32(typeId)
     ServerConnection.sendMessage(self,request)
 def sendQueueMessage(self,message):
     request = self.buildRequestPackage(self.CODE_SEND_MSG)
     request.addInt32(message)
     ServerConnection.sendMessage(self,request)
 def sendInviteMessage(self,recipient):
     print "Sending invite to", recipient
     request = self.buildRequestPackage(self.CODE_SEND_MSG)
     request.addString(recipient)
     ServerConnection.sendMessage(self,request)
 def sendChatMessage(self,message):
     request = self.buildRequestPackage(self.CODE_SEND_MSG)
     request.addString(message)
     ServerConnection.sendMessage(self,request)
 def sendCar(self,carId,paintId,tiresId):
     request = self.buildRequestPackage(self.CODE_SEND_CAR)
     request.addInt32(carId)
     request.addInt32(paintId)
     request.addInt32(tiresId)
     ServerConnection.sendMessage(self,request)