Ejemplo n.º 1
0
 def enableAimKeys(self):
     self.leftPressed = 0
     self.rightPressed = 0
     base.mouseWatcherNode.setModifierButtons(ModifierButtons())
     base.buttonThrowers[0].node().setModifierButtons(ModifierButtons())
     self.accept(ROTATE_LEFT_KEY, self.__handleLeftKeyPressed)
     self.accept(ROTATE_RIGHT_KEY, self.__handleRightKeyPressed)
     self.accept(FORWARD_KEY, self.__handleUpKeyPressed)
     self.accept(BACKWARDS_KEY, self.__handleDownKeyPressed)
Ejemplo n.º 2
0
 def __init__(self):
     self.__jumpPost = 0
     self.setPressHandlers(self.NULL_HANDLERS)
     self.setReleaseHandlers(self.NULL_HANDLERS)
     self.origMb = base.buttonThrowers[0].node().getModifierButtons()
     base.buttonThrowers[0].node().setModifierButtons(ModifierButtons())
     self.enable()
Ejemplo n.º 3
0
    def __init__(self):
        self.__jumpPost = 0

        self.setPressHandlers(self.NULL_HANDLERS)
        self.setReleaseHandlers(self.NULL_HANDLERS)

        # disable modifier-button combo messages (i.e. shift-right-key)
        self.origMb = base.buttonThrowers[0].node().getModifierButtons()
        base.buttonThrowers[0].node().setModifierButtons(ModifierButtons())

        self.enable()
 def __init__(self):
     self.UP_KEY = base.MOVE_UP
     self.DOWN_KEY = base.MOVE_DOWN
     self.LEFT_KEY = base.MOVE_LEFT
     self.RIGHT_KEY = base.MOVE_RIGHT
     self.JUMP_KEY = base.JUMP
     self.__jumpPost = 0
     self.setPressHandlers(self.NULL_HANDLERS)
     self.setReleaseHandlers(self.NULL_HANDLERS)
     self.origMb = base.buttonThrowers[0].node().getModifierButtons()
     base.buttonThrowers[0].node().setModifierButtons(ModifierButtons())
     self.enable()
Ejemplo n.º 5
0
 def setupMouse(self, win):
   """
   Creates the structures necessary to monitor the mouse input,
   using the indicated window.  If the mouse has already been set
   up for a different window, those structures are deleted first.
   """
   if self.buttonThrowers != None:
     for bt in self.buttonThrowers:
       mw = bt.getParent()
       mk = mw.getParent()
       bt.removeNode()
       mw.removeNode()
       mk.removeNode()
   # For each mouse/keyboard device, we create
   #  - MouseAndKeyboard
   #  - MouseWatcher
   #  - ButtonThrower
   # The ButtonThrowers are stored in a list, self.buttonThrowers.
   # Given a ButtonThrower, one can access the MouseWatcher and
   # MouseAndKeyboard using getParent.
   #
   # The MouseAndKeyboard generates mouse events and mouse
   # button/keyboard events; the MouseWatcher passes them through
   # unchanged when the mouse is not over a 2-d button, and passes
   # nothing through when the mouse *is* over a 2-d button.  Therefore,
   # objects that don't want to get events when the mouse is over a
   # button, like the driveInterface, should be parented to
   # MouseWatcher, while objects that want events in all cases, like the
   # chat interface, should be parented to the MouseAndKeyboard.
   
   self.buttonThrowers = []
   self.pointerWatcherNodes = []
   for i in range(win.getNumInputDevices()):
     name = win.getInputDeviceName(i)
     mk = base.dataRoot.attachNewNode(MouseAndKeyboard(win, i, name))
     mw = mk.attachNewNode(MouseWatcher("watcher%s" % (i)))
     mb = mw.node().getModifierButtons()
     mb.addButton(KeyboardButton.shift())
     mb.addButton(KeyboardButton.control())
     mb.addButton(KeyboardButton.alt())
     mb.addButton(KeyboardButton.meta())
     mw.node().setModifierButtons(mb)
     bt = mw.attachNewNode(ButtonThrower("buttons%s" % (i)))
     if (i != 0):
       bt.node().setPrefix('mousedev%s-' % (i))
     mods = ModifierButtons()
     mods.addButton(KeyboardButton.shift())
     mods.addButton(KeyboardButton.control())
     mods.addButton(KeyboardButton.alt())
     mods.addButton(KeyboardButton.meta())
     bt.node().setModifierButtons(mods)
     self.buttonThrowers.append(bt)
     if (win.hasPointer(i)):
       self.pointerWatcherNodes.append(mw.node())
   
   self.mouseWatcher = self.buttonThrowers[0].getParent()
   self.mouseWatcherNode = self.mouseWatcher.node()
   # print "ButtonThrowers = ", self.buttonThrowers
   # print "PointerWatcherNodes = ", self.pointerWatcherNodes
   
   # Now we have the main trackball & drive interfaces.
   # useTrackball() and useDrive() switch these in and out; only
   # one is in use at a given time.
   self.trackball = base.dataUnused.attachNewNode(Trackball('trackball'))
   self.drive = base.dataUnused.attachNewNode(DriveInterface('drive'))
   self.mouse2cam = base.dataUnused.attachNewNode(Transform2SG('mouse2cam'))
   self.mouse2cam.node().setNode(self.camera.node())
   
   # A special ButtonThrower to generate keyboard events and
   # include the time from the OS.  This is separate only to
   # support legacy code that did not expect a time parameter; it
   # will eventually be folded into the normal ButtonThrower,
   # above.
   mw = self.buttonThrowers[0].getParent()
   self.timeButtonThrower = mw.attachNewNode(ButtonThrower('timeButtons'))
   self.timeButtonThrower.node().setPrefix('time-')
   self.timeButtonThrower.node().setTimeFlag(1)
