Advertisement
Guest User

input controller

a guest
Sep 18th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.06 KB | None | 0 0
  1. import bge
  2.  
  3.  
  4. inputDict = {}
  5.  
  6. #  [ gameCommand, indexForSerialisation, ListToUse, Player
  7.  
  8. #movements
  9. inputDict['WKEY'] = [ 'Forward', 0, 0,0 ]
  10. inputDict['AKEY'] = [ 'Left', 1 , 0, 0 ]
  11. inputDict['SKEY'] = [ 'Back', 2 , 0, 0]
  12. inputDict['DKEY'] = [ 'Right', 3 , 0, 0]
  13.  
  14. #actions
  15. inputDict['MouseL'] = [ 'AimL', 0 , 1, 0]
  16. inputDict['MouseR'] = [ 'Fire', 1 , 1, 0]
  17. inputDict['QKEY'] = [ 'Grab', 2 , 1, 0]
  18.  
  19.  
  20. def main():
  21.  
  22.     cont = bge.logic.getCurrentController()
  23.     own = cont.owner
  24.  
  25.     key = cont.sensors['Keyboard']
  26.     mouseL = cont.sensors['MouseL']
  27.     mouseR = cont.sensors['MouseR']
  28.    
  29.     inputs = []
  30.    
  31.     outputs = [ [], [] ]
  32.    
  33.    
  34.     if key.positive:
  35.         for event in key.inputs:
  36.             string_in = bge.events.EventToString(event[0])
  37.            
  38.             inputs.append(string_in)
  39.            
  40.         #print(input)
  41.         for input in inputs:
  42.             if input in inputDict:
  43.                 v = inputDict[input]
  44.                 outputs[v[2]].append(v)
  45.    
  46.     if mouseL.positive:
  47.         if 'MouseL' in inputDict:
  48.             v = inputDict['MouseL']
  49.             outputs[v[2]].append(v)
  50.            
  51.     if mouseR.positive:
  52.         if 'MouseR' in inputDict:
  53.             v = inputDict['MouseR']
  54.             outputs[v[2]].append(v)        
  55.            
  56.                    
  57.     for outputList in outputs:            
  58.         outputList = sorted(outputList, key = lambda x: x[1])
  59.    
  60.    
  61.     #print(outputs)
  62.     NL = [[],[]]
  63.     index=0
  64.     for inputList in outputs:
  65.         for gameInput in inputList:
  66.             if gameInput[0] not in NL[index]:
  67.                 NL[index].append(gameInput[0])
  68.         index+=1
  69.                
  70.                  
  71.                        
  72.     #own['D'] = str(NL)
  73.    
  74.     if 'Actor' not in own:
  75.         own['Actor'] = own.scene.objects['Actor']
  76.     if NL[0]!=[] or NL[1]!=[]:
  77.         own['Actor']['Move']= str(NL[0])
  78.         own['Actor']['Act']= str(NL[1])
  79.         own['Actor']['Timer'] = 60
  80.     else:
  81.         own['Actor']['Move']=[]  
  82.    
  83.    
  84. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement