예제 #1
0
 def __updateNonlocalVehicle(self, task = None):
     self.curSpeed = self.smoother.getSmoothForwardVelocity()
     rotSpeed = -1 * self.smoother.getSmoothRotationalVelocity()
     self.leanAmount = self.curSpeed * rotSpeed / 500.0
     self.leanAmount = bound(self.leanAmount, -10, 10)
     self.__animate()
     return Task.cont
예제 #2
0
    def showArrow(self, arrowNum):
        arrows = self.arrows[arrowNum]
        cog = self.cogManager.cogs[arrowNum]
        points = [self.arena.find('**/cog%d_start_locator' % (arrowNum + 1)), self.arena.find('**/cog%d_end_locator' % (arrowNum + 1))]
        Y = cog.root.getY()
        for point in points:
            point.setY(Y)

        for i in range(len(arrows)):
            arrow = arrows[i]
            arrow.draw(points[i].getPos(), cog.root.getPos(), animate=False)
            arrow.unstash()

        i = -1
        length = PartyGlobals.CogActivityArenaLength
        for node, text in self.distanceLabels[arrowNum]:
            current = bound(i, 0, 1)
            node.setPos(cog.root.getPos(self.root) + Point3(i * 4, 2, 4))
            dist = PartyCogUtils.getCogDistanceUnitsFromCenter(cog.currentT)
            dist = abs(dist - i * length / 2)
            if dist > length - dist:
                node.setScale(2.8)
            else:
                node.setScale(2.2)
            text.setText(TTLocalizer.PartyCogDistance % dist)
            if dist > 0:
                node.unstash()
            else:
                arrows[current].stash()
            i += 2
예제 #3
0
 def __animate(self):
     speed = self.curSpeed
     self.spinWheels(speed / 10)
     enginePitch = bound(speed / 120.0, 0.5, 15)
     self.kartLoopSfx.setPlayRate(enginePitch)
     if not self.localVehicle:
         dist = (self.getPos() - localAvatar.getPos()).length()
     if self.localVehicle:
         if self.lifter.isOnGround():
             if self.offGround > 10:
                 kart = self.geom[0].find('**/main*')
                 bumpDown1 = kart.posInterval(0.1, Vec3(0, 0, -1))
                 bumpUp1 = kart.posInterval(0.15, Vec3(0, 0, 0))
                 bumpDown2 = kart.posInterval(0.5, Vec3(0, 0, -.4))
                 bumpUp2 = kart.posInterval(0.7, Vec3(0, 0, 0))
                 bumpSeq = Sequence(bumpDown1, bumpUp1, bumpDown2, bumpUp2)
                 bumpSeq.start()
             self.offGround = 0
         else:
             self.offGround += 1
     if self.offGround == 0:
         modifier = self.surfaceModifiers[self.groundType]['shake'] * (speed / 50.0)
     else:
         modifier = 1
     roll = self.leanAmount * 1.5
     roll += (random.random() * 2 - 1) * modifier
     pitch = self.acceleration * -.005
     pitch += (random.random() * 2 - 1) * modifier
     self.rollSuspension(roll)
     self.pitchSuspension(pitch)
     return Task.cont
예제 #4
0
    def pieHitsCog(self, avId, timestamp, hitCogNum, x, y, z, direction, part):
        # Basic sanity check
        av = self._getCaller()
        if not av:
            return

        if avId != av.doId:
            self.air.writeServerEvent('suspicious', av.doId, 'sent DistributedPartyCogActivityAI.pieHitsCog as someone else!', fakeId=avId)
            return

        if not (av.doId in self.toonIds[0] or av.doId in self.toonIds[1]):
            self.air.writeServerEvent('suspicious', avId, 'sent DistributedPartyCogActivityAI.pieHitsCog, but not playing')
            return

        if hitCogNum > 2:
            self.air.writeServerEvent('suspicious', avId, 'sent DistributedPartyCogActivityAI.pieHitsCog invalid cog num', hitCogNum=hitCogNum)
            return

        self.sendUpdate('pieHitsCog', [avId, timestamp, hitCogNum, x, y, z, direction, part])

        mult = PartyGlobals.CogPinataPushBodyFactor
        if part:
            mult = PartyGlobals.CogPinataPushHeadFactor

        if avId not in self.scores:
            self.scores[avId] = 0

        self.scores[avId] += mult

        self.cogDistances[hitCogNum] = bound(self.cogDistances[hitCogNum] + direction * mult, -1.0, 1.0)
        self.d_setCogDistances()
