Пример #1
0
	def positionCamera(self):
		carRepresentation=self.getCameraCar()

		lookAtSegment=carRepresentation.getSegmentPosition()+1
		if lookAtSegment>float(len(self.segments)-1):
			lookAtSegment=lookAtSegment-float(len(self.segments))

		carWorldPosition=TrackGeometry.getWorldPositionByTrackPosition(self.segments,
																			carRepresentation.getSegmentPosition(),
			  																carRepresentation.getSidewaysPosition())

		carBearingPosition=TrackGeometry.getWorldPositionByTrackPosition(self.segments,
																			lookAtSegment,
			  																carRepresentation.getSidewaysPosition())

		cameraSegmentPosition=carRepresentation.getSegmentPosition()-2.5
		if cameraSegmentPosition<0:
			cameraSegmentPosition=cameraSegmentPosition+len(self.segments)

		cameraWorldPosition=TrackGeometry.getWorldPositionByTrackPosition(self.segments,
																			cameraSegmentPosition,
			  																carRepresentation.getSidewaysPosition())

		base.camera.setPos(cameraWorldPosition["xpos"],cameraWorldPosition["ypos"],0.5)
		base.camera.lookAt(carWorldPosition["xpos"],carWorldPosition["ypos"],0.5);

		cameraVectorX=carWorldPosition["xpos"]-cameraWorldPosition["xpos"]
		cameraVectorY=carWorldPosition["ypos"]-cameraWorldPosition["ypos"]
		cameraDegreesRotation=self.convertVectorToDegreesRotation(Geometry.Point(cameraVectorX,cameraVectorY))
		self.visualTrackSession.setCameraDegreesRotationHint(cameraDegreesRotation)
Пример #2
0
    def positionCamera(self):
        carRepresentation = self.getCameraCar()

        lookAtSegment = carRepresentation.getSegmentPosition() + 1
        if lookAtSegment > float(len(self.segments) - 1):
            lookAtSegment = lookAtSegment - float(len(self.segments))

        carWorldPosition = TrackGeometry.getWorldPositionByTrackPosition(
            self.segments, carRepresentation.getSegmentPosition(),
            carRepresentation.getSidewaysPosition())

        carBearingPosition = TrackGeometry.getWorldPositionByTrackPosition(
            self.segments, lookAtSegment,
            carRepresentation.getSidewaysPosition())

        cameraSegmentPosition = carRepresentation.getSegmentPosition() - 2.5
        if cameraSegmentPosition < 0:
            cameraSegmentPosition = cameraSegmentPosition + len(self.segments)

        cameraWorldPosition = TrackGeometry.getWorldPositionByTrackPosition(
            self.segments, cameraSegmentPosition,
            carRepresentation.getSidewaysPosition())

        base.camera.setPos(cameraWorldPosition["xpos"],
                           cameraWorldPosition["ypos"], 0.5)
        base.camera.lookAt(carWorldPosition["xpos"], carWorldPosition["ypos"],
                           0.5)

        cameraVectorX = carWorldPosition["xpos"] - cameraWorldPosition["xpos"]
        cameraVectorY = carWorldPosition["ypos"] - cameraWorldPosition["ypos"]
        cameraDegreesRotation = self.convertVectorToDegreesRotation(
            Geometry.Point(cameraVectorX, cameraVectorY))
        self.visualTrackSession.setCameraDegreesRotationHint(
            cameraDegreesRotation)
Пример #3
0
	def addPuddle(self,percentDistance,trackSide):
		segmentIndex=int(float(len(self.segments))/100*percentDistance)
		if trackSide=='left':
			sidewaysPosition=-0.4
		else:
			sidewaysPosition=0.4

		currentSegmentVector=self.segments[segmentIndex].getVector()

		rotation=self.convertVectorToDegreesRotation(currentSegmentVector)+270.0
		if rotation>360.0:
			rotation=rotation-360.0

		worldPosition=TrackGeometry.getWorldPositionByTrackPosition(self.segments,segmentIndex,sidewaysPosition)
		self.visualTrackSession.addPuddle(worldPosition['xpos'],worldPosition['ypos'],rotation)
		self.puddlePositions.append({ 'sidewaysposition': sidewaysPosition, 'segment': float(segmentIndex) })
