当前位置: 首页>>代码示例>>Python>>正文


Python Input.moveInput方法代码示例

本文整理汇总了Python中Input.moveInput方法的典型用法代码示例。如果您正苦于以下问题:Python Input.moveInput方法的具体用法?Python Input.moveInput怎么用?Python Input.moveInput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Input的用法示例。


在下文中一共展示了Input.moveInput方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: import Input [as 别名]
# 或者: from Input import moveInput [as 别名]
def main():    
  ###Initial Stuff###
    
    import bge
    import math
    import mathutils
    import TMath
    import AnimationHelper
    import Input
    import Config as C
    import copy
    Vector = mathutils.Vector
    logic = bge.logic
    events = bge.events
    GD = logic.globalDict
    
    cont = logic.getCurrentController()
    own = cont.owner
    sce = logic.getCurrentScene()
    #Get the camera(specified by the player object's 'cam' property)
    cam = sce.objects[C.Cam]    
    orient = own.worldOrientation
    
    ##Here, I create various object properties that the script will need later, if they don't already exist
           
    if not 'State' in own:
        own['State'] = 'idle'
    state = own['State']
    #own['PlatformVelocity'] stores the velocity of the platform the player is stainding on (from the last frame)
    #It's LOCAL to the player's orientation, by the way
    if not 'PlatformVelocity' in own:
        own['PlatformVelocity'] = [0,0,0]
    platformVelocity = own['PlatformVelocity']
    #own['PrevOffset'] is used during ledge grab/hang/climb operations. I'll explain it the relevant sections
    if not 'PrevOffset' in own:
        own['PrevOffset'] = None
    #own['NoMoreGrab'] is used to temporarily toggle on/off ledgeGrab, so you don't re-grab a ledge after falling off.
    if not 'NoMoreGrab' in own:
        own['NoMoreGrab'] = False
    #own['RespawnCount'] counts the frames after you die, and when it reaches a certain value you respawn
    if not 'RespawnCount' in own:
        own['RespawnCount'] = 0
      
    ##Spawning at the start of scene
    
    #own['RespawnObj'] stores the place to respawn at (either the initial spawn point or last touched checkpoint)
    #If RespawnObj does not yet exist in own(e.g. this is the first frame this script has been run), spawn player at spawn object.
    #If Config.ResetSceneUpon death is enabled, then when player dies, respawnObj position and location are stashed in logic.globalDict.
    #Upon restart of scene, position and location are read from globalDict, and 'RespawnObj' is set to None, purely to indicate
    #that the player has finished respawning, so he won't respawn repeatedly.
    if not 'RespawnObj' in own:
        if 'PlayerSpawnPosition' in GD and GD['SpawnPositionScene'] == sce.name:            
            own.worldPosition = GD['PlayerSpawnPosition']
            own.worldOrientation = GD['PlayerSpawnOrientation']
            own['RespawnObj'] = None
        else:
            own['RespawnObj'] = sce.objects[C.SpawnObjectName]
            own.worldPosition = own['RespawnObj'].worldPosition
            own.worldOrientation = own['RespawnObj'].worldOrientation
        
    maxSpd = C.MaxSpeed
    walkSpd = C.WalkSpeed
    #get and tweak the turning smoothness factor
    smooth = (C.TurnSmoothness * .75) + .125
    
    
  ###Calculating The Forward Direction Vector(relative to the camera)###
    
    #Get the direction the camera is facing(as an XYZ vector)
    forwardAxis = -1 * mathutils.Vector(map(lambda x: x[2], cam.worldOrientation))
    #Get the X, Y, and Z axes of the player object
    axisX = mathutils.Vector(orient.col[0])
    axisY = mathutils.Vector(orient.col[1])
    axisZ = mathutils.Vector(orient.col[2])
    #Flatten the camera's direction onto the player object's local XY plane
    forwardAxis = TMath.VecToPlane(forwardAxis, axisX, axisY)
    
    
  ###Get Input###
    if Input.controlScheme == 'Gamepad':
        Input.pollButtons()
  
    input = Input.moveInput()
    
    isMoving = (input.length != 0)
    inputVec = input
    jump = Input.jumpInput()
    heldJump = Input.jumpIsHeldDown()
    drop = Input.dropInput()
            
  ###Floor Raycast### ###
    
    #The starting point of the ray is the player's position
    pos = own.worldPosition
    
    #Get the per-frame vertical offset caused by the player's velocity 
    #(to add to the length of the ray, so the player doesn't fall into the ground at high fall speeds
    velOffset = own.getLinearVelocity(1)[2]/60    
    
    #The ending point is the player's position minus (the player's height times the player's local z-axis(unit length)
#.........这里部分代码省略.........
开发者ID:elfnor,项目名称:mazes,代码行数:103,代码来源:Player.py


注:本文中的Input.moveInput方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。