def update(task): if s.mouseWatcherNode.is_button_down(KeyboardButton.up()): pingPong("accelerate", -1) elif s.mouseWatcherNode.is_button_down(KeyboardButton.down()): pingPong("accelerate", 1) else: pingPong("accelerate", 0) if s.mouseWatcherNode.is_button_down(KeyboardButton.right()): pingPong("turn", -1) elif s.mouseWatcherNode.is_button_down(KeyboardButton.left()): pingPong("turn", 1) else: pingPong("turn", 0) if s.mouseWatcherNode.is_button_down(KeyboardButton.ascii_key(b'd')): pingPong("strafe", -1) elif s.mouseWatcherNode.is_button_down(KeyboardButton.ascii_key(b'a')): pingPong("strafe", 1) else: pingPong("strafe", 0) if s.mouseWatcherNode.is_button_down(KeyboardButton.ascii_key(b's')): pingPong("hover", 1, 0, 0, 20) else: pingPong("hover", 0, 0, 0, 20) return task.cont
def __init__( self, node, mouseWatcherNode ): self.node = node self.focusNode = render.attachNewNode("CameraFocusNode") self.attachmentNode = None self.attached = True self.focusPoint = LPoint3() self.mouseWatcherNode = mouseWatcherNode self.bForward = KeyboardButton.ascii_key('w') self.bBackward = KeyboardButton.ascii_key('s') self.bLeft = KeyboardButton.ascii_key('a') self.bRight = KeyboardButton.ascii_key('d') self.bSpeed = KeyboardButton.lshift() self.speed = 0.2 self.zoom = 10 self.ang = 0 self.angY = math.pi*0.5 self.lastMousePos = (0,0)
def __init__(self, base): self.base = base self.is_down = base.mouseWatcherNode.is_button_down self.forward_button = KeyboardButton.ascii_key(b'w') self.backward_button = KeyboardButton.ascii_key(b's') self.strafe_left_button = KeyboardButton.ascii_key(b'a') self.strafe_right_button = KeyboardButton.ascii_key(b'd')
def rotate_tree(task): global tree_root rot_speed = 360 / 3 dt = globalClock.dt turn = 0 if base.mouseWatcherNode.is_button_down(KeyboardButton.ascii_key('a')): turn += rot_speed * dt if base.mouseWatcherNode.is_button_down(KeyboardButton.ascii_key('d')): turn -= rot_speed * dt tree_root.set_h(tree_root, turn) return task.cont
def update_thruster(self, task): heating = 0.33 cooling = 0.04 thruster_ramp_time = 0.4 thrusting = base.mouseWatcherNode.is_button_down( KeyboardButton.ascii_key(b's'), ) overheated = self.thruster_heat > 1.0 if overheated and not self.overheated: self.thruster_overheat_sound.play() self.overheated = overheated if thrusting and not overheated: self.thruster_power += (1 / thruster_ramp_time) * globalClock.dt else: self.thruster_power -= (1 / thruster_ramp_time) * globalClock.dt if self.thruster_power < 0.0: self.thruster_power = 0.0 if self.thruster_power > 1.0: self.thruster_power = 1.0 power = self.thruster_power self.thruster_heat += (-cooling * (1 - power) + heating * power) * globalClock.dt if self.thruster_heat < 0.0: self.thruster_heat = 0.0 self.thruster_sound.set_volume(self.thruster_power * 2) self.thruster_sound.set_play_rate(0.1 + ((random() / 50) + (self.thruster_power / 120))) self.thruster_heat_bar['value'] = self.thruster_heat * 100 self.thruster_heat_bar['text'] = "{:3.0f}%".format( self.thruster_power * 100, ) if self.thruster_heat > 1.0: self.thruster_heat_bar['barColor'] = (1, 1, 1, 1) else: self.thruster_heat_bar['barColor'] = (1, 0, 0, 1) return task.cont
def __init__(self): self.panra = 1 self.pwa = KeyboardButton.ascii_key("w") self.sano = Actor("HailPar.egg", {"Anaib": "Sbig-Armsjin"}) self.thago = threading.Thread(target=self.run) self.thago.start() self.sano.reparentTo(render)
def acceptMovement(self): # accept movement (x, y, z) = self.camera.getPos() (dx, dy, dz) = self.cameraSpeed (newX, newY, newZ) = (x + dx, y + dy, z + dz) forward_button = KeyboardButton.ascii_key('w') backward_button = KeyboardButton.ascii_key('s') leftward_button = KeyboardButton.ascii_key('a') rightward_button = KeyboardButton.ascii_key('d') # next line is from panda3D website is_down = self.mouseWatcherNode.is_button_down if is_down(forward_button): self.accForward() elif is_down(backward_button): self.accBackward() elif is_down(leftward_button): self.accLeftward() elif is_down(rightward_button): self.accRightward() else: self.cameraSpeed = (0, 0, dz)
def acceptMovement(self): # accept movement (x, y, z) = self.camera.getPos() (dx, dy, dz) = self.cameraSpeed (newX, newY, newZ) = (x+dx, y+dy, z+dz) forward_button = KeyboardButton.ascii_key('w') backward_button = KeyboardButton.ascii_key('s') leftward_button = KeyboardButton.ascii_key('a') rightward_button = KeyboardButton.ascii_key('d') # next line is from panda3D website is_down = self.mouseWatcherNode.is_button_down if is_down(forward_button): self.accForward() elif is_down(backward_button): self.accBackward() elif is_down(leftward_button): self.accLeftward() elif is_down(rightward_button): self.accRightward() else: self.cameraSpeed = (0, 0, dz)
def __init__(self): #Modify the Panda3D config on-the-fly #In this case, edit the window title load_prc_file_data( "", """window-title PoultryGeist threading-model /Draw multisamples 2 framebuffer-multisample 1 """) # Construct and create the pipeline self.render_pipeline = RenderPipeline() self.render_pipeline.create(self) self.width, self.height = (800, 600) render.setAntialias(AntialiasAttrib.MAuto) # Set the model quality, (low or high) self.quality = "low" print("[>] PoultryGeist:\t Setting Model Resolution to {}".format( self.quality.upper())) # Set the time self.render_pipeline.daytime_mgr.time = "20:15" # Turn off normal mouse controls self.disableMouse() # Hide the cursor props = WindowProperties() props.setCursorHidden(True) props.setMouseMode(WindowProperties.M_relative) # Lower the FOV to make the game more difficult self.win.requestProperties(props) self.camLens.setFov(90) # Register the buttons for movement self.w_button = KeyboardButton.ascii_key('w'.encode()) self.s_button = KeyboardButton.ascii_key('s'.encode()) self.switch_button = KeyboardButton.ascii_key('p'.encode()) # Initialise the SceneManager self.sceneMgr = SceneManager(self) # Add the sceneMgr events to run as a task taskMgr.add(self.sceneMgr.runSceneTasks, "scene-tasks")
def __init__(self, base): self.base = base self.forward = KeyboardButton.ascii_key('w') self.backward = KeyboardButton.ascii_key('s') self.left = KeyboardButton.ascii_key('a') self.right = KeyboardButton.ascii_key('d') self.node = self.base.loader.loadModel(self.model_path) self.node.reparentTo(self.base.render) # set initial position # x, y, z self.set_pos(0, 15, -1) self.set_rot(20, 10, 0) # create a task to check for movement self.add_task(self.check_movement, 'detect_player_movement')
def __init__(self, game, character): self.game = game self.character = character # class properties self.buttons = { "forward": KeyboardButton.ascii_key("w"), "backward": KeyboardButton.ascii_key("s"), "left": KeyboardButton.ascii_key("a"), "right": KeyboardButton.ascii_key("d"), "sprint": KeyboardButton.shift(), } self.moved = False # start movement task taskMgr.add(self.move, "Player.move") taskMgr.doMethodLater(1.0 / Constants.TICKRATE, self.sendLoc, "Player.sendLoc")
def update(self, entities_by_filter): left = 0 if base.mouseWatcherNode.is_button_down( KeyboardButton.ascii_key(b'w')): left += 1 if base.mouseWatcherNode.is_button_down( KeyboardButton.ascii_key(b's')): left -= 1 right = 0 if base.mouseWatcherNode.is_button_down(KeyboardButton.up()): right += 1 if base.mouseWatcherNode.is_button_down(KeyboardButton.down()): right -= 1 for entity in entities_by_filter['paddle']: if entity.get_component(Paddle).player == 0: entity.get_component(Movement).value.z = left elif entity.get_component(Paddle).player == 1: entity.get_component(Movement).value.z = right
def update(task): forward, turn, strafe, hover = 0, 0, 0, 0 if s.mouseWatcherNode.is_button_down(KeyboardButton.up()): forward += 1 if s.mouseWatcherNode.is_button_down(KeyboardButton.down()): forward -= 1 if s.mouseWatcherNode.is_button_down(KeyboardButton.left()): turn -= 1 if s.mouseWatcherNode.is_button_down(KeyboardButton.right()): turn += 1 if s.mouseWatcherNode.is_button_down(KeyboardButton.ascii_key(b'a')): strafe -= 1 if s.mouseWatcherNode.is_button_down(KeyboardButton.ascii_key(b'd')): strafe += 1 if s.mouseWatcherNode.is_button_down(KeyboardButton.ascii_key(b's')): hover += 1 animate(forward, turn, strafe, hover) #if s.mouseWatcherNode.is_button_down(KeyboardButton.space()): # control("hover") return task.cont
def update(self, entities_by_filter): for entity in entities_by_filter['paddle']: paddle = entity[Paddle] movement = entity[Movement] # What keys does the player use? if paddle.player == Players.LEFT: up_key = KeyboardButton.ascii_key(b'w') down_key = KeyboardButton.ascii_key(b's') elif paddle.player == Players.RIGHT: up_key = KeyboardButton.up() down_key = KeyboardButton.down() # Read player input delta = 0 if base.mouseWatcherNode.is_button_down(up_key): delta += 1 if base.mouseWatcherNode.is_button_down(down_key): delta -= 1 # Store movement movement.value.z = delta
def control_camera(self, task): theta = self.eye.yaw / 180 * math.pi phi = self.eye.pitch / 180 * math.pi eye_dir = np.array([ math.cos(theta) * math.cos(phi), math.sin(theta) * math.cos(phi), math.sin(phi), ]) up_dir = np.array([0.0, 0.0, 1.0]) side_dir = np.cross(eye_dir, up_dir) # Update camera based on move_speed = 10.0 * globalClock.get_dt() if base.mouseWatcherNode.is_button_down(KeyboardButton.shift()): move_speed *= 10.0 if base.mouseWatcherNode.is_button_down(KeyboardButton.ascii_key('w')): self.eye.pos[:] += move_speed * eye_dir if base.mouseWatcherNode.is_button_down(KeyboardButton.ascii_key('s')): self.eye.pos[:] -= move_speed * eye_dir if base.mouseWatcherNode.is_button_down(KeyboardButton.ascii_key('d')): self.eye.pos[:] += move_speed * side_dir if base.mouseWatcherNode.is_button_down(KeyboardButton.ascii_key('a')): self.eye.pos[:] -= move_speed * side_dir if self.capture_mouse: view_speed = 10.0 * globalClock.get_dt() win_x, win_y = base.win.getXSize(), base.win.getYSize() cursor = base.win.getPointer(0) dx = cursor.getX() - base.win.getXSize() // 2 dy = cursor.getY() - base.win.getYSize() // 2 self.eye.yaw = (self.eye.yaw - view_speed * dx) % 360.0 self.eye.pitch = min(85.0, max(-85.0, self.eye.pitch - move_speed * dy)) base.win.movePointer(0, win_x // 2, win_y // 2) self.update_camera() return Task.cont
def __init__(self, sb, mouse_magnitude=30, min_pitch=-60, max_pitch=60): self.base = sb self.mouse_magnitude = mouse_magnitude self.min_pitch = min_pitch self.max_pitch = max_pitch props = WindowProperties() props.set_cursor_hidden(True) props.set_mouse_mode(WindowProperties.MRelative) self.base.win.requestProperties(props) self.accept('mouse1', self.mouse1) tm = self.base.task_mgr tm.add(self.mouse_move, 'fp-mouse-move') tm.add(self.kb_move, 'fp-kb-move') self.keys = { 'forward': KeyboardButton.ascii_key(b'w'), 'left': KeyboardButton.ascii_key(b'a'), 'right': KeyboardButton.ascii_key(b'd'), 'backward': KeyboardButton.ascii_key(b's'), 'up': KeyboardButton.space(), 'down': KeyboardButton.control() }
def __init__(self, node, mouseWatcherNode, speed=0.2): self.node = node self.headingNode = render.attachNewNode("CameraHeadingRotNode") self.pitchNode = self.headingNode.attachNewNode("CameraPitchRotNode") self.node.reparentTo(self.pitchNode) self.headingNode.setPos(0, 0, 0.5) #self.focusNode = render.attachNewNode("CameraFocusNode") self.attached = False self.headingNode.attachNewNode(createAxes(0.1)) self.focusPoint = LPoint3() self.mouseWatcherNode = mouseWatcherNode self.bForward = KeyboardButton.ascii_key('w') self.bBackward = KeyboardButton.ascii_key('s') self.bLeft = KeyboardButton.ascii_key('a') self.bRight = KeyboardButton.ascii_key('d') self.bSpeed = KeyboardButton.lshift() self.speed = speed self.zoom = 10 self.heading = 0 self.pitch = -45 self.node.setPos(0, -self.zoom, 0) self.pitchNode.setHpr(0, self.pitch, 0) self.headingNode.setHpr(self.heading, 0, 0) self.lastMousePos = (0, 0)
def update_gyro(self, task): if base.mouseWatcherNode.is_button_down( KeyboardButton.ascii_key(b'w')): self.gyro_power = 1.0 if self.gyro_duration < 50: self.gyro_duration += 2 self.gyro_power_bar['value'] = self.gyro_power * 100 self.gyro_sound.set_volume(0.08 + self.gyro_power) self.gyro_sound.set_play_rate(0.08 + (self.gyro_duration / 400) + self.gyro_power * 0.25) self.gyro_power -= globalClock.dt if self.gyro_power < 0.0: self.gyro_power = 0.0 if self.gyro_duration > 1: self.gyro_duration -= 1 return task.cont
def __init__(self, screen_size=84, DEBUGGING=False, human_playable=False): ShowBase.__init__(self) self.forward_button = KeyboardButton.ascii_key(b'w') self.backward_button = KeyboardButton.ascii_key(b's') self.fps = 20 self.human_playable = human_playable self.actions = 3 self.last_frame_start_time = time.time() self.action_buffer = [1, 1, 1] self.last_teleport_time = 0.0 self.time_to_teleport = False if self.human_playable is False: winprops = WindowProperties.size(screen_size, screen_size) fbprops = FrameBufferProperties() fbprops.set_rgba_bits(8, 8, 8, 0) fbprops.set_depth_bits(24) self.pipe = GraphicsPipeSelection.get_global_ptr().make_module_pipe('pandagl') self.imageBuffer = self.graphicsEngine.makeOutput( self.pipe, "image buffer", 1, fbprops, winprops, GraphicsPipe.BFRefuseWindow) self.camera = Camera('cam') self.cam = NodePath(self.camera) self.cam.reparentTo(self.render) self.dr = self.imageBuffer.makeDisplayRegion() self.dr.setCamera(self.cam) self.render.setShaderAuto() self.cam.setPos(0.5, 0, 6) self.cam.lookAt(0.5, 0, 0) # Create Ambient Light self.ambientLight = AmbientLight('ambientLight') self.ambientLight.setColor((0.2, 0.2, 0.2, 1)) self.ambientLightNP = self.render.attachNewNode(self.ambientLight) self.render.setLight(self.ambientLightNP) # Spotlight self.light = Spotlight('light') self.light.setColor((0.9, 0.9, 0.9, 1)) self.lightNP = self.render.attachNewNode(self.light) self.lightNP.setPos(0, 10, 10) self.lightNP.lookAt(0, 0, 0) self.lightNP.node().getLens().setFov(40) self.lightNP.node().getLens().setNearFar(10, 100) self.lightNP.node().setShadowCaster(True, 1024, 1024) self.render.setLight(self.lightNP) self.world = BulletWorld() self.world.setGravity(Vec3(0, 0, -9.81)) if DEBUGGING is True: debugNode = BulletDebugNode('Debug') debugNode.showWireframe(True) debugNode.showConstraints(True) debugNode.showBoundingBoxes(False) debugNode.showNormals(False) debugNP = render.attachNewNode(debugNode) debugNP.show() self.world.setDebugNode(debugNP.node()) self.finger_speed_mps = 0.0 self.penalty_applied = False self.teleport_cooled_down = True self.fps = 20 self.framecount = 0 self.reset()
def __init__(self, quality): # Set the model quality, (super-low, low or high) self.quality = quality print("[>] PoultryGeist:\t Setting Model Resolution to {}".format( self.quality.upper())) load_prc_file_data("", "win-size 1920 1080") # Run the standard Showbase init if running in super-low resolution mode # Do some stuff if the game is running at normal or high resolution if self.quality != 'super-low': # Construct and create the pipeline self.render_pipeline = RenderPipeline() self.render_pipeline.pre_showbase_init() super(Application, self).__init__() self.render_pipeline.create(self) # Enable anti-aliasing for the game render.setAntialias(AntialiasAttrib.MAuto) # Set the time pipeline lighting simulation time self.render_pipeline.daytime_mgr.time = "20:15" else: super(Application, self).__init__() # Enable the filter handler self.filters = CommonFilters(base.win, base.cam) self.filters.setAmbientOcclusion() # Enable particles and physics self.enableParticles() #Modify the Panda3D config on-the-fly #In this case, edit the window title load_prc_file_data( "", """window-title PoultryGeist threading-model /Draw multisamples 2 framebuffer-multisample 1 """) # Set the window size self.width, self.height = (800, 600) # Initialise the movement controller self.controller = None # Turn off normal mouse controls self.disableMouse() # Hide the cursor self.props = WindowProperties() # self.props.setCursorHidden(True) # Lower the FOV to make the game more difficult self.win.requestProperties(self.props) self.camLens.setFov(60) # Reduces the distance of which the camera can render objects close to it self.camLens.setNear(0.1) # Store and empty renderTree for later use self.emptyRenderTree = deepcopy(self.render) # Register the buttons for movement # TODO remove this and overhaul the button handling self.w_button = KeyboardButton.ascii_key('w'.encode()) self.s_button = KeyboardButton.ascii_key('s'.encode()) self.l_button = KeyboardButton.ascii_key('l'.encode()) self.switch_button = KeyboardButton.ascii_key('p'.encode()) # Initialise the SceneManager self.sceneMgr = SceneManager(self) # Initialise the collision traverser self.collisionTraverser = CollisionTraverser('main_traverser') base.cTrav = self.collisionTraverser base.cTrav.showCollisions(self.render) # Add the sceneMgr events to run as a task taskMgr.add(self.sceneMgr.runSceneTasks, "scene-tasks")
def rollTask(self, task): # Standard technique for finding the amount of time since the last # frame #print("\r",self.maze.getR(), self.maze.getP(), self.ballRoot.getPos(), end="") dt = globalClock.getDt() print("\r{:.3} fps ".format(1 / dt), end="") # If dt is large, then there has been a # hiccup that could cause the ball # to leave the field if this functions runs, so ignore the frame if dt > .2: return Task.cont #print(action) if action == "start": a = 1 elif action == "stop": while action == "stop": a = 0 # elif action == "restart": in Line 531 elif action == "coord": a = 1 #ALGUNA CRIDA A METODE DE NARCIS/MARC key_down = base.mouseWatcherNode.is_button_down if self.ready_to_solve: if key_down(KeyboardButton.ascii_key('d')): screenshot = self.camera2_buffer.getScreenshot() if screenshot: v = memoryview(screenshot.getRamImage()).tolist() img = np.array(v, dtype=np.uint8) img = img.reshape( (screenshot.getYSize(), screenshot.getXSize(), 4)) img = img[::-1] #self.digitizer.set_src_img(img) #self.digitizer.digitalize_source() cv2.imshow('img', img) #cv2.waitKey(0) if key_down(KeyboardButton.ascii_key('s')): print("Screenshot!") self.camera2_buffer.saveScreenshot("screenshot.jpg") # The collision handler collects the collisions. We dispatch which function # to handle the collision based on the name of what was collided into for i in range(self.cHandler.getNumEntries()): entry = self.cHandler.getEntry(i) name = entry.getIntoNode().getName() if action == "restart": self.loseGame(entry) if name == "wall_col": self.wallCollideHandler(entry) elif name == "ground_col": self.groundCollideHandler(entry) elif name == "loseTrigger": vr.restart = 1 global th th = threading.Thread(target=listenVoice) th.start() self.loseGame(entry) # Read the mouse position and tilt the maze accordingly # Rotation axes use (roll, pitch, heave) """ if base.mouseWatcherNode.hasMouse(): mpos = base.mouseWatcherNode.getMouse() # get the mouse position self.maze.setP(mpos.getY() * -10) self.maze.setR(mpos.getX() * 10) """ ballPos = self.get_ball_position() #print("BALL POS: ", ballPos) posFPixel = self.path[self.indexPuntActual] xFinal = posFPixel[1] #posFPixel[1]/np.shape(laberint)[0]*13 - 6.5 yFinal = posFPixel[ 0] #-(posFPixel[0]/np.shape(laberint)[1]*13.5 - 6.8) dist = math.sqrt((xFinal - ballPos[1])**2 + (yFinal - ballPos[0])**2) if (dist < self.minDist): if (self.indexPuntActual == len(self.path) - 1): print("SOLVED!!", end="") while (self.aStar.distance( (ballPos[0], ballPos[1]), self.path[self.indexPuntActual]) < self.pas): if (self.indexPuntActual < len(self.path) - 1): self.indexPuntActual += 1 else: break # ball pos (y,x) #print("END POS: ", self.digitizer.endPos) if voice_solving: p_rotation = dir_veu[0] r_rotation = dir_veu[1] if p_rotation == 0 and r_rotation == 0 and ballPos is not None: p_rotation, r_rotation = self.pid.getPR( ballPos[1], ballPos[0], ballPos[1], ballPos[0], self.maze.getP(), self.maze.getR(), dt) else: p_rotation = 0 r_rotation = 0 #print(ballPos, dist) #print(ballPos) if ballPos is not None: p_rotation, r_rotation = self.pid.getPR( ballPos[1], ballPos[0], xFinal, yFinal, self.maze.getP(), self.maze.getR(), dt) #print(p_rotation, r_rotation) if key_down(KeyboardButton.up()): p_rotation = -1 elif key_down(KeyboardButton.down()): p_rotation = 1 if key_down(KeyboardButton.left()): r_rotation = -1 elif key_down(KeyboardButton.right()): r_rotation = 1 self.rotateMaze(p_rotation, r_rotation) # Finally, we move the ball # Update the velocity based on acceleration self.ballV += self.accelV * dt * ACCEL # Clamp the velocity to the maximum speed if self.ballV.lengthSquared() > MAX_SPEED_SQ: self.ballV.normalize() self.ballV *= MAX_SPEED # Update the position based on the velocity self.ballRoot.setPos(self.ballRoot.getPos() + (self.ballV * dt)) #print(self.ballRoot.getPos()) # This block of code rotates the ball. It uses something called a quaternion # to rotate the ball around an arbitrary axis. That axis perpendicular to # the balls rotation, and the amount has to do with the size of the ball # This is multiplied on the previous rotation to incrimentally turn it. prevRot = LRotationf(self.ball.getQuat()) axis = LVector3.up().cross(self.ballV) newRot = LRotationf(axis, 45.5 * dt * self.ballV.length()) self.ball.setQuat(prevRot * newRot) elif key_down(KeyboardButton.ascii_key('1')): self.solve() if key_down(KeyboardButton.ascii_key('i')): self.light.setY(self.light.getY() + 10 * dt) elif key_down(KeyboardButton.ascii_key('k')): self.light.setY(self.light.getY() - 10 * dt) if key_down(KeyboardButton.ascii_key('j')): self.light.setX(self.light.getX() - 10 * dt) elif key_down(KeyboardButton.ascii_key('l')): self.light.setX(self.light.getX() + 10 * dt) if key_down(KeyboardButton.ascii_key('u')): self.lightColor += 10000 * dt self.light.node().setColor( (self.lightColor, self.lightColor, self.lightColor, 1)) elif key_down(KeyboardButton.ascii_key('o')): self.lightColor -= 10000 * dt self.light.node().setColor( (self.lightColor, self.lightColor, self.lightColor, 1)) if key_down(KeyboardButton.ascii_key('8')): self.alightColor += 1 * dt self.ambientL.node().setColor( (self.alightColor, self.alightColor, self.alightColor, 1)) elif key_down(KeyboardButton.ascii_key('9')): self.alightColor -= 1 * dt self.ambientL.node().setColor( (self.alightColor, self.alightColor, self.alightColor, 1)) if key_down(KeyboardButton.ascii_key('r')): base.trackball.node().set_pos(0, 200, 0) base.trackball.node().set_hpr(0, 60, 0) return Task.cont # Continue the task indefinitely
def test_keyboardbutton_ascii(): assert KeyboardButton.space() == KeyboardButton.ascii_key(' ') assert KeyboardButton.backspace() == KeyboardButton.ascii_key('\x08') assert KeyboardButton.tab() == KeyboardButton.ascii_key('\x09') assert KeyboardButton.enter() == KeyboardButton.ascii_key('\x0d') assert KeyboardButton.escape() == KeyboardButton.ascii_key('\x1b') assert KeyboardButton.ascii_key(' ').name == 'space' assert KeyboardButton.ascii_key('\x08').name == 'backspace' assert KeyboardButton.ascii_key('\x09').name == 'tab' assert KeyboardButton.ascii_key('\x0d').name == 'enter' assert KeyboardButton.ascii_key('\x1b').name == 'escape' assert KeyboardButton.ascii_key('\x7f').name == 'delete' assert KeyboardButton.ascii_key('a').name == 'a'
from math import pi, sin, cos from direct.showbase.ShowBase import ShowBase from panda3d.core import AmbientLight, DirectionalLight, KeyboardButton from panda3d.core import TextNode, NodePath, LightAttrib from panda3d.core import LVector3 from direct.actor.Actor import Actor from direct.task.Task import Task from direct.gui.OnscreenText import OnscreenText from direct.showbase.DirectObject import DirectObject import gltf import sys x_button = KeyboardButton.ascii_key('q') y_button = KeyboardButton.ascii_key('w') z_button = KeyboardButton.ascii_key('e') def clamp(i, mn=-1, mx=1): return min(max(i, mn), mx) def genLabelText(text, i, self): return OnscreenText(text=text, parent=self.a2dTopLeft, scale=.06, pos=(0.06, -.08 * i), fg=(1, 1, 1, 1), shadow=(0, 0, 0, .5), align=TextNode.ALeft) class TccSample(ShowBase): def __init__(self): ShowBase.__init__(self)
def update(self, entities_by_filter): for entity in entities_by_filter['character']: character = entity[CharacterController] character.jumps = False character.sprints = False character.crouches = False character.move.x = 0.0 character.move.y = 0.0 character.heading = 0.0 character.pitch = 0.0 # For debug purposes, emulate analog stick on keyboard # input, being half-way pressed, by holding shift analog = 1 if base.mouseWatcherNode.is_button_down(KeyboardButton.shift()): analog = 0.5 if base.mouseWatcherNode.is_button_down( KeyboardButton.ascii_key("w")): character.move.y += analog if base.mouseWatcherNode.is_button_down( KeyboardButton.ascii_key("s")): character.move.y -= analog if base.mouseWatcherNode.is_button_down( KeyboardButton.ascii_key("a")): character.move.x -= analog if base.mouseWatcherNode.is_button_down( KeyboardButton.ascii_key("d")): character.move.x += analog # Rotation if base.mouseWatcherNode.is_button_down(KeyboardButton.up()): character.pitch += 1 if base.mouseWatcherNode.is_button_down(KeyboardButton.down()): character.pitch -= 1 if base.mouseWatcherNode.is_button_down(KeyboardButton.left()): character.heading += 1 if base.mouseWatcherNode.is_button_down(KeyboardButton.right()): character.heading -= 1 if TurntableCamera in entity: camera = entity[TurntableCamera] camera.heading = camera.pitch = 0 if base.mouseWatcherNode.is_button_down( KeyboardButton.ascii_key("j")): camera.heading = 1 if base.mouseWatcherNode.is_button_down( KeyboardButton.ascii_key("l")): camera.heading = -1 if base.mouseWatcherNode.is_button_down( KeyboardButton.ascii_key("i")): camera.pitch = -1 if base.mouseWatcherNode.is_button_down( KeyboardButton.ascii_key("k")): camera.pitch = 1 # Special movement modes. # By default, you run ("sprint"), unless you press e, in # which case you walk. You can crouch by pressing q; this # overrides walking and running. Jump by pressing space. # This logic is implemented by the Walking system. Here, # only intention is signalled. if base.mouseWatcherNode.is_button_down( KeyboardButton.ascii_key("e")): character.sprints = True if base.mouseWatcherNode.is_button_down( KeyboardButton.ascii_key("c")): character.crouches = True if base.mouseWatcherNode.is_button_down(KeyboardButton.space()): character.jumps = True