class DroppableCollectableJellybean(DroppableCollectableJellybeans):
    notify = directNotify.newCategory("DroppableCollectableJellybean")

    def __init__(self):
        DroppableCollectableJellybeans.__init__(self)
        self.bean = None
        self.spinIval = None
        self.collectSfx = base.loadSfx(
            "phase_3.5/audio/sfx/ci_s_money_smallBucks.ogg")

    def loadObject(self):
        self.removeObject()
        self.bean = loader.loadModel("phase_5.5/models/estate/jellyBean.bam")
        self.bean.setTwoSided(1)
        self.bean.setScale(1.5)
        self.bean.setZ(1.0)
        self.bean.reparentTo(self)
        # Give the bean a completely random color.
        self.bean.setColor(
            VBase4(random.uniform(0, 1), random.uniform(0, 1),
                   random.uniform(0, 1), 1.0))
        self.spin()

    def removeObject(self):
        if self.bean:
            self.bean.removeNode()
            self.bean = None

    def load(self):
        self.collectSfx = base.loadSfx(
            "phase_3.5/audio/sfx/ci_s_money_smallBucks.ogg")
        DroppableCollectableJellybeans.load(self)

    def unload(self):
        self.stopSpin()
        DroppableCollectableJellybeans.unload(self)

    def spin(self):
        self.stopSpin()
        self.spinIval = LerpHprInterval(
            self.bean,
            duration=3.0,
            hpr=Vec3(360, 0, 0),
            startHpr=(0, 0, 0),
        )
        self.spinIval.loop()

    def stopSpin(self):
        if self.spinIval:
            self.spinIval.finish()
            self.spinIval = None
Exemplo n.º 2
0
class JellybeanPickup(DistributedEntity):

    Colors = [(1, 0, 0, 1),
    (0, 0, 1, 1),
    (0, 1, 0, 1),
    (1, 0, 1, 1),
    (0, 1, 1, 1),
    (1, 1, 0, 1)]

    def __init__(self, cr):
        DistributedEntity.__init__(self, cr)
        self.rot = None

    def announceGenerate(self):
        DistributedEntity.announceGenerate(self)

        self.addSound("pickup", "sound/items/jellybean_pickup.ogg")

        import random
        color = random.choice(self.Colors)
        self.getModelNP().setColorScale(color, 1)

        from direct.interval.IntervalGlobal import LerpHprInterval
        self.rot = LerpHprInterval(self.getModelNP(), 1.0, (360, 0, 0), (0, 0, 0))
        self.rot.loop()

        from src.coginvasion.globals import CIGlobals
        from panda3d.bullet import BulletSphereShape, BulletGhostNode
        sph = BulletSphereShape(0.5)
        body = BulletGhostNode(self.uniqueName('jellybean-trigger'))
        body.addShape(sph)
        body.setIntoCollideMask(CIGlobals.EventGroup)
        self.setupPhysics(body, True)
        self.acceptOnce('enter' + self.uniqueName('jellybean-trigger'), self.__enterJellybeanTrigger)

    def __enterJellybeanTrigger(self, entry):
        print("Requesting money")
        self.playSound("pickup")
        self.hide()
        self.sendUpdate('pickup')

    def disable(self):
        self.ignore('enter' + self.uniqueName('jellybean-trigger'))
        if self.rot:
            self.rot.finish()
        self.rot = None
        DistributedEntity.disable(self)