Пример #4
0
    def addPuddle(self, percentDistance, trackSide):
        segmentIndex = int(float(len(self.segments)) / 100 * percentDistance)
        if trackSide == 'left':
            sidewaysPosition = -0.4
        else:
            sidewaysPosition = 0.4

        currentSegmentVector = self.segments[segmentIndex].getVector()

        rotation = self.convertVectorToDegreesRotation(
            currentSegmentVector) + 270.0
        if rotation > 360.0:
            rotation = rotation - 360.0

        worldPosition = TrackGeometry.getWorldPositionByTrackPosition(
            self.segments, segmentIndex, sidewaysPosition)
        self.visualTrackSession.addPuddle(worldPosition['xpos'],
                                          worldPosition['ypos'], rotation)
        self.puddlePositions.append({
            'sidewaysposition': sidewaysPosition,
            'segment': float(segmentIndex)
        })
Пример #5
0
	def advanceCars(self):
		soundServer=SoundServer.getInstance()

		for carRepresentation in self.logicalCarRepresentations:

			carRepresentation.move()

			carWorldPosition=TrackGeometry.getWorldPositionByTrackPosition(self.getSegments(),
																			carRepresentation.getSegmentPosition(),
			  																carRepresentation.getSidewaysPosition())
	
			carRepresentation.getVisualPeer().setPos(carWorldPosition["xpos"],carWorldPosition["ypos"],0)

			currentSegmentComponents=math.modf(carRepresentation.getSegmentPosition())
			distanceThroughCurrentSegment=currentSegmentComponents[0]

			currentSegmentIndex=int(math.floor(carRepresentation.getSegmentPosition()))
			nextSegmentIndex=currentSegmentIndex+1
			if nextSegmentIndex>len(self.segments)-1:
				nextSegmentIndex=nextSegmentIndex-len(self.segments)

			currentSegmentVector=self.segments[currentSegmentIndex].getVector()
			nextSegmentVector=self.segments[nextSegmentIndex].getVector()
			interpolatedX=currentSegmentVector.getX()+(nextSegmentVector.getX()-currentSegmentVector.getX())*distanceThroughCurrentSegment
			interpolatedY=currentSegmentVector.getY()+(nextSegmentVector.getY()-currentSegmentVector.getY())*distanceThroughCurrentSegment
			
			heading=self.convertVectorToDegreesRotation(Geometry.Point(interpolatedX,interpolatedY))
			heading=heading+270.0
			if heading>360.0:
				heading=heading-360.0

			if carRepresentation is self.getPlayerCar():
				pitch=carRepresentation.getEngine().getRevs()/6000+0.4

				SoundServer.getInstance().setEnginePitch(carRepresentation.getCarNumber(),pitch)

				heading=heading-(float)(carRepresentation.getSteering())*20
				if heading>360:
					heading=heading-360
				elif heading<0:
					heading=heading+360
			else:
				pitch=carRepresentation.getSpeed()*2+0.4
				soundServer.setEnginePitch(carRepresentation.getCarNumber(),pitch)

				distance=carRepresentation.getPlayerDistance()
				volume=(10.0-distance)/10.0
				soundServer.setEngineVolume(carRepresentation.getCarNumber(),volume)

				balance=self.getCameraCar().getSidewaysPosition()-carRepresentation.getSidewaysPosition()
				if balance<-1.0:
					balance=-1.0
				elif balance>1.0:
					balance=1.0
				soundServer.setEngineBalance(carRepresentation.getCarNumber(),balance)

			carRepresentation.getVisualPeer().setH(heading)

		playerCar=self.getPlayerCar()
		if playerCar is not None:
			playerCar.detectCollisions()
			playerCar.detectSceneryCollisions()

			if self.overtakeTrackingEnabled:
				playerSegmentPosition=playerCar.getSegmentPosition()
				playerLastSegmentPosition=playerCar.getLastSegmentPosition()
				if playerSegmentPosition>playerLastSegmentPosition:
					for car in self.getLogicalCarRepresentations():
						if car is not playerCar:
							if not car.getLastMoveWasWrap():
								computerSegmentPosition=car.getSegmentPosition()
								computerLastSegmentPosition=car.getLastSegmentPosition()
								if computerSegmentPosition>computerLastSegmentPosition:
									if playerLastSegmentPosition<computerLastSegmentPosition and playerSegmentPosition>computerSegmentPosition:
										self.carsPassed=self.carsPassed+1
									if playerLastSegmentPosition>computerLastSegmentPosition and playerSegmentPosition<computerSegmentPosition:
										self.carsPassed=self.carsPassed-1