Ejemplo n.º 6
0
    def __init__(self):
        base.win.setClearColor(Vec4(0, 0, 0, 1))

        # enable physics (and particle) engine

        self.throwMode = False
        self.freelook = False

        self.score = OnscreenText('0',
                                  pos=(-1.32, 0.9),
                                  fg=(1, 1, 1, 1),
                                  bg=(0, 0, 0, 0.5),
                                  scale=0.1,
                                  align=TextNode.ALeft)

        # Load the environment in which Eve will walk. Set its parent
        # to the render variable so that it is a top-lplayerl node.
        self.env = loader.loadModel('models/world/world.egg.pz')
        self.env.reparentTo(render)
        self.env.setPos(0, 0, 0)

        self.createCollisionHandlers()

        # Create an Actor instance for Eve. We also specify the animation
        # models that we want to use as a dictionary, where we can use to
        # keys to refer to the animations later on. The start point of Eve
        # is hardcoded in the world model somewhere, so we look that up.
        self.player = Eve('Eve', self,
                          self.env.find('**/start_point').getPos())
        #self.player.nodePath.setZ(self.player.nodePath.getZ() + 10)
        self.player.nodePath.reparentTo(render)

        # Create a floater object that always floats 2 units above Eve.
        # We make sure that it is attached to Eve by reparenting it to
        # Eve's object instance.
        self.floater = NodePath(PandaNode('floater'))
        self.floater.reparentTo(self.player.nodePath)
        self.floater.setZ(self.floater.getZ() + 2)

        # load baseball
        self.baseball = Baseball('baseball', self,
                                 self.player.nodePath.getPos())
        self.baseball.nodePath.reparentTo(render)
        self.player.pickUpItem(self.baseball)

        # Load the panda bear
        self.panda = Panda('panda', self, self.player.nodePath.getPos())
        self.panda.nodePath.reparentTo(render)

        # Disable controlling the camera using the mouse. Note that this does
        # not disable the mouse completely, it merely disables the camera
        # movement by mouse.
        base.disableMouse()

        self.hideMouseCursor()

        # Set the initial position for the camera as X, Y and Z values.
        base.camera.setPos(self.player.nodePath.getX(),
                           self.player.nodePath.getY() + 10, 2)

        # Disable modifier button compound events.
        base.mouseWatcherNode.setModifierButtons(ModifierButtons())
        base.buttonThrowers[0].node().setModifierButtons(ModifierButtons())

        # Register any control callbacks.
        self.accept('escape', sys.exit)
        self.accept('d', self.dropItem)
        self.accept('f', self.toggleFullscreen)

        self.accept('space', self.enterThrowMode)
        self.accept('space-up', self.leaveThrowMode)

        # Also make sure that we can, at any time, request the state (pressed
        # or not) for these keys.
        self.keys = keys.KeyStateManager()
        self.keys.registerKeys({
            'arrow_left': 'left',
            'arrow_right': 'right',
            'arrow_up': 'forward',
            'arrow_down': 'backward',
            'shift': 'shift',
            'r': 'reset'
        })

        self.mouse = mouse.MousePointerManager(0)

        # Schedule the move method to be executed in the game's main loop.
        taskMgr.add(self.update, 'update')