Exemplo n.º 3
0
class DistributedFuncRotating(DistributedEntity, FSM):

    def __init__(self, cr):
        DistributedEntity.__init__(self, cr)
        FSM.__init__(self, 'func_rotating')
        self.state = 0
        self.axis = Vec3.up()
        self.timeToFull = 5.0
        self.speed = 50.0
        self.spinTrack = None

    def setState(self, state):
        self.state = state
        if state == 0:
            self.request('Stopped')
        elif state == 1:
            self.request('Rotating')
        elif state == 2:
            self.request('StartRotating')
        elif state == 3:
            self.request('StopRotating')

    def disable(self):
        self.request('Off')
        self.__cleanupSpin()
        self.state = None
        self.axis = None
        self.timeToFull = None
        self.speed = None
        self.spinTrack = None
        DistributedEntity.disable(self)

    def load(self):
        DistributedEntity.load(self)

        self.axis = base.bspLoader.getEntityValueVector(self.entnum, "axis")
        self.speed = base.bspLoader.getEntityValueFloat(self.entnum, "speed")
        self.timeToFull = base.bspLoader.getEntityValueFloat(self.entnum, "timeToFull")

        base.materialData.update(PhysicsUtils.makeBulletCollFromGeoms(self.cEntity.getModelNp()))

    def __getRot(self):
        rot = Vec3(360, 360, 0)
        rot[0] *= self.axis[2]
        rot[1] *= self.axis[1]
        return rot

    def enterStopped(self):
        pass

    def exitStopped(self):
        pass

    def __cleanupSpin(self):
        if self.spinTrack:
            self.spinTrack.pause()
            self.spinTrack = None

    def enterRotating(self):
        print(self.__getRot())
        print("We are rotating")
        self.spinTrack = LerpHprInterval(self.cEntity.getModelNp(), 60.0 / self.speed, self.__getRot(), startHpr = (0, 0, 0))
        self.spinTrack.loop()

    def exitRotating(self):
        self.__cleanupSpin()

    def enterStartRotating(self):
        self.startTime = globalClock.getFrameTime()
        taskMgr.add(self.__startRotatingTask, self.uniqueName('srot'))

    def __startRotatingTask(self, task):
        currHpr = self.cEntity.getModelNp().getHpr()
        elapsed = globalClock.getFrameTime() - self.startTime
        speed = min(self.speed, self.speed * (elapsed / self.timeToFull))
        newHpr = currHpr + Vec3(self.axis[2] * speed, self.axis[1] * speed, 0)
        self.cEntity.getModelNp().setHpr(newHpr)

        return task.cont

    def exitStartRotating(self):
        taskMgr.remove(self.uniqueName('srot'))
        del self.startTime

    def enterStopRotating(self):
        self.startTime = globalClock.getFrameTime()
        taskMgr.add(self.__stopRotatingTask, self.uniqueName('strot'))

    def __stopRotatingTask(self, task):
        currHpr = self.cEntity.getModelNp().getHpr()
        elapsed = globalClock.getFrameTime() - self.startTime
        speed = max(0, self.speed - (self.speed * (elapsed / self.timeToFull)))
        newHpr = currHpr + Vec3(self.axis[2] * speed, self.axis[1] * speed, 0)
        self.cEntity.getModelNp().setHpr(newHpr)

        return task.cont

    def exitStopRotating(self):
        taskMgr.remove(self.uniqueName('strot'))
        del self.startTime