예제 #5
0
파일: PetTraits.py 프로젝트: nate97/src
 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 bound(howExtreme, 0.0, 1.0)
예제 #6
0
    def stickCarToGround(self):
        posList = []
        nWheels = len(self.wheelData)
        for nWheel in xrange(nWheels):
            cQueue = self.cQueue[nWheel]
            cQueue.sortEntries()
            if cQueue.getNumEntries() == 0:
                return
            entry = cQueue.getEntry(0)
            self.shakeWheel(nWheel, entry.getIntoNodePath())
            pos = entry.getSurfacePoint(render)
            wheelPos = self.wheelBases[nWheel].getPos(render)
            pos = wheelPos - pos
            posList.append(pos)
            cQueue.clearEntries()

        rf = posList[0].getZ()
        lf = posList[1].getZ()
        rr = posList[2].getZ()
        lr = posList[3].getZ()
        right = (rf + rr) / 2
        left = (lf + lr) / 2
        rollVal = right - left
        rollVal = bound(rollVal, -1, 1)
        curRoll = self.getR()
        newRoll = curRoll + rollVal * 2.0
        self.setR(newRoll)
        if not self.stopped:
            camera.setR(-newRoll)
        front = (rf + lf) / 2
        rear = (rr + lr) / 2
        center = (front + rear) / 2
        pitchVal = front - rear
        pitchVal = bound(pitchVal, -1, 1)
        curPitch = self.getP()
        newPitch = curPitch - pitchVal * 2.0
        self.setP((newPitch + curPitch) / 2.0)
        if self.proRacer:
            self.cameraNode.setP(-newPitch)
        elif not self.stopped:
            self.cameraNode.setP(-newPitch)
예제 #7
0
    def setTrickAptitude(self, trickId, aptitude, send = 1):
        aptitude = bound(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)
