Esempio n. 1
0
    def applyGroundFriction(self):

        startSlowdownSidewaysPosition = self.startSlowdownSidewaysPosition
        speedAtMaxSidewaysPosition = self.speedAtMaxSidewaysPosition
        speedAtStartSlowdownSidewaysPosition = self.speedAtStartSlowdownSidewaysPosition
        maxSidewaysPosition = self.maxSidewaysPosition

        absoluteSidewaysPosition = math.fabs(self.getSidewaysPosition())

        segmentPositionComponents = math.modf(self.segmentPosition)
        lastSegmentPositionComponents = math.modf(self.lastSegmentPosition)

        if absoluteSidewaysPosition > 0.725 and absoluteSidewaysPosition < 1.15:
            if segmentPositionComponents[0] < lastSegmentPositionComponents[0]:
                SoundServer.getInstance().playBump()

        if absoluteSidewaysPosition > startSlowdownSidewaysPosition:
            forcedSpeed = speedAtStartSlowdownSidewaysPosition + (
                speedAtMaxSidewaysPosition -
                speedAtStartSlowdownSidewaysPosition) / (
                    maxSidewaysPosition - startSlowdownSidewaysPosition
                ) * (absoluteSidewaysPosition - startSlowdownSidewaysPosition)
            currentSpeed = self.getSpeed()
            if currentSpeed > forcedSpeed:
                self.engine.setSpeed(currentSpeed - 0.01)
	def addComputerCar(self,segmentPosition,sidewaysPosition,currentLane,speed,carAppearance):
		newLogicalCar=ComputerCarRepresentation(self)
		newLogicalCar.setSegmentPosition(segmentPosition)
		newLogicalCar.setSidewaysPosition(sidewaysPosition)
		newLogicalCar.setCurrentLane(currentLane)
		newLogicalCar.setSpeed(speed)
		newLogicalCar.setTrackSegments(self.segments)
		self.logicalCarRepresentations.append(newLogicalCar)
		newLogicalCar.setCarNumber(len(self.logicalCarRepresentations))
		SoundServer.getInstance().startEngine(newLogicalCar.getCarNumber())
		newLogicalCar.setVisualPeer(self.visualTrackSession.addCar(carAppearance,False))
		return newLogicalCar
	def addPlayerCar(self,segmentPosition,sidewaysPosition,speed,carAppearance):
		newLogicalCar=PlayerCarRepresentation(self)
		newLogicalCar.setSegmentPosition(segmentPosition)
		newLogicalCar.setSidewaysPosition(sidewaysPosition)
		newLogicalCar.setSpeed(speed)
		newLogicalCar.setTrackSegments(self.segments)
		newLogicalCar.setDriver(KeyboardDriver())
		self.logicalCarRepresentations.append(newLogicalCar)
		newLogicalCar.setCarNumber(len(self.logicalCarRepresentations))
		SoundServer.getInstance().startEngine(newLogicalCar.getCarNumber())
		SoundServer.getInstance().setEngineVolume(newLogicalCar.getCarNumber(),1.0)
		newLogicalCar.setVisualPeer(self.visualTrackSession.addCar(carAppearance,True))
		return newLogicalCar
	def advanceTime(self):
		if self.ticks%60==0:
			self.currentLight=self.currentLight+1
			if self.currentLight>0:
				if self.currentLight>1:
					self.visualTrackSession.setStartingLight(self.currentLight-1,False)
				self.visualTrackSession.setStartingLight(self.currentLight,True)
				if self.currentLight==4:
					SoundServer.getInstance().playLowPitchedHorn()
					self.endOfLife=True
				else:
					SoundServer.getInstance().playHighPitchedHorn()
		self.ticks=self.ticks+1
