Example #1
0
 def __init__(self, cars, time, map, players, playername):
     self.carHitSound = base.loader.loadSfx("Sounds/CRASH2.wav")
     self.startSound = base.loader.loadSfx("Sounds/ENGINESTART.wav")
     
     self.time = time
     self.map = map
     self.players = players
     self.playername = playername
     self.playername += " (0)"
     self.playerscores = []
     self.timer = -1
     
     world_loader = w_loader()
     world_loader.load_world(map)
     
     self.textWaitObject = OnscreenText(text="Waiting for players...", style=1, fg=(1,1,1,1), pos=(0.7,-0.95), scale = .07)
     
     global spawn_locations
     
     self.carData = cars
     self.carData.spos = spawn_locations
     self.carData.addCar()
     self.carData.index = 0
     self.carUpdates = [() for c in self.carData.carlist]
     self.ignore = []
     
     self.cManager = QueuedConnectionManager()
     self.cListener = QueuedConnectionListener(self.cManager, 0)
     self.cReader = QueuedConnectionReader(self.cManager, 0)
     self.cWriter = ConnectionWriter(self.cManager,0)
     self.activeConnections = []
     
     self.port_address = 9099 #No-other TCP/IP services are using this port
     self.backlog = 1000 #If we ignore 1,000 connection attempts, something is wrong!
     self.tcpSocket = self.cManager.openTCPServerRendezvous(self.port_address, self.backlog)
     
     self.cListener.addConnection(self.tcpSocket)
     
     taskMgr.add(self.tskListenerPolling,"Poll the connection listener",-39)
     taskMgr.add(self.tskReaderPolling,"Poll the connection reader",-40)
Example #2
0
 def myProcessDataFunction(self, netDatagram):
     # check a message and do what it says
     myIterator = PyDatagramIterator(netDatagram)
     msgID = myIterator.getUint8()
     if msgID == PRINT_MESSAGE: # This is a debugging message
         messageToPrint = myIterator.getString()
         print messageToPrint
     elif msgID == PLAYER_ASSIGNMENT_MESSAGE: # This assigns the player to a car
         playerNum = myIterator.getUint8()
         self.carData.index = playerNum
         self.playername += " (%d)"%playerNum
         carXpos = myIterator.getFloat32()
         carYpos = myIterator.getFloat32()
         carXvel = myIterator.getFloat32()
         carYvel = myIterator.getFloat32()
         carHeading = myIterator.getFloat32()
         carInput = []
         for i in range(5):
             carInput.append(myIterator.getBool())
         carLights = myIterator.getBool()
         carHp = myIterator.getInt32()
         self.updatePositions(playerNum, (carXpos, carYpos, carXvel, carYvel, carHeading, carInput, carLights, carHp))
     elif msgID == CAR_MESSAGE: # This updates a car
         carNum = myIterator.getUint8()
         if carNum != self.carData.index:
             carXpos = myIterator.getFloat32()
             carYpos = myIterator.getFloat32()
             carXvel = myIterator.getFloat32()
             carYvel = myIterator.getFloat32()
             carHeading = myIterator.getFloat32()
             carInput = []
             for i in range(5):
                 carInput.append(myIterator.getBool())
             carLights = myIterator.getBool()
             carHp = myIterator.getInt32()
             self.updatePositions(carNum, (carXpos, carYpos, carXvel, carYvel, carHeading, carInput, carLights, carHp))
     elif msgID == COLLIDED_MESSAGE: # This runs car-car collisions
         collisionFrom = myIterator.getUint8()
         if collisionFrom == self.carData.index:
             self.carHitSound.play()
             self.doCarCollision(myIterator.getUint8())
             self.cWriter.send(self.verifyCollisionMessage(), self.myConnection)
     elif msgID == MAP_MESSAGE: # This sets the map
         map = myIterator.getString()
         print map
         world_loader = w_loader()
         world_loader.load_world(map)
         global spawn_locations
         self.carData.spos = spawn_locations
     elif msgID == BEGIN_MESSAGE: # This starts the game
         self.carData.go = True
         self.textWaitObject.destroy()
         self.startSound.play()
     elif msgID == END_MESSAGE: # This ends the game, and then displays the score on the second receipt
         self.carData.go = False
         num = myIterator.getInt32()
         if num == -1:
             scoreDatagram = self.scoreDatagram()
             self.cWriter.send(scoreDatagram, self.myConnection)
         else:
             textytext = "Most Numerous Deaths:"
             for i in range(num):
                 textytext += "\n\n%s: %d"%(myIterator.getString(), myIterator.getInt32())
             self.textScore = OnscreenText(text=textytext, style=1, fg=(1,1,1,1), pos=(0,0.9), scale = .08)
Example #3
0
import direct.directbase.DirectStart #starts Panda
from pandac.PandaModules import *    #basic Panda modules
from direct.showbase.DirectObject import DirectObject  #for event handling
from direct.actor.Actor import Actor #for animated models
from direct.interval.IntervalGlobal import *  #for compound intervals
from direct.task import Task         #for update fuctions
import sys, math, random
from w_loader import w_loader
from terrain import terrain
from fog import *
from smoke_emitter import *
from carData import CarData
import pythonServer, pythonClient

world_loader = w_loader()
world_loader.load_world(1)

class World(DirectObject): #subclassing here is necessary to accept events
    def __init__(self):
        #WxPandaShell.__init__(self, fStartDirect=True) 
        #turn off default mouse control, otherwise can't reposition camera
        base.disableMouse()
        camera.setPosHpr(0, -15, 7, 0, -15, 0)
        self.loadModels()
        self.setupLights()
        self.setupCollisions()
        render.setShaderAuto() #turns on per-pixel lighting, normal mapping, etc (you probably want to use this)
        self.keyMap = {"left":0, "right":0, "forward":0}
        taskMgr.add(self.move, "moveTask")
        self.prevtime = 0
        self.ismoving = False