def update(self): toonPos = self.toon.getPos() newOffset = Vec3(self.player.instantaneousVelocity.getX() * 0.1, self.player.instantaneousVelocity.getY() * 2.0, self.player.velocity.getZ()) targetPos = toonPos + self.camOffset + Vec3(0, 0, -newOffset.getZ() * 0.3) targetLookAt = toonPos + Vec3(0, 35, 0) + newOffset if self.player.instantaneousVelocity.getY() < 0.0 or ( self.player.instantaneousVelocity.getY() <= 0.0 and self.player.instantaneousVelocity.getZ() < 0.0): targetPos = targetPos + Vec3( 0, +2.0, abs(self.player.instantaneousVelocity.getZ() * 0.4)) targetLookAt = targetLookAt + Vec3( 0, 0, -abs(self.player.instantaneousVelocity.getZ() * 0.2)) targetLookAt[1] = toonPos[1] p = 0.90 targetPos[0] = clamp(targetPos[0], self.player.game.leftLimit * p, self.player.game.rightLimit * p) targetLookAt[0] = clamp(targetLookAt[0], self.player.game.leftLimit * p, self.player.game.rightLimit * p) #targetPos[2] = clamp(targetPos[2], self.player.game.downLimit*p, self.player.game.upLimit*p) p = 0.95 targetLookAt[2] = clamp(targetLookAt[2], self.player.game.downLimit * p, self.player.game.upLimit * p) self.cameraManager.setTargetPos(targetPos) self.cameraManager.setTargetLookAtPos(targetLookAt)
def dampenVelocityVal(self, velocityVal, typeNeg, typePos, minVal, maxVal, dt): if velocityVal > 0.0: velocityVal -= Globals.Gameplay.ToonDeceleration[typePos] * dt velocityVal = clamp(velocityVal, 0.0, maxVal) elif velocityVal < 0.0: velocityVal += Globals.Gameplay.ToonDeceleration[typeNeg] * dt velocityVal = clamp(velocityVal, minVal, 0.0) return velocityVal
def update(self): for (toon, marker) in self._toonMarkers.items(): progress = clamp( (toon.getY() - self._levelStartY) / self._levelDistance, self._levelStartY, self._levelEndY) marker.setZ( clamp(self._lineStart + self._lineDistance * progress, self._lineStart, self._lineEnd))
def update(self): toonPos = self.toon.getPos() self.parent.setPos( self.toon.getParent(), clamp(toonPos.getX(), self.minPos[0], self.maxPos[0]), clamp(toonPos.getY(), self.minPos[1], self.maxPos[1]), 0 )
def update(self, dt): toonPos = self.toon.getPos() self.parent.setPos( self.toon.getParent(), clamp(toonPos.getX(), self.minPos[0], self.maxPos[0]), clamp(toonPos.getY(), self.minPos[1], self.maxPos[1]), 0) if self._camDistance != self._camTargetDistance: self._updateCameraDistance() if self.shakeOffset > 0 or self.shakeStrength > 0: self.updateShake(dt) self.updateRumble(dt)
def _updateCam(self, dt): toonPos = self._toon.getPos() camPos = self._camParent.getPos() x = camPos[0] z = camPos[2] toonWorldX = self._toon.getX(render) maxX = Globals.Camera.MaxSpinX toonWorldX = clamp(toonWorldX, -1.0 * maxX, maxX) spinAngle = Globals.Camera.MaxSpinAngle * toonWorldX * toonWorldX / ( maxX * maxX) newH = 180.0 + spinAngle self._camParent.setH(newH) spinAngle = spinAngle * (pi / 180.0) distBehindToon = Globals.Camera.SpinRadius * cos(spinAngle) distToRightOfToon = Globals.Camera.SpinRadius * sin(spinAngle) d = self._camParent.getX() - clamp(toonPos[0], *self._bounds[0]) if abs(d) > Globals.Camera.LeewayX: if d > Globals.Camera.LeewayX: x = toonPos[0] + Globals.Camera.LeewayX else: x = toonPos[0] - Globals.Camera.LeewayX x = self._toon.getX(render) + distToRightOfToon boundToonZ = min(toonPos[2], self._bounds[2][1]) d = z - boundToonZ if d > Globals.Camera.MinLeewayZ: if self._player.velocity[2] >= 0 and toonPos[ 1] != self._prevToonY or self._player.velocity[2] > 0: z = boundToonZ + d * INVERSE_E**(dt * Globals.Camera.CatchUpRateZ) elif d > Globals.Camera.MaxLeewayZ: z = boundToonZ + Globals.Camera.MaxLeewayZ elif d < -Globals.Camera.MinLeewayZ: z = boundToonZ - Globals.Camera.MinLeewayZ if self._frozen: y = camPos[1] else: y = self._toon.getY(render) - distBehindToon self._camParent.setPos(x, smooth(camPos[1], y), smooth(camPos[2], z)) if toonPos[2] < self._bounds[2][1]: h = self._cameraLookAtNP.getH() if d >= Globals.Camera.MinLeewayZ: self._cameraLookAtNP.lookAt(self._toon, 0, 0, self._lookAtZ) elif d <= -Globals.Camera.MinLeewayZ: self._cameraLookAtNP.lookAt(self._camParent, 0, 0, self._lookAtZ) self._cameraLookAtNP.setHpr(h, self._cameraLookAtNP.getP(), 0) self._camera.setHpr( smooth(self._camera.getHpr(), self._cameraLookAtNP.getHpr())) self._prevToonY = toonPos[1]
def updateControlVelocity(self, dt): leftPressed = self._inputMgr.arrowKeys.leftPressed() rightPressed = self._inputMgr.arrowKeys.rightPressed() upPressed = self._inputMgr.arrowKeys.upPressed() downPressed = self._inputMgr.arrowKeys.downPressed() jumpPressed = self._inputMgr.arrowKeys.jumpPressed() if leftPressed: self.controlVelocity[0] -= Globals.Gameplay.ToonAcceleration['turning'] * dt if rightPressed: self.controlVelocity[0] += Globals.Gameplay.ToonAcceleration['turning'] * dt if upPressed: self.controlVelocity[1] += Globals.Gameplay.ToonAcceleration['forward'] * dt if downPressed: self.controlVelocity[2] -= Globals.Gameplay.ToonAcceleration['activeDropDown'] * dt self.controlVelocity[1] -= Globals.Gameplay.ToonAcceleration['activeDropBack'] * dt if jumpPressed and self.isFuelLeft(): self.controlVelocity[2] += Globals.Gameplay.ToonAcceleration['boostUp'] * dt minVal = -Globals.Gameplay.ToonVelMax['turning'] maxVal = Globals.Gameplay.ToonVelMax['turning'] if not leftPressed and not rightPressed or self.controlVelocity[0] > maxVal or self.controlVelocity[0] < minVal: x = self.dampenVelocityVal(self.controlVelocity[0], 'turning', 'turning', minVal, maxVal, dt) self.controlVelocity[0] = x minVal = -Globals.Gameplay.ToonVelMax['backward'] maxVal = Globals.Gameplay.ToonVelMax['forward'] if not upPressed and not downPressed or self.controlVelocity[1] > maxVal or self.controlVelocity[1] < minVal: y = self.dampenVelocityVal(self.controlVelocity[1], 'backward', 'forward', minVal, maxVal, dt) self.controlVelocity[1] = y if self.isFuelLeft(): minVal = -Globals.Gameplay.ToonVelMax['fall'] else: minVal = -Globals.Gameplay.ToonVelMax['fallNoFuel'] maxVal = Globals.Gameplay.ToonVelMax['boost'] if self.controlVelocity[2] > minVal: if (not self._inputMgr.arrowKeys.jumpPressed() or not self.isFuelLeft()) and not self.isToonOnFloor: self.controlVelocity[2] -= Globals.Gameplay.ToonAcceleration['fall'] * dt if self.controlVelocity[2] < 0.0 and self.isToonOnFloor: self.controlVelocity[2] = 0.0 minVal = -Globals.Gameplay.ToonVelMax['turning'] maxVal = Globals.Gameplay.ToonVelMax['turning'] self.controlVelocity[0] = clamp(self.controlVelocity[0], minVal, maxVal) minVal = -Globals.Gameplay.ToonVelMax['backward'] maxVal = Globals.Gameplay.ToonVelMax['forward'] self.controlVelocity[1] = clamp(self.controlVelocity[1], minVal, maxVal) if self.isFuelLeft(): minVal = -Globals.Gameplay.ToonVelMax['fall'] else: minVal = -Globals.Gameplay.ToonVelMax['fallNoFuel'] maxVal = Globals.Gameplay.ToonVelMax['boost'] self.controlVelocity[2] = clamp(self.controlVelocity[2], minVal, maxVal)
def getExtremeness(self, traitValue): percent = self._getTraitPercent(traitValue) if percent < 0.5: howExtreme = (0.5 - percent) * 2.0 else: howExtreme = (percent - 0.5) * 2.0 return clamp(howExtreme, 0.0, 1.0)
def updateToonPos(self, dt): toonWorldY = self.toon.getY(render) if self.hasPickedUpFirstPropeller == False: if toonWorldY > -7.6: self.toon.setY(-7.6) elif toonWorldY < -35.0: self.toon.setY(-35.0) return self.velocity = self.controlVelocity + self.fanVelocity vel = self.velocity * dt self.toon.setPos(self.toon, vel[0], vel[1], vel[2]) toonPos = self.toon.getPos() if Globals.Dev.DisableDeath: pass elif toonPos[2] < 0.0 and self.state in ['FreeFly', 'FlyingUp'] and self.allowFuelDeath(): self.postSpawnState = 'Running' self.game.distGame.b_toonDied(self.toon.doId) if toonPos[2] > self._levelBounds[2][1]: self.controlVelocity[2] = 0.0 self.fanVelocity[2] = 0.0 toonPos = Vec3(clamp(toonPos[0], self._levelBounds[0][0], self._levelBounds[0][1]), clamp(toonPos[1], self._levelBounds[1][0], self._levelBounds[1][1]), clamp(toonPos[2], self._levelBounds[2][0], self._levelBounds[2][1])) if self.isHeadInCeiling and toonPos[2] > self.surfacePoint[2]: toonPos[2] = self.surfacePoint[2] self.toon.setPos(toonPos) if self.toon.getY(render) < -10: self.toon.setY(-10.0)
def updateFanVelocity(self, dt): fanHeight = Globals.Gameplay.FanCollisionTubeHeight min = Globals.Gameplay.FanMinPower max = Globals.Gameplay.FanMaxPower powerRange = max - min for fan in self.activeFans: blowVec = fan.getBlowDirection() blowVec *= Globals.Gameplay.ToonAcceleration['fan'] * dt if Globals.Gameplay.UseVariableFanPower: distance = fan.model.getDistance(self.toon) power = math.fabs(distance / fanHeight - 1.0) * powerRange + min power = clamp(power, min, max) blowVec *= power if fan.index in self.fanIndex2ToonVelocity: fanVelocity = self.fanIndex2ToonVelocity[fan.index] fanVelocity += blowVec removeList = [] for fan in self.fansStillHavingEffect: if fan not in self.activeFans: blowVec = fan.getBlowDirection() blowVec *= Globals.Gameplay.ToonDeceleration['fan'] * dt if fan.index in self.fanIndex2ToonVelocity: fanVelocity = Vec3(self.fanIndex2ToonVelocity[fan.index]) lastLen = fanVelocity.length() fanVelocity -= blowVec if fanVelocity.length() > lastLen: removeList.append(fan) else: self.fanIndex2ToonVelocity[fan.index] = fanVelocity for fan in removeList: self.fansStillHavingEffect.remove(fan) if fan.index in self.fanIndex2ToonVelocity: del self.fanIndex2ToonVelocity[fan.index] self.fanVelocity = Vec3(0.0, 0.0, 0.0) for fan in self.fansStillHavingEffect: if fan.index in self.fanIndex2ToonVelocity: self.fanVelocity += self.fanIndex2ToonVelocity[fan.index] minVal = -Globals.Gameplay.ToonVelMax['fan'] maxVal = Globals.Gameplay.ToonVelMax['fan'] self.fanVelocity[0] = clamp(self.fanVelocity[0], minVal, maxVal) self.fanVelocity[1] = clamp(self.fanVelocity[1], minVal, maxVal) self.fanVelocity[2] = clamp(self.fanVelocity[2], minVal, maxVal)
def update(self, dt): toonPos = self.toon.getPos() self.parent.setPos(self.toon.getParent(), clamp(toonPos.getX(), self.minPos[0], self.maxPos[0]), clamp(toonPos.getY(), self.minPos[1], self.maxPos[1]), 0) if self._camDistance != self._camTargetDistance: self._updateCameraDistance() if self.shakeOffset > 0 or self.shakeStrength > 0: self.updateShake(dt) self.updateRumble(dt)
def _updateCamera(self, dt): numPlayers = 0.0 for player in self.game.players: if player != self and player.toon and self._isNearPlayer(player): numPlayers += 1 d = clamp(Globals.CameraMinDistance + numPlayers / (CogdoGameConsts.MaxPlayers - 1) * (Globals.CameraMaxDistance - Globals.CameraMinDistance), Globals.CameraMinDistance, Globals.CameraMaxDistance) self.cameraMgr.setCameraTargetDistance(d) self.cameraMgr.update(dt)
def _updateCogDistance(self, cogNum, direction, advantage, hitHead): if hitHead: factor = PartyGlobals.CogPinataPushHeadFactor else: factor = PartyGlobals.CogPinataPushBodyFactor distance = self.cogDistances[cogNum] + (factor * direction * advantage) self.cogDistances[cogNum] = clamp(distance, -1.0, 1.0)
def _updateCam(self, dt): toonPos = self._toon.getPos() camPos = self._camParent.getPos() x = camPos[0] z = camPos[2] toonWorldX = self._toon.getX(render) maxX = Globals.Camera.MaxSpinX toonWorldX = clamp(toonWorldX, -1.0 * maxX, maxX) spinAngle = Globals.Camera.MaxSpinAngle * toonWorldX * toonWorldX / (maxX * maxX) newH = 180.0 + spinAngle self._camParent.setH(newH) spinAngle = spinAngle * (pi / 180.0) distBehindToon = Globals.Camera.SpinRadius * cos(spinAngle) distToRightOfToon = Globals.Camera.SpinRadius * sin(spinAngle) d = self._camParent.getX() - clamp(toonPos[0], *self._bounds[0]) if abs(d) > Globals.Camera.LeewayX: if d > Globals.Camera.LeewayX: x = toonPos[0] + Globals.Camera.LeewayX else: x = toonPos[0] - Globals.Camera.LeewayX x = self._toon.getX(render) + distToRightOfToon boundToonZ = min(toonPos[2], self._bounds[2][1]) d = z - boundToonZ if d > Globals.Camera.MinLeewayZ: if self._player.velocity[2] >= 0 and toonPos[1] != self._prevToonY or self._player.velocity[2] > 0: z = boundToonZ + d * INVERSE_E ** (dt * Globals.Camera.CatchUpRateZ) elif d > Globals.Camera.MaxLeewayZ: z = boundToonZ + Globals.Camera.MaxLeewayZ elif d < -Globals.Camera.MinLeewayZ: z = boundToonZ - Globals.Camera.MinLeewayZ if self._frozen: y = camPos[1] else: y = self._toon.getY(render) - distBehindToon self._camParent.setPos(x, smooth(camPos[1], y), smooth(camPos[2], z)) if toonPos[2] < self._bounds[2][1]: h = self._cameraLookAtNP.getH() if d >= Globals.Camera.MinLeewayZ: self._cameraLookAtNP.lookAt(self._toon, 0, 0, self._lookAtZ) elif d <= -Globals.Camera.MinLeewayZ: self._cameraLookAtNP.lookAt(self._camParent, 0, 0, self._lookAtZ) self._cameraLookAtNP.setHpr(h, self._cameraLookAtNP.getP(), 0) self._camera.setHpr(smooth(self._camera.getHpr(), self._cameraLookAtNP.getHpr())) self._prevToonY = toonPos[1]
def update(self, dt = 0.0): if self._camera is None: return quadNum = clamp(self.getCameraActualQuadrant(), 0, self._numQuads - 1) if quadNum < self._numQuads: self.quadrants[quadNum].update(dt) if quadNum + 1 < self._numQuads: self.quadrants[quadNum + 1].update(dt) if quadNum != self._currentQuadNum: self._switchToQuadrant(quadNum)
def update(self, dt=0.0): if self._camera is None: return quadNum = clamp(self.getCameraActualQuadrant(), 0, self._numQuads - 1) if quadNum < self._numQuads: self.quadrants[quadNum].update(dt) if quadNum + 1 < self._numQuads: self.quadrants[quadNum + 1].update(dt) if quadNum != self._currentQuadNum: self._switchToQuadrant(quadNum)
def setTrickAptitude(self, trickId, aptitude, send = 1): aptitude = clamp(aptitude, 0.0, 1.0) aptitudes = self.trickAptitudes while len(aptitudes) - 1 < trickId: aptitudes.append(0.0) if aptitudes[trickId] != aptitude: aptitudes[trickId] = aptitude if send: self.b_setTrickAptitudes(aptitudes) else: self.setTrickAptitudes(aptitudes, local=1)
def enterLockOnToon(self, elapsedTime = 0.0): self.notify.info("enter%s: '%s' -> '%s', elapsedTime:%s" % (self.newState, self.oldState, self.newState, elapsedTime)) taskName = 'updateLockOnTask-%i' % self.index taskMgr.add(self.updateLockOnTask, taskName, 45, extraArgs = []) messenger.send(CogdoFlyingLegalEagle.LockOnToonEventName, [ self.target.doId]) range = self.target.getDistance(self.interestConeOrigin) / self.getInterestConeLength() range = clamp(range, 0.0, 1.0) dur = Globals.LegalEagle.LockOnTime if self.oldState == 'TakeOff': dur *= range else: dur += Globals.LegalEagle.ExtraPostCooldownTime taskName = 'exitLockOnToon-%i' % self.index taskMgr.doMethodLater(dur, self.requestNext, taskName, extraArgs = [])
def enterLockOnToon(self, elapsedTime=0.0): self.notify.info( "enter%s: '%s' -> '%s', elapsedTime:%s" % (self.newState, self.oldState, self.newState, elapsedTime) ) taskName = "updateLockOnTask-%i" % self.index taskMgr.add(self.updateLockOnTask, taskName, 45, extraArgs=[]) messenger.send(CogdoFlyingLegalEagle.LockOnToonEventName, [self.target.doId]) range = self.target.getDistance(self.interestConeOrigin) / self.getInterestConeLength() range = clamp(range, 0.0, 1.0) dur = Globals.LegalEagle.LockOnTime if self.oldState == "TakeOff": dur *= range else: dur += Globals.LegalEagle.ExtraPostCooldownTime taskName = "exitLockOnToon-%i" % self.index taskMgr.doMethodLater(dur, self.requestNext, taskName, extraArgs=[])
def suitTakeOver(self, suitTrack, difficulty, buildingHeight): if not self.isToonBlock(): return self.updateSavedBy(None) difficulty = clamp(difficulty, 0, len(SuitBuildingGlobals.SuitBuildingInfo) - 1) minFloors, maxFloors = self._getMinMaxFloors(difficulty) if buildingHeight == None: numFloors = random.randint(minFloors, maxFloors) else: numFloors = buildingHeight + 1 if numFloors < minFloors or numFloors > maxFloors: numFloors = random.randint(minFloors, maxFloors) self.track = suitTrack self.difficulty = difficulty self.numFloors = numFloors self.becameSuitTime = time.time() self.fsm.request('clearOutToonInterior') return
def update(self, time): placeSorter = [] placeCount = 0 for key in self.racerDict.keys(): racer = self.racerDict[key] curvetime = racer.curvetime face = racer.face mapspot = racer.mapspot maxlaphit = racer.maxlaphit if not racer.finished and racer.enabled: placeSorter.append((curvetime, key)) if racer.finished or racer.enabled: placeCount += 1 pt = Vec3(0, 0, 0) mapT = (curvetime % 1 + self.race.startT / self.race.curve.getMaxT()) % 1 * self.race.curve.getMaxT() self.race.curve.getPoint(mapT, pt) self.race.curve.getPoint(mapT % self.race.curve.getMaxT(), pt) lapT = clamp(curvetime / self.race.lapCount, 0.0, 1.0) faceX = self.faceStartPos[0] * (1 - lapT) + self.faceEndPos[0] * lapT racer.update(faceX=faceX, mapspotPt=pt) t = time - self.race.baseTime - self.raceTimeDelta if key == localAvatar.doId: if self.race.laps > maxlaphit: racer.update(maxlaphit=self.race.laps) self.maxLapHit = racer.maxlaphit if self.maxLapHit < self.race.lapCount: for y in self.timeLabels[self.maxLapHit - 1]: y.configure(text_font=ToontownGlobals.getSignFont()) for y in self.timeLabels[self.maxLapHit]: y.show() for y in self.timeLabels[self.maxLapHit]: y.configure(text_font=ToontownGlobals.getSignFont()) self.raceTimeDelta = globalClock.getFrameTime() - self.race.baseTime lapNotice = DirectLabel() lapNotice.setScale(0.1) if self.maxLapHit == self.race.lapCount - 1: lapNotice['text'] = TTLocalizer.KartRace_FinalLapText else: lapNotice['text'] = TTLocalizer.KartRace_LapText % str(self.maxLapHit + 1) taskMgr.doMethodLater(2, lapNotice.remove, 'removeIt', extraArgs=[]) self.lapLabel['text'] = str(clamp(self.maxLapHit + 1, 1, self.race.lapCount)) + '/' + str(self.race.lapCount) suffix = {1: TTLocalizer.KartRace_FirstSuffix, 2: TTLocalizer.KartRace_SecondSuffix, 3: TTLocalizer.KartRace_ThirdSuffix, 4: TTLocalizer.KartRace_FourthSuffix} placeSorter.sort() for x, p in zip(placeSorter, xrange(len(placeSorter), 0, -1)): self.racerDict[x[1]].update(place=p + placeCount - len(placeSorter)) localRacer = self.racerDict[localAvatar.doId] nearDiff, farDiff = RaceGlobals.TrackDict[self.race.trackId][8] if not localRacer.finished and self.faceEndPos[0] - localRacer.face.getX() < nearDiff: for racerId in self.racerDict.keys(): racer = self.racerDict[racerId] if not racer.enabled or racerId == localAvatar.doId or racer.face.getX() >= self.faceEndPos[0]: continue if self.faceEndPos[0] - racer.face.getX() < farDiff: self.photoFinish = True if self.photoFinish: self.photoFinishLabel.show() self.placeLabelNum['text'] = '' self.placeLabelStr['text'] = '' else: self.photoFinishLabel.hide() self.placeLabelNum['text'] = str(self.racerDict[localAvatar.doId].place) self.placeLabelStr['text'] = suffix[self.racerDict[localAvatar.doId].place] minutes = int(t / 60) t -= minutes * 60 seconds = int(t) padding = (seconds < 10 and ['0'] or [''])[0] t -= seconds fraction = str(t)[2:4] fraction = fraction + '0' * (2 - len(fraction)) if self.timerEnabled and self.maxLapHit < self.race.lapCount: self.timeLabels[self.maxLapHit][0]['text'] = "%d'" % minutes self.timeLabels[self.maxLapHit][1]['text'] = "%s%d''" % (padding, seconds) self.timeLabels[self.maxLapHit][2]['text'] = '%s' % fraction if self.race.wrongWay and not self.wrongWaySeq.isPlaying(): self.wrongWaySeq.loop() elif not self.race.wrongWay and self.wrongWaySeq.isPlaying(): self.wrongWaySeq.finish()
def updateDistance(self, distance): self.targetDistance = clamp(distance, -1.0, 1.0)
def __updateToonMovement(self): # move the local toon dt = globalClock.getDt() leftPressed = self.inputMgr.arrowKeys.leftPressed() rightPressed = self.inputMgr.arrowKeys.rightPressed() upPressed = self.inputMgr.arrowKeys.upPressed() downPressed = self.inputMgr.arrowKeys.downPressed() jumpPressed = self.inputMgr.arrowKeys.jumpPressed() # print leftPressed,rightPressed,upPressed,downPressed,jumpPressed self.instantaneousVelocity = (self.toon.getPos() - self.oldPos) / dt self.oldPos = self.toon.getPos() toonPos = self.toon.getPos() self.lastVelocity = Vec3(self.velocity) # Adds boost to velocity values and calculates toon pos changes if leftPressed: self.velocity[ 0] -= CogdoFlyingGameGlobals.FlyingGame.TOON_ACCELERATION[ "turning"] * dt if rightPressed: self.velocity[ 0] += CogdoFlyingGameGlobals.FlyingGame.TOON_ACCELERATION[ "turning"] * dt if upPressed: self.velocity[ 1] += CogdoFlyingGameGlobals.FlyingGame.TOON_ACCELERATION[ "forward"] * dt if downPressed: self.velocity[ 1] -= CogdoFlyingGameGlobals.FlyingGame.TOON_ACCELERATION[ "backward"] * dt # print jumpPressed if jumpPressed and self.isFuelLeft(): self.velocity[ 2] += CogdoFlyingGameGlobals.FlyingGame.TOON_ACCELERATION[ "vertical"] * dt if self.state == "FreeFly" and self.isInTransition() == False: #print "Going to flying up" self.request("FlyingUp") else: if self.state == "FlyingUp" and self.isInTransition() == False: #print "Going to free fly" self.request("FreeFly") toonPos += self.velocity * dt # TODO:flying: death probably needs to happen on the server... if (CogdoFlyingGameGlobals.FlyingGame.DISABLE_DEATH) or \ (base.config.GetBool('cogdo-flying-game-disable-death', 0)): pass else: # Tests to see whether the toon has dropped low enough to die if toonPos[2] < 0.0 and self.state in ["FreeFly", "FlyingUp"]: self.request("Death") toonPos[2] = clamp(toonPos[2], self.game.downLimit, self.game.upLimit) toonPos[0] = clamp(toonPos[0], self.game.leftLimit, self.game.rightLimit) # Sets toon position based on velocity self.toon.setPos(toonPos) #print "Before degrades:",self.velocity # Degrades left/right velocity values back to normal minVal = -CogdoFlyingGameGlobals.FlyingGame.TOON_VEL_MAX["turning"] maxVal = CogdoFlyingGameGlobals.FlyingGame.TOON_VEL_MAX["turning"] if (not leftPressed and not rightPressed) or (self.velocity[0] > maxVal or self.velocity[0] < minVal): if self.velocity[0] > 0.0: self.velocity[ 0] -= CogdoFlyingGameGlobals.FlyingGame.TOON_DECELERATION[ "turning"] * dt self.velocity[0] = clamp(self.velocity[0], 0.0, maxVal) elif self.velocity[0] < 0.0: self.velocity[ 0] += CogdoFlyingGameGlobals.FlyingGame.TOON_DECELERATION[ "turning"] * dt self.velocity[0] = clamp(self.velocity[0], minVal, 0.0) # Degrades forward/backward velocity values back to normal minVal = -CogdoFlyingGameGlobals.FlyingGame.TOON_VEL_MAX["backward"] maxVal = CogdoFlyingGameGlobals.FlyingGame.TOON_VEL_MAX["forward"] if (not upPressed and not downPressed) or (self.velocity[1] > maxVal or self.velocity[1] < minVal): if self.velocity[1] > 0.0: self.velocity[ 1] -= CogdoFlyingGameGlobals.FlyingGame.TOON_DECELERATION[ "forward"] * dt self.velocity[1] = clamp(self.velocity[1], 0.0, maxVal) elif self.velocity[1] < 0.0: self.velocity[ 1] += CogdoFlyingGameGlobals.FlyingGame.TOON_DECELERATION[ "backward"] * dt self.velocity[1] = clamp(self.velocity[1], minVal, 0.0) # Degrades boost/fall velocity values back to normal minVal = -CogdoFlyingGameGlobals.FlyingGame.TOON_VEL_MAX["vertical"] maxVal = CogdoFlyingGameGlobals.FlyingGame.TOON_VEL_MAX["vertical"] if self.velocity[2] > minVal: if not self.inputMgr.arrowKeys.jumpPressed(): self.velocity[ 2] -= CogdoFlyingGameGlobals.FlyingGame.TOON_DECELERATION[ "vertical"] * dt self.velocity[2] = clamp(self.velocity[2], minVal, maxVal)
def doDrift(curValue, timeToMedian, dt = float(dt)): newValue = curValue + dt / (timeToMedian * 7200) return clamp(newValue, 0.0, 1.0)
def addToMood(self, component, delta): value = self.mood.getComponent(component) value += delta self.setMoodComponent(component, clamp(value, 0.0, 1.0))
def update(self): for toon, marker in self._toonMarkers.items(): progress = clamp((toon.getY() - self._levelStartY) / self._levelDistance, self._levelStartY, self._levelEndY) marker.setZ(clamp(self._lineStart + self._lineDistance * progress, self._lineStart, self._lineEnd))