class DistributedDroppableCollectableJellybean(
        DistributedDroppableCollectableJellybeans):
    notify = directNotify.newCategory(
        'DistributedDroppableCollectableJellybean')

    def __init__(self, cr):
        DistributedDroppableCollectableJellybeans.__init__(self, cr)
        self.bean = None
        self.spinIval = None
        self.flyTrack = None
        self.tickSfx = None
        return

    def loadObject(self):
        self.removeObject()
        self.bean = loader.loadModel('phase_5.5/models/estate/jellyBean.bam')
        self.bean.setTwoSided(1)
        self.bean.setScale(1.5)
        self.bean.setZ(1.5)
        self.bean.reparentTo(self)
        self.bean.setColor(
            VBase4(random.uniform(0, 1), random.uniform(0, 1),
                   random.uniform(0, 1), 1.0))
        self.spin()

    def removeObject(self):
        if self.bean:
            self.bean.removeNode()
            self.bean = None
        return

    def handleCollisions(self, entry):
        self.sendUpdate('requestGrab', [])

    def handlePickup(self, avId):
        avatar = self.cr.doId2do[avId]
        avatarGoneName = avatar.uniqueName('disable')
        self.accept(avatarGoneName, self.unexpectedExit)
        flyTime = 1.0
        self.stopSpin()
        self.spinIval = Sequence(
            LerpHprInterval(self.bean,
                            duration=1.5,
                            hpr=Vec3(360, 0, 0),
                            startHpr=self.bean.getHpr()))
        self.spinIval.loop()
        self.actuallyCollect(avId, 1.2)
        track = ParallelEndTogether(
            Sequence(
                LerpPosInterval(self.bean,
                                flyTime,
                                pos=Point3(0, 0, 3),
                                startPos=self.bean.getPos(avatar),
                                blendType='easeInOut'),
                Func(self.bean.detachNode), Func(self.ignore, avatarGoneName)),
            LerpColorScaleInterval(self.bean, flyTime, Vec4(0, 0, 0, 0.1),
                                   Vec4(1, 1, 1, 1)))
        self.flyTrack = Sequence(track, name='treasureFlyTrack')
        self.bean.reparentTo(avatar)
        self.flyTrack.start()

    def actuallyCollect(self, avId, wait=None):
        DistributedDroppableCollectableJellybeans.handleCollisions(
            self, avId, wait)
        SoundInterval(self.tickSfx).start()

    def unexpectedExit(self):
        self.cleanupFlyTrack()

    def cleanupFlyTrack(self):
        if self.flyTrack:
            self.flyTrack.pause()
            self.flyTrack = None
        return

    def load(self):
        self.tickSfx = base.loadSfx('phase_3.5/audio/sfx/tick_counter.ogg')
        self.collectSfx = base.loadSfx(
            'phase_3.5/audio/sfx/tt_s_gui_sbk_cdrSuccess.ogg')
        DistributedDroppableCollectableJellybeans.load(self)

    def unload(self):
        self.tickSfx = None
        self.stopSpin()
        self.cleanupFlyTrack()
        DistributedDroppableCollectableJellybeans.unload(self)
        return

    def spin(self):
        self.stopSpin()
        self.spinIval = LerpHprInterval(self.bean,
                                        duration=3.0,
                                        hpr=Vec3(360, 0, 0),
                                        startHpr=(0, 0, 0))
        self.spinIval.loop()

    def stopSpin(self):
        if self.spinIval:
            self.spinIval.finish()
            self.spinIval = None
        return
Exemplo n.º 5
0
        def getToonsFlydownTrack():
            offset = 0.0
            track = Parallel()
            localAvCannon = None
            for toon in self.cr.doId2do.values():
                if not CIGlobals.isToon(toon):
                    continue
                tCannon = None
                for cannon in self.cannons:
                    if cannon.getOwner() == toon.doId:
                        if toon.doId == base.localAvatar.doId:
                            self.cannonId = cannon.doId
                            self.cannon = cannon
                        tCannon = cannon
                        break
                if tCannon:
                    propeller = loader.loadModel(
                        "phase_5/models/cogdominium/tt_m_ara_cfg_toonPropeller.bam"
                    )

                    torso = toon.getPart("torso")
                    bp = torso.attachNewNode('backpackInstance')
                    animal = toon.getAnimal()
                    bodyScale = ToonGlobals.BodyScales[animal]
                    bpHeight = ToonGlobals.TorsoHeightDict[
                        toon.getTorso()] * bodyScale - 0.5
                    bp.setPos(0, -0.325, bpHeight)

                    pInst = bp.attachNewNode("propellerInstance")
                    pInst.setPos(0, 0, 0)
                    pInst.setHpr(0, 20, 0)
                    pInst.setScale(1.0, 1.0, 1.25)

                    propeller.instanceTo(pInst)

                    ival = LerpHprInterval(propeller,
                                           duration=0.35,
                                           hpr=(360, 0, 0),
                                           startHpr=(0, 0, 0))
                    ival.loop()

                    toon.stopSmooth()
                    toon.loop('jump')
                    toon.wrtReparentTo(cannon)
                    toon.hide()
                    toon.setH(0)
                    track.append(
                        Sequence(
                            Wait(offset), Func(toon.show),
                            Parallel(
                                Sequence(Wait(3.5), Func(ival.pause),
                                         ActorInterval(toon, "zend"),
                                         Func(toon.loop, "neutral")),
                                LerpPosInterval(toon,
                                                duration=4.0,
                                                pos=(5, 0, 0),
                                                startPos=(5, 0, 20),
                                                blendType='easeOut')),
                            Func(propeller.removeNode), Func(pInst.removeNode),
                            Func(bp.removeNode),
                            Func(toon.wrtReparentTo, render)))
                offset += 0.5

            return track