Esempio n. 5
0
 def addComputerCar(self, segmentPosition, sidewaysPosition, currentLane,
                    speed, carAppearance):
     newLogicalCar = ComputerCarRepresentation(self)
     newLogicalCar.setSegmentPosition(segmentPosition)
     newLogicalCar.setSidewaysPosition(sidewaysPosition)
     newLogicalCar.setCurrentLane(currentLane)
     newLogicalCar.setSpeed(speed)
     newLogicalCar.setTrackSegments(self.segments)
     self.logicalCarRepresentations.append(newLogicalCar)
     newLogicalCar.setCarNumber(len(self.logicalCarRepresentations))
     SoundServer.getInstance().startEngine(newLogicalCar.getCarNumber())
     newLogicalCar.setVisualPeer(
         self.visualTrackSession.addCar(carAppearance, False))
     return newLogicalCar
	def advanceTime(self):

		if self.ticks%self.toggleVisibilityTicks==0:
			SoundServer.getInstance().playHighBeep()
			if self.visible==True:
				self.hide()
				self.visible=False
			else:
				self.show()
				self.visible=True

		self.ticks=self.ticks+1
		if self.ticks==self.toggleVisibilityTicks*10:
			self.endOfLife=True			
	def advanceTime(self):

		self.visualSession.advanceTime()
		self.ticks=self.ticks+1

		if self.ticks==10*60:
			self.setDestination("highscores")
			self.closeSession()
		else:
			space=self.keyboardHandler.getSpaceStatus()
			if space==1:
				SoundServer.getInstance().stopMusic()
				self.setDestination("qualifying")
				self.keyboardHandler.clearSpaceStatus()
				self.closeSession()
Esempio n. 8
0
    def advanceTime(self):

        self.visualSession.advanceTime()
        self.ticks = self.ticks + 1

        if self.ticks == 10 * 60:
            self.setDestination("highscores")
            self.closeSession()
        else:
            space = self.keyboardHandler.getSpaceStatus()
            if space == 1:
                SoundServer.getInstance().stopMusic()
                self.setDestination("qualifying")
                self.keyboardHandler.clearSpaceStatus()
                self.closeSession()
Esempio n. 9
0
 def advanceTime(self):
     if self.ticks % 60 == 0:
         self.currentLight = self.currentLight + 1
         if self.currentLight > 0:
             if self.currentLight > 1:
                 self.visualTrackSession.setStartingLight(
                     self.currentLight - 1, False)
             self.visualTrackSession.setStartingLight(
                 self.currentLight, True)
             if self.currentLight == 4:
                 SoundServer.getInstance().playLowPitchedHorn()
                 self.endOfLife = True
             else:
                 SoundServer.getInstance().playHighPitchedHorn()
     self.ticks = self.ticks + 1
Esempio n. 10
0
    def __init__(self, score, topScore, topSpeed, fastestLapTimeSeconds,
                 fastestLapTimeMilliseconds, whereFrom):
        self.initialsEntryActive = False
        self.viewingOnlyActive = False
        self.score = score
        self.ticks = 0
        self.topScore = 0
        self.keyboardHandler = KeyboardHandler.getInstance()
        self.confirmedInitials = ''

        if whereFrom == "titlescreen":
            destination = "titlescreen"
        else:
            destination = "gameover"

        super(HighScoreSession, self).__init__()

        self.loadScores()
        tablePosition = self.getTablePosition(score)
        self.tablePosition = tablePosition

        if tablePosition is None:
            self.createVisualSession(VisualHighScoreSessionType.viewingOnly)
            self.startViewingOnly()
            self.viewingOnlyActive = True
        elif tablePosition < 7:
            self.createVisualSession(
                VisualHighScoreSessionType.prizeWinnersInitialsEntry)
            self.startInitialsEntry(6, score, tablePosition)
        else:
            self.createVisualSession(
                VisualHighScoreSessionType.normalInitialsEntry)
            self.startInitialsEntry(8, score, tablePosition)

        self.setTopScore(topScore)
        self.setScore(score)
        self.setLapTime(fastestLapTimeSeconds, fastestLapTimeMilliseconds)
        self.setSpeed(topSpeed)

        SoundServer.getInstance().playMusic()

        self.countingDownToClose = False

        self.setOutcome({
            "sessiontype": SessionType.highScoreTable,
            "score": self.score,
            "destination": destination
        })