예제 #8
0
파일: camera.py 프로젝트: anossov/dorfdelf
    def move_camera(self, task):
        self.panning = any(self.keys.values())
        self.moving = self.panning or self.drag or self.zoomdrag

        dt = globalClock.getDt()
        move_speed = 25
        if self.keys['w']:
            self.body.setY(self.body, dt * move_speed)
        if self.keys['s']:
            self.body.setY(self.body, -dt * move_speed)
        if self.keys['a']:
            self.body.setX(self.body, -dt * move_speed)
        if self.keys['d']:
            self.body.setX(self.body, dt * move_speed)

        if self.panning:
            pos = self.body.getPos()
            self.body.setPos(bound(pos.x, 0, self.extents.x),
                             bound(pos.y, 0, self.extents.y),
                             pos.z)

        if self.drag or self.zoomdrag:
            if self.mouse.hasMouse():
                end = self.mouse.getMouse()

                if self.drag:
                    start, h, p = self.drag
                    self.body.setH(h + (start.x - end.x) * 50)
                    self.eye.setP(bound(p - (start.y - end.y) * 50, -90, 45))

                if self.zoomdrag:
                    startzoom, z = self.zoomdrag

                    self.body.setZ(max(0, z + (startzoom.y - end.y) * 20))


        return task.cont
 def setTime(self, time):
     time = bound(time, 0, 999)
     if time == self.currentTime:
         return
     self.currentTime = time
     timeStr = str(time)
     timeStrLen = len(timeStr)
     if timeStrLen == 1:
         if time <= 5 and self.highlightNearEnd:
             self.setTimeStr(timeStr, 0.34, (-0.025, -0.125), Vec4(1, 0, 0, 1))
         else:
             self.setTimeStr(timeStr, 0.34, (-0.025, -0.125))
     elif timeStrLen == 2:
         self.setTimeStr(timeStr, 0.27, (-0.025, -0.1))
     elif timeStrLen == 3:
         self.setTimeStr(timeStr, 0.2, (-0.01, -0.08))
    def __showSplat(self, position):
        if self.kaboomTrack is not None and self.kaboomTrack.isPlaying():
            self.kaboomTrack.finish()
        if not self.pieHitSound:
            self.notify.warning('Trying to play hit sound on destroyed player')
            return
        splatName = 'splat-creampie'
        self.splat = globalPropPool.getProp(splatName)
        self.splat.setBillboardPointEye()
        self.splat.reparentTo(render)
        self.splat.setPos(self.toon, position)
        self.splat.setY(self.toon, bound(self.splat.getY(), self.toon.getHeight() / 2.0, position.getY()))
        self.splat.setAlphaScale(1.0)
        targetscale = 0.75

        def setSplatAlpha(amount):
            self.splat.setAlphaScale(amount)

        self.kaboomTrack = Parallel(SoundInterval(self.pieHitSound, node=self.toon, volume=1.0, cutOff=PartyGlobals.PARTY_COG_CUTOFF), Sequence(Func(self.splat.showThrough), Parallel(Sequence(LerpScaleInterval(self.splat, duration=0.175, scale=targetscale, startScale=Point3(0.1, 0.1, 0.1), blendType='easeOut'), Wait(0.175)), Sequence(Wait(0.1), LerpFunc(setSplatAlpha, duration=1.0, fromData=1.0, toData=0.0, blendType='easeOut'))), Func(self.splat.cleanup), Func(self.splat.removeNode)))
        self.kaboomTrack.start()
        return
 def setRotation(self, rotation):
     self.__previousRotation = self._rotation
     self._rotation = bound(rotation, CANNON_ROTATION_MIN, CANNON_ROTATION_MAX)
 def setAngle(self, angle):
     self.__previousAngle = self._angle
     self._angle = bound(angle, CANNON_ANGLE_MIN, CANNON_ANGLE_MAX)
 def doCollisions(oldPos, newPos, self = self):
     x = bound(newPos[0], self.StageHalfWidth, -self.StageHalfWidth)
     y = bound(newPos[1], self.StageHalfHeight, -self.StageHalfHeight)
     newPos.setX(x)
     newPos.setY(y)
     return newPos
예제 #14
0
 def doDrift(curValue, timeToMedian, dt=float(dt)):
     newValue = curValue + dt / (timeToMedian * 7200)
     return bound(newValue, 0.0, 1.0)
 def checkOrthoDriveCollision(self, oldPos, newPos):
     x = bound(newPos[0], -16.800000000000001, 16.800000000000001)
     y = bound(newPos[1], -17.25, -24.100000000000001)
     newPos.setX(x)
     newPos.setY(y)
     return newPos
예제 #16
0
 def addToMood(self, component, delta):
     value = self.mood.getComponent(component)
     value += delta
     self.setMoodComponent(component, bound(value, 0.0, 1.0))
예제 #17
0
 def checkOrthoDriveCollision(self, oldPos, newPos):
     x = bound(newPos[0], -16.8, 16.8)
     y = bound(newPos[1], -17.25, -24.1)
     newPos.setX(x)
     newPos.setY(y)
     return newPos
