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
Beispiel #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)
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