def __pickColor(self, task = None): x = base.mouseWatcherNode.getMouseX() y = base.mouseWatcherNode.getMouseY() win_w, win_h = base.win.getSize() if win_w < win_h: y *= 1.0 * win_h / win_w else: x *= 1.0 * win_w / win_h x -= self.pickButton.getX(aspect2d) y -= self.pickButton.getZ(aspect2d) image_scale = self.pickButton['image_scale'] x = 0.5 + x / (2.0 * self.pickButton.getSx(aspect2d) * image_scale[0]) y = 0.5 + y / -(2.0 * self.pickButton.getSz(aspect2d) * image_scale[2]) x = clamp(x, 0, 1) y = clamp(y, 0, 1) self.pickSelector.setPos(clamp(x, 0, 1) - 0.5, 0, -clamp(y, 0, 1) + 0.5) if not (0.0 <= x <= 1.0 and 0.0 <= y <= 1.0): return Task.cont x = self.calcRelative(x, 0.0, 1.0, 0.25, 0.8) y = self.calcRelative(y, 0.0, 1.0, 0.4, 0.8) rgb = colorsys.hsv_to_rgb(self.hueSlider['value'], x, y) + (1,) rgb = tuple([ float('%.2f' % x) for x in rgb ]) self.rgbDisplay['text'] = 'RGB: %s %s %s' % (rgb[0] * 255, rgb[1] * 255, rgb[2] * 255) if self.partChoice in (0, 1): self.dna.headColor = rgb if self.partChoice in (0, 2): self.dna.armColor = rgb if self.partChoice in (0, 3): self.dna.legColor = rgb self.toon.swapToonColor(self.dna) return Task.cont
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 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, 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 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 = 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 _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 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 updateDistance(self, distance): self.targetDistance = clamp(distance, -1.0, 1.0)