Beispiel #1
0
 def onEnterPress( self, textEntered ):
   # set to last message
   self.textBufferPos = self.textBufferLength-self.numlines
   # clear line
   self.consoleEntry.enterText('')
   self.focus()
   # add text entered to user command list & remove oldest entry
   self.userCommandList.insert( 1, textEntered )
   self.userCommandList[0] = ''
   self.userCommandList.pop( -1 )
   self.userCommandPos = 0
   
   # call the interpreter to handle the input
   interpreter = cliClass(self.parent)
   result = interpreter.interpreter(textEntered)
   # write the entered text to the output
   self.write(textEntered, (0.0, 0.0, 1, 1))
   print textEntered
   # write each line seperately to the output
   try:
       for line in result.split('\n'):
           line = "        " + line
           self.write(line, (0, 0, 0, 1))
           print line
   except AttributeError:
       self.write("        function returned no answer", (0, 0, 0, 1))
Beispiel #2
0
 def onEnterPress( self, textEntered ):
   # set to last message
   self.textBufferPos = self.textBufferLength-self.numlines
   # clear line
   self.consoleEntry.enterText('')
   self.focus()
   # add text entered to user command list & remove oldest entry
   self.userCommandList.insert( 1, textEntered )
   self.userCommandList[0] = ''
   self.userCommandList.pop( -1 )
   self.userCommandPos = 0
   
   # call the interpreter to handle the input
   interpreter = cliClass()
   result = interpreter.interpreter(textEntered)
   # write the entered text to the output
   self.write(textEntered, (0.0, 0.0, 1, 1))
   print textEntered
   # write each line seperately to the output
   for line in result.split('\n'):
       line = "        " + line
       self.write(line, (0, 0, 0, 1))
       print line
Beispiel #3
0
	def update(self, stepSize):
		"""
		I use "forward" for standing up from a chair.
		"""
		if self.isSitting:
			camPos = base.cam.getPos(render)
			camQuat = base.cam.getQuat(render)
			self.updateAimCollisions(camPos, camQuat)
			
			if inputState.isSet("forward"):
				self.standUpFromChair()
			return
		elif self.isDisabled:
			return
		
		# MOVEMENT
		"""
		Handle input. Note that in the main.py file there's this line:
			base.buttonThrowers[0].node().setModifierButtons(ModifierButtons())
		It is very important to make sure you can, for example, walk forward,
		strafe and jump at the same time.
		"""
		newLinearVelocity = Vec3(0,0,0)
		
		moveAtSpeed = self.walkSpeed
		if inputState.isSet("run"): moveAtSpeed = self.runSpeed
		
		if inputState.isSet("forward" ): newLinearVelocity[1] = moveAtSpeed
		if inputState.isSet("backward" ): newLinearVelocity[1] = -moveAtSpeed
		if inputState.isSet("strafeLeft"): newLinearVelocity[0] = -moveAtSpeed
		if inputState.isSet("strafeRight"): newLinearVelocity[0] = moveAtSpeed
		
		
		if self.state == "fly":
			self.linearVelocity = base.cam.getQuat(render).xform(newLinearVelocity)
		else:
			self.linearVelocity = self.movementParent.getQuat(render).xform(newLinearVelocity)
		
		if inputState.isSet("crouch"):
			self.crouch()
		else:
			self.crouchStop()
		
		self.currentPos += self.linearVelocity * stepSize
		
		kinematicCharacterController.update(self, stepSize)
		
		# CAMERA
		camPos = self.currentPos + Vec3(0, 0, self.cameraHeight)
		camQuat = base.cam.getQuat(render)
		
		print camPos
		from interpreter import cliClass
		interpreter = cliClass()
		interpreter.sendPos(camPos)
    	
		base.cam.setX(camPos[0])
		base.cam.setY(camPos[1])
		
		if not self.cameraSteppingAnim:
			if self.state == "ground":		
				fromH = base.cam.getPos(render)[2]
				toH = camPos[2]
				
				self.cameraSteppingAnim = Sequence(
					LerpFunc(self.cameraAnimation, fromData = fromH, toData = toH, duration = 0.1),
					Func(self.clearCameraAnimation)
					)
				self.cameraSteppingAnim.start()
			else:
				base.cam.setZ(camPos[2])
		
		self.movementParent.setH(base.cam.getH(render))
		
		# AIMING
		self.updateAimCollisions(camPos, camQuat)
		
		# HELD ITEM
		held = self.heldItem
		if held:
			self.placeObjectInFrontOfCamera(held)
			
			if held.body and held.pickableType == "carry":
				held.body.enable()
				
				held.body.setLinearVel(Vec3(*[0.0]*3))
				held.body.setAngularVel(Vec3(*[0.0]*3))