def update(self):
        for event in pygame.event.get():
            if event.type not in (KEYUP, KEYDOWN):
                continue

            if event.key == K_SPACE:
                if event.type == KEYDOWN: self.callbacks["button"]()
                continue

            if event.type == KEYDOWN:
                self.keys.append(event.key)
            if event.type == KEYUP:
                self.keys.remove(event.key)

            center = self.locations[self.center]
            offset = Vector.null(); instructions = 0

            for key in self.keys:
                try:
                    offset += self.locations[key]
                    instructions += 1

                except KeyError:
                    pass

            try:
                offset = offset / instructions
                direction = offset - center

            except ZeroDivisionError:
                direction = Vector.null()

            self.callbacks["motion"](direction)
    def __init__(self, gui):
        Controller.__init__(self, gui)

        self.direction = Vector.null()
        self.controls = {
                K_RETURN : self.button_event,
                K_UP     : lambda type: self.motion_event(type,  0, -1),
                K_DOWN   : lambda type: self.motion_event(type,  0,  1),
                K_LEFT   : lambda type: self.motion_event(type, -1,  0),
                K_RIGHT  : lambda type: self.motion_event(type,  1,  0) }
Example #3
0
 def __init__(self):
     self.acceleration = Vector.null()