コード例 #1
0
ファイル: GUI.py プロジェクト: agakax/arkanoid
 def update (self, elapsedTime):
     is_down = self.__base.mouseWatcherNode.is_button_down
     if  (is_down(KeyboardButton.up()) and (self.__selected > 0)):
         self.changeSelected(self.__selected - 1)
     elif (is_down(KeyboardButton.down()) and (self.__selected < 1)):
         self.changeSelected(self.__selected + 1)
     elif is_down(KeyboardButton.enter()):
         self.runSelectedOption()
     pass
コード例 #2
0
ファイル: Paddle.py プロジェクト: agakax/arkanoid
 def update(self, elapsedTime):
     is_down = self.__base.mouseWatcherNode.is_button_down
     moveVector = LPoint3f(0, 0, 0)
     if self.reflectionVectorLength() > 0.5:
         moveVector = LVector3f(multiplyVectorsElements(self.__reflectionDirection, self.__velocity))
         moveVector *= elapsedTime
         self.__reflectionVector -= moveVector
     elif is_down(KeyboardButton.left()):
         moveVector = -self.__velocity*elapsedTime
     elif is_down(KeyboardButton.right()):
         moveVector = self.__velocity*elapsedTime
     newposition = self.__position + moveVector
     if newposition.x < 67 and newposition.x > 8:
         self.__position += moveVector
         self.__background.updateBackground(moveVector.x, elapsedTime)
     self.__paddle.setFluidPos(self.__position)
コード例 #3
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)
コード例 #4
0
	def __init__(self, inputWatcher, window, defaultKeys = []):
		'''
		Creates a new ControlScheme object.
		@param inputWatcher: The MouseWatcher object to use for tracking
		the mouse and keys.
		@param defaultKeys: is a collection of key types to be initialized
		by default (optional). Acceptable values are "left", "right", "up",
		"down", and "pause". The defaults for directional keys are the
		arrows, WASD, and the equivalents of WASD on common alternate
		keyboard layouts. The keys for "pause" are escape, p, and
		enter.
		'''
		self.inputWatcher = inputWatcher
		self.window = window
		properties = window.getProperties()
		self.centerX = properties.getXSize() // 2
		self.centerY = properties.getYSize() // 2
		self.prevMouseX = self.centerX
		
		self.keyMap = dict()
		
		self.addKeys(LEFT, [KeyboardButton.left(), KeyboardButton.asciiKey('a'), KeyboardButton.asciiKey('q')])
		self.addKeys(RIGHT, [KeyboardButton.right(), KeyboardButton.asciiKey('d'), KeyboardButton.asciiKey('e')])
		self.addKeys(UP, [KeyboardButton.up(), KeyboardButton.asciiKey('w'), KeyboardButton.asciiKey('z'), KeyboardButton.asciiKey(',')])
		self.addKeys(DOWN, [KeyboardButton.down(), KeyboardButton.asciiKey('s'), KeyboardButton.asciiKey('o')])
		self.addKeys(PAUSE, [KeyboardButton.escape(), KeyboardButton.asciiKey('p'), KeyboardButton.enter()])
		self.addKeys(SWITCH, [KeyboardButton.shift(), KeyboardButton.control(), KeyboardButton.asciiKey('f'), KeyboardButton.asciiKey('/'), MouseButton.two(), KeyboardButton.space()])
		self.addKeys(PUSH, [MouseButton.one()])
		self.addKeys(PULL, [MouseButton.three()])
		self.addKeys(QUIT, [KeyboardButton.asciiKey('q')])
		
		#in case the mouse leaves the window
		self.mouseX = 0
		self.mouseY = 0