aboutsummaryrefslogtreecommitdiff
path: root/behaviors/MoveBehavior.py
blob: 6f57437ad7011d62179cd2725da7a0724720ac0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from operationscore.Behavior import *
#import util.ComponentRegistry as compReg
#import util.Geo as Geo
#import util.Strings as Strings

class MoveBehavior(Behavior):
    """Moves current location by the x and y components of sensorInput.  Uses recurrences to track
    current input.  @Author: Euguene"""

    def processResponse(self, sensorInputs, recursiveInputs):
        if recursiveInputs:
            currRecLocs = recursiveInputs
        else:
            currRecLocs = [{'Location' : (5, 5), 'Color' : [255, 255, 255]}]

        #print sensorInputs
        if sensorInputs:   # if input exists, change location
            ret = []
            for currRecLoc in currRecLocs:
                currDict = dict(currRecLoc)
                for sensorInput in sensorInputs:
                    if 'type' in sensorInput and int(sensorInput['type']) == 1:
                        #currDict['Shake'] = 0
                        currDict['Location'] = (currDict['Location'][0] - int(sensorInput['x']) * self['XStep'], \
                                                currDict['Location'][1] + int(sensorInput['y']) * self['YStep'])
                        currDict['Color'] = [int(sensorInput['r']), int(sensorInput['g']), int(sensorInput['b'])]
                    elif int(sensorInput['type']) == 2:
                        #print sensorInput
                        currDict['Shake'] = 1
                        #currDict['Force'] = sensorInput['force']
                ret.append(currDict)
            return (ret, ret)

        else: # if not, return current recursive location.
            #print currRecLocs
            return (currRecLocs, currRecLocs)