Пример #6
0
	def __init__(self):

		super(TrackSession, self).__init__()

		self.paused=False

		trackData=TrackGeometry.loadFromFile('test.xml')
		self.segments=trackData.getTrackSegments()

		if self.getSessionType()==SessionType.qualifying:
			timeOfDay=TimeOfDay.earlyAfternoon
		else:
			timeOfDay=TimeOfDay.dusk

		self.visualTrackSession=VisualTrackSession(self,self.segments,timeOfDay)

		if self.getSessionType()==SessionType.qualifying:
			self.visualTrackSession.setExtendedPlayNotificationEnabled(False)

		self.sceneryPositions=[]
		self.puddlePositions=[]

		self.addStaticScenery('highsign-digdug',5,'left') # dig dug
		self.addStaticScenery('highsign-centipede',10,'right') # centipede
		self.addStaticScenery('highsign-rightarrow',15,'left') # right arrow
		self.addStaticScenery('highsign-poleposition',21,'left') # pole position
		self.addStaticScenery('highsign-atari',25,'right') # atari
		self.addStaticScenery('highsign-centipede',30,'right') # centipede
		self.addStaticScenery('highsign-amusement',31,'right') # namco
		self.addStaticScenery('lowsign-namco',35,'left') # namco
		self.addStaticScenery('highsign-digdug',32.5,'left') # dig dug
		self.addStaticScenery('lowsign-atari',39,'left') # atari
		self.addStaticScenery('highsign-leftarrow',48,'left') # left arrow 
		self.addStaticScenery('highsign-centipede',52,'right') # centipede
		self.addStaticScenery('lowsign-namco',54,'left')
		self.addStaticScenery('highsign-atari',60,'right')
		self.addStaticScenery('highsign-digdug',64,'left')
		self.addStaticScenery('highsign-amusement',68,'right')
		self.addStaticScenery('highsign-usa',72,'right')
		self.addStaticScenery('highsign-poleposition',77,'left')
		self.addStaticScenery('lowsign-atari',83,'left')
		self.addStaticScenery('highsign-digdug',87,'left')
		self.addStaticScenery('highsign-atari',91,'right')
		self.addStaticScenery('highsign-poleposition',93,'left')
		self.addStaticScenery('highsign-amusement',96,'right')

		# common to all sessions
		self.lapTimeTicks=-1
		self.frames=0
		self.secondsRemaining=-1
		self.logicalCarRepresentations=[]
		self.topScore=0
		self.events=[]
		self.score=0
		self.speed=0
		self.topSpeed=0
		self.scoringActive=False
		self.setPlayerCar(None)
		self.countdownTimerActive=False
		self.speedLimit=self.speedLimitUnlimited
		self.carsPassed=0

		self.initSession()

		self.setSessionLifecyclePoint(SessionLifecyclePoint.running)
Пример #7
0
    def advanceCars(self):
        soundServer = SoundServer.getInstance()

        for carRepresentation in self.logicalCarRepresentations:

            carRepresentation.move()

            carWorldPosition = TrackGeometry.getWorldPositionByTrackPosition(
                self.getSegments(), carRepresentation.getSegmentPosition(),
                carRepresentation.getSidewaysPosition())

            carRepresentation.getVisualPeer().setPos(carWorldPosition["xpos"],
                                                     carWorldPosition["ypos"],
                                                     0)

            currentSegmentComponents = math.modf(
                carRepresentation.getSegmentPosition())
            distanceThroughCurrentSegment = currentSegmentComponents[0]

            currentSegmentIndex = int(
                math.floor(carRepresentation.getSegmentPosition()))
            nextSegmentIndex = currentSegmentIndex + 1
            if nextSegmentIndex > len(self.segments) - 1:
                nextSegmentIndex = nextSegmentIndex - len(self.segments)

            currentSegmentVector = self.segments[
                currentSegmentIndex].getVector()
            nextSegmentVector = self.segments[nextSegmentIndex].getVector()
            interpolatedX = currentSegmentVector.getX() + (
                nextSegmentVector.getX() -
                currentSegmentVector.getX()) * distanceThroughCurrentSegment
            interpolatedY = currentSegmentVector.getY() + (
                nextSegmentVector.getY() -
                currentSegmentVector.getY()) * distanceThroughCurrentSegment

            heading = self.convertVectorToDegreesRotation(
                Geometry.Point(interpolatedX, interpolatedY))
            heading = heading + 270.0
            if heading > 360.0:
                heading = heading - 360.0

            if carRepresentation is self.getPlayerCar():
                pitch = carRepresentation.getEngine().getRevs() / 6000 + 0.4

                SoundServer.getInstance().setEnginePitch(
                    carRepresentation.getCarNumber(), pitch)

                heading = heading - (float)(
                    carRepresentation.getSteering()) * 20
                if heading > 360:
                    heading = heading - 360
                elif heading < 0:
                    heading = heading + 360
            else:
                pitch = carRepresentation.getSpeed() * 2 + 0.4
                soundServer.setEnginePitch(carRepresentation.getCarNumber(),
                                           pitch)

                distance = carRepresentation.getPlayerDistance()
                volume = (10.0 - distance) / 10.0
                soundServer.setEngineVolume(carRepresentation.getCarNumber(),
                                            volume)

                balance = self.getCameraCar().getSidewaysPosition(
                ) - carRepresentation.getSidewaysPosition()
                if balance < -1.0:
                    balance = -1.0
                elif balance > 1.0:
                    balance = 1.0
                soundServer.setEngineBalance(carRepresentation.getCarNumber(),
                                             balance)

            carRepresentation.getVisualPeer().setH(heading)

        playerCar = self.getPlayerCar()
        if playerCar is not None:
            playerCar.detectCollisions()
            playerCar.detectSceneryCollisions()

            if self.overtakeTrackingEnabled:
                playerSegmentPosition = playerCar.getSegmentPosition()
                playerLastSegmentPosition = playerCar.getLastSegmentPosition()
                if playerSegmentPosition > playerLastSegmentPosition:
                    for car in self.getLogicalCarRepresentations():
                        if car is not playerCar:
                            if not car.getLastMoveWasWrap():
                                computerSegmentPosition = car.getSegmentPosition(
                                )
                                computerLastSegmentPosition = car.getLastSegmentPosition(
                                )
                                if computerSegmentPosition > computerLastSegmentPosition:
                                    if playerLastSegmentPosition < computerLastSegmentPosition and playerSegmentPosition > computerSegmentPosition:
                                        self.carsPassed = self.carsPassed + 1
                                    if playerLastSegmentPosition > computerLastSegmentPosition and playerSegmentPosition < computerSegmentPosition:
                                        self.carsPassed = self.carsPassed - 1
