Package SmootLight :: Package behaviors :: Module MoveBehavior
[hide private]
[frames] | no frames]

Source Code for Module SmootLight.behaviors.MoveBehavior

 1  from operationscore.Behavior import * 
 2  #import util.ComponentRegistry as compReg 
 3  #import util.Geo as Geo 
 4  #import util.Strings as Strings 
 5   
6 -class MoveBehavior(Behavior):
7 """Moves current location by the x and y components of sensorInput. Uses recurrences to track 8 current input. @Author: Euguene""" 9
10 - def processResponse(self, sensorInputs, recursiveInputs):
11 if recursiveInputs: 12 currRecLocs = recursiveInputs 13 else: 14 currRecLocs = [{'Location' : (5, 5), 'Color' : [255, 255, 255]}] 15 16 if sensorInputs: # if input exists, change location 17 ret = [] 18 for currRecLoc in currRecLocs: 19 currDict = dict(currRecLoc) 20 for sensorInput in sensorInputs: 21 if 'type' in sensorInput and sensorInput['type'] == 1: 22 currDict['Shake'] = 0 23 currDict['Location'] = (currDict['Location'][0] - sensorInput['x'] * self['XStep'], \ 24 currDict['Location'][1] + sensorInput['y'] * self['YStep']) 25 currDict['Color'] = [sensorInput['r'], sensorInput['g'], sensorInput['b']] 26 elif sensorInput['type'] == 2: 27 currDict['Shake'] = 1 28 #currDict['Force'] = sensorInput['force'] 29 ret.append(currDict) 30 #print ret 31 return (ret, ret) 32 33 else: # if not, return current recursive location. 34 #print currRecLocs 35 return (currRecLocs, currRecLocs)
36