Ejemplo n.º 1
0
 def exitDoorEnterClosing(self, ts):
     doorFrameHoleLeft = self.findDoorNode('doorFrameHoleLeft')
     if doorFrameHoleLeft.isEmpty():
         self.notify.warning('enterOpening(): did not find flatDoors')
         return
     if ZoneUtil.isInterior(self.zoneId):
         doorFrameHoleLeft.setColor(1.0, 1.0, 1.0, 1.0)
     if self.leftSwing:
         h = -100
     else:
         h = 100
     leftDoor = self.findDoorNode('leftDoor')
     if not leftDoor.isEmpty():
         otherNP = self.getDoorNodePath()
         trackName = 'doorExitTrack-%d' % self.doId
         self.doorExitTrack = Parallel(Sequence(
             LerpHprInterval(nodePath=leftDoor,
                             duration=1.0,
                             hpr=VBase3(0, 0, 0),
                             startHpr=VBase3(h, 0, 0),
                             other=otherNP,
                             blendType='easeInOut'),
             Func(doorFrameHoleLeft.hide), Func(self.hideIfHasFlat,
                                                leftDoor)),
                                       Sequence(
                                           Wait(0.5),
                                           SoundInterval(self.closeSfx,
                                                         node=leftDoor)),
                                       name=trackName)
         self.doorExitTrack.start(ts)
Ejemplo n.º 2
0
 def load(self):
     btnGui = loader.loadModel('phase_3.5/models/gui/tt_m_gui_ign_newsBtnGui')
     bookModel = loader.loadModel('phase_3.5/models/gui/tt_m_gui_ign_shtickerBook')
     self.openNewNewsUp = btnGui.find('**/tt_t_gui_ign_new')
     self.openNewNewsUpBlink = btnGui.find('**/tt_t_gui_ign_newBlink')
     self.openNewNewsHover = btnGui.find('**/tt_t_gui_ign_newHover')
     self.openOldNewsUp = btnGui.find('**/tt_t_gui_ign_oldNews')
     self.openOldNewsHover = btnGui.find('**/tt_t_gui_ign_oldHover')
     self.closeNewsUp = bookModel.find('**/tt_t_gui_sbk_newsPage1')
     self.closeNewsHover = bookModel.find('**/tt_t_gui_sbk_newsPage2')
     btnGui.removeNode()
     bookModel.removeNode()
     oldScale = 0.5
     newScale = 0.9
     shtickerBookScale = 0.305
     newPos = VBase3(-0.380, 0, -0.134)
     shtickerBookPos = VBase3(1.175, 0, -0.83)
     textScale = 0.06
     self.newIssueButton = DirectButton(relief=None, sortOrder=DGG.BACKGROUND_SORT_INDEX - 1, image=(self.openNewNewsUp, self.openNewNewsHover, self.openNewNewsHover), text=('', TTLocalizer.EventsPageNewsTabName, TTLocalizer.EventsPageNewsTabName), text_fg=(1, 1, 1, 1), text_shadow=(0, 0, 0, 1), text_scale=textScale, text_font=ToontownGlobals.getInterfaceFont(), parent=base.a2dTopRight, pos=newPos, scale=newScale, command=self.__handleGotoNewsButton)
     self.gotoPrevPageButton = DirectButton(relief=None, image=(self.closeNewsUp, self.closeNewsHover, self.closeNewsHover), text_fg=(1, 1, 1, 1), text_shadow=(0, 0, 0, 1), text_scale=textScale, text_font=ToontownGlobals.getInterfaceFont(), pos=shtickerBookPos, scale=shtickerBookScale, command=self.__handleGotoPrevPageButton)
     self.goto3dWorldButton = DirectButton(relief=None, image=(self.closeNewsUp, self.closeNewsHover, self.closeNewsHover), text_fg=(1, 1, 1, 1), text_shadow=(0, 0, 0, 1), text_scale=textScale, text_font=ToontownGlobals.getInterfaceFont(), pos=shtickerBookPos, scale=shtickerBookScale, command=self.__handleGoto3dWorldButton)
     self.hideNewIssueButton()
     self.gotoPrevPageButton.hide()
     self.goto3dWorldButton.hide()
     self.accept('newIssueOut', self.handleNewIssueOut)
     self.__bookCheck = Sequence(Func(self.__checkButton), Wait(0.00001), Func(self.__checkButton), Wait(0.00001), Func(self.__checkButton), Wait(0.00001), Func(self.__checkButton), Wait(0.0001))
     self.__bookCheck.loop()
     self.__bookCheck.pause()
     self.__blinkIval = Sequence(Func(self.__showOpenEyes), Wait(2), Func(self.__showClosedEyes), Wait(0.1), Func(self.__showOpenEyes), Wait(0.1), Func(self.__showClosedEyes), Wait(0.1))
     self.__blinkIval.loop()
     self.__blinkIval.pause()
     self.buttonsLoaded = True
     return
Ejemplo n.º 3
0
 def enterClosing(self, ts):
     doorFrameHoleRight = self.findDoorNode('doorFrameHoleRight')
     if doorFrameHoleRight.isEmpty():
         self.notify.warning(
             'enterClosing(): did not find doorFrameHoleRight')
         return
     rightDoor = self.findDoorNode('rightDoor')
     if rightDoor.isEmpty():
         self.notify.warning('enterClosing(): did not find rightDoor')
         return
     otherNP = self.getDoorNodePath()
     trackName = 'doorClose-%d' % self.doId
     if self.rightSwing:
         h = 100
     else:
         h = -100
     self.finishDoorTrack()
     self.doorTrack = Parallel(Sequence(
         LerpHprInterval(nodePath=rightDoor,
                         duration=1.0,
                         hpr=VBase3(0, 0, 0),
                         startHpr=VBase3(h, 0, 0),
                         other=otherNP,
                         blendType='easeInOut'),
         Func(doorFrameHoleRight.hide), Func(self.hideIfHasFlat,
                                             rightDoor)),
                               Sequence(
                                   Wait(0.5),
                                   SoundInterval(self.closeSfx,
                                                 node=rightDoor)),
                               name=trackName)
     self.doorTrack.start(ts)
     if hasattr(self, 'done'):
         request = self.getRequestStatus()
         messenger.send('doorDoneEvent', [request])
Ejemplo n.º 4
0
 def generateAnalysis(self):
     if self.analyzeMode:
         self.cleanupAnalysis()
     
     self.analyzeMode = True
     cm = CardMaker('cm')
     self.analysisBar.show()
     loadingTime = self.loadingEnd - self.loadingStart
     for stepName in self.stepInfo:
         (startTime, duration, color, ticks, startPercent, percent, expectedTicks) = self.stepInfo[stepName]
         cm.setName(stepName)
         cm.setColor(color)
         cm.setFrame((startTime / loadingTime) * 1.8 - 0.90000000000000002, ((startTime + duration) / loadingTime) * 1.8 - 0.90000000000000002, -0.5, -0.10000000000000001)
         self.analysisBarRoot.attachNewNode(cm.generate())
         button = DirectFrame(parent = self.analysisBarRoot, geom = NodePath('empty'), image = NodePath('empty'), state = DGG.NORMAL, relief = None, frameSize = ((startTime / loadingTime) * 1.8 - 0.90000000000000002, ((startTime + duration) / loadingTime) * 1.8 - 0.90000000000000002, -0.5, -0.10000000000000001))
         button.bind(DGG.ENTER, self.showInfo, extraArgs = [
             stepName])
         self.analysisButtons.append(button)
         button = DirectFrame(parent = self.analysisBarRoot, geom = NodePath('empty'), image = NodePath('empty'), state = DGG.NORMAL, relief = None, frameSize = ((startPercent / self.loadScale / 100.0) * 1.8 - 0.90000000000000002, ((startPercent + percent) / self.loadScale / 100.0) * 1.8 - 0.90000000000000002, 0.10000000000000001, 0.5))
         button.bind(DGG.ENTER, self.showInfo, extraArgs = [
             stepName])
         self.analysisButtons.append(button)
         for tick in ticks:
             self.line.moveTo(VBase3((tick / loadingTime) * 1.8 - 0.90000000000000002, 0, -0.5))
             self.line.drawTo(VBase3((tick / loadingTime) * 1.8 - 0.90000000000000002, 0, -0.55000000000000004))
         
     
     for tick in self.unmappedTicks:
         self.line.moveTo(VBase3((tick / loadingTime) * 1.8 - 0.90000000000000002, 0, -0.5))
         self.line.drawTo(VBase3((tick / loadingTime) * 1.8 - 0.90000000000000002, 0, -0.55000000000000004))
     
     self.analysisSegs = self.analysisBarRoot.attachNewNode(self.line.create())
Ejemplo n.º 5
0
 def enterClosing(self, ts):
     bldgActor = self.getBuildingActor()
     rightDoor = bldgActor.controlJoint(None, 'modelRoot', 'def_right_door')
     if rightDoor.isEmpty():
         self.notify.warning('enterClosing(): did not find rightDoor')
         return
     otherNP = self.getDoorNodePath()
     trackName = 'doorClose-%d' % self.doId
     if self.rightSwing:
         h = 100
     else:
         h = -100
     self.finishDoorTrack()
     self.doorTrack = Sequence(LerpHprInterval(nodePath=rightDoor,
                                               duration=1.0,
                                               hpr=VBase3(0, 0, 0),
                                               startHpr=VBase3(h, 0, 0),
                                               blendType='easeInOut'),
                               SoundInterval(self.closeSfx, node=rightDoor),
                               name=trackName)
     self.doorTrack.start(ts)
     if hasattr(self, 'done'):
         request = self.getRequestStatus()
         messenger.send('doorDoneEvent', [request])
     return
Ejemplo n.º 6
0
 def start(self, text='Connecting...'):
     self.loadingText['text'] = text
     self.loadingCircle.show()
     self.background.show()
     self.background.wrtReparentTo(self.loadingGui)
     self.loadingText.wrtReparentTo(self.loadingGui)
     self.background.setBin('background', 1)
     self.loadingGui.reparentTo(aspect2d, 5000)
     self.loadingCircle.reparentTo(base.a2dBottomRight, 6000)
     self.loadingCircle.setPos(-0.1, 0, 0.1)
     self.Seq = Sequence(
         Func(self.loadingCircle.setHpr, VBase3(0, 0, 0)),
         self.loadingCircle.hprInterval(1, VBase3(0, 0, 360)))
     self.Seq.loop()
     self.logoSeq = Sequence(
         LerpScaleInterval(self.logo,
                           2,
                           Vec3(1.1, 1, 0.55),
                           Vec3(1, 1, 0.5),
                           blendType='easeInOut'),
         LerpScaleInterval(self.logo,
                           2,
                           Vec3(1, 1, 0.5),
                           Vec3(1.1, 1, 0.55),
                           blendType='easeInOut')).loop()
Ejemplo n.º 7
0
    def startCredits(self):
        base.musicManager.stopAllSounds()
        self.music = loader.loadMusic('phase_dubito/audio/bgm/event_credits.ogg')
        base.playMusic(self.music, looping = 1)

        self.creditsSequence = Sequence(
            Wait(2),
            Func(base.localAvatar.stopUpdateSmartCamera),
            Func(base.camera.wrtReparentTo, render),
            Func(base.transitions.letterboxOn, 1),
            base.camera.posHprInterval(3, Point3(0, -50, 10), VBase3(180, 90, 0)),
            Func(self.logo.show),
            LerpColorScaleInterval(self.logo, 2, Vec4(1, 1, 1, 1)),
            Wait(2),
            LerpColorScaleInterval(self.logo, 2, Vec4(1, 1, 1, 0)),
            Func(self.logo.hide),
            base.camera.posHprInterval(2, Point3(0, -100, 10), VBase3(180, -90, 0)),
            Wait(1),
            Func(self.displayText, dubito),
            Wait(6),
            Func(self.hideText),
            Wait(1),
            Func(self.displayText, rocket),
            Wait(6),
            Func(self.hideText),
            Wait(1),
            Func(self.displayText, toonjoey),
            Wait(6),
            Func(self.hideText),
            Wait(1),
            Func(self.displayText, leo),
            Wait(6),
            Func(self.hideText),
            ).start()
Ejemplo n.º 8
0
 def enterOpening(self, ts):
     bldgActor = self.getBuildingActor()
     rightDoor = bldgActor.controlJoint(None, 'modelRoot', 'def_right_door')
     if rightDoor.isEmpty():
         self.notify.warning('enterOpening(): did not find rightDoor')
         return
     otherNP = self.getDoorNodePath()
     trackName = 'doorOpen-%d' % self.doId
     if self.rightSwing:
         h = 100
     else:
         h = -100
     self.finishDoorTrack()
     self.doorTrack = Parallel(SoundInterval(self.openSfx, node=rightDoor),
                               Sequence(
                                   HprInterval(rightDoor, VBase3(0, 0, 0)),
                                   Wait(0.4),
                                   LerpHprInterval(nodePath=rightDoor,
                                                   duration=0.6,
                                                   hpr=VBase3(h, 0, 0),
                                                   startHpr=VBase3(0, 0, 0),
                                                   blendType='easeInOut')),
                               name=trackName)
     self.doorTrack.start(ts)
     return
Ejemplo n.º 9
0
 def exitDoorEnterOpening(self, ts):
     bldgActor = self.getBuildingActor()
     leftDoor = bldgActor.controlJoint(None, 'modelRoot', 'def_left_door')
     if self.leftSwing:
         h = -100
     else:
         h = 100
     if not leftDoor.isEmpty():
         otherNP = self.getDoorNodePath()
         trackName = 'doorDoorExitTrack-%d' % self.doId
         self.finishDoorExitTrack()
         self.doorExitTrack = Parallel(SoundInterval(self.openSfx,
                                                     node=leftDoor),
                                       Sequence(
                                           LerpHprInterval(
                                               nodePath=leftDoor,
                                               duration=0.6,
                                               hpr=VBase3(h, 0, 0),
                                               startHpr=VBase3(0, 0, 0),
                                               blendType='easeInOut')),
                                       name=trackName)
         self.doorExitTrack.start(ts)
     else:
         self.notify.warning(
             'exitDoorEnterOpening(): did not find leftDoor')
     return
Ejemplo n.º 10
0
 def loadAvatar(self):
     config = ConfigParser.SafeConfigParser()
     config.read('data.ini')
     pos = VBase3(float(config.get('Avatar', 'X')),
                  float(config.get('Avatar', 'Y')),
                  float(config.get('Avatar', 'Z')))
     hpr = VBase3(float(config.get('Avatar', 'H')),
                  float(config.get('Avatar', 'P')),
                  float(config.get('Avatar', 'R')))
     """
Ejemplo n.º 11
0
 def doInverseRelativeSweepTest(self, relativePoint, bitMask=None, height=0.1):
     globalPoint = self.scene.Base.render.getRelativePoint(self.bodyNP, relativePoint)
     fromT = TransformState.makePos(self.bodyNP.getPos(self.scene.Base.render) + VBase3(0, 0, height))
     toT = TransformState.makePos(globalPoint + VBase3(0, 0, height))
     if bitMask != None:
         r = self.scene.world.sweepTestClosest(self.shape, toT, fromT, bitMask)
     else:
         r = self.scene.world.sweepTestClosest(self.shape, toT, fromT)
     if r.getNode() == self.body:
         return BulletClosestHitSweepResult.empty()
     else:
         return r
Ejemplo n.º 12
0
 def expandExplosion(self, Task):
     # expand the explosion rign each frame until a certain size
     if self.explosionModel.getScale() < VBase3(60.0, 60.0, 60.0):
         factor = globalClock.getDt()
         scale = self.explosionModel.getScale()
         scale = scale + VBase3(factor * 40, factor * 40, factor * 40)
         self.explosionModel.setScale(scale)
         return Task.cont
     else:
         self.explosionModel.setScale(0)
         self.exploding = False
         self.resetPlayer()
    def start(self, text='Connecting...'):
        self.loadingGui.reparentTo(aspect2d, 3000)
        self.background.reparentTo(aspect2d, 2999)
        self.loadingText['text'] = text
        self.loadingCircle.show()
        self.background.show()

        self.background.wrtReparentTo(self.loadingGui)
        self.loadingText.wrtReparentTo(self.loadingGui)
        self.loadingCircle.wrtReparentTo(self.loadingGui)

        self.Seq = Sequence(
            Func(self.loadingCircle.setHpr, VBase3(0, 0, 0)),
            self.loadingCircle.hprInterval(1, VBase3(0, 0, 360)))
        self.Seq.loop()
Ejemplo n.º 14
0
    def singleCurveAnimation(self, nodePath, curve, time):
        rope = curve[OG.OBJ_NP]
        self.points = rope.getPoints(time)
        self.hprs = []
        temp = render.attachNewNode("temp")
        temp.setHpr(0, 0, 0)
        for i in range(len(self.points) - 1):
            temp.setPos(self.points[i])
            temp.lookAt(self.points[i + 1])
            hpr = temp.getHpr()
            ## self.hprs.append(hpr)
            self.hprs.append(VBase3(hpr[0] + 180, hpr[1], hpr[2]))
        self.hprs.append(self.hprs[len(self.points) - 2])

        curveSequenceName = str(nodePath[OG.OBJ_UID]) + ' ' + str(
            curve[OG.OBJ_UID]) + ' ' + str(time)
        self.curveSequence = Sequence(name=curveSequenceName)

        for i in range(len(self.points) - 1):
            myLerp = LerpPosHprInterval(nodePath[OG.OBJ_NP],
                                        float(1) / float(24),
                                        self.points[i + 1], self.hprs[i + 1],
                                        self.points[i], self.hprs[i])
            self.curveSequence.append(myLerp)

        return self.curveSequence
Ejemplo n.º 15
0
    def render(self, binary=True):
        base = self.base
        # context
        base.win.setClearColor(self._clear_color)
        base.camera.set_pos(VBase3(0, -self.get_camera_radius(), 0))
        self.obj_node.set_hpr(self._obj_hpr)
        self.direct_node.set_hpr(self._light_hpr)

        # redner
        base.graphics_engine.render_frame()
        tex = base.win.get_screenshot()

        # export
        bytes_image = bytes(tex.get_ram_image_as('RGBA'))
        pil_image = PIL.Image.frombytes('RGBA', base.get_size(), bytes_image)
        pil_image = pil_image.transpose(PIL.Image.FLIP_TOP_BOTTOM)
        if tuple(self.obj_translate) != (0, 0):
            np_clear_color = np.array(self._clear_color * 255, dtype=int)
            translated_image = PIL.Image.new('RGBA', pil_image.size,
                                             tuple(np_clear_color))
            np_obj_translate = np.array(self.obj_translate, dtype=int)
            translated_image.paste(pil_image, tuple(np_obj_translate))
            pil_image = translated_image

        if not binary:
            return pil_image

        bin_image = PIL.Image.new('1', pil_image.size)
        bin_image.paste(1, None, pil_image)

        return pil_image, bin_image
Ejemplo n.º 16
0
def showPopupMenu(self, event=None):
    """
    Make popup visible and try to position it below the main control.
    Adjust popup position if default position puts it outside of
    visible screen region
    """
    # Show the menu
    self.popupMenu.show()
    # Make sure its at the right scale
    self.popupMenu.setScale(self, VBase3(1))
    # Compute bounds
    b = self.getBounds()
    fb = self.popupMenu.getBounds()
    # Position menu at midpoint of button
    self.popupMenu.setX(self, b[0])
    # Try to set height to line up selected item with button
    self.popupMenu.setZ(self, -0.25)
    # Make sure the whole popup menu is visible
    pos = self.popupMenu.getPos(render2d)
    scale = self.popupMenu.getScale(render2d)
    # How about up and down?
    minZ = pos[2] + fb[2] * scale[2]
    maxZ = pos[2] + fb[3] * scale[2]
    if minZ < -1.0:
        # Menu too low, move it up
        self.popupMenu.setZ(render2d, pos[2] + (-1.0 - minZ))
    elif maxZ > 1.0:
        # Menu too high, move it down
        self.popupMenu.setZ(render2d, pos[2] + (1.0 - maxZ))
    # Also display cancel frame to catch clicks outside of the popup
    self.cancelFrame.show()
    # Position and scale cancel frame to fill entire window
    self.cancelFrame.setPos(render2d, 0, 0, 0)
    self.cancelFrame.setScale(render2d, 1, 1, 1)
    def onSetAction(self, action):
        self.model.reparentTo(self.eyeRoot)
        self.model.setScale(0.01)
        self.model.setHpr(VBase3(-155.0, -20.0, 0.0))
        self.model.setLightOff()

        self.avatar.doingActivity = False

        if action == self.StateThrow:
            self.avatar.doingActivity = True

            eyeTrack = Sequence(
                Func(self.model.show), Wait(self.HoldStart),
                LerpScaleInterval(self.model,
                                  self.HoldDuration,
                                  Point3(self.ModelScale),
                                  startScale=0.01),
                Wait(self.EyeHoldDuration * 0.3),
                LerpHprInterval(self.model, 0.02, Point3(205, 40, 0)),
                Wait(self.EyeHoldDuration * 0.7), Func(self.model.hide))

            self.setAnimTrack(Parallel(
                Sequence(Wait(1.3), Func(self.eyeSfx.play)),
                Sequence(
                    self.getAnimationTrack('glower',
                                           endTime=self.HoldStart,
                                           fullBody=False),
                    Wait(self.HoldDuration),
                    self.getAnimationTrack('glower',
                                           startTime=self.HoldStart,
                                           fullBody=False)), eyeTrack),
                              startNow=True)
 def attachGun(self, gunName):
     self.detachGun()
     if gunName == "pistol":
         self.gun = loader.loadModel("phase_4/models/props/water-gun.bam")
         self.gun.reparentTo(self.find('**/def_joint_right_hold'))
         self.gun.setPos(Point3(0.28, 0.1, 0.08))
         self.gun.setHpr(VBase3(85.6, -4.44, 94.43))
         self.gunAttached = True
     elif gunName == "shotgun":
         self.gun = loader.loadModel("phase_4/models/props/shotgun.egg")
         self.gun.setScale(0.75)
         self.gun.reparentTo(self.find('**/def_joint_right_hold'))
         self.gun.setPos(Point3(-0.5, -0.2, 0.19))
         self.gun.setHpr(Vec3(350, 272.05, 0))
         color = random.choice([
             VBase4(1, 0.25, 0.25, 1),
             VBase4(0.25, 1, 0.25, 1),
             VBase4(0.25, 0.25, 1, 1)
         ])
         self.gun.setColorScale(color)
         self.gunAttached = True
     elif gunName == "sniper":
         self.gun = loader.loadModel("phase_4/models/props/sniper.egg")
         self.gun.setScale(0.75)
         self.gun.reparentTo(self.find('**/def_joint_right_hold'))
         self.gun.setPos(Point3(-0.5, -0.2, 0.19))
         self.gun.setHpr(Vec3(350, 272.05, 0))
         color = random.choice([
             VBase4(1, 0.25, 0.25, 1),
             VBase4(0.25, 1, 0.25, 1),
             VBase4(0.25, 0.25, 1, 1)
         ])
         self.gun.setColorScale(color)
         self.gunAttached = True
Ejemplo n.º 19
0
 def handleToonExited(self, toonId):
     DistributedPartyTeamActivity.handleToonExited(self, toonId)
     if toonId == base.localAvatar.doId:
         self.cameraMoveIval.pause()
         if toonId not in self.fallenToons:
             if toonId in self.toonIdsToAnimIntervals and self.toonIdsToAnimIntervals[
                     toonId] is not None:
                 self.toonIdsToAnimIntervals[toonId].finish()
             toon = self.getAvatar(toonId)
             targetH = fitDestAngle2Src(toon.getH(self.root), 180.0)
             targetPos = self.hopOffPositions[self.getTeam(toonId)][
                 self.getIndex(toonId, self.getTeam(toonId))]
             hopOffAnim = Sequence(
                 Func(toon.startPosHprBroadcast, 0.1),
                 toon.hprInterval(0.2,
                                  VBase3(targetH, 0.0, 0.0),
                                  other=self.root),
                 Func(toon.b_setAnimState, 'jump', 1.0), Wait(0.4),
                 PartyUtils.arcPosInterval(0.75, toon, targetPos, 5.0,
                                           self.root),
                 Func(toon.stopPosHprBroadcast),
                 Func(toon.sendCurrentPosition),
                 Func(self.hopOffFinished, toonId))
             self.toonIdsToAnimIntervals[toonId] = hopOffAnim
             self._hopOffFinishedSV.set(False)
             self.toonIdsToAnimIntervals[toonId].start()
         else:
             self._hopOffFinishedSV.set(True)
             del self.toonIdsToAnimIntervals[toonId]
     return
Ejemplo n.º 20
0
    def showPopupMenu(self, event=None):
        self.popupMenu.show()
        self.popupMenu.setScale(self, VBase3(1))
        b = self.getBounds()
        fb = self.popupMenu.getBounds()

        xPos = (b[1] - b[0])/2.0 - fb[0]
        self.popupMenu.setX(self, xPos)

        items = self['items']
        if len(items) in (len(NumToColor), len(ClothesColorNames)- 1):
            self.popupMenu.setZ(self._parent, 0.8)
        else:
            self.popupMenu.setZ(self, self.minZ + (self.selectedIndex + 1) * self.maxHeight)

        pos = self.popupMenu.getPos(render2d)
        scale = self.popupMenu.getScale(render2d)
        maxX = pos[0] + fb[1] * scale[0]
        if maxX > 1.0:
            self.popupMenu.setX(render2d, pos[0] + (1.0 - maxX))

        minZ = pos[2] + fb[2] * scale[2]
        maxZ = pos[2] + fb[3] * scale[2]
        if minZ < -1.0:
            self.popupMenu.setZ(render2d, pos[2] + (-1.0 - minZ))
        elif maxZ > 1.0:
            self.popupMenu.setZ(render2d, pos[2] + (1.0 - maxZ))

        self.cancelFrame.show()
        self.cancelFrame.setPos(render2d, 0, 0, 0)
        self.cancelFrame.setScale(render2d, 1, 1, 1)
Ejemplo n.º 21
0
    def setupJellyBeans(self):
        self.beanAnims = []
        self.beansToCollect = []
        self.beanDetails = []
        self.numBeansCollected = 0
        for i in range(self.numJellyBeans):
            bean = self.beans[i]
            guiBean = self.guiBeans[i]
            height = self.jellyBeanPositions[i]
            if self.toon:
                avHeight = self.toon.getHeight()
            else:
                avHeight = 3
            bean.setZ(height + self.toon.getHeight() + self.beanOffset)
            guiBean.setZ(height * self.indicatorFactor + self.guiBeanOffset)
            bean.setH(0.0)
            bean.unstash()
            guiBean.unstash()
            beanAnim = bean.hprInterval(
                1.5, VBase3((i % 2 * 2 - 1) * 360.0, 0.0, 0.0))
            beanAnim.loop()
            self.beanAnims.append(beanAnim)
            self.beanDetails.append((height, bean, guiBean, beanAnim))

        self.beansToCollect = range(self.numJellyBeans)
Ejemplo n.º 22
0
def stabilize(task):
    tau = 0.1
    inertia = 1.0

    orientation = mass_node.get_quat()
    delta_orientation = target_node.get_quat() * invert(orientation)
    delta_node.set_quat(invert(delta_orientation))

    delta_angle = delta_orientation.get_angle_rad()
    if abs(delta_angle) < (pi / 360 * 0.1):
        delta_angle = 0
        axis_of_torque = VBase3(0, 0, 0)
    else:
        axis_of_torque = delta_orientation.get_axis()
        axis_of_torque.normalize()
        axis_of_torque = s.render.get_relative_vector(
            mass_node,
            axis_of_torque,
        )
    if delta_angle > pi:
        delta_angle -= 2 * pi
    axis_node.set_scale(axis_of_torque * 0.2)

    # If the mass was standing still, this would be the velocity that has to be
    # reached to achieve the targeted orientation in tau seconds.
    target_angular_velocity = axis_of_torque * delta_angle / tau
    # But we also have to cancel out the current velocity for that.
    angular_velocity = mass.get_angular_velocity()  # radians / sec
    countering_velocity = -angular_velocity

    # An impulse of 1 causes an angular velocity of 2.5 rad on a unit mass, so
    # we have to adjust accordingly.
    target_impulse = target_angular_velocity / 2.5 * inertia
    countering_impulse = countering_velocity / 2.5 * inertia

    # Now just sum those up, and we have the impulse that needs to be applied to
    # steer towards target.
    impulse = target_impulse + countering_impulse

    # Clamp the impulse to what the "motor" can produce.
    max_impulse = 0.4
    if impulse.length() > max_impulse:
        clamped_impulse = impulse / impulse.length() * max_impulse
    else:
        clamped_impulse = impulse

    print("{:4.0f} deg, "
          "{:2.5f} of {:2.5f} impulse, "
          "{:3.2f}% power of {:4.2f}% "
          "({:5.2f}% steering, {:5.2f}% countering) requested".format(
              delta_angle / (2 * pi) * 360,
              clamped_impulse.length(),
              impulse.length(),
              clamped_impulse.length() / max_impulse * 100,
              impulse.length() / max_impulse * 100,
              target_angular_velocity.length() / pi * 100,
              countering_velocity.length() / pi * 100,
          ))
    mass.apply_torque_impulse(clamped_impulse)
    return task.cont
    def setupJellyBeans(self):
        self.beanAnims = []
        self.beansToCollect = []
        self.beanDetails = []
        self.numBeansCollected = 0
        for i in range(self.numJellyBeans):
            bean = self.beans[i]
            guiBean = self.guiBeans[i]
            height = self.jellyBeanPositions[i]
            color = random.choice(self.jellyBeanColors)
            bean.find('**/jellybean').setColor(color)
            if self.toon.doId == base.localAvatar.doId:
                bean.setAlphaScale(1.0)
            else:
                bean.setAlphaScale(0.5)
            guiBean.setColor(color)
            bean.setZ(height + self.toon.getHeight() + self.beanOffset)
            guiBean.setZ(height * self.indicatorFactor + self.guiBeanOffset)
            bean.setH(0.0)
            bean.unstash()
            guiBean.unstash()
            beanAnim = bean.hprInterval(1.5, VBase3((i % 2 * 2 - 1) * 360.0, 0.0, 0.0))
            beanAnim.loop()
            self.beanAnims.append(beanAnim)
            self.beanDetails.append((height,
             bean,
             guiBean,
             beanAnim))

        self.beansToCollect = range(self.numJellyBeans)
Ejemplo n.º 24
0
 def makeSpot(parent, color=VBase4(1, 1, 1, 1), fov=8, atten=.003):
     x = parent.attachNewNode(Spotlight("spot"))
     x.node().setColor(color)
     lens = PerspectiveLens()
     lens.setFov(fov)
     x.node().setLens(lens)
     x.node().setAttenuation(VBase3(0, 0, atten))
     return x
Ejemplo n.º 25
0
    def __init__(self):
        ShowBase.__init__(self)

        # Override defaults
        self.disableMouse()
        self.setBackgroundColor(VBase3(160, 200, 150) / 255.0)
        self.setFrameRateMeter(True)

        # Lights
        dlight = DirectionalLight("dlight")
        dlnp = self.render.attachNewNode(dlight)
        dlnp.setHpr(180.0, -70.0, 0)
        self.render.setLight(dlnp)

        alight = AmbientLight("alight")
        alnp = self.render.attachNewNode(alight)
        alight.setColor(VBase4(0.4, 0.4, 0.4, 1))
        self.render.setLight(alnp)

        # Collision traverser
        self.cTrav = CollisionTraverser("collisionTraverser")
        #self.cTrav.showCollisions(self.render)

        # Collision handlers
        self.carCollisionHandler = CollisionHandlerEvent()
        self.carCollisionHandler.addInPattern("%fn-into-%in")

        # Camera controls
        self.cameraController = CameraController(self, 400, math.pi / 4.0,
                                                 math.pi / 4.0)
        #self.cameraController = CameraController(self, 300, -math.pi, math.pi / 4.0)

        # Load the track
        #self.track = self.loader.loadModel("models/trackMotegi")
        self.track = self.loader.loadModel("models/trackValencia")
        checkpointsCollision = self.track.find("checkpoints").node()
        checkpointsCollision.setIntoCollideMask(BitMask32(0xF0))
        self.numCheckpoints = checkpointsCollision.getNumSolids()
        self.track.reparentTo(self.render)

        # Load the car
        #self.car = KeyboardCar(self)
        self.car = NeuralNetworkCar(self)
        self.cameraController.follow(self.car.getNodePath())
        #self.cameraController.setTarget(self.car.getNodePath())

        # Reposition the car
        #self.car.getNodePath().setH(180.0)

        # Register car collisions with track
        self.cTrav.addCollider(self.car.carCollider, self.carCollisionHandler)
        self.accept("carCollider-into-trackCollision", self.car.onCrash)
        self.accept("carCollider-into-checkpoints", self.car.onCheckpoint)

        # State logger
        self.loggingActive = False
        self.log = []
        self.accept("l", self.toggleStateLogger)
Ejemplo n.º 26
0
 def hideOptions(self):
     self.optionsMgr.hideOptions()
     self.closeOptionsButton.hide()
     Parallel(
         self.PlayButton.posInterval(.5, Point3(PlayBtnPos), blendType = 'easeInOut'),
         self.OptionsButton.posInterval(.5, Point3(OptionsBtnPos), blendType = 'easeInOut'),
         self.QuitButton.posInterval(.5, Point3(QuitBtnPos), blendType = 'easeInOut'),
         self.logo.posInterval(.5, Point3(0, 0, .5), blendType = 'easeInOut')).start()
     base.camera.posHprInterval(0.5, Point3(MAIN_POS), VBase3(MAIN_HPR), blendType = 'easeInOut').start()
 def releaseToon(self):
     self._hideFlashMessage()
     self.ignore('arrow_left')
     self.ignore('arrow_left-up')
     self.ignore('arrow_right')
     self.ignore('arrow_right-up')
     taskMgr.remove(self.uniqueName('TrampolineActivity.updateTask'))
     self.hopOffAnim = Sequence(self.toon.hprInterval(0.5, VBase3(-90.0, 0.0, 0.0), other=self.tramp), Func(self.toon.b_setAnimState, 'jump', 1.0), Func(self.toon.dropShadow.reparentTo, hidden), Wait(0.4), PartyUtils.arcPosInterval(0.75, self.toon, self.hopOffPos, 5.0, self.tramp), Func(self.postHopOff))
     self.hopOffAnim.start()
Ejemplo n.º 28
0
 def spinCameraTask(self, task):
     angle_deg = int(round(self.camera.getH())) + cam_delta_angle
     angle_rad = angle_deg * DEG_RAD
     delta_v = VBase3(self.char.getX() + cam_dist * math.sin(angle_rad),
                      self.char.getY() - cam_dist * math.cos(angle_rad),
                      self.camera.getZ())
     self.camera.setPos(delta_v)
     self.camera.lookAt(self.char)
     return task.done
Ejemplo n.º 29
0
 def startAnimation(self):
     holidayIds = base.cr.newsManager.getHolidayIdList()
     if ToontownGlobals.VALENTINES_DAY in holidayIds:
         originalScale = self.nodePath.getScale()
         throbScale = VBase3(0.85, 0.85, 0.85)
         throbInIval = LerpScaleInterval(self.nodePath, 0.3, scale=throbScale, startScale=originalScale, blendType='easeIn')
         throbOutIval = LerpScaleInterval(self.nodePath, 0.3, scale=originalScale, startScale=throbScale, blendType='easeOut')
         self.heartThrobIval = Sequence(throbInIval, throbOutIval, Wait(0.75))
         self.heartThrobIval.loop()
Ejemplo n.º 30
0
 def enterHoncho(self, timestamp):
     Sequence(
         self.headHoncho1.beginSupaFlyMove(Vec3(68, -2, 4.024),
                                           True,
                                           'firstCogInvadeFlyIn',
                                           walkAfterLanding=False),
         Func(self.headHoncho1.loop, 'walk'),
         self.headHoncho1.hprInterval(2, VBase3(90, 0, 0)),
         Func(self.headHoncho1.loop, 'neutral')).start()
Ejemplo n.º 31
0
    def repaint(self, level):
        """divide or mark to show this chunk node, depend - distance to char coords
        """
        if self.level > level:
            #divide_dist = self.config.chunk_len * (3 ** (25 - self.level))
            #show_dist = self.chunks_map.far
            s2 = self.size * self.size
            s2 += s2
            divide_dist = math.sqrt(s2)
            length = VBase3.length(Vec3(self.center) - Vec3(self.chunks_map.charX,
                                                                self.chunks_map.charY,
                                                                self.chunks_map.charZ))
            #length = VBase2.length(Vec2(self.center[0], self.center[1]) - Vec2(self.chunks_map.charX,
                                                                #self.chunks_map.charY))

            if length <= divide_dist:
                #print 'Divide: ', divide_dist, self.size, self.level, length
                self.divide(level)
            else:
                self.mark_show()
        else:
            self.mark_show()