Пример #8
0
    def __init__(self):

        super(TrackSession, self).__init__()

        self.paused = False

        trackData = TrackGeometry.loadFromFile('test.xml')
        self.segments = trackData.getTrackSegments()

        if self.getSessionType() == SessionType.qualifying:
            timeOfDay = TimeOfDay.earlyAfternoon
        else:
            timeOfDay = TimeOfDay.dusk

        self.visualTrackSession = VisualTrackSession(self, self.segments,
                                                     timeOfDay)

        if self.getSessionType() == SessionType.qualifying:
            self.visualTrackSession.setExtendedPlayNotificationEnabled(False)

        self.sceneryPositions = []
        self.puddlePositions = []

        self.addStaticScenery('highsign-digdug', 5, 'left')  # dig dug
        self.addStaticScenery('highsign-centipede', 10, 'right')  # centipede
        self.addStaticScenery('highsign-rightarrow', 15, 'left')  # right arrow
        self.addStaticScenery('highsign-poleposition', 21,
                              'left')  # pole position
        self.addStaticScenery('highsign-atari', 25, 'right')  # atari
        self.addStaticScenery('highsign-centipede', 30, 'right')  # centipede
        self.addStaticScenery('highsign-amusement', 31, 'right')  # namco
        self.addStaticScenery('lowsign-namco', 35, 'left')  # namco
        self.addStaticScenery('highsign-digdug', 32.5, 'left')  # dig dug
        self.addStaticScenery('lowsign-atari', 39, 'left')  # atari
        self.addStaticScenery('highsign-leftarrow', 48, 'left')  # left arrow
        self.addStaticScenery('highsign-centipede', 52, 'right')  # centipede
        self.addStaticScenery('lowsign-namco', 54, 'left')
        self.addStaticScenery('highsign-atari', 60, 'right')
        self.addStaticScenery('highsign-digdug', 64, 'left')
        self.addStaticScenery('highsign-amusement', 68, 'right')
        self.addStaticScenery('highsign-usa', 72, 'right')
        self.addStaticScenery('highsign-poleposition', 77, 'left')
        self.addStaticScenery('lowsign-atari', 83, 'left')
        self.addStaticScenery('highsign-digdug', 87, 'left')
        self.addStaticScenery('highsign-atari', 91, 'right')
        self.addStaticScenery('highsign-poleposition', 93, 'left')
        self.addStaticScenery('highsign-amusement', 96, 'right')

        # common to all sessions
        self.lapTimeTicks = -1
        self.frames = 0
        self.secondsRemaining = -1
        self.logicalCarRepresentations = []
        self.topScore = 0
        self.events = []
        self.score = 0
        self.speed = 0
        self.topSpeed = 0
        self.scoringActive = False
        self.setPlayerCar(None)
        self.countdownTimerActive = False
        self.speedLimit = self.speedLimitUnlimited
        self.carsPassed = 0

        self.initSession()

        self.setSessionLifecyclePoint(SessionLifecyclePoint.running)