コード例 #1
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
コード例 #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)