예제 #18
0
    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 = bound(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(bound(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()
예제 #19
0
파일: PetMood.py 프로젝트: plmkoplmko/src
 def doDrift(curValue, timeToMedian, dt = float(dt)):
     newValue = curValue + dt / (timeToMedian * 7200)
     return bound(newValue, 0.0, 1.0)
예제 #20
0
    def __watchControls(self, task):
        dt = globalClock.getDt()
        curVelocity = self.actorNode.getPhysicsObject().getVelocity()
        curSpeed = curVelocity.length()
        fvec = self.forward.getPos(render) - self.getPos(render)
        fvec.normalize()
        dotProduct = curVelocity.dot(fvec)
        goingBack = -1
        if dotProduct < 0:
            goingBack = 1
        if self.proRacer:
            self.__computeTurnRatio(curSpeed)
            self.__updateWheelPos(dt, curSpeed)
        newHForTurning = self.getH()
        if self.proRacer or not self.stopped and self.arrowHorz and curSpeed > 1:
            if self.proRacer:
                turnHelp = 0
                if self.hittingWall or goingBack == 1:
                    turnHelp = self.arrowHorz
                effectiveSpeed = curSpeed
                if effectiveSpeed > self.speedMinTurn:
                    effectiveSpeed = self.speedMinTurn
                rotation = -goingBack * (self.wheelPosition * dt * self.turnRatio * -1.8 * curSpeed / 100 + turnHelp * dt * self.turnRatio * -1.2)
                self.outPutCounter += 1
                if self.outPutCounter > 5:
                    self.outPutCounter = 0
            else:
                rotation = self.arrowHorz * dt * self.turnRatio * -1.2
            oldH = self.getH()
            newH = (oldH + rotation) % 360
            self.setH(newH)
            newHForTurning = newH
            if self.groundType == 'ice':
                newHForTurning = (oldH + rotation * iceTurnFactor) % 360
        pitch = -self.getP() + 5
        accelBase = self.accelerationBase
        pitch += accelBase
        pitch = bound(pitch, accelBase - 5, accelBase + 5)
        self.accelerationMult = pitch * 2
        if self.groundType == 'ice':
            self.accelerationMult *= iceAccelFactor
        if self.stopped:
            self.acceleration = 0
        else:
            self.acceleration = self.arrowVert * self.accelerationMult * self.cheatFactor
            if self.proRacer:
                if self.skidding:
                    self.acceleration = self.arrowVert * self.accelerationMult * self.cheatFactor * 0.5
            if self.turbo:
                self.acceleration += self.accelerationMult * 1.5
        self.engine.setVector(Vec3(0, self.acceleration, 0))
        if self.groundType == 'ice':
            rotMat = Mat3.rotateMatNormaxis(newHForTurning, Vec3.up())
        else:
            rotMat = Mat3.rotateMatNormaxis(self.getH(), Vec3.up())
        curHeading = rotMat.xform(Vec3.forward())
        push = (3 - self.getP()) * 0.02
        curHeading.setZ(curHeading.getZ() - min(0.2, max(-.2, push)))
        onScreenDebug.append('vehicle curHeading = %s\n' % curHeading.pPrintValues())
        onScreenDebug.append('vehicle H = %s  newHForTurning=%f\n' % (self.getH(), newHForTurning))
        windResistance = self.surfaceModifiers[self.groundType]['windResistance']
        self.windResistance.setCoef(windResistance)
        physicsFrame = int((globalClock.getFrameTime() - self.physicsEpoch) * self.physicsCalculationsPerSecond)
        numFrames = min(physicsFrame - self.lastPhysicsFrame, self.maxPhysicsFrames)
        self.lastPhysicsFrame = physicsFrame
        leanIncrement = self.arrowHorz * self.physicsDt * self.turnRatio
        if self.stopped:
            leanIncrement = 0
        driftMin = self.surfaceModifiers[self.groundType]['driftMin']
        if self.proRacer:
            driftMin = self.surfaceModifiers[self.groundType]['driftMin'] * 0.2
            if self.skidding:
                driftMin = self.surfaceModifiers[self.groundType]['driftMin']
        for i in xrange(int(numFrames)):
            self.physicsMgr.doPhysics(self.physicsDt)
            curVelocity = self.actorNode.getPhysicsObject().getVelocity()
            idealVelocity = curHeading * curSpeed
            curVelocity *= self.imHitMult
            driftVal = abs(self.leanAmount) * 16 / self.cheatFactor + 15 / self.cheatFactor
            curVelocity = Vec3((curVelocity * driftVal + idealVelocity) / (driftVal + 1))
            curSpeed = curVelocity.length()
            curVelocity.normalize()
            curVelocity *= min(curSpeed, 600)
            self.actorNode.getPhysicsObject().setVelocity(curVelocity)
            curSpeed = curVelocity.length()
            speedFactor = min(curSpeed, 150) / 162.0
            self.leanAmount = (self.leanAmount + leanIncrement) * speedFactor
            self.leanAmount = bound(self.leanAmount, -10, 10)

        self.cWallTrav.traverse(render)
        self.curSpeed = curSpeed
        if self.proRacer:
            self.turnWheels(self.wheelPosition * -45)
        else:
            self.turnWheels(self.arrowHorz * -10)
        self.__animate()
        if self.proRacer:
            speedProporation = 1.0
            if curSpeed < self.speedMaxTurn:
                speedProporation = 0.0
            else:
                speedProporation = (curSpeed - self.speedMaxTurn) / self.speedMinTurn
            cameraDist = self.cameraArmBase + self.cameraArmExtend * speedProporation
            cameraOffset = Point3(0, -cameraDist, 0)
            self.cameraNode.setPos(cameraOffset)
            behindPos = render.getRelativePoint(self, Point3(0, -30, 0))
            self.proCameraDummyNode.setPos(render, behindPos)
            self.proCameraDummyNode.lookAt(self)
            self.cameraNode.lookAt(self)
            dir1 = self.proCameraDummyNode.getH()
            dir2 = self.proCameraHeading
            if dir1 > 180:
                dir1 -= 360
            elif dir1 < -180:
                dir1 += 360
            if dir2 > 180:
                dir2 -= 360
            elif dir2 < -180:
                dir2 += 360
            self.proCameraHeading = dir2
            dif = dir1 - dir2
            if dif > 180:
                dif -= 360
            elif dif < -180:
                dif += 360
            speedDif = abs(dif)
            if speedDif > 90:
                speedDif = 90
            cameraTightener = 1.0
            if curSpeed > self.speedMinTurn:
                cameraTightener = self.cameraTightener
            else:
                cameraTightener = 1.0 + curSpeed / self.speedMinTurn * (self.cameraTightener - 1.0)
            swingSpeedRatio = speedDif / 90
            swingSpeed = self.armSwingSpeedPerp * swingSpeedRatio + self.armSwingSpeedPara * (1 - swingSpeedRatio)
            self.proCameraHeading += dif * cameraTightener * (dt / swingSpeed)
            self.cameraArmNode.setH(self.proCameraHeading - self.getH())
        elif not self.stopped:
            self.cameraNode.setH(self.leanAmount)
        self.updateParticles(self.leanAmount)
        if (self.leanAmount > 8 or self.leanAmount < -8) and self.offGround <= 0:
            self.startSkid()
        else:
            self.stopSkid()
        if self.speedometer:
            self.speedometer['text'] = str(int(curSpeed / 3))
            self.speedGauge.setR(min(110, max(0, curSpeed / 3 / 120 * 110)))
        if not self.stopped:
            self.stickCarToGround()
        if self.__clampPosition():
            self.notify.debug('did a clampPosition on %d' % self.doId)
        return Task.cont
예제 #21
0
 def setRotation(self, rotation):
     self.__previousRotation = self._rotation
     self._rotation = bound(rotation, CANNON_ROTATION_MIN,
                            CANNON_ROTATION_MAX)
예제 #22
0
 def setAngle(self, angle):
     self.__previousAngle = self._angle
     self._angle = bound(angle, CANNON_ANGLE_MIN, CANNON_ANGLE_MAX)
예제 #23
0
 def addToMood(self, component, delta):
     value = self.mood.getComponent(component)
     value += delta
     self.setMoodComponent(component, bound(value, 0.0, 1.0))
예제 #24
0
파일: main.py 프로젝트: anossov/dorfdelf
 def change_slice(self, n, rel=True):
     s = self.current_slice + n if rel else n
     self.current_slice = bound(s, 0, self.world.depth - 1)
     self.messenger.send('slice-changed', [self.current_slice, self.explore_mode])
예제 #25
0
 def doCollisions(oldPos, newPos, self=self):
     x = bound(newPos[0], self.StageHalfWidth, -self.StageHalfWidth)
     y = bound(newPos[1], self.StageHalfHeight, -self.StageHalfHeight)
     newPos.setX(x)
     newPos.setY(y)
     return newPos