def on_start(self): "Initialize midi input" self.midi_state = midistate() try: pygame.midi.quit() pygame.midi.init() if self.input_id == -1: self.input_id = pygame.midi.get_default_input_id() if self.input_id == -1: print "Midi_Input.on_start: No midi device available" self.enabled = False return if self.test_mode: print "Midi_Input Device List:" self.print_device_info() print "Midi_Input using device",self.input_id,"\n ", self.print_device_info(self.input_id) except: print "Midi_Input.on_start: Midi input initialization error" self.enabled = False return try: self.input = pygame.midi.Input( self.input_id) except: print "Midi_Input.on_start: Midi port error!" self.enabled = False return self.tick_action = RealTickFunc(self.get_midi).do()
def start_facing_target(self, target=None): "start_facing_target(target=None): if target is None, use target field" self.stop_facing_target() if target: self.target = target self.tick_action = RealTickFunc( self.check_facing).do() self.check_facing() # prevents jerky start
def set_forward_motion(self, speed=None): """set_forward_motion(self, speed=None) speed: set object's forward velocity or acceleration to this value. Defaults to self.speed """ if speed == None: speed = self.speed else: self.speed = speed if self.speed < 0: self.actual_offset = self.offset + 180 else: self.actual_offset = self.offset self.speed_vector = Vector(0, -speed) if speed: if not self.tick_action: self.tick_action = RealTickFunc(self.update_forward_motion) self.tick_action.do() else: if self.tick_action: self.tick_action.abort() self.tick_action = None self.last_rotation = None self.last_speed = None self.set_motion()
def start_following_mouse(self): "Start following the mouse pointer" if not self.tick_action: self.tick_action = RealTickFunc(self.follow).do()
def set_face_motion(self): """set_face_motion(): Set object to face its motion.""" self.tick_action = RealTickFunc(self.face_motion).do() self.face_motion()