Esempio n. 11
0
 def addPlayerCar(self, segmentPosition, sidewaysPosition, speed,
                  carAppearance):
     newLogicalCar = PlayerCarRepresentation(self)
     newLogicalCar.setSegmentPosition(segmentPosition)
     newLogicalCar.setSidewaysPosition(sidewaysPosition)
     newLogicalCar.setSpeed(speed)
     newLogicalCar.setTrackSegments(self.segments)
     newLogicalCar.setDriver(KeyboardDriver())
     self.logicalCarRepresentations.append(newLogicalCar)
     newLogicalCar.setCarNumber(len(self.logicalCarRepresentations))
     SoundServer.getInstance().startEngine(newLogicalCar.getCarNumber())
     SoundServer.getInstance().setEngineVolume(newLogicalCar.getCarNumber(),
                                               1.0)
     newLogicalCar.setVisualPeer(
         self.visualTrackSession.addCar(carAppearance, True))
     return newLogicalCar
Esempio n. 12
0
    def closeSession(self):
        soundServer = SoundServer.getInstance()
        for carRepresentation in self.logicalCarRepresentations:
            soundServer.stopEngine(carRepresentation.getCarNumber())

        self.setSessionLifecyclePoint(SessionLifecyclePoint.closing)
        self.visualTrackSession.closeSession()
        self.setSessionLifecyclePoint(SessionLifecyclePoint.closed)
Esempio n. 13
0
	def closeSession(self):
		soundServer=SoundServer.getInstance()
		for carRepresentation in self.logicalCarRepresentations:
			soundServer.stopEngine(carRepresentation.getCarNumber())

		self.setSessionLifecyclePoint(SessionLifecyclePoint.closing)
		self.visualTrackSession.closeSession()
		self.setSessionLifecyclePoint(SessionLifecyclePoint.closed)
	def __init__(self,score,topScore,topSpeed,fastestLapTimeSeconds,fastestLapTimeMilliseconds,whereFrom):
		self.initialsEntryActive=False
		self.viewingOnlyActive=False
		self.score=score
		self.ticks=0
		self.topScore=0
		self.keyboardHandler=KeyboardHandler.getInstance()
		self.confirmedInitials=''

		if whereFrom=="titlescreen":
			destination="titlescreen"
		else:
			destination="gameover"

		super(HighScoreSession, self).__init__()

		self.loadScores()
		tablePosition=self.getTablePosition(score)
		self.tablePosition=tablePosition

		if tablePosition is None:
			self.createVisualSession(VisualHighScoreSessionType.viewingOnly)
			self.startViewingOnly()
			self.viewingOnlyActive=True
		elif tablePosition<7:
			self.createVisualSession(VisualHighScoreSessionType.prizeWinnersInitialsEntry)
			self.startInitialsEntry(6,score,tablePosition)
		else:
			self.createVisualSession(VisualHighScoreSessionType.normalInitialsEntry)
			self.startInitialsEntry(8,score,tablePosition)

		self.setTopScore(topScore)
		self.setScore(score)
		self.setLapTime(fastestLapTimeSeconds,fastestLapTimeMilliseconds)
		self.setSpeed(topSpeed)
		
		SoundServer.getInstance().playMusic()

		self.countingDownToClose=False

		self.setOutcome({"sessiontype":SessionType.highScoreTable,
                         "score":self.score,
                         "destination":destination})
	def __init__(self):
		self.setSessionLifecyclePoint(SessionLifecyclePoint.initialising)
		self.visualSession=VisualTitleScreenSession()
		self.setSessionLifecyclePoint(SessionLifecyclePoint.running)
		self.ticks=0
		self.keyboardHandler=KeyboardHandler.getInstance()

		soundServer=SoundServer.getInstance()

		if not soundServer.isMusicPlaying():
			soundServer.playMusic()
