Esempio n. 1
0
    def __move_interval_stop(self, actor, toggleEvent, itvl):

        if itvl.animName == "run_forward":
            self.__playerMovingForward = False

        if itvl.animName == "run_backward":
            self.__playerMovingBackward = False

        currFrame = itvl.getCurrentFrame()
        endFrame = actor.getNumFrames(itvl.animName)

        itvl.finish()

        standItvl = ActorInterval(actor, "stand")
        standItvl.start()
Esempio n. 2
0
    def __showSplat(self, position, direction, hot=False):
        if self.kaboomTrack is not None and self.kaboomTrack.isPlaying():
            self.kaboomTrack.finish()
        self.clearHitInterval()
        splatName = 'splat-creampie'
        self.splat = globalPropPool.getProp(splatName)
        self.splat.setBillboardPointEye()
        self.splat.reparentTo(render)
        self.splat.setPos(self.root, position)
        self.splat.setAlphaScale(1.0)
        if not direction == 1.0:
            self.splat.setColorScale(PartyGlobals.CogActivitySplatColors[0])
            if self.currentFacing > 0.0:
                facing = 'HitFront'
            else:
                facing = 'HitBack'
        else:
            self.splat.setColorScale(PartyGlobals.CogActivitySplatColors[1])
            if self.currentFacing > 0.0:
                facing = 'HitBack'
            else:
                facing = 'HitFront'
        if hot:
            targetscale = 0.75
            part = 'head'
        else:
            targetscale = 0.5
            part = 'body'

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

        self.hitInterval = Sequence(
            ActorInterval(self.actor, part + facing, loop=0),
            Func(self.actor.loop, 'idle'))
        self.hitInterval.start()
        self.kaboomTrack = Parallel(
            SoundInterval(self.pieHitSound,
                          volume=1.0,
                          node=self.actor,
                          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
Esempio n. 3
0
 def exitDown(self):
     self.root.setR(0.0)
     self.root.setH(0.0)
     self.targetDistance = 0.0
     self.targetFacing = 0.0
     self.currentT = 0.0
     self.setAlongSpline(0.0)
     self.clearHitInterval()
     startScale = self.hole.getScale()
     endScale = Point3(5, 5, 5)
     self.hitInterval = Sequence(
         LerpScaleInterval(self.hole,
                           duration=0.175,
                           scale=endScale,
                           startScale=startScale,
                           blendType='easeIn'),
         Parallel(
             SoundInterval(self.upSound,
                           volume=0.6,
                           node=self.actor,
                           cutOff=PartyGlobals.PARTY_COG_CUTOFF),
             ActorInterval(self.actor, 'up', loop=0)),
         Func(self.actor.loop, 'idle'),
         LerpScaleInterval(self.hole,
                           duration=0.175,
                           scale=Point3(3, 3, 3),
                           startScale=endScale,
                           blendType='easeOut'))
     self.hitInterval.start()
Esempio n. 4
0
 def enterDown(self):
     if self.oldState == 'Off':
         downAnimControl = self.actor.getAnimControl('down')
         self.actor.pose('down', downAnimControl.getNumFrames() - 1)
         return
     self.clearHitInterval()
     startScale = self.hole.getScale()
     endScale = Point3(5, 5, 5)
     self.hitInterval = Sequence(
         LerpFunc(self.setAlongSpline,
                  duration=1.0,
                  fromData=self.currentT,
                  toData=0.0),
         LerpScaleInterval(self.hole,
                           duration=0.175,
                           scale=endScale,
                           startScale=startScale,
                           blendType='easeIn'),
         Parallel(
             SoundInterval(self.upSound,
                           volume=0.6,
                           node=self.actor,
                           cutOff=PartyGlobals.PARTY_COG_CUTOFF),
             ActorInterval(self.actor, 'down', loop=0)),
         LerpScaleInterval(self.hole,
                           duration=0.175,
                           scale=Point3(3, 3, 3),
                           startScale=endScale,
                           blendType='easeOut'))
     self.hitInterval.start()
    def getTossPieInterval(self, toon, x, y, z, h, p, r, power, beginFlyIval = Sequence()):
        ToontownBattleGlobals = ToontownBattleGlobals
        import toontown.toonbase
        BattleProps = BattleProps
        import toontown.battle
        pie = toon.getPieModel()
        pie.setScale(0.5)
        flyPie = pie.copyTo(NodePath('a'))
        pieName = ToontownBattleGlobals.pieNames[toon.pieType]
        pieType = BattleProps.globalPropPool.getPropType(pieName)
        animPie = Sequence()
        if pieType == 'actor':
            animPie = ActorInterval(pie, pieName, startFrame = 48)
        
        sound = loader.loadSfx('phase_3.5/audio/sfx/AA_pie_throw_only.mp3')
        t = power / 100.0
        dist = lerp(PartyGlobals.CogActivityPieMinDist, PartyGlobals.CogActivityPieMaxDist, t)
        time = lerp(1.0, 1.5, t)
        proj = ProjectileInterval(None, startPos = Point3(0, 0, 0), endPos = Point3(0, dist, 0), duration = time)
        relVel = proj.startVel
        
        def getVelocity(toon = toon, relVel = relVel):
            return render.getRelativeVector(toon, relVel) * 0.59999999999999998

        
        def _PartyCogActivity__safeSetAnimState(toon = toon, state = 'Happy'):
            if toon and hasattr(toon, 'animFSM'):
                toon.setAnimState('Happy')
            else:
                self.notify.warning('The toon is being destroyed. No attribute animState.')

        toss = Track((0, Sequence(Func(toon.setPosHpr, x, y, z, h, p, r), Func(pie.reparentTo, toon.rightHand), Func(pie.setPosHpr, 0, 0, 0, 0, 0, 0), animPie, Parallel(ActorInterval(toon, 'throw', startFrame = 48, playRate = 1.5, partName = 'torso'), animPie), Func(_PartyCogActivity__safeSetAnimState, toon, 'Happy'))), (16.0 / 24.0, Func(pie.detachNode)))
        fly = Track((14.0 / 24.0, SoundInterval(sound, node = toon, cutOff = PartyGlobals.PARTY_COG_CUTOFF)), (16.0 / 24.0, Sequence(Func(flyPie.reparentTo, render), Func(flyPie.setPosHpr, toon, 0.52000000000000002, 0.96999999999999997, 2.2400000000000002, 0, -45, 0), beginFlyIval, ProjectileInterval(flyPie, startVel = getVelocity, duration = 6), Func(flyPie.detachNode))))
        return (toss, fly, flyPie)
Esempio n. 6
0
    def getTossPieInterval(self,
                           toon,
                           x,
                           y,
                           z,
                           h,
                           p,
                           r,
                           power,
                           beginFlyIval=Sequence()):
        """Adapted from toon.py to suit our needs.
        Returns (toss, pie, flyPie), where toss is an interval to
        animate the toon tossing a pie, pie is the interval to
        animate the pie flying through the air, and pieModel is the
        model that flies.  This is used in the final BossBattle
        sequence of CogHQ when we all throw pies directly at the
        boss cog.
        """

        from toontown.toonbase import ToontownBattleGlobals
        from toontown.battle import BattleProps

        pie = toon.getPieModel()
        pie.setScale(0.5)
        flyPie = pie.copyTo(NodePath('a'))
        pieName = ToontownBattleGlobals.pieNames[toon.pieType]
        pieType = BattleProps.globalPropPool.getPropType(pieName)
        animPie = Sequence()
        if pieType == 'actor':
            animPie = ActorInterval(pie, pieName, startFrame=48)

        sound = loader.loadSfx('phase_3.5/audio/sfx/AA_pie_throw_only.mp3')

        # First, create a ProjectileInterval to compute the relative
        # velocity.

        assert 0 <= power <= 100, "invalid pie throw power %s" % power

        t = power / 100.0

        # Distance ranges from CogActivityPieMinDist to CogActivityPieMaxDist ft, time ranges from 1 to 1.5 s.
        dist = lerp(PartyGlobals.CogActivityPieMinDist,
                    PartyGlobals.CogActivityPieMaxDist, t)
        time = lerp(1.0, 1.5, t)

        proj = ProjectileInterval(None,
                                  startPos=Point3(0, 0, 0),
                                  endPos=Point3(0, dist, 0),
                                  duration=time)
        relVel = proj.startVel

        def getVelocity(toon=toon, relVel=relVel):
            return render.getRelativeVector(toon, relVel) * 0.6

        toss = Track(
            (
                0,
                Sequence(
                    Func(toon.setPosHpr, x, y, z, h, p, r),
                    Func(pie.reparentTo, toon.rightHand),
                    Func(pie.setPosHpr, 0, 0, 0, 0, 0, 0),
                    animPie,
                    Parallel(
                        ActorInterval(
                            toon,
                            'throw',
                            startFrame=48,
                            #duration=0.25, #self.throwPieLimitTime,
                            playRate=1.5,
                            partName='torso'),
                        animPie),
                    Func(toon.setAnimState, 'Happy'),
                )),
            (16. / 24., Func(pie.detachNode)))

        fly = Track(
            (14. / 24.,
             SoundInterval(
                 sound, node=toon, cutOff=PartyGlobals.PARTY_COG_CUTOFF)),
            (
                16. / 24.,
                Sequence(
                    Func(flyPie.reparentTo, render),
                    Func(flyPie.setPosHpr, toon, 0.52, 0.97, 2.24, 0, -45, 0),
                    beginFlyIval,
                    ProjectileInterval(
                        flyPie, startVel=getVelocity, duration=6),
                    #LerpPosInterval(flyPie, duration = 3, Point3(0.52,50,2.24)),
                    Func(flyPie.detachNode),
                )),
        )
        return (toss, fly, flyPie)
Esempio n. 7
0
    def __init__(self):
        ShowBase.__init__(self)

        self.actorModelPath = "/e/models/ralph"
        self.actorAnimaPath = {
            "run": "/e/models/ralph-run",
            "walk": "/e/models/ralph-walk",
            "jump": "/e/models/ralph-jump"
        }

        self.actor = Actor(self.actorModelPath,
                           self.actorAnimaPath)
        self.actor.reparentTo(self.render)
        self.actor.setPos(0, 0, 0)
        self.actor.setScale(0.75)

        print self.actor.getAnimNames()

        self.actorAnimaKeymap = {
            "run_forward": False,
            "run_backward": False,
            "run_left": False,
            "run_right": False,
            "jump": False
        }

        self.jumpItval = ActorInterval(
            actor=self.actor,
            animName="jump",
            #constrainedLoop=0,
            #startFrame=0,
            #endFrame=self.actor.getNumFrames("jump")
        )
        print self.jumpItval.getName()
        self.isMoving = False
        self.isJumping = False

        self.actorCurrH = 0

        self.disableMouse()
        self.camera.setPos(0, 15, self.actor.getZ() + 15)
        self.camera.lookAt(0, 0, self.actor.getZ())
        camVec = self.camera.getPos() - self.actor.getPos()
        print "camVec Length : ", camVec.length()
        print "Z : ", self.actor.getZ()

        self.actor.accept("w", self.set_keymap, ["run_forward", True])
        self.actor.accept("w-up", self.set_keymap, ["run_forward", False])
        self.actor.accept("s", self.set_keymap, ["run_backward", True])
        self.actor.accept("s-up", self.set_keymap, ["run_backward", False])
        self.actor.accept("a", self.set_keymap, ["run_left", True])
        self.actor.accept("a-up", self.set_keymap, ["run_left", False])
        self.actor.accept("d", self.set_keymap, ["run_right", True])
        self.actor.accept("d-up", self.set_keymap, ["run_right", False])
        self.actor.accept("space", self.jump_up)
        # self.actor.accept("space-up", self.jump_up, [False])
        # self.actor.accept("space-up", self.jump_up, ["jump", False])

        self.accept("wheel_up", self.camera_move, ["wheel_up"])
        self.accept("wheel_down", self.camera_move, ["wheel_down"])
        self.accept("arrow_left", self.camera_move, ["arrow_left"])
        self.accept("arrow_right", self.camera_move, ["arrow_right"])

        self.taskMgr.add(self.actor_animate, "actor_animate")
        # self.taskMgr.add(self.debug_check_actor_pos, "debug_check_actor_pos")

        self.isFullscreen = False
        self.accept("f", self.set_fullscreen)
Esempio n. 8
0
class ActorControl(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)

        self.actorModelPath = "/e/models/ralph"
        self.actorAnimaPath = {
            "run": "/e/models/ralph-run",
            "walk": "/e/models/ralph-walk",
            "jump": "/e/models/ralph-jump"
        }

        self.actor = Actor(self.actorModelPath,
                           self.actorAnimaPath)
        self.actor.reparentTo(self.render)
        self.actor.setPos(0, 0, 0)
        self.actor.setScale(0.75)

        print self.actor.getAnimNames()

        self.actorAnimaKeymap = {
            "run_forward": False,
            "run_backward": False,
            "run_left": False,
            "run_right": False,
            "jump": False
        }

        self.jumpItval = ActorInterval(
            actor=self.actor,
            animName="jump",
            #constrainedLoop=0,
            #startFrame=0,
            #endFrame=self.actor.getNumFrames("jump")
        )
        print self.jumpItval.getName()
        self.isMoving = False
        self.isJumping = False

        self.actorCurrH = 0

        self.disableMouse()
        self.camera.setPos(0, 15, self.actor.getZ() + 15)
        self.camera.lookAt(0, 0, self.actor.getZ())
        camVec = self.camera.getPos() - self.actor.getPos()
        print "camVec Length : ", camVec.length()
        print "Z : ", self.actor.getZ()

        self.actor.accept("w", self.set_keymap, ["run_forward", True])
        self.actor.accept("w-up", self.set_keymap, ["run_forward", False])
        self.actor.accept("s", self.set_keymap, ["run_backward", True])
        self.actor.accept("s-up", self.set_keymap, ["run_backward", False])
        self.actor.accept("a", self.set_keymap, ["run_left", True])
        self.actor.accept("a-up", self.set_keymap, ["run_left", False])
        self.actor.accept("d", self.set_keymap, ["run_right", True])
        self.actor.accept("d-up", self.set_keymap, ["run_right", False])
        self.actor.accept("space", self.jump_up)
        # self.actor.accept("space-up", self.jump_up, [False])
        # self.actor.accept("space-up", self.jump_up, ["jump", False])

        self.accept("wheel_up", self.camera_move, ["wheel_up"])
        self.accept("wheel_down", self.camera_move, ["wheel_down"])
        self.accept("arrow_left", self.camera_move, ["arrow_left"])
        self.accept("arrow_right", self.camera_move, ["arrow_right"])

        self.taskMgr.add(self.actor_animate, "actor_animate")
        # self.taskMgr.add(self.debug_check_actor_pos, "debug_check_actor_pos")

        self.isFullscreen = False
        self.accept("f", self.set_fullscreen)

    def set_fullscreen(self):
        winProps = WindowProperties()
        self.isFullscreen = not self.isFullscreen
        winProps.setFullscreen(self.isFullscreen)
        self.win.requestProperties(winProps)

    def set_keymap(self, key, value):
        self.actorAnimaKeymap[key] = value
        # print key, " : ", value

    def jump_up(self):
        self.jumpItval.loop()

    def actor_animate(self, task):

        dt = globalClock.getDt()

        actorRunSpeed = 5

        actorCurrH = self.actor.getH()
        if self.actorAnimaKeymap["run_forward"]:
            self.actorCurrH = 0
            if self.actorAnimaKeymap["run_left"]:
                self.actorCurrH = 45
            if self.actorAnimaKeymap["run_right"]:
                self.actorCurrH = 315
            self.actor.setH(self.actorCurrH)
            self.actor.setY(self.actor.getY() - actorRunSpeed * dt)
        if self.actorAnimaKeymap["run_backward"]:
            self.actorCurrH = 180
            if self.actorAnimaKeymap["run_left"]:
                self.actorCurrH = 135
            if self.actorAnimaKeymap["run_right"]:
                self.actorCurrH = 225
            self.actor.setH(self.actorCurrH)
            self.actor.setY(self.actor.getY() + actorRunSpeed * dt)
        if self.actorAnimaKeymap["run_left"]:
            self.actorCurrH = 90
            if self.actorAnimaKeymap["run_forward"]:
                self.actorCurrH = 45
            if self.actorAnimaKeymap["run_backward"]:
                self.actorCurrH = 135
            self.actor.setH(self.actorCurrH)
            self.actor.setX(self.actor.getX() + actorRunSpeed * dt)
        if self.actorAnimaKeymap["run_right"]:
            self.actorCurrH = 270
            if self.actorAnimaKeymap["run_forward"]:
                self.actorCurrH = 315
            if self.actorAnimaKeymap["run_backward"]:
                self.actorCurrH = 225
            self.actor.setH(self.actorCurrH)
            self.actor.setX(self.actor.getX() - actorRunSpeed * dt)

        if self.actorAnimaKeymap["run_forward"] or \
                self.actorAnimaKeymap["run_backward"] or \
                self.actorAnimaKeymap["run_left"] or \
                self.actorAnimaKeymap["run_right"]:
            if self.isMoving is False:
                self.actor.loop("run")
                self.isMoving = True

        else:
            if self.isMoving:
                self.actor.stop()
                self.actor.play("walk")
                self.actor.pose("walk", 4)
                self.isMoving = False

        # camVec = self.actor.getPos() - self.camera.getPos()
        # camVec.setZ(0)
        # camDist = camVec.length()
        # camVec.normalize()
        # if camDist > 10.0:
        #     self.camera.setPos(self.camera.getPos() + camVec * (camDist - 10))
        #     camDist = 10.0
        # if camDist < 5.0:
        #     self.camera.setPos(self.camera.getPos() - camVec * (5 - camDist))
        #     camDist = 5.0

        return task.cont

    def camera_move(self, mouseEvent):

        mouseCurrY = self.camera.getY()
        mouseMoveOffset = 2

        if mouseEvent == "wheel_up":
            self.camera.setY(mouseCurrY + mouseMoveOffset)

        if mouseEvent == "wheel_down":
            self.camera.setY(mouseCurrY - mouseMoveOffset)

        print "Camera Pos : ", self.camera.getPos()

    def debug_check_actor_pos(self, task):
        # sleep(1)
        print "actor pos : ", self.actor.getPos()
        return task.cont