Esempio n. 16
0
	def advanceTime(self):

		colourIndex=self.ticks%6
		r,g,b=self.cyclingColours[colourIndex]
		self.setPassingBonusColour(r,g,b)

		if self.ticksUntilNextCountdownNumberChange==0:
			if self.currentCountdownNumber==0:
				self.endOfLife=True
			else:
				SoundServer.getInstance().playHighBeep()
				self.currentCountdownNumber=self.currentCountdownNumber-1
				self.ticksUntilNextCountdownNumberChange=self.ticksPerCountdownNumber
				self.setPassingBonusValue('50x'+str(self.currentCountdownNumber))
				self.visualTrackSession.addEvent(self.visualTrackSession.passingBonusScoreUpdateEvent,
                                                 {"currentcountdownnumber":self.currentCountdownNumber,
                                                  "startcountdownnumber":self.startCountdownNumber})

		self.ticks=self.ticks+1
		self.ticksUntilNextCountdownNumberChange=self.ticksUntilNextCountdownNumberChange-1
Esempio n. 17
0
    def __init__(self):
        self.setSessionLifecyclePoint(SessionLifecyclePoint.initialising)
        self.visualSession = VisualTitleScreenSession()
        self.setSessionLifecyclePoint(SessionLifecyclePoint.running)
        self.ticks = 0
        self.keyboardHandler = KeyboardHandler.getInstance()

        soundServer = SoundServer.getInstance()

        if not soundServer.isMusicPlaying():
            soundServer.playMusic()
	def applyGroundFriction(self):

		startSlowdownSidewaysPosition=self.startSlowdownSidewaysPosition
		speedAtMaxSidewaysPosition=self.speedAtMaxSidewaysPosition
		speedAtStartSlowdownSidewaysPosition=self.speedAtStartSlowdownSidewaysPosition
		maxSidewaysPosition=self.maxSidewaysPosition

		absoluteSidewaysPosition=math.fabs(self.getSidewaysPosition())

		segmentPositionComponents=math.modf(self.segmentPosition)
		lastSegmentPositionComponents=math.modf(self.lastSegmentPosition)

		if absoluteSidewaysPosition>0.725 and absoluteSidewaysPosition<1.15:
			if segmentPositionComponents[0]<lastSegmentPositionComponents[0]:
				SoundServer.getInstance().playBump()

		if absoluteSidewaysPosition>startSlowdownSidewaysPosition:
			forcedSpeed=speedAtStartSlowdownSidewaysPosition+(speedAtMaxSidewaysPosition-speedAtStartSlowdownSidewaysPosition)/(maxSidewaysPosition-startSlowdownSidewaysPosition)*(absoluteSidewaysPosition-startSlowdownSidewaysPosition)
			currentSpeed=self.getSpeed()
			if currentSpeed>forcedSpeed:
				self.engine.setSpeed(currentSpeed-0.01)
 def advanceTime(self):
     if self.ticks == 240:
         self.visualTrackSession.setStartingLight(4, True)
         self.endOfLife = True
         SoundServer.getInstance().playHighPitchedHorn()
     self.ticks = self.ticks + 1
Esempio n. 20
0
 def explode(self):
     super(PlayerCarRepresentation, self).explode()
     self.preExplosionSteering = self.driver.getSteering()
     SoundServer.getInstance().playExplosion()
     self.trackSession.setSpeedLimit(0.25)
	def explode(self):
		super(PlayerCarRepresentation, self).explode()
		self.preExplosionSteering=self.driver.getSteering()
		SoundServer.getInstance().playExplosion()
		self.trackSession.setSpeedLimit(0.25)
Esempio n. 22
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
Esempio n. 23
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
	def advanceTime(self):
		if self.ticks==240:
			self.visualTrackSession.setStartingLight(4,True)
			self.endOfLife=True
			SoundServer.getInstance().playHighPitchedHorn()
		self.ticks=self.ticks+1